public void UpdateNodeText(string text) { if (currentNode != null) { object item = ((NodeInstance)currentNode.Tag).Instance.Item; if (item is IHasFullyQualifiedName) { currentNode.Text = ((IHasFullyQualifiedName)item).FullyQualfiedName; } else { currentNode.Text = text; } if (item is Symbol) { string newSymbolName = ((Symbol)item).Name; string newStructureName = ((Symbol)item).Structure; // Update the symbol list if it has changed. if (symbolName != newSymbolName) { // TODO: Yuck. Clean this up so the model is king, and drives any controller, and remove the inc/dec from the respective view! ApplicationController.SymbolListController. IfNotNull(ctrl => ctrl.ReplaceSymbol(symbolName, newSymbolName)). Else(() => { ApplicationModel.DecrementSymbolReference(symbolName); ApplicationModel.IncrementSymbolReference(newSymbolName); }); symbolName = newSymbolName; } if (structureName != newStructureName) { ApplicationController.StructureListController. IfNotNull(ctrl => ctrl.ReplaceStructure(structureName, newStructureName)). Else(() => { ApplicationModel.DecrementStructureReference(structureName); ApplicationModel.IncrementStructureReference(newStructureName); }); structureName = newStructureName; } // If the symbol being selected already exists, copy over the current structure here as well. // TODO: What happens if the referencing structure changes? We need to update all the types with that reference. // TODO: Verify that we're at a child node -- we can't have duplicate top level symbols. if (ApplicationModel.SymbolRefCount[newSymbolName] > 1) { CopySymbolStructure(currentNode, newSymbolName); } } } }
protected void RecurseCollection(NodeDef node, dynamic collection, TreeNode tnCurrent) { if (node.Nodes.Count > 0) { // Collection is a Dictionary<string, dynamic> where dynamic is a List<T> // obj is a KeyValuePair<string, dynamic> foreach (var kvp in collection.Collection) { string collectionName = kvp.Key; var collectionItems = kvp.Value; // Doesn't matter what nodeDef we find, this is only to get the TypeName and number of child nodes on recursion. // But it does allow us to separate the serialization order from the tree definition order. List <NodeDef> matchingNodes = node.Nodes.FindAll(t => t.TypeName.Contains(collectionName)); NodeDef nodeDef = node.Nodes.Find(t => t.TypeName.Contains(collectionName)); foreach (var item in collectionItems) { // Do not create new instances for the items, as they have already been created! IXtreeNode controller = (IXtreeNode)Activator.CreateInstance(Type.GetType(nodeDef.TypeName), new object[] { false }); controller.Item = item; TreeNode tn = View.AddNode(controller, tnCurrent); // If the item is a symbol, then we want to also show in the symbol and structure lists the associated symbol and structure! if (item is Symbol) { // TODO: Yuck. Clean this up so the model is king, and drives any controller, and remove the inc/dec from the respective view! ApplicationController.SymbolListController.IfNotNull(ctrl => ctrl.AddSymbol(item.Name)).Else(() => ApplicationModel.IncrementSymbolReference(item.Name)); ApplicationController.StructureListController.IfNotNull(ctrl => ctrl.AddStructure(item.Structure)).Else(() => ApplicationModel.IncrementStructureReference(item.Structure)); } else { if (!String.IsNullOrEmpty(item.Name)) { tn.Text = item.Name; } } // string name = ((IHasCollection)item).Name; // tn.Text = (String.IsNullOrWhiteSpace(name) ? tn.Text : name); RecurseCollection(nodeDef, item, tn); } } } }
/// <summary> /// Recursively copy the tree at src into dest. /// </summary> protected void CopyNodes(TreeNode dest, TreeNode src) { foreach (TreeNode childSrcNode in src.Nodes) { NodeInstance childInst = (NodeInstance)childSrcNode.Tag; Symbol childInstSymbol = (Symbol)childInst.Instance.Item; // Create a new controller. IXtreeNode controller = (IXtreeNode)Activator.CreateInstance(Type.GetType(childInst.NodeDef.TypeName), new object[] { false }); // Create a new symbol. Symbol item = new Symbol() { Name = childInstSymbol.Name, Structure = childInstSymbol.Structure }; controller.Item = item; // Add the new symbol to the destination symbol collection. ((Symbol)((NodeInstance)dest.Tag).Instance.Item).Symbols.Add(item); TreeNode childDestNode = View.AddNode(controller, dest); // TODO: Yuck. Clean this up so the model is king, and drives any controller, and remove the inc/dec from the respective view! ApplicationController.SymbolListController.IfNotNull(ctrl => ctrl.AddSymbol(item.Name)).Else(() => ApplicationModel.IncrementSymbolReference(item.Name)); ApplicationController.StructureListController.IfNotNull(ctrl => ctrl.AddStructure(item.Structure)).Else(() => ApplicationModel.IncrementStructureReference(item.Structure)); // Recurse. CopyNodes(childDestNode, childSrcNode); } }