Browse Source

Implemented insertion of "#End Region" Tags.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3685 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Siegfried Pammer 17 years ago
parent
commit
aa66c1f847
  1. 26
      src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBNetFormattingStrategy.cs
  2. 4
      src/Main/Base/Project/Src/Commands/CustomStringTagProvider.cs
  3. 57
      src/Main/Base/Project/Src/Commands/TemplateCommands.cs
  4. 10
      src/Main/Base/Project/Src/Internal/Templates/File/FileTemplate.cs
  5. 6
      src/Main/Base/Project/Src/Internal/Templates/Project/ProjectTemplate.cs
  6. 98
      src/Main/Base/Project/Src/Internal/Templates/TemplateCreator.cs

26
src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBNetFormattingStrategy.cs

@ -209,7 +209,7 @@ namespace VBNetBinding.FormattingStrategy @@ -209,7 +209,7 @@ namespace VBNetBinding.FormattingStrategy
if (doInsertion)
{
if (Regex.IsMatch(texttoreplace.Trim(), @"^If .*[^_]$", RegexOptions.IgnoreCase)) {
if (false == Regex.IsMatch(texttoreplace, @"\bthen\b", RegexOptions.IgnoreCase)) {
if (!Regex.IsMatch(texttoreplace, @"\bthen\b", RegexOptions.IgnoreCase)) {
string specialThen = "Then"; // do special check in cases like If t = True' comment
if (textArea.Document.GetCharAt(lineAbove.Offset + texttoreplace.Length) == '\'')
specialThen += " ";
@ -220,6 +220,12 @@ namespace VBNetBinding.FormattingStrategy @@ -220,6 +220,12 @@ namespace VBNetBinding.FormattingStrategy
texttoreplace += specialThen;
}
}
// check #Region statements
if (Regex.IsMatch(texttoreplace.Trim(), @"^#Region", RegexOptions.IgnoreCase) && LookForEndRegion(textArea)) {
string indentation = GetIndentation(textArea, lineNr - 1);
texttoreplace += indentation + "\r\n" + indentation + "#End Region";
textArea.Document.Replace(curLine.Offset, curLine.Length, texttoreplace);
}
foreach (VBStatement statement_ in statements) {
VBStatement statement = statement_; // allow passing statement byref
if (Regex.IsMatch(texttoreplace.Trim(), statement.StartRegex, RegexOptions.IgnoreCase)) {
@ -313,6 +319,24 @@ namespace VBNetBinding.FormattingStrategy @@ -313,6 +319,24 @@ namespace VBNetBinding.FormattingStrategy
}
}
bool LookForEndRegion(TextArea area)
{
string lineText = area.Document.GetText(area.Document.GetLineSegment(0));
int count = 0;
int lineNr = 0;
while ((!Regex.IsMatch(lineText, @"^\s*#End\s+Region", RegexOptions.IgnoreCase) || count >= 0) && (lineNr < area.Document.TotalNumberOfLines)) {
if (Regex.IsMatch(lineText, @"^\s*#Region", RegexOptions.IgnoreCase))
count++;
if (Regex.IsMatch(lineText, @"^\s*#End\s+Region", RegexOptions.IgnoreCase))
count--;
lineNr++;
if (lineNr < area.Document.TotalNumberOfLines)
lineText = area.Document.GetText(area.Document.GetLineSegment(lineNr));
}
return (count > 0);
}
bool IsElseConstruct(string line)
{
string t = StripComment(line).ToLowerInvariant();

4
src/Main/Base/Project/Src/Commands/CustomStringTagProvider.cs

@ -29,7 +29,7 @@ namespace ICSharpCode.SharpDevelop.Commands @@ -29,7 +29,7 @@ namespace ICSharpCode.SharpDevelop.Commands
"ProjectDir", "ProjectFilename",
"CombineDir", "CombineFilename",
"SolutionDir", "SolutionFilename",
"Startuppath",
"Startuppath", "ConfigDirectory",
"TaskService.Warnings", "TaskService.Errors", "TaskService.Messages"
};
@ -161,6 +161,8 @@ namespace ICSharpCode.SharpDevelop.Commands @@ -161,6 +161,8 @@ namespace ICSharpCode.SharpDevelop.Commands
break;
case "STARTUPPATH":
return Application.StartupPath;
case "CONFIGDIRECTORY":
return PropertyService.ConfigDirectory;
}
return String.Empty;
}

57
src/Main/Base/Project/Src/Commands/TemplateCommands.cs

@ -0,0 +1,57 @@ @@ -0,0 +1,57 @@
/*
* 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();
}
}
}

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

@ -288,13 +288,16 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates @@ -288,13 +288,16 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates
}
}
static FileTemplate()
public static void UpdateTemplates()
{
string dataTemplateDir = FileUtility.Combine(PropertyService.DataDirectory, "templates", "file");
List<string> files = FileUtility.SearchDirectory(dataTemplateDir, "*.xft");
foreach (string templateDirectory in AddInTree.BuildItems<string>(ProjectTemplate.TemplatePath, null, false)) {
if (!Directory.Exists(templateDirectory))
Directory.CreateDirectory(templateDirectory);
files.AddRange(FileUtility.SearchDirectory(templateDirectory, "*.xft"));
}
FileTemplates.Clear();
foreach (string file in files) {
try {
FileTemplates.Add(new FileTemplate(file));
@ -308,5 +311,10 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates @@ -308,5 +311,10 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates
}
FileTemplates.Sort();
}
static FileTemplate()
{
UpdateTemplates();
}
}
}

6
src/Main/Base/Project/Src/Internal/Templates/Project/ProjectTemplate.cs

@ -99,10 +99,10 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates @@ -99,10 +99,10 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates
#if DEBUG
// Always reload project templates if debugging.
// TODO: Make this a configurable option.
LoadProjectTemplates();
UpdateTemplates();
#else
if (projectTemplates == null) {
LoadProjectTemplates();
UpdateTemplates();
}
#endif
return projectTemplates.AsReadOnly();
@ -416,7 +416,7 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates @@ -416,7 +416,7 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates
public const string TemplatePath = "/SharpDevelop/BackendBindings/Templates";
static void LoadProjectTemplates()
public static void UpdateTemplates()
{
projectTemplates = new List<ProjectTemplate>();
string dataTemplateDir = FileUtility.Combine(PropertyService.DataDirectory, "templates", "project");

98
src/Main/Base/Project/Src/Internal/Templates/TemplateCreator.cs

@ -0,0 +1,98 @@ @@ -0,0 +1,98 @@
/*
* 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…
Cancel
Save