diff options
author | Lluis Sanchez <lluis@novell.com> | 2009-07-24 13:32:37 +0400 |
---|---|---|
committer | Lluis Sanchez <lluis@novell.com> | 2009-07-24 13:32:37 +0400 |
commit | 328d35535efa3c1fa2644b2a8f0f4d491aabd009 (patch) | |
tree | 271c2212a791fcbd6188cfa58d74509dc2dc37a2 /main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates | |
parent | da816e5d700db7874c078279aae7a1ddbd6c127c (diff) |
* Makefile.am:
* MonoDevelop.Ide.csproj:
* MonoDevelop.Ide.Templates/ProjectTemplate.cs:
* MonoDevelop.Ide.Templates/CombineDescriptor.cs:
* MonoDevelop.Ide.Templates/SolutionDescriptor.cs:
* MonoDevelop.Ide.Gui.Dialogs/NewProjectDialog.cs: Rewrite of
CombineDescriptor, now renamed to SolutionDescriptor. Patch by
Viktoria Dudka.
svn path=/trunk/monodevelop/; revision=138613
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates')
3 files changed, 158 insertions, 159 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/CombineDescriptor.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/CombineDescriptor.cs deleted file mode 100644 index f00a79e9a8..0000000000 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/CombineDescriptor.cs +++ /dev/null @@ -1,156 +0,0 @@ -// CombineDescriptor.cs -// -// This file was derived from a file from #Develop. -// -// Copyright (C) 2001-2007 Mike Krüger <mkrueger@novell.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -using System; -using System.IO; -using System.Xml; -using System.Collections; -using System.Collections.Generic; -using System.Collections.Specialized; -using System.Diagnostics; -using System.Reflection; - -using MonoDevelop.Core; -using MonoDevelop.Projects; -using MonoDevelop.Core.Gui; -using MonoDevelop.Core.ProgressMonitoring; - -namespace MonoDevelop.Ide.Templates -{ - internal class CombineDescriptor - { - ArrayList entryDescriptors = new ArrayList(); - - string name; - string startupProject = null; - string relativeDirectory = null; - string typeName; - - public string StartupProject { - get { - return startupProject; - } - } - - protected CombineDescriptor (string name, string type) - { - this.name = name; - this.typeName = type; - } - - public ISolutionItemDescriptor[] EntryDescriptors { - get { return (ISolutionItemDescriptor[]) entryDescriptors.ToArray (typeof(ISolutionItemDescriptor)); } - } - - public WorkspaceItem CreateEntry (ProjectCreateInformation projectCreateInformation, string defaultLanguage) - { - WorkspaceItem item; - - if (typeName != null && typeName.Length > 0) { - Type type = Type.GetType (typeName); - if (type == null || !typeof(WorkspaceItem).IsAssignableFrom (type)) { - MessageService.ShowError (GettextCatalog.GetString ("Can't create solution with type: {0}", typeName)); - return null; - } - item = (WorkspaceItem) Activator.CreateInstance (type); - } else - item = new Solution (); - - string newCombineName = StringParserService.Parse(name, new string[,] { - {"ProjectName", projectCreateInformation.CombineName} - }); - - item.Name = newCombineName; - - string oldCombinePath = projectCreateInformation.CombinePath; - string oldProjectPath = projectCreateInformation.ProjectBasePath; - if (relativeDirectory != null && relativeDirectory.Length > 0 && relativeDirectory != ".") { - projectCreateInformation.CombinePath = projectCreateInformation.CombinePath + Path.DirectorySeparatorChar + relativeDirectory; - projectCreateInformation.ProjectBasePath = projectCreateInformation.CombinePath + Path.DirectorySeparatorChar + relativeDirectory; - if (!Directory.Exists(projectCreateInformation.CombinePath)) { - Directory.CreateDirectory(projectCreateInformation.CombinePath); - } - if (!Directory.Exists(projectCreateInformation.ProjectBasePath)) { - Directory.CreateDirectory(projectCreateInformation.ProjectBasePath); - } - } - - Solution sol = item as Solution; - if (sol != null) { - List<string> configs = new List<string> (); - - // Create sub projects - foreach (ISolutionItemDescriptor entryDescriptor in entryDescriptors) { - SolutionEntityItem sit = entryDescriptor.CreateItem (projectCreateInformation, defaultLanguage); - entryDescriptor.InitializeItem (sol.RootFolder, projectCreateInformation, defaultLanguage, sit); - sol.RootFolder.Items.Add (sit); - if (sit is IConfigurationTarget) { - foreach (ItemConfiguration c in ((IConfigurationTarget)sit).Configurations) { - if (!configs.Contains (c.Id)) - configs.Add (c.Id); - } - } - } - - // Create configurations - foreach (string conf in configs) - sol.AddConfiguration (conf, true); - } - - projectCreateInformation.CombinePath = oldCombinePath; - projectCreateInformation.ProjectBasePath = oldProjectPath; - item.SetLocation (projectCreateInformation.CombinePath, newCombineName); - - return item; - } - - public static CombineDescriptor CreateCombineDescriptor(XmlElement element) - { - CombineDescriptor combineDescriptor = new CombineDescriptor(element.GetAttribute ("name"), element.GetAttribute ("type")); - - if (element.Attributes["directory"] != null) { - combineDescriptor.relativeDirectory = element.Attributes["directory"].InnerText; - } - - if (element["Options"] != null && element["Options"]["StartupProject"] != null) { - combineDescriptor.startupProject = element["Options"]["StartupProject"].InnerText; - } - - foreach (XmlNode node in element.ChildNodes) { - if (node != null) { - switch (node.Name) { - case "Project": - combineDescriptor.entryDescriptors.Add (ProjectDescriptor.CreateProjectDescriptor((XmlElement)node)); - break; - case "Solution": - case "Combine": - combineDescriptor.entryDescriptors.Add (CreateCombineDescriptor((XmlElement)node)); - break; - case "CombineEntry": - case "SolutionItem": - combineDescriptor.entryDescriptors.Add (SolutionItemDescriptor.CreateDescriptor((XmlElement)node)); - break; - } - } - } - return combineDescriptor; - } - } -} diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ProjectTemplate.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ProjectTemplate.cs index 2384e3c534..c5fd610707 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ProjectTemplate.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ProjectTemplate.cs @@ -59,8 +59,8 @@ namespace MonoDevelop.Ide.Templates private string createdSolutionName; private ProjectCreateInformation createdProjectInformation = null; - private CombineDescriptor solutionDescriptor = null; - public CombineDescriptor CombineDescriptor + private SolutionDescriptor solutionDescriptor = null; + public SolutionDescriptor SolutionDescriptor { get { return solutionDescriptor; } } @@ -198,7 +198,7 @@ namespace MonoDevelop.Ide.Templates throw new InvalidOperationException ("Combine element not found"); } else { - solutionDescriptor = CombineDescriptor.CreateCombineDescriptor (xmlDocument.DocumentElement ["Combine"]); + solutionDescriptor = SolutionDescriptor.CreateSolutionDescriptor (xmlDocument.DocumentElement ["Combine"]); } if (xmlDocument.DocumentElement ["Actions"] != null) { diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/SolutionDescriptor.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/SolutionDescriptor.cs new file mode 100644 index 0000000000..0e109abd74 --- /dev/null +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/SolutionDescriptor.cs @@ -0,0 +1,155 @@ +// SolutionDescriptor.cs +// +// This file was derived from a file from #Develop. +// +// Copyright (C) 2001-2007 Mike Krüger <mkrueger@novell.com> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +using System; +using System.IO; +using System.Threading; +using System.Diagnostics; +using MonoDevelop.Core; +using MonoDevelop.Core.Execution; +using MonoDevelop.Core.Gui; +using MonoDevelop.Core.Gui.ProgressMonitoring; +using MonoDevelop.Projects; +using MonoDevelop.Components; +using MonoDevelop.Ide.Gui; +using MonoDevelop.Components.Commands; +using System.Collections.Generic; +using System.Xml; + +namespace MonoDevelop.Ide.Templates +{ + internal class SolutionDescriptor + { + string startupProject; + string directory; + string name; + string type; + + private List<ISolutionItemDescriptor> entryDescriptors = new List<ISolutionItemDescriptor> (); + public ISolutionItemDescriptor[] EntryDescriptors + { + get { return entryDescriptors.ToArray(); } + } + + public static SolutionDescriptor CreateSolutionDescriptor (XmlElement xmlElement) + { + SolutionDescriptor solutionDescriptor = new SolutionDescriptor (); + + if (xmlElement.Attributes["name"] != null) + solutionDescriptor.name = xmlElement.Attributes["name"].Value; + else + throw new InvalidOperationException ("Attribute 'name' not found"); + + if (xmlElement.Attributes["type"] != null) + solutionDescriptor.type = xmlElement.Attributes["type"].Value; + + if (xmlElement.Attributes["directory"] != null) + solutionDescriptor.directory = xmlElement.Attributes["directory"].Value; + + if (xmlElement["Options"] != null && xmlElement["Options"]["StartupProject"] != null) + solutionDescriptor.startupProject = xmlElement["Options"]["StartupProject"].InnerText; + + + foreach (XmlNode xmlNode in xmlElement.ChildNodes) { + if (xmlNode is XmlElement) { + XmlElement xmlNodeElement = (XmlElement)xmlNode; + switch (xmlNodeElement.Name) { + case "Project": + solutionDescriptor.entryDescriptors.Add (ProjectDescriptor.CreateProjectDescriptor (xmlNodeElement)); + break; + case "CombineEntry": + case "SolutionItem": + solutionDescriptor.entryDescriptors.Add (SolutionItemDescriptor.CreateDescriptor (xmlNodeElement)); + break; + + } + } + } + + return solutionDescriptor; + } + + public WorkspaceItem CreateEntry (ProjectCreateInformation projectCreateInformation, string defaultLanguage) + { + WorkspaceItem workspaceItem = null; + + if (string.IsNullOrEmpty (type)) + workspaceItem = new Solution (); + else { + Type workspaceItemType = Type.GetType (type); + if (workspaceItemType != null) + workspaceItem = Activator.CreateInstance (workspaceItemType) as WorkspaceItem; + + if (workspaceItem == null) { + MessageService.ShowError (GettextCatalog.GetString ("Can't create solution with type: {0}", type)); + return null; + } + } + + workspaceItem.Name = StringParserService.Parse (name, new string[,] { {"ProjectName", projectCreateInformation.SolutionName} }); + + workspaceItem.SetLocation (projectCreateInformation.SolutionPath, workspaceItem.Name); + + ProjectCreateInformation localProjectCI; + if (!string.IsNullOrEmpty (directory) && directory != ".") { + localProjectCI = new ProjectCreateInformation (projectCreateInformation); + + localProjectCI.SolutionPath = Path.Combine (localProjectCI.SolutionPath, directory); + localProjectCI.ProjectBasePath = Path.Combine (localProjectCI.ProjectBasePath, directory); + + if (!Directory.Exists (localProjectCI.SolutionPath)) + Directory.CreateDirectory (localProjectCI.SolutionPath); + + if (!Directory.Exists (localProjectCI.ProjectBasePath)) + Directory.CreateDirectory (localProjectCI.ProjectBasePath); + } + else + localProjectCI = projectCreateInformation; + + Solution solution = workspaceItem as Solution; + if (solution != null) { + for ( int i = 0; i < entryDescriptors.Count; i++ ) + { + ISolutionItemDescriptor solutionItem = entryDescriptors[i]; + + SolutionEntityItem info = solutionItem.CreateItem (localProjectCI, defaultLanguage); + entryDescriptors[i].InitializeItem (solution.RootFolder, localProjectCI, defaultLanguage, info); + + IConfigurationTarget configurationTarget = info as IConfigurationTarget; + if (configurationTarget != null) { + foreach (ItemConfiguration configuration in configurationTarget.Configurations) { + bool flag = false; + foreach (SolutionConfiguration solutionCollection in solution.Configurations) { + if (solutionCollection.Id == configuration.Id) + flag = true; + } + if (!flag) + solution.AddConfiguration (configuration.Id, true); + } + } + + solution.RootFolder.Items.Add (info); + } + } + + return workspaceItem; + } + } +} |