Browse Source

File and project template categories can now specify a sort order if required. Defaults to sorting by category name. Updated string resources for new templates.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@990 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 20 years ago
parent
commit
787617378c
  1. BIN
      data/resources/StringResources.de.resources
  2. BIN
      data/resources/StringResources.fr.resources
  3. BIN
      data/resources/StringResources.hu.resources
  4. BIN
      data/resources/StringResources.kr.resources
  5. BIN
      data/resources/StringResources.ro.resources
  6. 1
      data/templates/file/CSharp/CSharp.Forms.Form.xft
  7. 1
      data/templates/file/CSharp/CSharp.Forms.UserControl.xft
  8. 4
      data/templates/file/CSharp/CSharp.Gtk.Window.xft
  9. 5
      data/templates/file/CSharp/FileCategorySortOrder.xml
  10. 4
      data/templates/project/CSharp/ConsoleProject.xpt
  11. 4
      data/templates/project/CSharp/ControlLibrary.xpt
  12. 2
      data/templates/project/CSharp/Direct3DProject.xpt
  13. 3
      data/templates/project/CSharp/EmptyProject.xpt
  14. 4
      data/templates/project/CSharp/FormsProject.xpt
  15. 6
      data/templates/project/CSharp/GladeProject.xpt
  16. 6
      data/templates/project/CSharp/GtkProject.xpt
  17. 3
      data/templates/project/CSharp/Library.xpt
  18. 5
      data/templates/project/CSharp/ProjectCategorySortOrder.xml
  19. 4
      data/templates/project/CSharp/Service.xpt
  20. 2
      data/templates/project/ComplexExample.xpt.test
  21. 2
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  22. 10
      src/Main/Base/Project/Resources/NewFileDialog.xfrm
  23. 34
      src/Main/Base/Project/Src/Gui/Dialogs/NewFileDialog.cs
  24. 33
      src/Main/Base/Project/Src/Gui/Dialogs/NewProjectDialog.cs
  25. 49
      src/Main/Base/Project/Src/Gui/Dialogs/TemplateCategoryComparer.cs
  26. 20
      src/Main/Base/Project/Src/Internal/Templates/Project/ProjectTemplate.cs
  27. 152
      src/Main/Base/Project/Src/Internal/Templates/TemplateCategorySortOrderFile.cs
  28. 4
      src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj
  29. 80
      src/Main/Base/Test/Templates/CategorySortOrderTests.cs
  30. 98
      src/Main/Base/Test/Templates/FileTemplateCategoryComparerTests.cs
  31. 98
      src/Main/Base/Test/Templates/ProjectTemplateCategoryComparerTests.cs
  32. BIN
      src/Main/StartUp/Project/Resources/StringResources.resources
  33. 2
      src/SharpDevelop.Tests.sln

BIN
data/resources/StringResources.de.resources

Binary file not shown.

BIN
data/resources/StringResources.fr.resources

Binary file not shown.

BIN
data/resources/StringResources.hu.resources

Binary file not shown.

BIN
data/resources/StringResources.kr.resources

Binary file not shown.

BIN
data/resources/StringResources.ro.resources

Binary file not shown.

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

@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
name = "${res:Templates.File.WindowsForm.Name}"
icon = "C#.File.Form"
category = "C#"
subcategory = "${res:Templates.File.Categories.WindowsApplications}"
defaultname = "Form${Number}.cs"
language = "C#"/>

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

@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
name = "${res:Templates.File.WindowsUserControl.Name}"
icon = "C#.File.Form"
category = "C#"
subcategory = "${res:Templates.File.Categories.WindowsApplications}"
defaultname = "UserControl${Number}.cs"
language = "C#"
/>

4
data/templates/file/CSharp/CSharp.Gtk.Window.xft

@ -2,14 +2,14 @@ @@ -2,14 +2,14 @@
<Template author="Matt Ward" version="1.0">
<Config
name = "Gtk# Window"
name = "${res:Templates.File.GtkSharpWindow.Name}"
icon = "C#.File.Form"
category = "C#"
subcategory = "Mono"
defaultname = "Window${Number}.cs"
language = "C#"/>
<Description>A window for a Gtk# application.</Description>
<Description>${res:Templates.File.GtkSharpWindow.Description}</Description>
<!--
Special new file templates:

5
data/templates/file/CSharp/FileCategorySortOrder.xml

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
<Categories>
<Category Name="C#">
<Category Name="${res:Templates.File.Categories.WindowsApplications}" SortOrder="10"/>
</Category>
</Categories>

4
data/templates/project/CSharp/ConsoleProject.xpt

