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. 4
      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. 4
      data/templates/file/VBNet/VBNet.UnitTest.xft
  7. 20
      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 @@ @@ -11,6 +11,11 @@
<Description>${res:Templates.File.WindowsForm.Description}</Description>
<References>
<Reference include="System.Drawing" />
<Reference include="System.Windows.Forms" />
</References>
<!--
Special new file templates:
${StandardNamespace} -> Standardnamespace of the current project or FileNameWithoutExtension

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

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

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

@ -46,6 +46,10 @@ @@ -46,6 +46,10 @@
/>
</Properties>
<References>
<Reference include="NUnit.Framework" hintPath="$(SharpDevelopBinPath)\Tools\NUnit\NUnit.Framework.dll" />
</References>
<Files>
<File name="${FullName}" language="C#"><![CDATA[${StandardHeader.C#}
<% if (ConditionalClass) { %>#if TEST

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

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

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

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

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

@ -38,6 +38,10 @@ @@ -38,6 +38,10 @@
/>
</Properties>
<References>
<Reference include="NUnit.Framework" hintPath="$(SharpDevelopBinPath)\Tools\NUnit\NUnit.Framework.dll" />
</References>
<Files>
<File name="${FullName}" language="VBNET"><![CDATA[${StandardHeader.VBNET}

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

@ -5,20 +5,20 @@ @@ -5,20 +5,20 @@
// <version>$Revision$</version>
// </file>
using ICSharpCode.TextEditor.Document;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor;
using ICSharpCode.SharpDevelop.Gui.XmlForms;
using ICSharpCode.SharpDevelop.Internal.Templates;
using ICSharpCode.SharpDevelop.Project;
using Microsoft.Build.BuildEngine;
namespace ICSharpCode.SharpDevelop.Gui
{
@ -472,6 +472,22 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -472,6 +472,22 @@ namespace ICSharpCode.SharpDevelop.Gui
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) {
Properties customizer = new Properties();

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

@ -12,6 +12,7 @@ using System.IO; @@ -12,6 +12,7 @@ using System.IO;
using System.Xml;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.SharpDevelop.Internal.Templates
{
@ -119,6 +120,7 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates @@ -119,6 +120,7 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates
List<FileDescriptionTemplate> files = new List<FileDescriptionTemplate>();
List<TemplateProperty> properties = new List<TemplateProperty>();
List<TemplateType> customTypes = new List<TemplateType>();
List<ReferenceProjectItem> requiredAssemblyReferences = new List<ReferenceProjectItem>();
XmlElement fileoptions = null;
@ -205,6 +207,10 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates @@ -205,6 +207,10 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates
}
}
public List<ReferenceProjectItem> RequiredAssemblyReferences {
get { return requiredAssemblyReferences; }
}
public bool HasProperties {
get {
return properties != null && properties.Count > 0;
@ -257,6 +263,16 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates @@ -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"];
doc.DocumentElement.SetAttribute("fileName", filename); // used for template loading warnings

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

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

Loading…
Cancel
Save