Changeset 12513
- Timestamp:
- 06/25/15 15:26:35 (9 years ago)
- Location:
- branches/EnumValue in CreateExperiment/HeuristicLab.Optimizer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/EnumValue in CreateExperiment/HeuristicLab.Optimizer
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Optimizer merged: 12504,12506,12512
- Property svn:mergeinfo changed
-
branches/EnumValue in CreateExperiment/HeuristicLab.Optimizer/3.3/NewItemDialog.cs
r12466 r12513 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 tokens = fullName.Split('#'); 99 var name = tokens.Last(); 100 var parents = tokens.Take(tokens.Length - 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; 101 113 102 114 var categoryNode = new TreeNode(name, imageIndex: 1, selectedImageIndex: 1) { 103 115 Name = fullName, 104 Tag = fullName116 Tag = rawName 105 117 }; 106 118 119 var parents = CreatableAttribute.Categories.GetParentRawNames(rawName); 107 120 var parentNode = FindOrCreateParentNode(rootNode, parents); 108 121 if (parentNode != null) … … 114 127 return rootNode; 115 128 } 116 private TreeNode FindOrCreateParentNode(TreeNode node, IEnumerable<string> parentCategories) {129 private TreeNode FindOrCreateParentNode(TreeNode node, IEnumerable<string> rawParentNames) { 117 130 TreeNode parentNode = null; 118 string fullName = null; 119 foreach (string parentCategory in parentCategories) { 120 fullName = fullName == null ? parentCategory : fullName + "#" + 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); 121 135 parentNode = node.Nodes.Find(fullName, searchAllChildren: false).SingleOrDefault(); 122 136 if (parentNode == null) { 123 parentNode = new TreeNode(parentCategory, imageIndex: 1, selectedImageIndex: 1) { 137 var name = CreatableAttribute.Categories.GetName(rawName); 138 parentNode = new TreeNode(name, imageIndex: 1, selectedImageIndex: 1) { 124 139 Name = fullName, 125 Tag = fullName140 Tag = rawName 126 141 }; 127 142 node.Nodes.Add(parentNode); … … 133 148 private void CreateItemNodes(TreeNode node, IEnumerable<IGrouping<string, Type>> categories) { 134 149 foreach (var category in categories) { 135 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(); 136 152 foreach (var creatable in category) { 137 153 var itemNode = CreateItemNode(creatable); 138 itemNode.Name = itemNode.Name + ":" + category.Key;154 itemNode.Name = itemNode.Name + ":" + fullName; 139 155 categoryNode.Nodes.Add(itemNode); 140 156 } … … 165 181 SelectedType = null; 166 182 typesTreeView.SelectedNode = null; 167 typesTreeView.CollapseAll();168 183 UpdateDescription(); 184 185 foreach (TreeNode node in typesTreeView.Nodes) 186 node.Expand(); 187 typesTreeView.Nodes[0].EnsureVisible(); 169 188 } 170 189 … … 253 272 254 273 if (typesTreeView.SelectedNode != null) { 255 string category = typesTreeView.SelectedNode.Tag as string; 274 var node = typesTreeView.SelectedNode; 275 string category = node.Tag as string; 256 276 if (category != null) { 257 itemDescriptionTextBox.Text = category;258 } 259 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; 260 280 if (type != null) { 261 281 string description = ItemAttribute.GetDescription(type); … … 429 449 430 450 private class ItemTreeNodeComparer : IComparer { 451 private static readonly IComparer<string> Comparer = new NaturalStringComparer(); 431 452 public int Compare(object x, object y) { 432 453 var lhs = (TreeNode)x; … … 434 455 435 456 if (lhs.Tag is string && rhs.Tag is string) { 436 return lhs.Name.CompareTo(rhs.Name);457 return Comparer.Compare((string)lhs.Tag, (string)rhs.Tag); 437 458 } else if (lhs.Tag is string) { 438 459 return -1;
Note: See TracChangeset
for help on using the changeset viewer.