@ -1,13 +1,13 @@ @@ -1,13 +1,13 @@
<?xml version="1.0"?>
<Template originator = "Mike Krueger"
created = "06/10/2001"
lastModified = "11/01/2006">
lastModified = "14/01/2006">
<!-- Template Header -->
<TemplateConfiguration>
<Name>${res:Templates.Project.ConsoleProject.Name}</Name>
<Category>C#</Category>
<Subcategory>Windows Applications</Subcategory>
<Subcategory>${res:Templates.File.Categories.WindowsApplications}</Subcategory>
<Icon>C#.Project.DOSProject</Icon>
<LanguageName>C#</LanguageName>
<Description>${res:Templates.Project.ConsoleProject.Description}</Description>

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

@ -1,13 +1,13 @@ @@ -1,13 +1,13 @@
<?xml version="1.0"?>
<Template originator = "Mike Krueger"
created = "06/10/2001"
lastModified = "11/01/2006">
lastModified = "14/01/2006">
<!-- Template Header -->
<TemplateConfiguration>
<Name>${res:Templates.Project.UserControlLibrary.Name}</Name>
<Category>C#</Category>
<Subcategory>Windows Applications</Subcategory>
<Subcategory>${res:Templates.File.Categories.WindowsApplications}</Subcategory>
<Icon>C#.Project.ControlLibrary</Icon>
<LanguageName>C#</LanguageName>
<Description>${res:Templates.Project.UserControlLibrary.Description}</Description>

2
data/templates/project/CSharp/Direct3DProject.xpt

@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
<TemplateConfiguration>
<Name>${res:Templates.Project.Direct3DApplication.Name}</Name>
<Category>C#</Category>
<Subcategory>Windows Applications</Subcategory>
<Subcategory>${res:Templates.File.Categories.WindowsApplications}</Subcategory>
<Icon>C#.Project.FullProject</Icon>
<LanguageName>C#</LanguageName>
<Description>${res:Templates.Project.Direct3DApplication.Description}</Description>

3
data/templates/project/CSharp/EmptyProject.xpt

@ -1,13 +1,12 @@ @@ -1,13 +1,12 @@
<?xml version="1.0"?>
<Template originator = "Mike Krueger"
created = "01/10/2001"
lastModified = "11/01/2006">
lastModified = "12/01/2006">
<!-- Template Header -->
<TemplateConfiguration>
<Name>${res:Templates.Project.EmptyProject.Name}</Name>
<Category>C#</Category>
<Subcategory>Other</Subcategory>
<Icon>C#.Project.EmptyProject</Icon>
<LanguageName>C#</LanguageName>
<Description>${res:Templates.Project.EmptyProject.Description}</Description>

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

@ -1,13 +1,13 @@ @@ -1,13 +1,13 @@
<?xml version="1.0"?>
<Template originator = "Mike Krueger"
created = "06/10/2001"
lastModified = "11/01/2006">
lastModified = "14/01/2006">
<!-- Template Header -->
<TemplateConfiguration>
<Name>${res:Templates.Project.WindowsApplication.Name}</Name>
<Category>C#</Category>
<Subcategory>Windows Applications</Subcategory>
<Subcategory>${res:Templates.File.Categories.WindowsApplications}</Subcategory>
<Icon>C#.Project.Form</Icon>
<LanguageName>C#</LanguageName>
<Description>${res:Templates.Project.WindowsApplication.Description}</Description>

6
data/templates/project/CSharp/GladeProject.xpt

@ -1,16 +1,16 @@ @@ -1,16 +1,16 @@
<?xml version="1.0"?>
<Template originator = "Matt Ward"
created = "01/10/2001"
lastModified = "11/01/2006">
lastModified = "14/01/2006">
<!-- Template Header -->
<TemplateConfiguration>
<Name>Glade# Application</Name>
<Name>${res:Templates.Project.GladeSharpProject.Name}</Name>
<Category>C#</Category>
<Subcategory>Mono</Subcategory>
<Icon>C#.Project.Form</Icon>
<LanguageName>C#</LanguageName>
<Description>A project that creates a Glade# application</Description>
<Description>${res:Templates.Project.GladeSharpProject.Description}</Description>
</TemplateConfiguration>
<!-- Actions -->

6
data/templates/project/CSharp/GtkProject.xpt

@ -1,16 +1,16 @@ @@ -1,16 +1,16 @@
<?xml version="1.0"?>
<Template originator = "Matt Ward"
created = "01/01/2006"
lastModified = "11/06/2006">
lastModified = "14/06/2006">
<!-- Template Header -->
<TemplateConfiguration>
<Name>Gtk# Application</Name>
<Name>${res:Templates.Project.GtkSharpProject.Name}</Name>
<Category>C#</Category>
<Subcategory>Mono</Subcategory>
<Icon>C#.Project.Form</Icon>
<LanguageName>C#</LanguageName>
<Description>A project that creates a Gtk# application</Description>
<Description>${res:Templates.Project.GtkSharpProject.Description}</Description>
</TemplateConfiguration>
<!-- Actions -->

