Author: mhutch
Date: 2007-09-07 15:36:37 -0400 (Fri, 07 Sep 2007)
New Revision: 85502
Added:
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ParentProjectFileTemplateCondition.cs
Modified:
trunk/monodevelop/Core/src/MonoDevelop.Ide/ChangeLog
trunk/monodevelop/Core/src/MonoDevelop.Ide/Makefile.am
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Dialogs/NewFileDialog.cs
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ClrVersionFileTemplateCondition.cs
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Templates/FileTemplate.cs
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Templates/FileTemplateCondition.cs
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Templates/PartialTypeFileTemplateCondition.cs
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.addin.xml
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.mdp
Log:
* MonoDevelop.Ide.Templates/FileTemplate.cs,
MonoDevelop.Ide.Templates/FileTemplateCondition.cs,
MonoDevelop.Ide.Templates/ParentProjectFileTemplateCondition.cs,
MonoDevelop.Ide.Templates/ClrVersionFileTemplateCondition.cs,
MonoDevelop.Ide.Templates/PartialTypeFileTemplateCondition.cs,
MonoDevelop.Ide.Gui.Dialogs/NewFileDialog.cs,
MonoDevelop.Ide.addin.xml: Add support for file templates with
fixed names and for suggesting default filenames. Add support for
filtering on selected project directory. Remove defunct
FileTemplate.FileOptions element.
* MonoDevelop.Ide.mdp, Makefile.am: Updated.
Modified: trunk/monodevelop/Core/src/MonoDevelop.Ide/ChangeLog
===================================================================
--- trunk/monodevelop/Core/src/MonoDevelop.Ide/ChangeLog 2007-09-07
19:24:27 UTC (rev 85501)
+++ trunk/monodevelop/Core/src/MonoDevelop.Ide/ChangeLog 2007-09-07
19:36:37 UTC (rev 85502)
@@ -1,3 +1,16 @@
+2007-09-07 Michael Hutchinson <[EMAIL PROTECTED]>
+
+ * MonoDevelop.Ide.Templates/FileTemplate.cs,
+ MonoDevelop.Ide.Templates/FileTemplateCondition.cs,
+ MonoDevelop.Ide.Templates/ParentProjectFileTemplateCondition.cs,
+ MonoDevelop.Ide.Templates/ClrVersionFileTemplateCondition.cs,
+ MonoDevelop.Ide.Templates/PartialTypeFileTemplateCondition.cs,
+ MonoDevelop.Ide.Gui.Dialogs/NewFileDialog.cs,
MonoDevelop.Ide.addin.xml:
+ Add support for file templates with fixed names and for suggesting
+ default filenames. Add support for filtering on selected project
+ directory. Remove defunct FileTemplate.FileOptions element.
+ * MonoDevelop.Ide.mdp, Makefile.am: Updated.
+
2007-09-07 Lluis Sanchez Gual <[EMAIL PROTECTED]>
* MonoDevelop.Ide.Gui.Content/CompletionTextEditorExtension.cs,
Modified: trunk/monodevelop/Core/src/MonoDevelop.Ide/Makefile.am
===================================================================
--- trunk/monodevelop/Core/src/MonoDevelop.Ide/Makefile.am 2007-09-07
19:24:27 UTC (rev 85501)
+++ trunk/monodevelop/Core/src/MonoDevelop.Ide/Makefile.am 2007-09-07
19:36:37 UTC (rev 85502)
@@ -313,6 +313,7 @@
MonoDevelop.Ide.Templates/ICombineEntryDescriptor.cs \
MonoDevelop.Ide.Templates/ICombineEntryFeature.cs \
MonoDevelop.Ide.Templates/INewFileCreator.cs \
+ MonoDevelop.Ide.Templates/ParentProjectFileTemplateCondition.cs \
MonoDevelop.Ide.Templates/PartialTypeFileTemplateCondition.cs \
MonoDevelop.Ide.Templates/ProjectDescriptor.cs \
MonoDevelop.Ide.Templates/ProjectTemplate.cs \
Modified:
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Dialogs/NewFileDialog.cs
===================================================================
---
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Dialogs/NewFileDialog.cs
2007-09-07 19:24:27 UTC (rev 85501)
+++
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Dialogs/NewFileDialog.cs
2007-09-07 19:36:37 UTC (rev 85502)
@@ -47,6 +47,9 @@
Project parentProject;
string basePath;
+ string userEditedEntryText = null;
+ string previousDefaultEntryText = null;
+
public NewFileDialog (Project parentProject, string basePath) :
base ()
{
Build ();
@@ -205,11 +208,11 @@
if (!boxProject.Visible || projectAddCheckbox.Active)
project = parentProject;
- foreach (FileTemplate template in
FileTemplate.GetFileTemplates (project)) {
+ foreach (FileTemplate template in
FileTemplate.GetFileTemplates (project, basePath)) {
if (template.Icon != null) {
icons[template.Icon] = 0; // "create
template icon"
}
- List<string> langs =
template.GetCompatibleLanguages (project);
+ List<string> langs =
template.GetCompatibleLanguages (project, basePath);
if (langs != null) {
foreach (string language in langs) {
AddTemplate (new TemplateItem
(template, language), language);
@@ -319,8 +322,31 @@
if (item != null) {
infoLabel.Text = item.Description;
+
+ //desensitise the text entry if the
name is fixed
+ //careful to store user-entered text so
we can replace it if they change their selection
+ if (item.IsFixedFilename) {
+ if (userEditedEntryText == null)
+ userEditedEntryText =
nameEntry.Text;
+ nameEntry.Text =
item.DefaultFilename;
+ nameEntry.Sensitive = false;
+ } else {
+ if (userEditedEntryText != null)
+ nameEntry.Text =
userEditedEntryText;
+ nameEntry.Sensitive = true;
+ }
+
+ //fill in a default name if text entry
is empty or contains a default name
+ if ((string.IsNullOrEmpty
(nameEntry.Text) || (previousDefaultEntryText == nameEntry.Text))
+ && !string.IsNullOrEmpty
(item.DefaultFilename) ) {
+ nameEntry.Text =
item.DefaultFilename;
+ previousDefaultEntryText =
item.DefaultFilename;
+ }
+
+
okButton.Sensitive = item.IsValidName
(nameEntry.Text, sel.Language);
} else {
+ nameEntry.Sensitive = true;
okButton.Sensitive = false;
}
} catch (Exception ex) {
Modified:
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ClrVersionFileTemplateCondition.cs
===================================================================
---
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ClrVersionFileTemplateCondition.cs
2007-09-07 19:24:27 UTC (rev 85501)
+++
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ClrVersionFileTemplateCondition.cs
2007-09-07 19:36:37 UTC (rev 85502)
@@ -58,7 +58,7 @@
}
}
- public override bool ShouldEnableFor (Project proj)
+ public override bool ShouldEnableFor (Project proj, string
creationPath)
{
if (condition == ClrVersionCondition.None)
return true;
Modified:
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Templates/FileTemplate.cs
===================================================================
---
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Templates/FileTemplate.cs
2007-09-07 19:24:27 UTC (rev 85501)
+++
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Templates/FileTemplate.cs
2007-09-07 19:36:37 UTC (rev 85502)
@@ -44,13 +44,14 @@
string description = null;
string icon = null;
+ string defaultFilename = null;
+ bool isFixedFilename = false;
+
string wizardpath = null;
List<FileDescriptionTemplate> files = new
List<FileDescriptionTemplate> ();
List<FileTemplateCondition> conditions = new
List<FileTemplateCondition> ();
- XmlElement fileoptions = null;
-
public string Id {
get {
return id;
@@ -117,12 +118,18 @@
}
}
- public XmlElement FileOptions {
+ public string DefaultFilename {
get {
- return fileoptions;
+ return defaultFilename;
}
}
+ public bool IsFixedFilename {
+ get {
+ return isFixedFilename;
+ }
+ }
+
public List<FileDescriptionTemplate> Files {
get {
return files;
@@ -185,7 +192,17 @@
fileTemplate.wizardpath =
config["Wizard"].Attributes["path"].InnerText;
}
- fileTemplate.fileoptions =
doc.DocumentElement["FileOptions"];
+ if (config["DefaultFilename"] != null) {
+ fileTemplate.defaultFilename =
config["DefaultFilename"].InnerText;
+ if
(config["DefaultFilename"].Attributes["IsFixed"] != null) {
+ string isFixedStr =
config["DefaultFilename"].Attributes["IsFixed"].InnerText;
+ try {
+ fileTemplate.isFixedFilename =
bool.Parse (isFixedStr);
+ } catch (FormatException) {
+ throw new
InvalidOperationException ("Invalid value for IsFixed in template.");
+ }
+ }
+ }
// load the files
XmlElement files =
doc.DocumentElement["TemplateFiles"];
@@ -242,11 +259,11 @@
}
}
- internal static ArrayList GetFileTemplates (Project project)
+ internal static ArrayList GetFileTemplates (Project project,
string projectPath)
{
ArrayList list = new ArrayList ();
foreach (FileTemplate t in fileTemplates) {
- if (t.IsValidForProject (project))
+ if (t.IsValidForProject (project, projectPath))
list.Add (t);
}
return list;
@@ -323,7 +340,7 @@
}
}
- protected virtual bool IsValidForProject (Project project)
+ protected virtual bool IsValidForProject (Project project,
string projectPath)
{
// When there is no project, only single template files
can be created.
if (project == null) {
@@ -338,14 +355,14 @@
return false;
foreach (FileTemplateCondition condition in
conditions)
- if (!condition.ShouldEnableFor
(project))
+ if (!condition.ShouldEnableFor
(project, projectPath))
return false;
}
return true;
}
- public virtual List<string> GetCompatibleLanguages (Project
project)
+ public virtual List<string> GetCompatibleLanguages (Project
project, string projectPath)
{
if (project == null)
return SupportedLanguages;
@@ -358,7 +375,7 @@
foreach (string lang in langMatches) {
bool shouldEnable = true;
foreach (FileTemplateCondition condition in
conditions) {
- if (!condition.ShouldEnableFor
(project, lang)) {
+ if (!condition.ShouldEnableFor
(project, projectPath, lang)) {
shouldEnable = false;
break;
}
Modified:
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Templates/FileTemplateCondition.cs
===================================================================
---
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Templates/FileTemplateCondition.cs
2007-09-07 19:24:27 UTC (rev 85501)
+++
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Templates/FileTemplateCondition.cs
2007-09-07 19:36:37 UTC (rev 85502)
@@ -72,15 +72,15 @@
public abstract void Load (XmlElement element);
- //restricts whether the template should be shown for a given
project
- public virtual bool ShouldEnableFor (Project proj)
+ //restricts whether the template should be shown for a given
path within a given project
+ public virtual bool ShouldEnableFor (Project proj, string
projectPath)
{
return true;
}
//restricts whether a given language should be available for a
given project
//called after ShouldEnableFor (Project proj)
- public virtual bool ShouldEnableFor (Project proj, string
language)
+ public virtual bool ShouldEnableFor (Project proj, string
projectPath, string language)
{
return true;
}
Added:
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ParentProjectFileTemplateCondition.cs
===================================================================
---
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ParentProjectFileTemplateCondition.cs
2007-09-07 19:24:27 UTC (rev 85501)
+++
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ParentProjectFileTemplateCondition.cs
2007-09-07 19:36:37 UTC (rev 85502)
@@ -0,0 +1,82 @@
+//
+// ParentProjectFileTemplateCondition.cs
+//
+// Author:
+// Michael Hutchinson <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+using System;
+using System.Xml;
+using System.IO;
+
+using MonoDevelop.Projects;
+
+namespace MonoDevelop.Ide.Templates
+{
+
+ public class ParentProjectFileTemplateCondition : FileTemplateCondition
+ {
+ bool requireExists = false;
+ string relativePath = null;
+ string projectType = null;
+
+ public override void Load (XmlElement element)
+ {
+ //GetAttribute returns String.Empty even if the attr
does not exist
+ //but we want null (empty attribute is significant), so
do an extra check
+ if (element.HasAttribute ("RelativePath"))
+ relativePath =
element.GetAttribute("RelativePath");
+
+ if (element.HasAttribute ("ProjectType"))
+ projectType =
element.GetAttribute("ProjectType");
+
+ string requireExistsStr = element.GetAttribute
("RequireExists");
+ if (!string.IsNullOrEmpty (requireExistsStr)) {
+ try {
+ requireExists = bool.Parse
(requireExistsStr);
+ } catch (FormatException) {
+ throw new InvalidOperationException
("Invalid value for RequireExists in template.");
+ }
+ }
+ }
+
+ public override bool ShouldEnableFor (Project proj, string
projectPath)
+ {
+ if (proj == null)
+ return !requireExists;
+
+ if (projectType != null && proj.ProjectType !=
projectType)
+ return false;
+
+ if (relativePath != null) {
+ if (projectPath == null)
+ return false;
+ string ppath = Path.Combine
(proj.BaseDirectory, relativePath);
+ if (Path.GetFullPath (ppath) !=
Path.GetFullPath (projectPath))
+ return false;
+ }
+
+ return true;
+ }
+ }
+}
Modified:
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Templates/PartialTypeFileTemplateCondition.cs
===================================================================
---
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Templates/PartialTypeFileTemplateCondition.cs
2007-09-07 19:24:27 UTC (rev 85501)
+++
trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Templates/PartialTypeFileTemplateCondition.cs
2007-09-07 19:36:37 UTC (rev 85502)
@@ -50,7 +50,7 @@
}
}
- public override bool ShouldEnableFor (Project proj, string
language)
+ public override bool ShouldEnableFor (Project proj, string
creationPath, string language)
{
DotNetProject dnp = proj as DotNetProject;
if (dnp == null)
Modified: trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.addin.xml
===================================================================
--- trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.addin.xml
2007-09-07 19:24:27 UTC (rev 85501)
+++ trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.addin.xml
2007-09-07 19:36:37 UTC (rev 85502)
@@ -1318,6 +1318,7 @@
<Extension path = "/MonoDevelop/Ide/FileTemplateConditionTypes">
<FileTemplateConditionType name = "ClrVersion" class =
"MonoDevelop.Ide.Templates.ClrVersionFileTemplateCondition"/>
<FileTemplateConditionType name = "PartialTypeSupport" class =
"MonoDevelop.Ide.Templates.PartialTypeFileTemplateCondition"/>
+ <FileTemplateConditionType name = "ParentProject" class =
"MonoDevelop.Ide.Templates.ParentProjectFileTemplateCondition"/>
</Extension>
<Extension path = "/MonoDevelop/Ide/ProjectTemplates">
Modified: trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.mdp
===================================================================
--- trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.mdp
2007-09-07 19:24:27 UTC (rev 85501)
+++ trunk/monodevelop/Core/src/MonoDevelop.Ide/MonoDevelop.Ide.mdp
2007-09-07 19:36:37 UTC (rev 85502)
@@ -333,6 +333,7 @@
<File name="./MonoDevelop.Ide.Templates/FileTemplateCondition.cs"
subtype="Code" buildaction="Compile" />
<File
name="./MonoDevelop.Ide.Templates/PartialTypeFileTemplateCondition.cs"
subtype="Code" buildaction="Compile" />
<File name="./AssemblyInfo.cs" subtype="Code" buildaction="Compile" />
+ <File
name="./MonoDevelop.Ide.Templates/ParentProjectFileTemplateCondition.cs"
subtype="Code" buildaction="Compile" />
<File
name="./MonoDevelop.Ide.Gui.Content/CompletionTextEditorExtension.cs"
subtype="Code" buildaction="Compile" />
</Contents>
<References>
@@ -382,7 +383,7 @@
<AsmRefVar Sync="True" Name="REFS" Prefix="-r:" />
<ProjectRefVar Sync="True" Name="REFS" Prefix="-r:" />
</MonoDevelop.Autotools.MakefileInfo>
- <GtkDesignInfo partialTypes="True" isWidgetLibrary="True">
+ <GtkDesignInfo isWidgetLibrary="True">
<ExportedWidgets>
<Widget>MonoDevelop.Ide.Gui.Dialogs.CombineEntryFeatureSelector</Widget>
<Widget>MonoDevelop.Ide.StandardHeaders.StandardHeaderPanel</Widget>
@@ -393,4 +394,4 @@
<DeploymentInformation strategy="File">
<excludeFiles />
</DeploymentInformation>
-</Project>
\ No newline at end of file
+</Project>
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches