Browse Source

C# form template now uses partial classes. File templates now can use the "DependentUpon" attribute.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1022 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
3d398142f4
  1. 31
      data/templates/file/CSharp/CSharp.Forms.Form.xft
  2. 32
      data/templates/file/CSharp/CSharp.Forms.UserControl.xft
  3. 34
      data/templates/project/CSharp/ControlLibrary.xpt
  4. 53
      data/templates/project/CSharp/FormsProject.xpt
  5. 3
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs
  6. 3
      src/AddIns/BackendBindings/VBNetBinding/Project/Src/Parser/Parser.cs
  7. 6
      src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.cs
  8. 2
      src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/LoadedModulesPad.cs
  9. 4
      src/Libraries/NRefactory/Project/Src/Parser/Visitors/VBNetConstructsConvertVisitor.cs
  10. 2
      src/Main/Base/Project/Src/Gui/Components/ExtTreeView/ExtTreeNode.cs
  11. 31
      src/Main/Base/Project/Src/Gui/Dialogs/NewFileDialog.cs
  12. 19
      src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/Commands/FolderNodeCommands.cs
  13. 6
      src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/DirectoryNode.cs
  14. 55
      src/Main/Base/Project/Src/Internal/Templates/File/FileDescriptionTemplate.cs
  15. 7
      src/Main/Base/Project/Src/Internal/Templates/File/INewFileCreator.cs
  16. 12
      src/Main/Base/Project/Src/Internal/Templates/Project/ProjectDescriptor.cs
  17. 10
      src/Main/Base/Project/Src/Services/ParserService/ParserService.cs
  18. 3
      src/Main/Base/Project/Src/Services/ProjectService/ParseableFileContentEnumerator.cs

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

@ -33,7 +33,7 @@ namespace ${StandardNamespace}
/// <summary> /// <summary>
/// Description of ${ClassName}. /// Description of ${ClassName}.
/// </summary> /// </summary>
public class ${ClassName} : System.Windows.Forms.Form public partial class ${ClassName}
{ {
public ${ClassName}() public ${ClassName}()
{ {
@ -46,8 +46,33 @@ namespace ${StandardNamespace}
// TODO: Add constructor code after the InitializeComponent() call. // TODO: Add constructor code after the InitializeComponent() call.
// //
} }
}
}
]]></File>
<File name="${Path}/${FileNameWithoutExtension}.Designer.cs" dependentUpon="${FileName}" language="C#"><![CDATA[${StandardHeader.C#}
namespace ${StandardNamespace}
{
partial class ${ClassName} : System.Windows.Forms.Form
{
/// <summary>
/// Designer variable used to keep track of non-visual components.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Disposes resources used by the form.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing) {
if (components != null) {
components.Dispose();
}
}
base.Dispose(disposing);
}
#region Windows Forms Designer generated code
/// <summary> /// <summary>
/// This method is required for Windows Forms designer support. /// This method is required for Windows Forms designer support.
/// Do not change the method contents inside the source code editor. The Forms designer might /// Do not change the method contents inside the source code editor. The Forms designer might
@ -59,11 +84,9 @@ namespace ${StandardNamespace}
// ${ClassName} // ${ClassName}
// //
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 266);
this.Text = "${ClassName}"; this.Text = "${ClassName}";
this.Name = "${ClassName}"; this.Name = "${ClassName}";
} }
#endregion
} }
} }
]]></File> ]]></File>

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

@ -34,7 +34,7 @@ namespace ${StandardNamespace}
/// <summary> /// <summary>
/// Description of ${ClassName}. /// Description of ${ClassName}.
/// </summary> /// </summary>
public class ${ClassName} : System.Windows.Forms.UserControl public partial class ${ClassName}
{ {
public ${ClassName}() public ${ClassName}()
{ {
@ -47,8 +47,33 @@ namespace ${StandardNamespace}
// TODO: Add constructor code after the InitializeComponent() call. // TODO: Add constructor code after the InitializeComponent() call.
// //
} }
}
}
]]></File>
<File name="${Path}/${FileNameWithoutExtension}.Designer.cs" dependentUpon="${FileName}" language="C#"><![CDATA[${StandardHeader.C#}
namespace ${StandardNamespace}
{
partial class ${ClassName} : System.Windows.Forms.UserControl
{
/// <summary>
/// Designer variable used to keep track of non-visual components.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Disposes resources used by the form.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing) {
if (components != null) {
components.Dispose();
}
}
base.Dispose(disposing);
}
#region Windows Forms Designer generated code
/// <summary> /// <summary>
/// This method is required for Windows Forms designer support. /// This method is required for Windows Forms designer support.
/// Do not change the method contents inside the source code editor. The Forms designer might /// Do not change the method contents inside the source code editor. The Forms designer might
@ -59,10 +84,9 @@ namespace ${StandardNamespace}
// //
// ${ClassName} // ${ClassName}
// //
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Name = "${ClassName}"; this.Name = "${ClassName}";
this.Size = new System.Drawing.Size(292, 266);
} }
#endregion
} }
} }
]]></File> ]]></File>

34
data/templates/project/CSharp/ControlLibrary.xpt