3
data/templates/project/CSharp/Library.xpt

@ -1,13 +1,12 @@ @@ -1,13 +1,12 @@
<?xml version="1.0"?>
<Template originator = "Mike Krueger"
created = "02/01/2003"
lastModified = "11/01/2006">
lastModified = "12/01/2006">
<!-- Template Header -->
<TemplateConfiguration>
<Name>${res:Templates.Project.ClassLibrary.Name}</Name>
<Category>C#</Category>
<Subcategory>Other</Subcategory>
<Icon>C#.Project.Library</Icon>
<LanguageName>C#</LanguageName>
<Description>${res:Templates.Project.ClassLibrary.Description}</Description>

5
data/templates/project/CSharp/ProjectCategorySortOrder.xml

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
<Categories>
<Category Name="C#">
<Category Name="${res:Templates.File.Categories.WindowsApplications}" SortOrder="10"/>
</Category>
</Categories>

4
data/templates/project/CSharp/Service.xpt

@ -1,13 +1,13 @@ @@ -1,13 +1,13 @@
<?xml version="1.0"?>
<Template originator = "Mike Krueger"
created = "02/01/2003"
lastModified = "11/01/2006">
lastModified = "14/01/2006">
<!-- Template Header -->
<TemplateConfiguration>
<Name>${res:Templates.Project.WindowsService.Name}</Name>
<Category>C#</Category>
<Subcategory>Windows Applications</Subcategory>
<Subcategory>${res:Templates.File.Categories.WindowsApplications}</Subcategory>
<Icon>C#.Project.ServiceProject</Icon>
<LanguageName>C#</LanguageName>
<Description>${res:Templates.Project.WindowsService.Description}</Description>

2
data/templates/project/ComplexExample.xpt.test

@ -7,6 +7,8 @@ @@ -7,6 +7,8 @@
<TemplateConfiguration>
<Name>Complex EXAMPLE</Name>
<Category>C#</Category>
<!-- Optional subcategory -->
<Subcategory>Windows Applications</Subcategory>
<Icon>C#.Project.DOSProject</Icon>
<LanguageName>C#</LanguageName>
<Description>Example template that tries to use every feature once</Description>

2
src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

@ -743,6 +743,8 @@ @@ -743,6 +743,8 @@
<Compile Include="Src\TextEditor\Commands\CodeGenerators\CodeGenerationForm.cs" />
<Compile Include="Src\Dom\NRefactoryResolver\NRefactoryInformationProvider.cs" />
<Compile Include="Src\Project\Converter\LanguageConverter.cs" />
<Compile Include="Src\Gui\Dialogs\TemplateCategoryComparer.cs" />
<Compile Include="Src\Internal\Templates\TemplateCategorySortOrderFile.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Libraries\DockPanel_Src\WinFormsUI\WinFormsUI.csproj">

10
src/Main/Base/Project/Resources/NewFileDialog.xfrm

@ -102,12 +102,12 @@ @@ -102,12 +102,12 @@
<Name value="splitter" />
<TabIndex value="1" />
<Size value="{Width=4, Height=290}" />
<Location value="{X=144,Y=0}" />
<Location value="{X=174,Y=0}" />
</System.Windows.Forms.Splitter>
<System.Windows.Forms.Panel>
<Name value="categoryPanel" />
<Location value="{X=0,Y=0}" />
<Size value="{Width=144, Height=290}" />
<Size value="{Width=174, Height=290}" />
<DockPadding value="" />
<TabIndex value="0" />
<Dock value="Left" />
@ -120,7 +120,7 @@ @@ -120,7 +120,7 @@
<Scrollable value="False" />
<Location value="{X=0,Y=23}" />
<SelectedImageIndex value="-1" />
<Size value="{Width=144, Height=267}" />
<Size value="{Width=174, Height=267}" />
<HotTracking value="True" />
<HideSelection value="False" />
</System.Windows.Forms.TreeView>
@ -129,7 +129,7 @@ @@ -129,7 +129,7 @@
<Text value="${res:Dialog.NewFile.CategoryText}" />
<TextAlign value="BottomLeft" />
<TabIndex value="0" />
<Size value="{Width=144, Height=23}" />
<Size value="{Width=174, Height=23}" />
<Location value="{X=0,Y=0}" />
<Dock value="Top" />
</System.Windows.Forms.Label>
@ -139,4 +139,4 @@ @@ -139,4 +139,4 @@
</System.Windows.Forms.Panel>
</Controls>
</System.Windows.Forms.Form>
</Components>
</Components>

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

