Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@990 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
33 changed files with 575 additions and 61 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,5 @@
@@ -0,0 +1,5 @@
|
||||
<Categories> |
||||
<Category Name="C#"> |
||||
<Category Name="${res:Templates.File.Categories.WindowsApplications}" SortOrder="10"/> |
||||
</Category> |
||||
</Categories> |
||||
@ -0,0 +1,5 @@
@@ -0,0 +1,5 @@
|
||||
<Categories> |
||||
<Category Name="C#"> |
||||
<Category Name="${res:Templates.File.Categories.WindowsApplications}" SortOrder="10"/> |
||||
</Category> |
||||
</Categories> |
||||
@ -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); |
||||
} |
||||
} |
||||
} |
||||
@ -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()); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -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); |
||||
} |
||||
|
||||
} |
||||
} |
||||
@ -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)); |
||||
} |
||||
} |
||||
} |
||||
@ -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)); |
||||
} |
||||
} |
||||
} |
||||
Binary file not shown.
Loading…
Reference in new issue