public NodeMenuItem(string text, TreeNode tn, NodeDef parentNode, NodeDef childNode, Popup popup) : base(text) { this.tn = tn; this.parentNode = parentNode; this.childNode = childNode; this.popup = popup; }
protected void BuildFlatNodeList(NodeDef node) { foreach (NodeDef child in node.Nodes) { if (child.Name == null) { throw new ApplicationException("NodeDef Name cannot be null."); } // System.Diagnostics.Debug.WriteLine("Child='" + child.Text + "'"); // System.Diagnostics.Debug.WriteLine("Adding controller node map:" + (child.ImplementingType==null ? "null" : child.ImplementingType.ToString()) + ", " + (child.TypeData==null ? "null" : child.TypeData.ToString())); nodeList[child.Name] = child; controllerToNodeDefMap[new ControllerInfo(child.ImplementingType, child.TypeData)] = child; nameToNodeDefMap[child.Name] = child; if (!child.Recurse) { BuildFlatNodeList(child); } } }
protected void UpdateImageList(TreeNode tn, NodeDef nodeDef, IXtreeNode inst) { if (nodeDef.ImageList != null) { // Have images been loaded into the TreeView's image list? if (nodeDef.ImageOffset == -1) { // No. Load them and save the offset. nodeDef.ImageOffset = ImageList.Images.Count; foreach (Image img in nodeDef.ImageList.Images) { ImageList.Images.Add(img); } } // Yes, just update the indices. tn.ImageIndex = nodeDef.ImageOffset + inst.IconIndex; tn.SelectedImageIndex = nodeDef.ImageOffset + inst.SelectedIconIndex; } }
public ContextMenu BuildContextMenu(TreeNode tn, NodeDef n) { ContextMenu cm = new ContextMenu(); bool first = true; // Populate from this node's popup collection. if (n.PopupItems.Count != 0) { foreach (Popup popup in n.PopupItems) { NodeMenuItem nmi = new NodeMenuItem(popup.Text, tn, n, null, popup); if (popup.PopupItems.Count == 0) { nmi.Click += new EventHandler(OnContextItem); nmi.Enabled = ((NodeInstance)tn.Tag).Instance.IsEnabled(popup.Tag, popup.Enabled); } BuildChildPopups(nmi, popup, tn, n, null); cm.MenuItems.Add(nmi); } first = false; } // For each child node, populate from the child's ParentPopupItems collection. foreach (NodeDef child in n.Nodes) { NodeDef refNode = child; // Resolve any referenced node. if (child.IsRef) { if (!nodeList.ContainsKey(child.RefName)) { throw new ApplicationException("referenced node does not exist."); } refNode = nodeList[child.RefName]; } if (refNode.ParentPopupItems.Count != 0) { if (!first) { if (child.Separator) { cm.MenuItems.Add(new NodeMenuItem("-", tn, n, null, null)); } } first = false; // Populate the items. foreach (Popup popup in refNode.ParentPopupItems) { NodeMenuItem nmi = new NodeMenuItem(popup.Text, tn, n, refNode, popup); if (popup.PopupItems.Count == 0) { nmi.Click += new EventHandler(OnContextItem); nmi.Enabled = ((NodeInstance)tn.Tag).Instance.IsEnabled(popup.Tag, popup.Enabled); } BuildChildPopups(nmi, popup, tn, n, refNode); cm.MenuItems.Add(nmi); //NodeMenuItem nmi = new NodeMenuItem(popup.Text, tn, n, refNode, popup); //nmi.Click += new EventHandler(OnContextItem); //nmi.Enabled = ((NodeInstance)tn.Tag).Instance.IsEnabled(popup.Tag, popup.Enabled); //cm.MenuItems.Add(nmi); } } } // Add custom items. NodeMenuItem spacer = new NodeMenuItem("-", tn, n, null, null); cm.MenuItems.Add(spacer); NodeMenuItem collapse = new NodeMenuItem("Collapse", tn, n, null, null); collapse.Click += new EventHandler(OnCollapse); cm.MenuItems.Add(collapse); NodeMenuItem expand = new NodeMenuItem("Expand", tn, n, null, null); expand.Click += new EventHandler(OnExpand); cm.MenuItems.Add(expand); NodeMenuItem expandAll = new NodeMenuItem("Expand All", tn, n, null, null); expandAll.Click += new EventHandler(OnExpandAll); cm.MenuItems.Add(expandAll); return cm; }
protected void BuildChildPopups(NodeMenuItem nmi, Popup popup, TreeNode tn, NodeDef n, NodeDef refNode) { foreach (Popup childPopup in popup.PopupItems) { NodeMenuItem nmiChild = new NodeMenuItem(childPopup.Text, tn, n, refNode, childPopup); if (childPopup.PopupItems.Count == 0) { nmiChild.Click += new EventHandler(OnContextItem); nmiChild.Enabled = ((NodeInstance)tn.Tag).Instance.IsEnabled(childPopup.Tag, childPopup.Enabled); } BuildChildPopups(nmiChild, childPopup, tn, n, refNode); nmi.MenuItems.Add(nmiChild); } }
public TreeNode CreateNodeAndRequiredChildren(NodeDef nodeDef, IXtreeNode parentInst) { TreeNode tn = CreateNode(nodeDef, parentInst); UpdateImageList(tn, nodeDef, parentInst); foreach (NodeDef child in nodeDef.Nodes) { // If the current node is recursive, then ignore nodes from the parent // that are NOT recursive. In other words, the current node should only // select itself. This prevents required nodes of the parent from being added. if ((nodeDef.Recurse) && (!child.Recurse)) { continue; } if (child.IsRequired) { IXtreeNode inst = child.CreateImplementingType(parentInst); // Set the qualifier to distinguish a generic controller with a concrete type that it manages. inst.TypeData = child.TypeData; TreeNode tnChild = CreateNodeAndRequiredChildren(child, inst); bool success = inst.AddNode(parentInst, null); OnNewNode(new NewNodeEventArgs(inst, nodeDef, tnChild)); tn.Nodes.Add(tnChild); tn.Expand(); } } return tn; }
public TreeNode CreateNode(NodeDef nodeDef, IXtreeNode inst) { TreeNode tn = new TreeNode(); tn.Text = nodeDef.Text; // If no controller is specified, use the text in the NodeDef. if (!(inst is PlaceholderInstance)) { // Otherwise, get the text from the controller... if (inst.Name != null) { // if it's not null! tn.Text = inst.Name; } } tn.Tag = new NodeInstance(tn, nodeDef, inst); UpdateImageList(tn, nodeDef, inst); return tn; }
public NewNodeEventArgs(IXtreeNode instanceNode, NodeDef nodeDef, TreeNode treeNode) { this.instanceNode = instanceNode; this.nodeDef = nodeDef; this.treeNode = treeNode; }
public NodeInstance(TreeNode tn, NodeDef def, IXtreeNode instance) { this.tn = tn; nodeDef = def; this.instance = instance; }
public NodeInstance(TreeNode tn, NodeDef def) { this.tn = tn; nodeDef = def; }