@ -47,7 +47,7 @@ namespace ${StandardNamespace}
/// <summary> /// <summary>
/// Description of UserControl1. /// Description of UserControl1.
/// </summary> /// </summary>
public class UserControl1 : System.Windows.Forms.UserControl public partial class UserControl1
{ {
public UserControl1() public UserControl1()
{ {
@ -60,8 +60,32 @@ namespace ${StandardNamespace}
// TODO: Add constructor code after the InitializeComponent() call. // TODO: Add constructor code after the InitializeComponent() call.
// //
} }
}
}]]></File>
<File name="UserControl1.Designer.cs" dependentUpon="UserControl1.cs" language="C#"><![CDATA[${StandardHeader.C#}
namespace ${StandardNamespace}
{
partial class UserControl1 : System.Windows.Forms.UserControl
{
/// <summary>
/// Designer variable used to keep track of non-visual components.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Disposes resources used by the form.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing) {
if (components != null) {
components.Dispose();
}
}
base.Dispose(disposing);
}
#region Windows Forms Designer generated code
/// <summary> /// <summary>
/// This method is required for Windows Forms designer support. /// This method is required for Windows Forms designer support.
/// Do not change the method contents inside the source code editor. The Forms designer might /// Do not change the method contents inside the source code editor. The Forms designer might
@ -72,12 +96,12 @@ namespace ${StandardNamespace}
// //
// UserControl1 // UserControl1
// //
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Name = "UserControl1"; this.Name = "UserControl1";
this.Size = new System.Drawing.Size(292, 266);
} }
#endregion
} }
}]]></File> }
]]></File>
<File name="AssemblyInfo.cs"> <File name="AssemblyInfo.cs">
<![CDATA[using System.Reflection; <![CDATA[using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;

53
data/templates/project/CSharp/FormsProject.xpt

@ -35,7 +35,8 @@
</ProjectItems> </ProjectItems>
<Files> <Files>
<File name="MainForm.cs"><![CDATA[${StandardHeader.C#} <File name="MainForm.cs" language="C#"><![CDATA[${StandardHeader.C#}
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
@ -46,8 +47,16 @@ namespace ${StandardNamespace}
/// <summary> /// <summary>
/// Description of MainForm. /// Description of MainForm.
/// </summary> /// </summary>
public class MainForm : System.Windows.Forms.Form public partial class MainForm
{ {
[STAThread]
public static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
public MainForm() public MainForm()
{ {
// //
@ -59,16 +68,33 @@ namespace ${StandardNamespace}
// TODO: Add constructor code after the InitializeComponent() call. // TODO: Add constructor code after the InitializeComponent() call.
// //
} }
}
}
]]></File>
<File name="MainForm.Designer.cs" dependentUpon="MainForm.cs" language="C#"><![CDATA[${StandardHeader.C#}
namespace ${StandardNamespace}
{
partial class MainForm : System.Windows.Forms.Form
{
/// <summary>
/// Designer variable used to keep track of non-visual components.
/// </summary>
private System.ComponentModel.IContainer components = null;
[STAThread] /// <summary>
public static void Main(string[] args) /// Disposes resources used by the form.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{ {
Application.EnableVisualStyles(); if (disposing) {
Application.SetCompatibleTextRenderingDefault(false); if (components != null) {
Application.Run(new MainForm()); components.Dispose();
}
}
base.Dispose(disposing);
} }
#region Windows Forms Designer generated code
/// <summary> /// <summary>
/// This method is required for Windows Forms designer support. /// This method is required for Windows Forms designer support.
/// Do not change the method contents inside the source code editor. The Forms designer might /// Do not change the method contents inside the source code editor. The Forms designer might
@ -77,17 +103,16 @@ namespace ${StandardNamespace}
private void InitializeComponent() private void InitializeComponent()
{ {
// //
// Form1 // MainForm
// //
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 266); this.Text = "${ProjectName}";
this.Text = "MainForm";
this.Name = "MainForm"; this.Name = "MainForm";
} }
#endregion
} }
}]]></File> }
<File name="AssemblyInfo.cs"> ]]></File>
<File name="AssemblyInfo.cs" language="C#">
<![CDATA[using System.Reflection; <![CDATA[using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;

3
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs

@ -85,8 +85,7 @@ namespace CSharpBinding.Parser
public ICompilationUnit Parse(IProjectContent projectContent, string fileName) public ICompilationUnit Parse(IProjectContent projectContent, string fileName)
{ {
Properties textEditorProperties = ((Properties)PropertyService.Get("ICSharpCode.TextEditor.Document.Document.DefaultDocumentAggregatorProperties", new Properties())); using (ICSharpCode.NRefactory.Parser.IParser p = ICSharpCode.NRefactory.Parser.ParserFactory.CreateParser(fileName, ParserService.DefaultFileEncoding)) {
using (ICSharpCode.NRefactory.Parser.IParser p = ICSharpCode.NRefactory.Parser.ParserFactory.CreateParser(fileName, Encoding.GetEncoding(textEditorProperties.Get("Encoding", 1252)))) {
return Parse(p, fileName, projectContent); return Parse(p, fileName, projectContent);
} }
} }

3
src/AddIns/BackendBindings/VBNetBinding/Project/Src/Parser/Parser.cs

@ -93,8 +93,7 @@ namespace VBNetBinding.Parser
public ICompilationUnit Parse(IProjectContent projectContent, string fileName) public ICompilationUnit Parse(IProjectContent projectContent, string fileName)
{ {
Properties textEditorProperties = ((Properties)PropertyService.Get("ICSharpCode.TextEditor.Document.Document.DefaultDocumentAggregatorProperties", new Properties())); using (ICSharpCode.NRefactory.Parser.IParser p = ICSharpCode.NRefactory.Parser.ParserFactory.CreateParser(fileName, ParserService.DefaultFileEncoding)) {
using (ICSharpCode.NRefactory.Parser.IParser p = ICSharpCode.NRefactory.Parser.ParserFactory.CreateParser(fileName, Encoding.GetEncoding(textEditorProperties.Get("Encoding", 1252)))) {
return Parse(p, fileName, projectContent); return Parse(p, fileName, projectContent);
} }
} }

6
src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.cs

@ -127,7 +127,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
ToolStripMenuItem argNamesItem; ToolStripMenuItem argNamesItem;
argNamesItem = new ToolStripMenuItem(); argNamesItem = new ToolStripMenuItem();
argNamesItem.Text = "${res:MainWindow.Windows.Debug.CallStack.ShowArgumentNames}"; argNamesItem.Text = ResourceService.GetString("MainWindow.Windows.Debug.CallStack.ShowArgumentNames");
argNamesItem.Checked = ShowArgumentNames; argNamesItem.Checked = ShowArgumentNames;
argNamesItem.Click += argNamesItem.Click +=
delegate { delegate {
@ -137,7 +137,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
ToolStripMenuItem argValuesItem; ToolStripMenuItem argValuesItem;
argValuesItem = new ToolStripMenuItem(); argValuesItem = new ToolStripMenuItem();
argValuesItem.Text = "${res:MainWindow.Windows.Debug.CallStack.ShowArgumentValues}"; argValuesItem.Text = ResourceService.GetString("MainWindow.Windows.Debug.CallStack.ShowArgumentValues");
argValuesItem.Checked = ShowArgumentValues; argValuesItem.Checked = ShowArgumentValues;
argValuesItem.Click += argValuesItem.Click +=
delegate { delegate {
@ -147,7 +147,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
ToolStripMenuItem extMethodsItem; ToolStripMenuItem extMethodsItem;
extMethodsItem = new ToolStripMenuItem(); extMethodsItem = new ToolStripMenuItem();
extMethodsItem.Text = "${res:MainWindow.Windows.Debug.CallStack.ShowExternalMethods}"; extMethodsItem.Text = ResourceService.GetString("MainWindow.Windows.Debug.CallStack.ShowExternalMethods");
extMethodsItem.Checked = ShowExternalMethods; extMethodsItem.Checked = ShowExternalMethods;
extMethodsItem.Click += extMethodsItem.Click +=
delegate { delegate {

2
src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/LoadedModulesPad.cs

@ -119,7 +119,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
"", "",
"", "",
"", "",
e.Module.SymbolsLoaded.ToString(), //StringParser.Parse(m.symbolsLoaded ? "${res:MainWindow.Windows.Debug.HasSymbols}" : "${res:MainWindow.Windows.Debug.HasNoSymbols}") StringParser.Parse(e.Module.SymbolsLoaded ? "${res:MainWindow.Windows.Debug.HasSymbols}" : "${res:MainWindow.Windows.Debug.HasNoSymbols}")
}); });
newItem.Tag = e.Module; newItem.Tag = e.Module;
loadedModulesList.Items.Add(newItem); loadedModulesList.Items.Add(newItem);

4
src/Libraries/NRefactory/Project/Src/Parser/Visitors/VBNetConstructsConvertVisitor.cs

@ -54,7 +54,7 @@ namespace ICSharpCode.NRefactory.Parser
public override object Visit(Using @using, object data) public override object Visit(Using @using, object data)
{ {
if (!@using.IsAlias) { if (usings != null && !@using.IsAlias) {
usings[@using.Name] = @using.Name; usings[@using.Name] = @using.Name;
} }
return base.Visit(@using, data); return base.Visit(@using, data);
@ -93,7 +93,7 @@ namespace ICSharpCode.NRefactory.Parser
public override object Visit(DeclareDeclaration declareDeclaration, object data) public override object Visit(DeclareDeclaration declareDeclaration, object data)
{ {
if (!usings.ContainsKey("System.Runtime.InteropServices")) { if (usings != null && !usings.ContainsKey("System.Runtime.InteropServices")) {
UsingDeclaration @using = new UsingDeclaration("System.Runtime.InteropServices"); UsingDeclaration @using = new UsingDeclaration("System.Runtime.InteropServices");
addedUsings.Add(@using); addedUsings.Add(@using);
base.Visit(@using, data); base.Visit(@using, data);

2
src/Main/Base/Project/Src/Gui/Components/ExtTreeView/ExtTreeNode.cs

@ -153,7 +153,7 @@ namespace ICSharpCode.SharpDevelop.Gui
} }
} }
List<ExtTreeNode> invisibleNodes = new List<ExtTreeNode>(); protected List<ExtTreeNode> invisibleNodes = new List<ExtTreeNode>();
public virtual void UpdateVisibility() public virtual void UpdateVisibility()
{ {
for (int i = 0; i < invisibleNodes.Count;) { for (int i = 0; i < invisibleNodes.Count;) {

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

@ -32,16 +32,16 @@ namespace ICSharpCode.SharpDevelop.Gui
/// <summary> /// <summary>
/// This class is for creating a new "empty" file /// This class is for creating a new "empty" file
/// </summary> /// </summary>
public class NewFileDialog : BaseSharpDevelopForm, INewFileCreator public class NewFileDialog : BaseSharpDevelopForm
{ {
ArrayList alltemplates = new ArrayList(); ArrayList alltemplates = new ArrayList();
ArrayList categories = new ArrayList(); ArrayList categories = new ArrayList();
Hashtable icons = new Hashtable(); Hashtable icons = new Hashtable();
bool allowUntitledFiles; bool allowUntitledFiles;
string basePath; string basePath;
List<string> createdFiles = new List<string>(); List<KeyValuePair<string, PropertyGroup>> createdFiles = new List<KeyValuePair<string, PropertyGroup>>();
public List<string> CreatedFiles { public List<KeyValuePair<string, PropertyGroup>> CreatedFiles {
get { get {
return createdFiles; return createdFiles;
} }
@ -176,8 +176,8 @@ namespace ICSharpCode.SharpDevelop.Gui
} }
if (template.NewFileDialogVisible == true) { if (template.NewFileDialogVisible == true) {
Category cat = GetCategory(StringParser.Parse(titem.Template.Category), StringParser.Parse(titem.Template.Subcategory)); Category cat = GetCategory(StringParser.Parse(titem.Template.Category), StringParser.Parse(titem.Template.Subcategory));
cat.Templates.Add(titem); cat.Templates.Add(titem);
if (cat.Selected == false && template.WizardPath == null) { if (cat.Selected == false && template.WizardPath == null) {
cat.Selected = true; cat.Selected = true;
} }
@ -235,7 +235,7 @@ namespace ICSharpCode.SharpDevelop.Gui
if (localizedTypeDescriptor == null) { if (localizedTypeDescriptor == null) {
localizedTypeDescriptor = new LocalizedTypeDescriptor(); localizedTypeDescriptor = new LocalizedTypeDescriptor();
} }
if (!Controls.Contains(propertyGrid)) { if (!Controls.Contains(propertyGrid)) {
this.SuspendLayout(); this.SuspendLayout();
propertyGrid.Location = new Point(Width - GridMargin, GridMargin); propertyGrid.Location = new Point(Width - GridMargin, GridMargin);
@ -367,16 +367,21 @@ namespace ICSharpCode.SharpDevelop.Gui
return true; return true;
} }
public void SaveFile(string filename, string content, string languageName, bool showFile) public void SaveFile(FileDescriptionTemplate newfile, string content)
{ {
string parsedFileName = StringParser.Parse(filename); string parsedFileName = StringParser.Parse(newfile.Name);
IWorkbenchWindow window = FileService.NewFile(Path.GetFileName(parsedFileName), StringParser.Parse(languageName), StringParser.Parse(content)); if (newfile.IsDependentFile && Path.IsPathRooted(parsedFileName)) {
if (window != null) { File.WriteAllText(parsedFileName, StringParser.Parse(content), ParserService.DefaultFileEncoding);
createdFiles.Add(parsedFileName); } else {
IWorkbenchWindow window = FileService.NewFile(Path.GetFileName(parsedFileName), StringParser.Parse(newfile.Language), StringParser.Parse(content));
if (window == null) {
return;
}
if (Path.IsPathRooted(parsedFileName)) { if (Path.IsPathRooted(parsedFileName)) {
window.ViewContent.Save(parsedFileName); window.ViewContent.Save(parsedFileName);
} }
} }
createdFiles.Add(new KeyValuePair<string, PropertyGroup>(parsedFileName, newfile.CreateMSBuildProperties()));
} }
string GenerateValidClassName(string className) string GenerateValidClassName(string className)
@ -460,7 +465,7 @@ namespace ICSharpCode.SharpDevelop.Gui
ScriptRunner scriptRunner = new ScriptRunner(); ScriptRunner scriptRunner = new ScriptRunner();
foreach (FileDescriptionTemplate newfile in item.Template.FileDescriptionTemplates) { foreach (FileDescriptionTemplate newfile in item.Template.FileDescriptionTemplates) {
SaveFile(newfile.Name, scriptRunner.CompileScript(item.Template, newfile), newfile.Language, true); SaveFile(newfile, scriptRunner.CompileScript(item.Template, newfile));
} }
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;
} }
@ -544,7 +549,7 @@ namespace ICSharpCode.SharpDevelop.Gui
imglist.Images.Add(IconService.GetBitmap("Icons.16x16.OpenFolderBitmap")); imglist.Images.Add(IconService.GetBitmap("Icons.16x16.OpenFolderBitmap"));
imglist.Images.Add(IconService.GetBitmap("Icons.16x16.ClosedFolderBitmap")); imglist.Images.Add(IconService.GetBitmap("Icons.16x16.ClosedFolderBitmap"));
((TreeView)ControlDictionary["categoryTreeView"]).ImageList = imglist; ((TreeView)ControlDictionary["categoryTreeView"]).ImageList = imglist;
((TreeView)ControlDictionary["categoryTreeView"]).AfterSelect += new TreeViewEventHandler(CategoryChange); ((TreeView)ControlDictionary["categoryTreeView"]).AfterSelect += new TreeViewEventHandler(CategoryChange);
((TreeView)ControlDictionary["categoryTreeView"]).BeforeSelect += new TreeViewCancelEventHandler(OnBeforeExpand); ((TreeView)ControlDictionary["categoryTreeView"]).BeforeSelect += new TreeViewCancelEventHandler(OnBeforeExpand);
((TreeView)ControlDictionary["categoryTreeView"]).BeforeExpand += new TreeViewCancelEventHandler(OnBeforeExpand); ((TreeView)ControlDictionary["categoryTreeView"]).BeforeExpand += new TreeViewCancelEventHandler(OnBeforeExpand);

19
src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/Commands/FolderNodeCommands.cs

@ -16,6 +16,7 @@ using System.ComponentModel;
using System.Windows.Forms; using System.Windows.Forms;
using System.Diagnostics; using System.Diagnostics;
using ICSharpCode.SharpDevelop.Internal.Templates;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
@ -181,15 +182,14 @@ namespace ICSharpCode.SharpDevelop.Project.Commands
public class AddNewItemsToProject : AbstractMenuCommand public class AddNewItemsToProject : AbstractMenuCommand
{ {
FileNode CreateNewFile(DirectoryNode upper, string fileName) FileProjectItem CreateNewFile(DirectoryNode upper, string fileName)
{ {
upper.Expanding(); upper.Expanding();
FileNode fileNode = new FileNode(fileName, FileNodeStatus.InProject); FileNode fileNode = new FileNode(fileName, FileNodeStatus.InProject);
fileNode.AddTo(upper); fileNode.AddTo(upper);
fileNode.EnsureVisible(); fileNode.EnsureVisible();
IncludeFileInProject.IncludeFileNode(fileNode); return IncludeFileInProject.IncludeFileNode(fileNode);
return fileNode;
} }
public override void Run() public override void Run()
@ -207,8 +207,17 @@ namespace ICSharpCode.SharpDevelop.Project.Commands
using (NewFileDialog nfd = new NewFileDialog(node.Directory)) { using (NewFileDialog nfd = new NewFileDialog(node.Directory)) {
if (nfd.ShowDialog(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainForm) == DialogResult.OK) { if (nfd.ShowDialog(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainForm) == DialogResult.OK) {
foreach (string createdFile in nfd.CreatedFiles) { bool additionalProperties = false;
CreateNewFile(node, createdFile); foreach (KeyValuePair<string, PropertyGroup> createdFile in nfd.CreatedFiles) {
FileProjectItem item = CreateNewFile(node, createdFile.Key);
if (createdFile.Value.PropertyCount > 0) {
additionalProperties = true;
item.Properties.Merge(createdFile.Value);
}
}
if (additionalProperties) {
node.Project.Save();
node.RecreateSubNodes();
} }
} }
} }

6
src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/DirectoryNode.cs

@ -91,7 +91,7 @@ namespace ICSharpCode.SharpDevelop.Project
} else { } else {
node = new DirectoryNode(item.FileName.Trim('\\', '/'), status); node = new DirectoryNode(item.FileName.Trim('\\', '/'), status);
node.ProjectItem = item; node.ProjectItem = item;
} }
return node; return node;
} }
} }
@ -281,8 +281,9 @@ namespace ICSharpCode.SharpDevelop.Project
return false; return false;
} }
void RecreateSubNodes() public void RecreateSubNodes()
{ {
invisibleNodes.Clear();
if (autoClearNodes) { if (autoClearNodes) {
Nodes.Clear(); Nodes.Clear();
} else { } else {
@ -296,6 +297,7 @@ namespace ICSharpCode.SharpDevelop.Project
} }
} }
Initialize(); Initialize();
UpdateVisibility();
} }
protected override void Initialize() protected override void Initialize()

55
src/Main/Base/Project/Src/Internal/Templates/File/FileDescriptionTemplate.cs

@ -10,6 +10,8 @@ using System.IO;
using System.Xml; using System.Xml;
using System.Collections; using System.Collections;
using System.Diagnostics; using System.Diagnostics;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.SharpDevelop.Internal.Templates namespace ICSharpCode.SharpDevelop.Internal.Templates
{ {
@ -22,7 +24,13 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates
string copyToOutputDirectory; string copyToOutputDirectory;
string dependentUpon; string dependentUpon;
string subType; string subType;
public bool IsDependentFile {
get {
return !string.IsNullOrEmpty(dependentUpon);
}
}
public FileDescriptionTemplate(XmlElement xml) public FileDescriptionTemplate(XmlElement xml)
{ {
name = xml.GetAttribute("name"); name = xml.GetAttribute("name");
@ -34,6 +42,24 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates
content = xml.InnerText; content = xml.InnerText;
} }
/// <summary>
/// Sets MSBuild properties.
/// </summary>
public PropertyGroup CreateMSBuildProperties()
{
PropertyGroup pg = new PropertyGroup();
if (!string.IsNullOrEmpty(copyToOutputDirectory)) {
pg.Set("CopyToOutputDirectory", StringParser.Parse(copyToOutputDirectory));
}
if (!string.IsNullOrEmpty(dependentUpon)) {
pg.Set("DependentUpon", StringParser.Parse(dependentUpon));
}
if (!string.IsNullOrEmpty(subType)) {
pg.Set("SubType", StringParser.Parse(subType));
}
return pg;
}
public FileDescriptionTemplate(string name, string language, string content) public FileDescriptionTemplate(string name, string language, string content)
{ {
this.name = name; this.name = name;
@ -67,32 +93,5 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates
buildAction = value; buildAction = value;
} }
} }
public string CopyToOutputDirectory {
get {
return copyToOutputDirectory ?? "";
}
set {
copyToOutputDirectory = value;
}
}
public string DependentUpon {
get {
return dependentUpon ?? "";
}
set {
dependentUpon = value;
}
}
public string SubType {
get {
return subType ?? "";
}
set {
subType = value;
}
}
} }
} }

7
src/Main/Base/Project/Src/Internal/Templates/File/INewFileCreator.cs

@ -13,10 +13,5 @@ using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.SharpDevelop.Internal.Templates namespace ICSharpCode.SharpDevelop.Internal.Templates
{ {
public interface INewFileCreator
{
bool IsFilenameAvailable(string fileName);
void SaveFile(string filename, string content, string languageName, bool showFile);
}
} }

12
src/Main/Base/Project/Src/Internal/Templates/Project/ProjectDescriptor.cs

@ -157,6 +157,8 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates
string fileName = Path.Combine(projectCreateInformation.ProjectBasePath, StringParser.Parse(file.Name, new string[,] { {"ProjectName", projectCreateInformation.ProjectName} })); string fileName = Path.Combine(projectCreateInformation.ProjectBasePath, StringParser.Parse(file.Name, new string[,] { {"ProjectName", projectCreateInformation.ProjectName} }));
FileProjectItem projectFile = new FileProjectItem(project, ItemType.Compile); FileProjectItem projectFile = new FileProjectItem(project, ItemType.Compile);
projectFile.Properties.Merge(file.CreateMSBuildProperties());
if (file.BuildAction.Length > 0) { if (file.BuildAction.Length > 0) {
projectFile.BuildAction = (FileProjectItem.FileBuildAction)Enum.Parse(typeof(FileProjectItem.FileBuildAction), file.BuildAction); projectFile.BuildAction = (FileProjectItem.FileBuildAction)Enum.Parse(typeof(FileProjectItem.FileBuildAction), file.BuildAction);
} else { } else {
@ -164,18 +166,8 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates
projectFile.BuildAction = FileProjectItem.FileBuildAction.None; projectFile.BuildAction = FileProjectItem.FileBuildAction.None;
} }
} }
if (file.CopyToOutputDirectory.Length > 0) {
projectFile.CopyToOutputDirectory = (CopyToOutputDirectory)Enum.Parse(typeof(CopyToOutputDirectory), file.CopyToOutputDirectory);
}
if (file.DependentUpon.Length > 0) {
projectFile.DependentUpon = file.DependentUpon;
}
if (file.SubType.Length > 0) {
projectFile.SubType = file.SubType;
}
projectFile.Include = FileUtility.GetRelativePath(project.Directory, fileName); projectFile.Include = FileUtility.GetRelativePath(project.Directory, fileName);
while (projectFile.Include.Length > 1 && projectFile.Include.StartsWith(".")) { while (projectFile.Include.Length > 1 && projectFile.Include.StartsWith(".")) {
projectFile.Include = projectFile.Include.Substring(2); projectFile.Include = projectFile.Include.Substring(2);
} }

