- Timestamp:
- 01/25/10 12:59:38 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Operators.Programmable/3.2/ProgrammableOperatorView.cs
r2668 r2680 228 228 private void InitializeNamespacesList() { 229 229 initializing = true; 230 TreeNode oldTree = new TreeNode("root"); 231 CloneTreeNodeCollection(oldTree, namespacesTreeView.Nodes); 230 232 namespacesTreeView.Nodes.Clear(); 231 233 var selectedNamespaces = new HashSet<string>(ProgrammableOperator.Namespaces); 232 234 foreach (var ns in ProgrammableOperator.GetAllNamespaces(true)) 233 AddNamespace(namespacesTreeView.Nodes, ns, selectedNamespaces.Contains(ns) );235 AddNamespace(namespacesTreeView.Nodes, ns, selectedNamespaces.Contains(ns), oldTree); 234 236 codeEditor.Prefix = GetGeneratedPrefix(); 235 237 initializing = false; 236 238 } 237 239 238 private void AddNamespace(TreeNodeCollection parentNodes, string ns, bool isSelected) { 240 private void CloneTreeNodeCollection(TreeNode root, TreeNodeCollection nodes) { 241 foreach (TreeNode n in nodes) { 242 TreeNode newNode = root.Nodes.Add(n.Text, n.Text); 243 newNode.Checked = n.Checked; 244 CloneTreeNodeCollection(newNode, n.Nodes); 245 if (n.IsExpanded) 246 newNode.Expand(); 247 } 248 } 249 250 private bool AddNamespace(TreeNodeCollection parentNodes, string ns, bool isSelected, TreeNode oldTree) { 239 251 int dotIndex = ns.IndexOf('.'); 240 252 string prefix = ns; 241 253 if (dotIndex != -1) 242 254 prefix = ns.Substring(0, dotIndex); 255 TreeNode node = GetOrCreateNode(parentNodes, prefix); 256 TreeNode oldNode = MaybeGetNode(oldTree, prefix); 257 bool isNew = oldNode == null; 258 if (dotIndex != -1 && dotIndex + 1 < ns.Length) { 259 isNew = AddNamespace(node.Nodes, ns.Substring(dotIndex + 1, ns.Length - (dotIndex + 1)), isSelected, oldNode); 260 } else { 261 node.Checked = isSelected; 262 } 263 if (isNew || oldNode != null && oldNode.IsExpanded) 264 node.Expand(); 265 if (isNew) 266 namespacesTreeView.SelectedNode = node; 267 return isNew; 268 } 269 270 private static TreeNode MaybeGetNode(TreeNode parentNode, string key) { 271 if (parentNode == null) 272 return null; 273 if (parentNode.Nodes.ContainsKey(key)) 274 return parentNode.Nodes[key]; 275 return null; 276 } 277 278 private static TreeNode GetOrCreateNode(TreeNodeCollection parentNodes, string key) { 243 279 TreeNode node = null; 244 if (parentNodes.ContainsKey(prefix)) { 245 node = parentNodes[prefix]; 246 } else { 247 node = parentNodes.Add(prefix, prefix); 248 } 249 if (dotIndex != -1 && dotIndex + 1 < ns.Length) { 250 AddNamespace(node.Nodes, ns.Substring(dotIndex + 1, ns.Length - (dotIndex + 1)), isSelected); 251 if (isSelected) 252 node.Expand(); 253 } else 254 node.Checked = isSelected; 280 if (parentNodes.ContainsKey(key)) { 281 node = parentNodes[key]; 282 } else { 283 node = parentNodes.Add(key, key); 284 } 285 return node; 255 286 } 256 287
Note: See TracChangeset
for help on using the changeset viewer.