Changeset 12512
- Timestamp:
- 06/25/15 15:02:26 (9 years ago)
- Location:
- trunk/sources
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core/3.3/Attributes/CreatableAttribute.cs
r12506 r12512 21 21 22 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 23 25 24 26 namespace HeuristicLab.Core { … … 49 51 public const string Scripts = "5" + OrderToken + "Scripts"; 50 52 53 public static string GetFullName(string rawName) { 54 return string.Join(SplitToken, GetTokens(rawName)); 55 } 56 public static string GetName(string rawName) { 57 return GetTokens(rawName).Last(); 58 } 59 public static IEnumerable<string> GetParentRawNames(string rawName) { 60 var tokens = GetTokensWithOrdering(rawName).ToList(); 61 return tokens.Take(tokens.Count - 1); 62 } 51 63 64 private static IEnumerable<string> GetTokensWithOrdering(string rawName) { 65 return rawName.Split(new[] { SplitToken }, StringSplitOptions.RemoveEmptyEntries); 66 } 67 private static IEnumerable<string> GetTokens(string rawName) { 68 return GetTokensWithOrdering(rawName) 69 .Select(t => t.Split(new[] { OrderToken }, StringSplitOptions.RemoveEmptyEntries).Last()); 70 } 52 71 } 53 72 #endregion -
trunk/sources/HeuristicLab.Optimizer/3.3/NewItemDialog.cs
r12506 r12512 26 26 using System.Linq; 27 27 using System.Windows.Forms; 28 using HeuristicLab.Common; 28 29 using HeuristicLab.Core; 29 30 using HeuristicLab.PluginInfrastructure; … … 63 64 if (isInitialized) return; 64 65 66 // Sorted by hasOrdering to create category nodes first with concrete ordering. 67 // Items with categoryname without ordering are inserted afterwards correctly 65 68 var categories = 66 69 from type in ApplicationManager.Manager.GetTypes(typeof(IItem)) 70 where CreatableAttribute.IsCreatable(type) 67 71 let category = CreatableAttribute.GetCategory(type) 72 let hasOrdering = category.Contains(CreatableAttribute.Categories.OrderToken) 68 73 let name = ItemAttribute.GetName(type) 69 74 let priority = CreatableAttribute.GetPriority(type) 70 75 let version = ItemAttribute.GetVersion(type) 71 where CreatableAttribute.IsCreatable(type) 72 orderby category, priority, name, version ascending 76 orderby category, hasOrdering descending, priority, name, version ascending 73 77 group type by category into categoryGroup 74 78 select categoryGroup; … … 94 98 var rootNode = new TreeNode(); 95 99 100 // CategoryNode 101 // Tag: raw string, used for sorting, e.g. 1$$$Algorithms###2$$$Single Solution 102 // Name: full name = combined category name with parent categories, used for finding nodes in tree, e.g. Algorithms###Single Solution 103 // Text: category name, used for displaying on node itself, e.g. Single Solution 104 96 105 foreach (var category in categories) { 97 var fullName = category.Key; 98 var tokensWithOrdering = fullName.Split(new[] { CreatableAttribute.Categories.SplitToken }, StringSplitOptions.RemoveEmptyEntries); 99 var tokens = tokensWithOrdering.Select(t => t.Split(new[] { CreatableAttribute.Categories.OrderToken }, StringSplitOptions.RemoveEmptyEntries).Last()).ToList(); 100 var name = tokens.Last(); 101 var parents = tokensWithOrdering.Take(tokens.Count - 1); 106 var rawName = category.Key; 107 string fullName = CreatableAttribute.Categories.GetFullName(rawName); 108 string name = CreatableAttribute.Categories.GetName(rawName); 109 110 // Skip categories with same full name because the raw name can still be different (missing order) 111 if (rootNode.Nodes.Find(fullName, searchAllChildren: true).Length > 0) 112 continue; 102 113 103 114 var categoryNode = new TreeNode(name, imageIndex: 1, selectedImageIndex: 1) { 104 115 Name = fullName, 105 Tag = fullName116 Tag = rawName 106 117 }; 107 118 119 var parents = CreatableAttribute.Categories.GetParentRawNames(rawName); 108 120 var parentNode = FindOrCreateParentNode(rootNode, parents); 109 121 if (parentNode != null) … … 115 127 return rootNode; 116 128 } 117 private TreeNode FindOrCreateParentNode(TreeNode node, IEnumerable<string> parentCategories) {129 private TreeNode FindOrCreateParentNode(TreeNode node, IEnumerable<string> rawParentNames) { 118 130 TreeNode parentNode = null; 119 string fullName = null; 120 foreach (string parentCategory in parentCategories) { 121 fullName = fullName == null ? parentCategory : fullName + CreatableAttribute.Categories.SplitToken + parentCategory; 131 string rawName = null; 132 foreach (string rawParentName in rawParentNames) { 133 rawName = rawName == null ? rawParentName : rawName + CreatableAttribute.Categories.SplitToken + rawParentName; 134 var fullName = CreatableAttribute.Categories.GetFullName(rawName); 122 135 parentNode = node.Nodes.Find(fullName, searchAllChildren: false).SingleOrDefault(); 123 136 if (parentNode == null) { 124 parentNode = new TreeNode(parentCategory, imageIndex: 1, selectedImageIndex: 1) { 137 var name = CreatableAttribute.Categories.GetName(rawName); 138 parentNode = new TreeNode(name, imageIndex: 1, selectedImageIndex: 1) { 125 139 Name = fullName, 126 Tag = fullName140 Tag = rawName 127 141 }; 128 142 node.Nodes.Add(parentNode); … … 134 148 private void CreateItemNodes(TreeNode node, IEnumerable<IGrouping<string, Type>> categories) { 135 149 foreach (var category in categories) { 136 var categoryNode = node.Nodes.Find(category.Key, searchAllChildren: true).Single(); 150 var fullName = CreatableAttribute.Categories.GetFullName(category.Key); 151 var categoryNode = node.Nodes.Find(fullName, searchAllChildren: true).Single(); 137 152 foreach (var creatable in category) { 138 153 var itemNode = CreateItemNode(creatable); 139 itemNode.Name = itemNode.Name + ":" + category.Key;154 itemNode.Name = itemNode.Name + ":" + fullName; 140 155 categoryNode.Nodes.Add(itemNode); 141 156 } … … 257 272 258 273 if (typesTreeView.SelectedNode != null) { 259 string category = typesTreeView.SelectedNode.Tag as string; 274 var node = typesTreeView.SelectedNode; 275 string category = node.Tag as string; 260 276 if (category != null) { 261 itemDescriptionTextBox.Text = category;262 } 263 Type type = typesTreeView.SelectedNode.Tag as Type;277 itemDescriptionTextBox.Text = string.Join(" - ", node.Name.Split(new[] { CreatableAttribute.Categories.SplitToken }, StringSplitOptions.RemoveEmptyEntries)); 278 } 279 Type type = node.Tag as Type; 264 280 if (type != null) { 265 281 string description = ItemAttribute.GetDescription(type); … … 433 449 434 450 private class ItemTreeNodeComparer : IComparer { 451 private static readonly IComparer<string> Comparer = new NaturalStringComparer(); 435 452 public int Compare(object x, object y) { 436 453 var lhs = (TreeNode)x; … … 438 455 439 456 if (lhs.Tag is string && rhs.Tag is string) { 440 return lhs.Name.CompareTo(rhs.Name);457 return Comparer.Compare((string)lhs.Tag, (string)rhs.Tag); 441 458 } else if (lhs.Tag is string) { 442 459 return -1;
Note: See TracChangeset
for help on using the changeset viewer.