@ -103,6 +103,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -103,6 +103,7 @@ namespace ICSharpCode.SharpDevelop.Gui
((ListView)ControlDictionary["templateListView"]).SmallImageList = smalllist;
InsertCategories(null, categories);
((TreeView)ControlDictionary["categoryTreeView"]).TreeViewNodeSorter = new TemplateCategoryComparer();
((TreeView)ControlDictionary["categoryTreeView"]).Sort();
SelectLastSelectedCategoryNode(((TreeView)ControlDictionary["categoryTreeView"]).Nodes, PropertyService.Get("Dialogs.NewFileDialog.LastSelectedCategory", "C#"));
@ -147,7 +148,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -147,7 +148,7 @@ namespace ICSharpCode.SharpDevelop.Gui
}
}
}
Category newcategory = new Category(categoryname);
Category newcategory = new Category(categoryname, TemplateCategorySortOrderFile.GetFileCategorySortOrder(categoryname));
categories.Add(newcategory);
if (subcategoryname != null) {
return GetSubcategory(newcategory, subcategoryname);
@ -161,7 +162,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -161,7 +162,7 @@ namespace ICSharpCode.SharpDevelop.Gui
if (subcategory.Name == name)
return subcategory;
}
Category newsubcategory = new Category(name);
Category newsubcategory = new Category(name, TemplateCategorySortOrderFile.GetFileCategorySortOrder(parentCategory.Name, name));
parentCategory.Categories.Add(newsubcategory);
return newsubcategory;
}
@ -174,7 +175,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -174,7 +175,7 @@ namespace ICSharpCode.SharpDevelop.Gui
icons[titem.Template.Icon] = 0; // "create template icon"
}
if (template.NewFileDialogVisible == true) {
Category cat = GetCategory(titem.Template.Category, titem.Template.Subcategory);
Category cat = GetCategory(StringParser.Parse(titem.Template.Category), StringParser.Parse(titem.Template.Subcategory));
cat.Templates.Add(titem);
if (cat.Selected == false && template.WizardPath == null) {
@ -469,25 +470,25 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -469,25 +470,25 @@ namespace ICSharpCode.SharpDevelop.Gui
/// <summary>
/// Represents a category
/// </summary>
internal class Category : TreeNode
public class Category : TreeNode, ICategory
{
ArrayList categories = new ArrayList();
ArrayList templates = new ArrayList();
// string name;
int sortOrder = TemplateCategorySortOrderFile.UndefinedSortOrder;
public bool Selected = false;
public bool HasSelectedTemplate = false;
public Category(string name) : base(StringParser.Parse(name))
public Category(string name, int sortOrder) : base(StringParser.Parse(name))
{
this.Name = name;
this.Name = StringParser.Parse(name);
ImageIndex = 1;
this.sortOrder = sortOrder;
}
public Category(string name) : this(name, TemplateCategorySortOrderFile.UndefinedSortOrder)
{
}
// public string Name {
// get {
// return name;
// }
// }
public ArrayList Categories {
get {
return categories;
@ -498,6 +499,15 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -498,6 +499,15 @@ namespace ICSharpCode.SharpDevelop.Gui
return templates;
}
}
public int SortOrder {
get {
return sortOrder;
}
set {
sortOrder = value;
}
}
}
/// <summary>

33
src/Main/Base/Project/Src/Gui/Dialogs/NewProjectDialog.cs

@ -99,6 +99,7 @@ namespace ICSharpCode.SharpDevelop.Project.Dialogs @@ -99,6 +99,7 @@ namespace ICSharpCode.SharpDevelop.Project.Dialogs
((ListView)ControlDictionary["templateListView"]).SmallImageList = smalllist;
InsertCategories(null, categories);
((TreeView)ControlDictionary["categoryTreeView"]).TreeViewNodeSorter = new TemplateCategoryComparer();
((TreeView)ControlDictionary["categoryTreeView"]).Sort();
SelectLastSelectedCategoryNode(((TreeView)ControlDictionary["categoryTreeView"]).Nodes, PropertyService.Get("Dialogs.NewProjectDialog.LastSelectedCategory", "C#"));
}
@ -126,7 +127,7 @@ namespace ICSharpCode.SharpDevelop.Project.Dialogs @@ -126,7 +127,7 @@ namespace ICSharpCode.SharpDevelop.Project.Dialogs
}
}
}
Category newcategory = new Category(categoryname);
Category newcategory = new Category(categoryname, TemplateCategorySortOrderFile.GetProjectCategorySortOrder(categoryname));
categories.Add(newcategory);
if (subcategoryname != null) {
return GetSubcategory(newcategory, subcategoryname);
@ -140,7 +141,7 @@ namespace ICSharpCode.SharpDevelop.Project.Dialogs @@ -140,7 +141,7 @@ namespace ICSharpCode.SharpDevelop.Project.Dialogs
if (subcategory.Text == name)
return subcategory;
}
Category newsubcategory = new Category(name);
Category newsubcategory = new Category(name, TemplateCategorySortOrderFile.GetProjectCategorySortOrder(parentCategory.Name, name));
parentCategory.Categories.Add(newsubcategory);
return newsubcategory;
}
@ -153,7 +154,7 @@ namespace ICSharpCode.SharpDevelop.Project.Dialogs @@ -153,7 +154,7 @@ namespace ICSharpCode.SharpDevelop.Project.Dialogs
icons[titem.Template.Icon] = 0; // "create template icon"
}
if (template.NewProjectDialogVisible == true) {
Category cat = GetCategory(titem.Template.Category, titem.Template.Subcategory);
Category cat = GetCategory(StringParser.Parse(titem.Template.Category), StringParser.Parse(titem.Template.Subcategory));
cat.Templates.Add(titem);
if (cat.Templates.Count == 1)
titem.Selected = true;
@ -450,23 +451,31 @@ namespace ICSharpCode.SharpDevelop.Project.Dialogs @@ -450,23 +451,31 @@ namespace ICSharpCode.SharpDevelop.Project.Dialogs
/// <summary>
/// Represents a category
/// </summary>
public class Category : TreeNode
public class Category : TreeNode, ICategory
{
ArrayList categories = new ArrayList();
ArrayList templates = new ArrayList();
// string name;
int sortOrder = TemplateCategorySortOrderFile.UndefinedSortOrder;
public Category(string name) : base(name)
public Category(string name) : this(name, TemplateCategorySortOrderFile.UndefinedSortOrder)
{
this.Name = name;
}
public Category(string name, int sortOrder) : base(StringParser.Parse(name))
{
this.Name = StringParser.Parse(name);
ImageIndex = 1;
this.sortOrder = sortOrder;
}
// public string Name {
// get {
// return name;
// }
// }
public int SortOrder {
get {
return sortOrder;
}
set {
sortOrder = value;
}
}
public ArrayList Categories {
get {
return categories;

49
src/Main/Base/Project/Src/Gui/Dialogs/TemplateCategoryComparer.cs

@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.SharpDevelop.Internal.Templates;
using System;
using System.Collections;
namespace ICSharpCode.SharpDevelop.Gui
{
public interface ICategory
{
string Name {get; set;}
int SortOrder {get; set;}
}
/// <summary>
/// Sorts categories in the project/file template tree.
/// </summary>
public class TemplateCategoryComparer : IComparer
{
public TemplateCategoryComparer()
{
}
public int Compare(object x, object y)
{
ICategory categoryX = x as ICategory;
ICategory categoryY = y as ICategory;
if (categoryX.SortOrder != TemplateCategorySortOrderFile.UndefinedSortOrder && categoryY.SortOrder != TemplateCategorySortOrderFile.UndefinedSortOrder) {
if (categoryX.SortOrder > categoryY.SortOrder) {
return 1;
} else if (categoryX.SortOrder < categoryY.SortOrder) {
return -1;
}
} else if (categoryX.SortOrder != TemplateCategorySortOrderFile.UndefinedSortOrder) {
return -1;
} else if (categoryY.SortOrder != TemplateCategorySortOrderFile.UndefinedSortOrder) {
return 1;
}
return String.Compare(categoryX.Name, categoryY.Name);
}
}
}

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

@ -45,16 +45,16 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates @@ -45,16 +45,16 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates
{
public static ArrayList ProjectTemplates = new ArrayList();
string originator = null;
string created = null;
string lastmodified = null;
string name = null;
string category = null;
string languagename = null;
string description = null;
string icon = null;
string wizardpath = null;
string subcategory = null;
string originator = null;
string created = null;
string lastmodified = null;
string name = null;
string category = null;
string languagename = null;
string description = null;
string icon = null;
string wizardpath = null;
string subcategory = null;
int IComparable.CompareTo(object other)
{

152
src/Main/Base/Project/Src/Internal/Templates/TemplateCategorySortOrderFile.cs

@ -0,0 +1,152 @@ @@ -0,0 +1,152 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
namespace ICSharpCode.SharpDevelop.Internal.Templates
{
/// <summary>
/// File that defines the sort order for the file and project template
/// categories.
/// </summary>
public class TemplateCategorySortOrderFile
{
public const int UndefinedSortOrder = -1;
public const string ProjectCategorySortOrderFileName = "ProjectCategorySortOrder.xml";
public const string FileCategorySortOrderFileName = "FileCategorySortOrder.xml";
Dictionary<string, int> sortOrders = new Dictionary<string, int>();
static List<TemplateCategorySortOrderFile> projectCategorySortOrderFiles;
static List<TemplateCategorySortOrderFile> fileCategorySortOrderFiles;
public TemplateCategorySortOrderFile(string fileName) : this(new XmlTextReader(new StreamReader(fileName, true)))
{
}
public TemplateCategorySortOrderFile(XmlTextReader reader)
{
using (reader) {
XmlDocument doc = new XmlDocument();
doc.Load(reader);
foreach (XmlElement category in doc.DocumentElement.SelectNodes("Category")) {
string name = StringParser.Parse(category.GetAttribute("Name"));
if (name.Length > 0 && category.HasAttribute("SortOrder")) {
sortOrders.Add(name, GetSortOrder(category.GetAttribute("SortOrder")));
}
foreach (XmlElement subCategory in category.SelectNodes("Category")) {
if (subCategory.HasAttribute("Name")) {
sortOrders.Add(String.Concat(name, ",", StringParser.Parse(subCategory.GetAttribute("Name"))), GetSortOrder(subCategory.GetAttribute("SortOrder")));
}
}
}
}
}
public int GetCategorySortOrder(string name)
{
if (sortOrders.ContainsKey(name)) {
return sortOrders[name];
}
return UndefinedSortOrder;
}
public int GetCategorySortOrder(string name, string subcategoryName)
{
string key = String.Concat(name, ",", subcategoryName);
return GetCategorySortOrder(key);
}
public static int GetProjectCategorySortOrder(string name)
{
if (projectCategorySortOrderFiles == null) {
ReadProjectCategorySortOrderFiles();
}
foreach (TemplateCategorySortOrderFile file in projectCategorySortOrderFiles) {
int sortOrder = file.GetCategorySortOrder(name);
if (sortOrder != UndefinedSortOrder) {
return sortOrder;
}
}
return UndefinedSortOrder;
}
public static int GetProjectCategorySortOrder(string name, string subcategoryName)
{
string key = String.Concat(name, ",", subcategoryName);
return GetProjectCategorySortOrder(key);
}
public static int GetFileCategorySortOrder(string name)
{
if (fileCategorySortOrderFiles == null) {
ReadFileCategorySortOrderFiles();
}
foreach (TemplateCategorySortOrderFile file in fileCategorySortOrderFiles) {
int sortOrder = file.GetCategorySortOrder(name);
if (sortOrder != UndefinedSortOrder) {
return sortOrder;
}
}
return UndefinedSortOrder;
}
public static int GetFileCategorySortOrder(string name, string subcategoryName)
{
string key = String.Concat(name, ",", subcategoryName);
return GetFileCategorySortOrder(key);
}
int GetSortOrder(string s)
{
int sortOrder;
if (Int32.TryParse(s, out sortOrder)) {
return sortOrder;
}
return UndefinedSortOrder;
}
static void ReadProjectCategorySortOrderFiles()
{
projectCategorySortOrderFiles = new List<TemplateCategorySortOrderFile>();
string dataTemplateDir = FileUtility.Combine(PropertyService.DataDirectory, "templates", "project");
List<string> files = FileUtility.SearchDirectory(dataTemplateDir, ProjectCategorySortOrderFileName);
foreach (string templateDirectory in AddInTree.BuildItems(ProjectTemplate.TemplatePath, null, false)) {
files.AddRange(FileUtility.SearchDirectory(templateDirectory, ProjectCategorySortOrderFileName));
}
foreach (string fileName in files) {
try {
projectCategorySortOrderFiles.Add(new TemplateCategorySortOrderFile(fileName));
} catch (Exception ex) {
LoggingService.Debug("Failed to load project category sort order file: " + fileName + " : " + ex.ToString());
}
}
}
static void ReadFileCategorySortOrderFiles()
{
fileCategorySortOrderFiles = new List<TemplateCategorySortOrderFile>();
string dataTemplateDir = FileUtility.Combine(PropertyService.DataDirectory, "templates", "file");
List<string> files = FileUtility.SearchDirectory(dataTemplateDir, FileCategorySortOrderFileName);
foreach (string templateDirectory in AddInTree.BuildItems(ProjectTemplate.TemplatePath, null, false)) {
files.AddRange(FileUtility.SearchDirectory(templateDirectory, FileCategorySortOrderFileName));
}
foreach (string fileName in files) {
try {
fileCategorySortOrderFiles.Add(new TemplateCategorySortOrderFile(fileName));
} catch(Exception ex) {
LoggingService.Debug("Failed to load project category sort order file: " + fileName + " : " + ex.ToString());
}
}
}
}
}

4
src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj

@ -63,6 +63,9 @@ @@ -63,6 +63,9 @@
<Compile Include="WebReferences\WebServicesReferenceExistsTests.cs" />
<Compile Include="WebReferences\ProjectWebReferenceItemsTests.cs" />
<Compile Include="WebReferences\WebReferenceChangesTest.cs" />
<Compile Include="Templates\ProjectTemplateCategoryComparerTests.cs" />
<Compile Include="Templates\CategorySortOrderTests.cs" />
<Compile Include="Templates\FileTemplateCategoryComparerTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Project\ICSharpCode.SharpDevelop.csproj">
@ -103,6 +106,7 @@ @@ -103,6 +106,7 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Folder Include="WebReferences" />
<Folder Include="Templates" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
</Project>

80
src/Main/Base/Test/Templates/CategorySortOrderTests.cs

@ -0,0 +1,80 @@ @@ -0,0 +1,80 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.SharpDevelop.Internal.Templates;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project.Dialogs;
using NUnit.Framework;
using System;
using System.IO;
using System.Xml;
namespace ICSharpCode.SharpDevelop.Tests.Templates
{
[TestFixture]
public class CategorySortOrderTests
{
TemplateCategorySortOrderFile sortOrderFile;
int csharpSortOrder;
int windowsAppsSortOrder;
int miscSortOrder;
int errorSortOrder;
int misTypedNameSortOrder;
[TestFixtureSetUp]
public void SetUpFixture()
{
string xml = "<Categories>\r\n" +
" <Category Name='C#'>\r\n" +
" <Category Name='Windows Applications' SortOrder='10'/>\r\n" +
" </Category>\r\n" +
" <Category Name='Misc' SortOrder='20'/>\r\n" +
" <Category Name='Error' SortOrder='A'/>\r\n" +
" <Category mis-typed-Name='Test' SortOrder='100'/>\r\n" +
"</Categories>";
sortOrderFile = new TemplateCategorySortOrderFile(new XmlTextReader(new StringReader(xml)));
csharpSortOrder = sortOrderFile.GetCategorySortOrder("C#");
windowsAppsSortOrder = sortOrderFile.GetCategorySortOrder("C#", "Windows Applications");
miscSortOrder = sortOrderFile.GetCategorySortOrder("Misc");
errorSortOrder = sortOrderFile.GetCategorySortOrder("Error");
misTypedNameSortOrder = sortOrderFile.GetCategorySortOrder(String.Empty);
}
[Test]
public void CSharpCategorySortOrder()
{
Assert.AreEqual(TemplateCategorySortOrderFile.UndefinedSortOrder, csharpSortOrder);
}
[Test]
public void MiscCategorySortOrder()
{
Assert.AreEqual(20, miscSortOrder);
}
[Test]
public void WindowsAppsSortOrder()
{
Assert.AreEqual(10, windowsAppsSortOrder);
}
[Test]
public void InvalidSortOrder()
{
Assert.AreEqual(TemplateCategorySortOrderFile.UndefinedSortOrder, errorSortOrder);
}
[Test]
public void InvalidAttributeName()
{
Assert.AreEqual(TemplateCategorySortOrderFile.UndefinedSortOrder, misTypedNameSortOrder);
}
}
}

98
src/Main/Base/Test/Templates/FileTemplateCategoryComparerTests.cs

@ -0,0 +1,98 @@ @@ -0,0 +1,98 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project.Dialogs;
using NUnit.Framework;
using System;
namespace ICSharpCode.SharpDevelop.Tests.Templates
{
[TestFixture]
public class FileTemplateCategoryComparerTests
{
TemplateCategoryComparer comparer;
[TestFixtureSetUp]
public void SetUpFixture()
{
comparer = new TemplateCategoryComparer();
}
[Test]
public void NameEquals()
{
NewFileDialog.Category category1 = new NewFileDialog.Category("aa");
NewFileDialog.Category category2 = new NewFileDialog.Category("aa");
Assert.AreEqual(0, comparer.Compare(category1, category2));
}
[Test]
public void NameNotEqual1()
{
NewFileDialog.Category category1 = new NewFileDialog.Category("aa");
NewFileDialog.Category category2 = new NewFileDialog.Category("bb");
Assert.AreEqual(-1, comparer.Compare(category1, category2));
}
[Test]
public void NameNotEqual2()
{
NewFileDialog.Category category1 = new NewFileDialog.Category("bb");
NewFileDialog.Category category2 = new NewFileDialog.Category("aa");
Assert.AreEqual(1, comparer.Compare(category1, category2));
}
[Test]
public void IndexNotEqual1()
{
NewFileDialog.Category category1 = new NewFileDialog.Category("zz", 0);
NewFileDialog.Category category2 = new NewFileDialog.Category("zz", 1);
Assert.AreEqual(-1, comparer.Compare(category1, category2));
}
[Test]
public void IndexNotEqual2()
{
NewFileDialog.Category category1 = new NewFileDialog.Category("zz", 1);
NewFileDialog.Category category2 = new NewFileDialog.Category("zz", 0);
Assert.AreEqual(1, comparer.Compare(category1, category2));
}
[Test]
public void IndexEqual1()
{
NewFileDialog.Category category1 = new NewFileDialog.Category("aa", 0);
NewFileDialog.Category category2 = new NewFileDialog.Category("bb", 0);
Assert.AreEqual(-1, comparer.Compare(category1, category2));
}
[Test]
public void OneIndexNotSet1()
{
NewFileDialog.Category category1 = new NewFileDialog.Category("zz", 0);
NewFileDialog.Category category2 = new NewFileDialog.Category("aa");
Assert.AreEqual(-1, comparer.Compare(category1, category2));
}
[Test]
public void OneIndexNotSet2()
{
NewFileDialog.Category category1 = new NewFileDialog.Category("aa");
NewFileDialog.Category category2 = new NewFileDialog.Category("zz", 0);
Assert.AreEqual(1, comparer.Compare(category1, category2));
}
}
}

98
src/Main/Base/Test/Templates/ProjectTemplateCategoryComparerTests.cs

@ -0,0 +1,98 @@ @@ -0,0 +1,98 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project.Dialogs;
using NUnit.Framework;
using System;
namespace ICSharpCode.SharpDevelop.Tests.Templates
{
[TestFixture]
public class ProjectTemplateCategoryComparerTests
{
TemplateCategoryComparer comparer;
[TestFixtureSetUp]
public void SetUpFixture()
{
comparer = new TemplateCategoryComparer();
}
[Test]
public void NameEquals()
{
NewProjectDialog.Category category1 = new NewProjectDialog.Category("aa");
NewProjectDialog.Category category2 = new NewProjectDialog.Category("aa");
Assert.AreEqual(0, comparer.Compare(category1, category2));
}
[Test]
public void NameNotEqual1()
{
NewProjectDialog.Category category1 = new NewProjectDialog.Category("aa");
NewProjectDialog.Category category2 = new NewProjectDialog.Category("bb");
Assert.AreEqual(-1, comparer.Compare(category1, category2));
}
[Test]
public void NameNotEqual2()
{
NewProjectDialog.Category category1 = new NewProjectDialog.Category("bb");
NewProjectDialog.Category category2 = new NewProjectDialog.Category("aa");
Assert.AreEqual(1, comparer.Compare(category1, category2));
}
[Test]
public void IndexNotEqual1()
{
NewProjectDialog.Category category1 = new NewProjectDialog.Category("zz", 0);
NewProjectDialog.Category category2 = new NewProjectDialog.Category("zz", 1);
Assert.AreEqual(-1, comparer.Compare(category1, category2));
}
[Test]
public void IndexNotEqual2()
{
NewProjectDialog.Category category1 = new NewProjectDialog.Category("zz", 1);
NewProjectDialog.Category category2 = new NewProjectDialog.Category("zz", 0);
Assert.AreEqual(1, comparer.Compare(category1, category2));
}
[Test]
public void IndexEqual1()
{
NewProjectDialog.Category category1 = new NewProjectDialog.Category("aa", 0);
NewProjectDialog.Category category2 = new NewProjectDialog.Category("bb", 0);
Assert.AreEqual(-1, comparer.Compare(category1, category2));
}
[Test]
public void OneIndexNotSet1()
{
NewProjectDialog.Category category1 = new NewProjectDialog.Category("zz", 0);
NewProjectDialog.Category category2 = new NewProjectDialog.Category("aa");
Assert.AreEqual(-1, comparer.Compare(category1, category2));
}
[Test]
public void OneIndexNotSet2()
{
NewProjectDialog.Category category1 = new NewProjectDialog.Category("aa");
NewProjectDialog.Category category2 = new NewProjectDialog.Category("zz", 0);
Assert.AreEqual(1, comparer.Compare(category1, category2));
}
}
}

BIN
src/Main/StartUp/Project/Resources/StringResources.resources

Binary file not shown.

2
src/SharpDevelop.Tests.sln

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
Microsoft Visual Studio Solution File, Format Version 9.00
# SharpDevelop 2.0.0.936
# SharpDevelop 2.0.0.960
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AddIns", "AddIns", "{14A277EE-7DF1-4529-B639-7D1EF334C1C5}"
ProjectSection(SolutionItems) = postProject
EndProjectSection

Loading…
Cancel
Save