Browse Source

Fixed SD2-1253 / SD2-1368 (Allow file templates to add GAC references to the project), based on patch by Siegfried Pammer

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3140 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 17 years ago
parent
commit
b626e87b20
  1. 5
      data/templates/file/CSharp/CSharp.Forms.Form.xft
  2. 5
      data/templates/file/CSharp/CSharp.Forms.UserControl.xft
  3. 6
      data/templates/file/CSharp/CSharp.UnitTest.xft
  4. 5
      data/templates/file/VBNet/VBNet.Forms.Form.xft
  5. 5
      data/templates/file/VBNet/VBNet.Forms.UserControl.xft
  6. 6
      data/templates/file/VBNet/VBNet.UnitTest.xft
  7. 22
      src/Main/Base/Project/Src/Gui/Dialogs/NewFileDialog.cs
  8. 16
      src/Main/Base/Project/Src/Internal/Templates/File/FileTemplate.cs
  9. 5
      src/Main/Base/Project/Src/Project/Items/ProjectItem.cs

5
data/templates/file/CSharp/CSharp.Forms.Form.xft

@ -11,6 +11,11 @@
<Description>${res:Templates.File.WindowsForm.Description}</Description> <Description>${res:Templates.File.WindowsForm.Description}</Description>
<References>
<Reference include="System.Drawing" />
<Reference include="System.Windows.Forms" />
</References>
<!-- <!--
Special new file templates: Special new file templates:
${StandardNamespace} -> Standardnamespace of the current project or FileNameWithoutExtension ${StandardNamespace} -> Standardnamespace of the current project or FileNameWithoutExtension

5
data/templates/file/CSharp/CSharp.Forms.UserControl.xft

@ -12,6 +12,11 @@
<Description>${res:Templates.File.WindowsUserControl.Description}</Description> <Description>${res:Templates.File.WindowsUserControl.Description}</Description>
<References>
<Reference include="System.Drawing" />
<Reference include="System.Windows.Forms" />
</References>
<!-- <!--
Special new file templates: Special new file templates:
${StandardNamespace} -> Standardnamespace of the current project or FileNameWithoutExtension ${StandardNamespace} -> Standardnamespace of the current project or FileNameWithoutExtension

6
data/templates/file/CSharp/CSharp.UnitTest.xft

