Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3686 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
2 changed files with 0 additions and 155 deletions
@ -1,57 +0,0 @@ |
|||||||
/* |
|
||||||
* Created by SharpDevelop. |
|
||||||
* User: HP |
|
||||||
* Date: 21.09.2008 |
|
||||||
* Time: 09:19 |
|
||||||
*/ |
|
||||||
using System; |
|
||||||
using System.IO; |
|
||||||
using System.Windows.Forms; |
|
||||||
|
|
||||||
using ICSharpCode.Core; |
|
||||||
using ICSharpCode.SharpDevelop; |
|
||||||
using ICSharpCode.SharpDevelop.Gui; |
|
||||||
using ICSharpCode.SharpDevelop.Internal.Templates; |
|
||||||
using ICSharpCode.SharpDevelop.Project; |
|
||||||
|
|
||||||
namespace ICSharpCode.SharpDevelop.Commands |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// Description of CreateTemplateFromFileCommand
|
|
||||||
/// </summary>
|
|
||||||
public class CreateTemplateFromFile : AbstractMenuCommand |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// Starts the command
|
|
||||||
/// </summary>
|
|
||||||
public override void Run() |
|
||||||
{ |
|
||||||
string language = ProjectService.CurrentProject.Language; |
|
||||||
string fileName = MessageService.ShowInputBox("Create new template", "Enter name for new template:", "NewFileTemplate"); |
|
||||||
string ext = Path.GetExtension(WorkbenchSingleton.Workbench.ActiveViewContent.PrimaryFileName); |
|
||||||
string content = new StreamReader(WorkbenchSingleton.Workbench.ActiveViewContent.PrimaryFile.OpenRead()).ReadToEnd(); |
|
||||||
FileService.OpenFile(TemplateCreator.CreateFileTemplate(language, fileName, ext, content)); |
|
||||||
FileTemplate.UpdateTemplates(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Description of CreateTemplateFromFileCommand
|
|
||||||
/// </summary>
|
|
||||||
public class CreateTemplateFromProject : AbstractMenuCommand |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// Starts the command
|
|
||||||
/// </summary>
|
|
||||||
public override void Run() |
|
||||||
{ |
|
||||||
MessageService.ShowMessage("All opened files need to be saved before creating a project template!"); |
|
||||||
foreach (OpenedFile file in FileService.OpenedFiles) { |
|
||||||
file.SaveToDisk(); |
|
||||||
} |
|
||||||
string fileName = MessageService.ShowInputBox("Create new template", "Enter name for new template:", "NewProjectTemplate"); |
|
||||||
FileService.OpenFile(TemplateCreator.CreateProjectTemplate(fileName, ProjectService.OpenSolution)); |
|
||||||
ProjectTemplate.UpdateTemplates(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,98 +0,0 @@ |
|||||||
/* |
|
||||||
* Created by SharpDevelop. |
|
||||||
* User: HP |
|
||||||
* Date: 21.09.2008 |
|
||||||
* Time: 09:11 |
|
||||||
*/ |
|
||||||
using System; |
|
||||||
using System.IO; |
|
||||||
using System.Xml; |
|
||||||
|
|
||||||
using ICSharpCode.Core; |
|
||||||
using ICSharpCode.SharpDevelop.Project; |
|
||||||
|
|
||||||
namespace ICSharpCode.SharpDevelop.Internal.Templates |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// Creates a template from the specified current buffer or current project/solution.
|
|
||||||
/// </summary>
|
|
||||||
public static class TemplateCreator |
|
||||||
{ |
|
||||||
public static string CreateFileTemplate(string language, string name, string ext, string fileContent) |
|
||||||
{ |
|
||||||
XmlDocument template = new XmlDocument(); |
|
||||||
template.AppendChild(template.CreateXmlDeclaration("1.0", null, null)); |
|
||||||
|
|
||||||
XmlElement root = template.CreateElement("Template"); |
|
||||||
root.SetAttribute("author", StringParser.Parse("${USER}")); |
|
||||||
root.SetAttribute("version", "1.0"); |
|
||||||
|
|
||||||
XmlElement config = template.CreateElement("Config"); |
|
||||||
config.SetAttribute("name", name); |
|
||||||
config.SetAttribute("icon", language + ".File.EmptyFile"); |
|
||||||
config.SetAttribute("category", GetCategoryForLang(language)); |
|
||||||
config.SetAttribute("defaultname", name + "${Number}" + ext); |
|
||||||
config.SetAttribute("language", language); |
|
||||||
|
|
||||||
XmlElement description = template.CreateElement("Description"); |
|
||||||
description.InnerText = name + " is a new template!"; |
|
||||||
|
|
||||||
XmlElement files = template.CreateElement("Files"); |
|
||||||
|
|
||||||
XmlElement file1 = template.CreateElement("File"); |
|
||||||
file1.SetAttribute("name", "${FullName}"); |
|
||||||
file1.SetAttribute("language", language); |
|
||||||
|
|
||||||
file1.AppendChild(template.CreateCDataSection(fileContent)); |
|
||||||
|
|
||||||
files.AppendChild(file1); |
|
||||||
|
|
||||||
root.AppendChild(config); |
|
||||||
root.AppendChild(description); |
|
||||||
|
|
||||||
root.AppendChild(files); |
|
||||||
|
|
||||||
template.AppendChild(root); |
|
||||||
|
|
||||||
string path = Path.Combine(PropertyService.ConfigDirectory, "UserTemplates"); |
|
||||||
|
|
||||||
Directory.CreateDirectory(path); |
|
||||||
|
|
||||||
string newFile = Path.Combine(path, name + ext + ".xft"); |
|
||||||
|
|
||||||
template.Save(newFile); |
|
||||||
|
|
||||||
return newFile; |
|
||||||
} |
|
||||||
|
|
||||||
public static string CreateProjectTemplate(string name, Solution solution) |
|
||||||
{ |
|
||||||
string path = Path.Combine(PropertyService.ConfigDirectory, "UserTemplates"); |
|
||||||
|
|
||||||
Directory.CreateDirectory(path); |
|
||||||
|
|
||||||
string newFile = Path.Combine(path, name + ".xpt"); |
|
||||||
|
|
||||||
XmlDocument template = new XmlDocument(); |
|
||||||
|
|
||||||
template.LoadXml(""); |
|
||||||
template.CreateXmlDeclaration("1.0", null, null); |
|
||||||
|
|
||||||
template.Save(newFile); |
|
||||||
|
|
||||||
return newFile; |
|
||||||
} |
|
||||||
|
|
||||||
static string GetCategoryForLang(string lang) |
|
||||||
{ |
|
||||||
switch (lang) { |
|
||||||
case "C#": |
|
||||||
return "C#"; |
|
||||||
case "VBNet": |
|
||||||
return "VB"; |
|
||||||
default: |
|
||||||
return lang; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
Loading…
Reference in new issue