/** * Recursively create subtree and add OperatorTypeButtons */ private void PopulateTree(ItemsControl item, OperatorTypeTree typeTree, String prefix, HashSet <string> expandedItems) { typeTree.Children.Sort(CompareOpsTypeTreeByName); foreach (var subtree in typeTree.Children) { var newSubTreeItem = new TreeViewItem() { IsExpanded = expandedItems.Contains(prefix + subtree.Name), Header = subtree.Name, DataContext = subtree, }; newSubTreeItem.ContextMenu = CreateContextMenu(); item.Items.Add(newSubTreeItem); PopulateTree(newSubTreeItem, subtree, prefix + subtree.Name, expandedItems); } typeTree.Operators.Sort(CompareOpsByName); foreach (var op in typeTree.Operators) { var b = new OperatorTypeButton(op, false); _operatorTypeButtons.Add(b); item.Items.Add(b); } }
public void SortInOperator(Core.MetaOperator metaOp) { if (metaOp == null || metaOp.Namespace == null) { return; } var spaces = metaOp.Namespace.Split(new[] { '.' }); var currentNode = this; var expandingSubTree = false; var parentSpaces = new List <OperatorTypeTree>(); foreach (var spaceName in spaces) { if (spaceName == "") { continue; } if (!expandingSubTree) { var node = currentNode.FindNodeDataByName(spaceName); if (node != null) { currentNode = node; parentSpaces.Add(node); } else { expandingSubTree = true; } } if (expandingSubTree) { var newNode = new OperatorTypeTree(spaceName, new List <OperatorTypeTree>(parentSpaces)); currentNode._children.Add(newNode); parentSpaces.Add(newNode); currentNode = newNode; } } currentNode._operators.Add(metaOp); }
private static int CompareOpsTypeTreeByName(OperatorTypeTree lhs, OperatorTypeTree rhs) { return(lhs.Name.CompareTo(rhs.Name)); }