@ -45,7 +45,11 @@
description = "${res:Templates.File.Properties.AddTearDownCode.Description}" description = "${res:Templates.File.Properties.AddTearDownCode.Description}"
/> />
</Properties> </Properties>
<References>
<Reference include="NUnit.Framework" hintPath="$(SharpDevelopBinPath)\Tools\NUnit\NUnit.Framework.dll" />
</References>
<Files> <Files>
<File name="${FullName}" language="C#"><![CDATA[${StandardHeader.C#} <File name="${FullName}" language="C#"><![CDATA[${StandardHeader.C#}
<% if (ConditionalClass) { %>#if TEST <% if (ConditionalClass) { %>#if TEST

5
data/templates/file/VBNet/VBNet.Forms.Form.xft

@ -12,6 +12,11 @@
<Description>${res:Templates.File.WindowsForm.Description}</Description> <Description>${res:Templates.File.WindowsForm.Description}</Description>
<References>
<Reference include="System.Drawing" />
<Reference include="System.Windows.Forms" />
</References>
<!-- <!--
Special new file templates: Special new file templates:
${StandardNamespace} -> Standardnamespace of the current project or FileNameWithoutExtension ${StandardNamespace} -> Standardnamespace of the current project or FileNameWithoutExtension

5
data/templates/file/VBNet/VBNet.Forms.UserControl.xft

@ -11,6 +11,11 @@
<Description>${res:Templates.File.WindowsUserControl.Description}</Description> <Description>${res:Templates.File.WindowsUserControl.Description}</Description>
<References>
<Reference include="System.Drawing" />
<Reference include="System.Windows.Forms" />
</References>
<!-- <!--
Special new file templates: Special new file templates:
${StandardNamespace} -> Standardnamespace of the current project or FileNameWithoutExtension ${StandardNamespace} -> Standardnamespace of the current project or FileNameWithoutExtension

6
data/templates/file/VBNet/VBNet.UnitTest.xft

@ -37,7 +37,11 @@
description = "${res:Templates.File.Properties.AddTearDownCode.Description}" description = "${res:Templates.File.Properties.AddTearDownCode.Description}"
/> />
</Properties> </Properties>
<References>
<Reference include="NUnit.Framework" hintPath="$(SharpDevelopBinPath)\Tools\NUnit\NUnit.Framework.dll" />
</References>
<Files> <Files>
<File name="${FullName}" language="VBNET"><![CDATA[${StandardHeader.VBNET} <File name="${FullName}" language="VBNET"><![CDATA[${StandardHeader.VBNET}

22
src/Main/Base/Project/Src/Gui/Dialogs/NewFileDialog.cs

@ -5,20 +5,20 @@
// <version>$Revision$</version> // <version>$Revision$</version>
// </file> // </file>
using ICSharpCode.TextEditor.Document;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Linq;
using System.Text; using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor;
using ICSharpCode.SharpDevelop.Gui.XmlForms; using ICSharpCode.SharpDevelop.Gui.XmlForms;
using ICSharpCode.SharpDevelop.Internal.Templates; using ICSharpCode.SharpDevelop.Internal.Templates;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
using Microsoft.Build.BuildEngine;
namespace ICSharpCode.SharpDevelop.Gui namespace ICSharpCode.SharpDevelop.Gui
{ {
@ -251,7 +251,7 @@ namespace ICSharpCode.SharpDevelop.Gui
} else { } else {
string defVal = property.DefaultValue == null ? String.Empty : property.DefaultValue.ToString(); string defVal = property.DefaultValue == null ? String.Empty : property.DefaultValue.ToString();
StringParser.Properties["Properties." + localizedProperty.Name] = defVal; StringParser.Properties["Properties." + localizedProperty.Name] = defVal;
localizedProperty.DefaultValue = defVal; localizedProperty.DefaultValue = defVal;
} }
} }
localizedProperty.LocalizedName = property.LocalizedName; localizedProperty.LocalizedName = property.LocalizedName;
@ -472,6 +472,22 @@ namespace ICSharpCode.SharpDevelop.Gui
StringParser.Properties["ClassName"] = GenerateValidClassOrNamespaceName(Path.GetFileNameWithoutExtension(fileName), false); StringParser.Properties["ClassName"] = GenerateValidClassOrNamespaceName(Path.GetFileNameWithoutExtension(fileName), false);
// when adding a file to a project (but not when creating a standalone file while a project is open):
if (ProjectService.CurrentProject != null && !this.allowUntitledFiles) {
// add required assembly references to the project
bool changes = false;
foreach (ReferenceProjectItem reference in item.Template.RequiredAssemblyReferences) {
IEnumerable<ProjectItem> refs = ProjectService.CurrentProject.GetItemsOfType(ItemType.Reference);
if (!refs.Any(projItem => string.Equals(projItem.Include, reference.Include, StringComparison.InvariantCultureIgnoreCase))) {
ReferenceProjectItem projItem = (ReferenceProjectItem)reference.CloneFor(ProjectService.CurrentProject);
ProjectService.AddProjectItem(ProjectService.CurrentProject, projItem);
changes = true;
}
}
if (changes) {
ProjectService.CurrentProject.Save();
}
}
if (item.Template.WizardPath != null) { if (item.Template.WizardPath != null) {
Properties customizer = new Properties(); Properties customizer = new Properties();

16
src/Main/Base/Project/Src/Internal/Templates/File/FileTemplate.cs

@ -12,6 +12,7 @@ using System.IO;
using System.Xml; using System.Xml;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.SharpDevelop.Internal.Templates namespace ICSharpCode.SharpDevelop.Internal.Templates
{ {
@ -119,6 +120,7 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates
List<FileDescriptionTemplate> files = new List<FileDescriptionTemplate>(); List<FileDescriptionTemplate> files = new List<FileDescriptionTemplate>();
List<TemplateProperty> properties = new List<TemplateProperty>(); List<TemplateProperty> properties = new List<TemplateProperty>();
List<TemplateType> customTypes = new List<TemplateType>(); List<TemplateType> customTypes = new List<TemplateType>();
List<ReferenceProjectItem> requiredAssemblyReferences = new List<ReferenceProjectItem>();
XmlElement fileoptions = null; XmlElement fileoptions = null;
@ -205,6 +207,10 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates
} }
} }
public List<ReferenceProjectItem> RequiredAssemblyReferences {
get { return requiredAssemblyReferences; }
}
public bool HasProperties { public bool HasProperties {
get { get {
return properties != null && properties.Count > 0; return properties != null && properties.Count > 0;
@ -257,6 +263,16 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates
} }
} }
if (doc.DocumentElement["References"] != null) {
XmlNodeList references = doc.DocumentElement["References"].SelectNodes("Reference");
foreach (XmlElement reference in references) {
if (!reference.HasAttribute("include"))
throw new InvalidDataException("Reference without 'include' attribute!");
ReferenceProjectItem item = new ReferenceProjectItem(null, reference.GetAttribute("include"));
requiredAssemblyReferences.Add(item);
}
}
fileoptions = doc.DocumentElement["AdditionalOptions"]; fileoptions = doc.DocumentElement["AdditionalOptions"];
doc.DocumentElement.SetAttribute("fileName", filename); // used for template loading warnings doc.DocumentElement.SetAttribute("fileName", filename); // used for template loading warnings

5
src/Main/Base/Project/Src/Project/Items/ProjectItem.cs

@ -8,11 +8,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.IO; using System.IO;
using System.Text; using System.Linq;
using System.Xml;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;

Loading…
Cancel
Save