Changeset 12217
- Timestamp:
- 03/17/15 16:33:01 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/NewItemDialog/HeuristicLab.Optimizer/3.3/NewItemDialog.cs
r12215 r12217 31 31 namespace HeuristicLab.Optimizer { 32 32 internal partial class NewItemDialog : Form { 33 private const string RootMarker = "<ROOT>";34 35 33 private bool isInitialized; 36 34 … … 93 91 imageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.Namespace); // plugins 94 92 95 var rootNode = new TreeNode( RootMarker) { Name = RootMarker, Tag = RootMarker };93 var rootNode = new TreeNode(); 96 94 97 95 foreach (var category in categories) { 98 var categoryFullName = category.Key;99 var categoryTokens = categoryFullName.Split('#');100 var categoryName = categoryTokens.Last();101 var parent Categories = categoryTokens.Take(categoryTokens.Length - 1);102 103 var categoryNode = new TreeNode( categoryName, 1, 1) {104 Name = categoryName,105 Tag = categoryName96 var fullName = category.Key; 97 var tokens = fullName.Split('#'); 98 var name = tokens.Last(); 99 var parents = tokens.Take(tokens.Length - 1); 100 101 var categoryNode = new TreeNode(name, 1, 1) { 102 Name = fullName, 103 Tag = fullName 106 104 }; 107 105 108 var parentNode = FindOrCreateParentNode(rootNode, parent Categories);106 var parentNode = FindOrCreateParentNode(rootNode, parents); 109 107 if (parentNode != null) 110 108 parentNode.Nodes.Add(categoryNode); … … 117 115 private TreeNode FindOrCreateParentNode(TreeNode node, IEnumerable<string> parentCategories) { 118 116 TreeNode parentNode = null; 117 string fullName = null; 119 118 foreach (string parentCategory in parentCategories) { 120 parentNode = node.Nodes.Find(parentCategory, searchAllChildren: false).SingleOrDefault(); 119 fullName = fullName == null ? parentCategory : fullName + "#" + parentCategory; 120 parentNode = node.Nodes.Find(fullName, searchAllChildren: false).SingleOrDefault(); 121 121 if (parentNode == null) { 122 122 parentNode = new TreeNode(parentCategory, 1, 1) { 123 Name = parentCategory,124 Tag = parentCategory123 Name = fullName, 124 Tag = fullName 125 125 }; 126 126 node.Nodes.Add(parentNode); … … 133 133 private void CreateItemNodes(TreeNode node, IEnumerable<IGrouping<string, Type>> categories) { 134 134 foreach (var category in categories) { 135 var categoryNode = FindCategoryNode(node, category.Key);135 var categoryNode = node.Nodes.Find(category.Key, searchAllChildren: true).Single(); 136 136 foreach (var creatable in category) { 137 137 var itemNode = CreateItemNode(creatable); 138 itemNode.Name = itemNode.Name + ":" + category.Key; 138 139 categoryNode.Nodes.Add(itemNode); 139 140 } 140 141 } 141 }142 private TreeNode FindCategoryNode(TreeNode node, string fullCategoryName) {143 var categories = fullCategoryName.Split('#');144 foreach (string category in categories)145 node = node.Nodes.Find(category, searchAllChildren: false).Single();146 return node;147 142 } 148 143 … … 152 147 var itemNode = new TreeNode(name) { 153 148 ImageIndex = 0, 154 Tag = creatable 149 Tag = creatable, 150 Name = name 155 151 }; 156 152 … … 189 185 // remove nodes 190 186 typesTreeView.BeginUpdate(); 187 var searchTokens = searchString.Split(' '); 188 191 189 int i = 0; 192 var searchTokens = searchString.Split(' ');193 190 while (i < typesTreeView.Nodes.Count) { 194 int j = 0; 195 while (j < typesTreeView.Nodes[i].Nodes.Count) { 196 if (searchTokens.Any(searchToken => !typesTreeView.Nodes[i].Nodes[j].Text.ToLower().Contains(searchToken))) { 197 var node = typesTreeView.Nodes[i].Nodes[j]; 198 if (node != null && node.Tag is Type && (node.Tag as Type).Equals(SelectedType)) 199 SelectedType = null; 200 typesTreeView.Nodes[i].Nodes[j].Remove(); 201 } else 202 j++; 203 } 204 if (typesTreeView.Nodes[i].Nodes.Count == 0) 205 typesTreeView.Nodes[i].Remove(); 206 else 207 i++; 191 var categoryNode = typesTreeView.Nodes[i]; 192 bool remove = FilterNode(categoryNode, searchTokens); 193 if (remove) 194 typesTreeView.Nodes.RemoveAt(i); 195 else i++; 208 196 } 209 197 typesTreeView.EndUpdate(); … … 225 213 } 226 214 UpdateDescription(); 215 } 216 } 217 218 private bool FilterNode(TreeNode node, string[] searchTokens) { 219 if (node.Tag is string) { 220 int i = 0; 221 while (i < node.Nodes.Count) { 222 bool remove = FilterNode(node.Nodes[i], searchTokens); 223 if (remove) 224 node.Nodes.RemoveAt(i); 225 else i++; 226 } 227 return node.Nodes.Count == 0; 228 } else if (node.Tag is Type) { 229 var text = node.Text; 230 if (searchTokens.Any(searchToken => !text.ToLower().Contains(searchToken))) { 231 var typeTag = (Type)node.Tag; 232 if (typeTag.Equals(SelectedType)) 233 SelectedType = null; 234 return true; 235 } 236 return false; 237 } else { 238 return true; 227 239 } 228 240 } … … 284 296 private void RestoreSelectedNode(TreeNode selectedNode) { 285 297 if (selectedNode != null) { 286 foreach (TreeNode node in typesTreeView.Nodes) { 287 if (node.Text.Equals(selectedNode.Text)) typesTreeView.SelectedNode = node; 288 foreach (TreeNode child in node.Nodes) { 289 if ((child.Text.Equals(selectedNode.Text)) && (child.Tag == selectedNode.Tag)) 290 typesTreeView.SelectedNode = child; 291 } 292 } 298 var node = typesTreeView.Nodes.Find(selectedNode.Name, searchAllChildren: true).SingleOrDefault(); 299 typesTreeView.SelectedNode = node; 293 300 if (typesTreeView.SelectedNode == null) SelectedType = null; 294 301 }
Note: See TracChangeset
for help on using the changeset viewer.