10
src/Main/Base/Project/Src/Services/ParserService/ParserService.cs

@ -514,11 +514,17 @@ namespace ICSharpCode.Core
// return res; // return res;
// load file // load file
Properties textEditorProperties = PropertyService.Get("ICSharpCode.TextEditor.Document.Document.DefaultDocumentAggregatorProperties", new Properties()); Encoding tmp = DefaultFileEncoding;
Encoding tmp = Encoding.GetEncoding(textEditorProperties.Get("Encoding", 1252));
return ICSharpCode.TextEditor.Util.FileReader.ReadFileContent(fileName, ref tmp, tmp); return ICSharpCode.TextEditor.Util.FileReader.ReadFileContent(fileName, ref tmp, tmp);
} }
public static Encoding DefaultFileEncoding {
get {
Properties textEditorProperties = PropertyService.Get("ICSharpCode.TextEditor.Document.Document.DefaultDocumentAggregatorProperties", new Properties());
return Encoding.GetEncoding(textEditorProperties.Get("Encoding", 1252));
}
}
public static ParseInformation GetParseInformation(string fileName) public static ParseInformation GetParseInformation(string fileName)
{ {
if (fileName == null || fileName.Length == 0) { if (fileName == null || fileName.Length == 0) {

3
src/Main/Base/Project/Src/Services/ProjectService/ParseableFileContentEnumerator.cs

@ -74,8 +74,7 @@ namespace ICSharpCode.SharpDevelop.Project
if (projectItems.Length > 0) { if (projectItems.Length > 0) {
nextItem = projectItems[0]; nextItem = projectItems[0];
} }
Properties textEditorProperties = PropertyService.Get("ICSharpCode.TextEditor.Document.Document.DefaultDocumentAggregatorProperties", new Properties()); defaultEncoding = ParserService.DefaultFileEncoding;
defaultEncoding = Encoding.GetEncoding(textEditorProperties.Get("Encoding", 1252));
} }
string GetParseableFileContent(IProject project, string fileName) string GetParseableFileContent(IProject project, string fileName)

Loading…
Cancel
Save