public new TriStateTreeNode this[String name] { get { return(_tnc[name] as TriStateTreeNode); } set { if (_tnc.ContainsKey(name)) { int index = _tnc.IndexOf(_tnc[name]);//함께 갱신해야 하므로.. _tnc.RemoveByKey(name); if (value is TriStateTreeNode) { value.Name = name; _tnc.Insert(index, value); } else { TriStateTreeNode node = new TriStateTreeNode(value); value.Name = name; _tnc.Insert(index, value); } } else { value.Name = name; _tnc.Add(value); } } }
void DisplayObjectService_DisplayObjectVisibleChanged(object sender, DisplayObjectEventArgs e) { string[] groups = DisplayObjectService.GetGroups(e.DisplayObject); string name = DisplayObjectService.GetDisplayName(e.DisplayObject); TreeNodeCollection parentCollection = this.Nodes; for (int i = 0; i < groups.Length; i++) { // if the group node doesn't exist, get out if (!parentCollection.ContainsKey(groups[i])) { return; } parentCollection = parentCollection[groups[i]].Nodes; } // we have the collection for the immediate parent if (parentCollection.ContainsKey(name)) { if (Services.DisplayObjectService.IsVisible(e.DisplayObject)) { parentCollection[name].NodeFont = boldFont; } else { parentCollection[name].NodeFont = this.Font; } } }
void stub(string key, string label) { string[] names = label.Split('/'); // create or traverse intervening nodes TreeNodeCollection children = tv.Nodes; for (int i = 0; i < names.Length - 1; i++) { if (children.ContainsKey(names[i])) { children = children[names[i]].Nodes; } else { children = children.Add(names[i], names[i]).Nodes; } } // now create the leaf node string prefix = names[names.Length - 1]; if (!children.ContainsKey(prefix)) { // do we even need to track TreeNode in the dict, since it has a unique key? TreeNode node = children.Add(key, prefix); treeNodes.Add(key, new Tuple <TreeNode, string>(node, prefix)); } else { logger.error("stubSetting: label already exists: {0}", label); } }
void Refresh(LuaRef table, TreeNodeCollection node, int depth) { if (depth <= 0) { return; } var meta = table.GetMetaTable(); if (meta) { var k = "metatable"; var v = meta; TreeNode n; if (!node.ContainsKey(k)) { n = node.Add(k, k); n.Tag = v; } else { n = node[k]; } Refresh(v, n.Nodes, depth - 1); } foreach (var t in table) { var key = t.Key(); var k = key.ToString(); if (k == "_G") { continue; } var v = t.Value(); TreeNode n; if (!node.ContainsKey(k)) { n = node.Add(k, k); n.Tag = v; } else { n = node[k]; } if (v.IsTable) { Refresh(v, n.Nodes, depth - 1); } } }
void DisplayObjectService_DisplayObjectAdded(object sender, DisplayObjectEventArgs e) { // add to the nodes string[] groups = DisplayObjectService.GetGroups(e.DisplayObject); string name = DisplayObjectService.GetDisplayName(e.DisplayObject); TreeNodeCollection parentCollection = this.Nodes; for (int i = 0; i < groups.Length; i++) { TreeNode node = null; if (parentCollection.ContainsKey(groups[i])) { node = parentCollection[groups[i]]; } else { node = new TreeNode(groups[i]); node.SelectedImageKey = node.ImageKey = "folder closed"; node.Name = groups[i]; parentCollection.Add(node); } node.Expand(); parentCollection = node.Nodes; } // we have the collection for the immediate parent // add the node if it doesn't exist if (!parentCollection.ContainsKey(name)) { TreeNode node = new TreeNode(name); node.Name = name; node.Tag = e.DisplayObject; node.SelectedImageKey = node.ImageKey = "display object"; if (Services.DisplayObjectService.IsVisible(e.DisplayObject)) { node.NodeFont = boldFont; } parentCollection.Add(node); // walk to the root and expand all while (node.Parent != null) { node = node.Parent; node.Expand(); } } }
void DisplayObjectService_DisplayObjectRemoved(object sender, DisplayObjectEventArgs e) { string[] groups = DisplayObjectService.GetGroups(e.DisplayObject); string name = DisplayObjectService.GetDisplayName(e.DisplayObject); TreeNode parentNode = null; TreeNodeCollection parentCollection = this.Nodes; for (int i = 0; i < groups.Length; i++) { // if the group node doesn't exist, get out if (!parentCollection.ContainsKey(groups[i])) { return; } parentNode = parentCollection[groups[i]]; parentCollection = parentNode.Nodes; } // we have the collection for the immediate parent if (parentCollection.ContainsKey(name)) { parentCollection.RemoveByKey(name); } // walk up the parents and see if the folder is empty while (parentNode != null) { if (parentCollection.Count == 0) { // get the parent node and it's collection TreeNode removeNode = parentNode; parentNode = parentNode.Parent; if (parentNode == null) { parentCollection = this.Nodes; } else { parentCollection = parentNode.Nodes; } parentCollection.Remove(removeNode); } else { break; } } }
/// <summary> /// Adds the supplied component as a node with its corresponding parents and children. /// </summary> /// <param name="component"></param> public void AddComponent(ComponentOccurrence component) { if (!component.Visible) { return; } TreeNode node = new TreeNode(component.Name); node.Name = node.Text; node.Tag = component; node = GenerateFullTree(component, node); TreeNodeCollection iterator = Nodes; while (iterator.ContainsKey(node.Name) && node.Nodes.Count == 1) { iterator = iterator[iterator.IndexOfKey(node.Name)].Nodes; node = node.Nodes[0]; } iterator.RemoveByKey(node.Name); iterator.Add(node); }
private void AddNode(TenshiEntry i) { string[] Path = i.EntryPath; int index; TreeNodeCollection root = FileTree.Nodes; TreeNodeCollection working = root; for (index = 0; index < Path.Length; index++) { string node = Path[index]; if (!working.ContainsKey(node)) { break; } working = working[node].Nodes; } TreeNode last = null; for (; index < Path.Length; index++) { working.Add(new TreeNode(Path[index]) { Name = Path[index], Tag = null }); last = working[Path[index]]; working = working[Path[index]].Nodes; } if (last != null) { last.Tag = i; } }
public void refreshUI() { treeView1.Nodes.Clear(); ProjectManager pm = ProjectManager.GetInstance(); foreach (String path in pm.Components.Keys) { String[] ss = path.Split('.', '\\'); TreeNodeCollection nodes = treeView1.Nodes;//first lv collection nodes for (int i = 0; i < ss.Length; i++) { if (nodes.ContainsKey(ss[i])) { nodes = treeView1.Nodes[ss[i]].Nodes;//get next level nodes collections } else { nodes = nodes.Add(ss[i], ss[i]).Nodes;//add ss[i] to itself and get its collection (of couse empty) } } } treeView1.ExpandAll(); if (treeView1.Nodes.Count > 0) { treeView1.SelectedNode = treeView1.Nodes[0];//select the first } }
public bool Checker(TreeNodeCollection nodes, string key, ref string path) { bool result = false; if (nodes.Count > 0) { if (!nodes.ContainsKey(key)) { foreach (TreeNode node in nodes) { path += " " + node.Name; bool t = Checker(node.Nodes, key, ref path); if (t) { result = t; break; } else { path = path.Remove(path.Length - 1 - node.Name.Length); } } } else { result = true; path += " " + key; } } else { result = false; } return(result); }
void AddNode(TreeNodeCollection nodes, string path, ITreeViewItem item) { string[] structure = path.Split(new[] { Path.DirectorySeparatorChar }, 2, StringSplitOptions.RemoveEmptyEntries); string root = structure[0]; string nextPath = null; if (structure.Length > 1) { nextPath = structure[1]; } if (nodes.ContainsKey(root)) { AddNode(nodes[root].Nodes, nextPath, item); } else { ITreeViewItem value = null; if (nextPath == null) { value = item; } TreeNode node = new TreeNode { Name = root, Text = root, Tag = value }; if (nextPath != null) { AddNode(node.Nodes, nextPath, item); } nodes.Add(node); } }
private int GetInsertionIdx(string txt, TreeNode destination, TreeNodeCollection nodes) { if (nodes.ContainsKey(txt)) // (nodes.Find(source.Text, true).Length > 0) { return(-1); } int idx = 0; if (destination != null) { if (destination.Nodes.Count > 0 && DropIntoFolder) { idx = destination.Nodes.Count; } else { idx = (destination != null) ? destination.Index : 0; } } if (InsertAfter) { ++idx; } return(idx); }
private void SyncEntityView(TreeNodeCollection nodes, IEnumerable <Entity> entities) { List <TreeNode> removeList = new List <TreeNode>(); foreach (TreeNode node in nodes) { var e = ((EntityTreeNode)node).MonitorEntity; if (!e.IsAlive) { removeList.Add(node); } } foreach (var node in removeList) { nodes.Remove(node); } foreach (var e in entities) { if (!nodes.ContainsKey(e.ID.ToString())) { var node = new EntityTreeNode() { ImageIndex = 0, SelectedImageIndex = 0, Name = e.ID.ToString(), MonitorEntity = e, Text = string.Format("[{0}] {1}", e.ID, e.Name), }; node.Nodes.Add(NothingComponentTreeNode); nodes.Add(node); } } }
private TreeNodeCollection GetFolder(string fullPath) { TreeNodeCollection result = symbolTree.Nodes; if (fullPath != null && fullPath != "") { string[] folders = fullPath.Split(new string[] { symbolTree.PathSeparator }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < folders.Length; i++) { if (result.ContainsKey(folders[i])) { result = result[folders[i]].Nodes; } else { FolderTreeNode newFolder = new FolderTreeNode(folders[i], result.GetType(), 3, 4); newFolder.Name = folders[i]; result.Add(newFolder); newFolder.ResetDate(); result = newFolder.Nodes; newFolder.Expand(); } } } return(result); }
private void BuildTree(DirectoryInfo directoryInfo, TreeNodeCollection addInMe) { TreeNode curNode = null; if (addInMe.ContainsKey(directoryInfo.FullName) == false) { curNode = addInMe.Add(directoryInfo.FullName, directoryInfo.Name); } else { curNode = addInMe.Find(directoryInfo.FullName, false)[0]; } foreach (FileInfo file in directoryInfo.GetFiles()) { if (curNode.Nodes.ContainsKey(file.FullName) == false) { curNode.Nodes.Add(file.FullName, file.Name); } } foreach (DirectoryInfo subdir in directoryInfo.GetDirectories()) { BuildTree(subdir, curNode.Nodes); } }
public void AddFilePath(string path) { TreeNodeCollection nodes = treeView1.Nodes; foreach (var i in path.Split(new char[] { Path.DirectorySeparatorChar })) { if (!nodes.ContainsKey(i)) { TreeNode node = nodes.Add(i, i); node.ImageKey = GetImageKey(GetPathByNode(node)); node.SelectedImageKey = node.ImageKey; } nodes = nodes[i].Nodes; } string dir = Path.GetDirectoryName(path); if (!m_fileSysWatchers.ContainsKey(dir)) { FileSystemWatcher watcher = new FileSystemWatcher(dir); watcher.EnableRaisingEvents = true; watcher.IncludeSubdirectories = false; watcher.Changed += (o, e) => { DelegateQueue.PostDelegate(() => { if (this.FileChanged != null) { this.FileChanged(e.FullPath); } }); }; watcher.Deleted += (o, e) => { DelegateQueue.PostDelegate(() => { if (this.FileDeleted != null) { this.FileDeleted(e.FullPath); } }); }; m_fileSysWatchers.Add(dir, watcher); } }
private void TreeView_CreateTagNode(TreeView treeView, string fileName, TagId id) { //Split TreeNode node = null; string[] parts = fileName.Split('\\'); TreeNodeCollection collection = treeView.Nodes; string lastPart = parts.Last(); //Loop for (int i = 0; i < parts.Length - 1; i++) { //Check if (!collection.ContainsKey(parts[i])) { node = collection.Add(parts[i], parts[i], 0); } else { node = collection[parts[i]]; } //Get nodes collection = node.Nodes; } //Add file node node = collection.Add(lastPart, lastPart, 1); node.Tag = id; }
private void SettingsNodeRemoved(SettingsNode sender, SettingsNodeChangeEventArgs e) { string[] nodeNames = e.Node.FullPath.Split(e.Node.PathSeparator); if (nodeNames.Length < 1) { return; } TreeNodeCollection nodes = treeView.Nodes; for (int i = 0; i < nodeNames.Length - 1; i++) { TreeNode node = nodes[nodeNames[i]]; if (node == null) { return; } nodes = node.Nodes; } UIUtility.Invoke(this, () => { if (nodes.ContainsKey(e.Node.Name)) { nodes.RemoveByKey(e.Node.Name); } }); }
public static TreeNode GetOrCreate(this TreeNodeCollection nodes, string key) { if (nodes.ContainsKey(key) == false) { return(nodes.Add(key, key)); } return(nodes[key]); }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { //Prepare TreeNode currentNode = null; TreeNodeCollection currentCollection = null; string[] parts = null; //Start tagTreeView.BeginUpdate(); tagTreeView.Nodes.Clear(); tagTreeView.TreeViewNodeSorter = null; //Open using (OpenFileDialog openDlg = new OpenFileDialog()) { openDlg.Filter = "Halo Map Files (*.map)|*.map"; if (openDlg.ShowDialog() == DialogResult.OK) { //Close Map.Close(); Map.Dispose(); //Load Map.Load(openDlg.FileName); } } //Loop foreach (IndexEntry entry in Map.IndexEntries) { //Setup currentCollection = tagTreeView.Nodes; parts = $"{entry.Filename}.{entry.Root}".Split('\\'); for (int i = 0; i < parts.Length - 1; i++) { if (!currentCollection.ContainsKey(parts[i])) { currentNode = currentCollection.Add(parts[i], parts[i]); } else { currentNode = currentCollection[parts[i]]; } currentCollection = currentNode.Nodes; } currentNode = currentCollection.Add(parts.Last(), parts.Last()); currentNode.Tag = entry; } //End tagTreeView.TreeViewNodeSorter = null; tagTreeView.Sort(); tagTreeView.EndUpdate(); }
/// <summary> /// Used internally to deeply copy the SettingsDocument. /// </summary> /// <param name="settingsCollection">The current settings collection.</param> /// <param name="treeCollection">The current tree node collection.</param> private void CopySettingsToTree(SettingsNodeList settingsCollection, TreeNodeCollection treeCollection) { if (settingsCollection == null) { return; } List <TreeNode> validTreeNodes = new List <TreeNode>(); List <TreeNode> invalidTreeNodes = new List <TreeNode>(); for (int i = 0; i < settingsCollection.Count; i++) { if (settingsCollection[i] != null) { string nodeName = settingsCollection[i].Name; TreeNode treeNode = null; if (!treeCollection.ContainsKey(nodeName)) { treeNode = new TreeNode(nodeName); treeNode.Name = nodeName; treeNode.Tag = settingsCollection[i]; treeCollection.Add(treeNode); } else { treeNode = treeCollection[nodeName]; treeNode.Tag = settingsCollection[i]; } if (treeNode.Text != treeNode.Name) { treeNode.Text = treeNode.Name; } validTreeNodes.Add(treeNode); CopySettingsToTree(settingsCollection[i].Nodes, treeNode.Nodes); } } foreach (TreeNode node in treeCollection) { if (!validTreeNodes.Contains(node)) { invalidTreeNodes.Add(node); } } foreach (TreeNode node in invalidTreeNodes) { treeCollection.Remove(node); } }
private void populateTreeControl(XmlNode document, TreeNodeCollection nodes) { // Dictionary<string, TreeNode> aNodeNames = new Dictionary<string, TreeNode>(); foreach (System.Xml.XmlNode node in document.ChildNodes) { string text = node.Name; if (text == cstrExtraWhitespace) { continue; } text = String.Format(cstrElementFormat, text); if (node.Value != null) { text += String.Format(" = [{0}]", node.Value); } TreeNode thisBranch = null; string strPrefix = String.IsNullOrEmpty(node.Prefix) ? cstrDefaultNameSpaceAbrev : node.Prefix; if (!nodes.ContainsKey(node.Name)) { thisBranch = nodes.Add(node.Name, text); // do it once thisBranch.Tag = strPrefix; if (!m_mapPrefix2NamespaceURI.ContainsKey(strPrefix) && !String.IsNullOrEmpty(node.NamespaceURI)) { m_mapPrefix2NamespaceURI.Add(strPrefix, node.NamespaceURI); } } else { thisBranch = nodes[node.Name]; System.Diagnostics.Debug.Assert(strPrefix == (string)thisBranch.Tag); } // if there are any attributes for this branch/node, then put them in as children if ((node.Attributes != null) && (node.Attributes.Count > 0)) { foreach (XmlAttribute attr in node.Attributes) { TreeNodeCollection tc = thisBranch.Nodes; if (!tc.ContainsKey(attr.Name)) { int nNumAttrs = GetAttrCount(tc); string strAttrKeyValue = String.Format("{0}[{1}] = [{2}] ", cstrAttributeLabel, attr.Name, attr.Value); TreeNode newAttr = thisBranch.Nodes.Insert(nNumAttrs, attr.Name, strAttrKeyValue); } } } // iterate to the children of thisBranch populateTreeControl(node, thisBranch.Nodes); } }
public TreeNode FindNode(TreeNodeCollection nodes, string key) { if (nodes.ContainsKey(key)) { return(nodes[key]); } else { return(null); } }
public void LoadFiles(string folder, string type, string race) { string[] files = Directory.GetFiles(folder); foreach (string f in files) { string Race = race; if (f.EndsWith(".lua") || f.EndsWith(".nil")) { string fileName = f.Remove(0, folder.Length + 1); if (Race == null || Race == "") { Race = DataDumper.GetRace(fileName); } if (Race == "none") { continue; } TreeNodeCollection t1 = this.treeView1.Nodes; string subs = ""; switch (type) { case "Unit": subs = "Squads"; break; case "Building": subs = "Buildings"; break; } TreeNode t1_sub = t1.Find(subs, false)[0]; foreach (TreeNode node in t1_sub.Nodes) { if (node.Text == Race) { TreeNodeCollection t1_sub_race = node.Nodes; TreeNode newNode = new TreeNode(fileName); newNode.Name = fileName; if (!t1_sub_race.ContainsKey(newNode.Name)) { t1_sub_race.Add(newNode); } break; } } } } }
public void refreshUI() { ProjectManager pm = ProjectManager.GetInstance(); treeView1.Nodes.Clear(); results = new List <ResultItem>(); treeView1.Nodes.Add("Motor"); parseMotorDerivedParams("Motor"); treeView1.Nodes.Add("Static"); AbstractAnalyticalAnalyser aa = pm.analyticalAnalyser; AbstractStaticAnalyser sa = pm.staticAnalyser; parseComparisonResults("Static", aa == null ? null : aa.getResults(), sa == null ? null : sa.getResults()); foreach (String name in pm.GetAnalysisResultsNames()) { // add nodes to treeview of results String[] ss = name.Split('.', '\\'); TreeNodeCollection nodes = treeView1.Nodes;//first lv collection nodes for (int i = 0; i < ss.Length; i++) { if (nodes.ContainsKey(ss[i])) { nodes = treeView1.Nodes[ss[i]].Nodes;//get next level nodes collections } else { nodes = nodes.Add(ss[i], ss[i]).Nodes;//add ss[i] to itself and get its collection (of couse empty) } } // now parse the results data object result = pm.GetAnalysisResults(name); if (result == null) { continue; } if (result is AbstractFEMResults) { parseResults(name, (AbstractFEMResults)result); } } treeView1.ExpandAll(); showResultsInDGV(currentPath); }
public void SelectPath(string path) { try { if (!(File.Exists(path) || Directory.Exists(path))) { return; } tre_Explorer.Select(); if (tre_Explorer.SelectedNode != null) { if (tre_Explorer.SelectedNode.Tag is DirectoryInfo) { if ((tre_Explorer.SelectedNode.Tag as DirectoryInfo).FullName.Equals(path)) { return; } } if (tre_Explorer.SelectedNode.Tag is FileInfo) { if ((tre_Explorer.SelectedNode.Tag as FileInfo).FullName.Equals(path)) { return; } } } TreeNodeCollection nodeRoots = tre_Explorer.Nodes[0].Nodes; foreach (string name in path.Split('\\')) { if (nodeRoots.ContainsKey(name.ToUpper())) { tre_Explorer.SelectedNode = nodeRoots[name.ToUpper()]; nodeRoots = nodeRoots[name.ToUpper()].Nodes; tre_Explorer.SelectedNode.EnsureVisible(); continue; } foreach (TreeNode node in nodeRoots) { tre_Explorer.SelectedNode = node; if (node.Nodes.ContainsKey(name.ToUpper())) { tre_Explorer.SelectedNode = node.Nodes[name.ToUpper()]; nodeRoots = node.Nodes[name.ToUpper()].Nodes; break; } } } }catch (Exception ex) { } }
private static void addCategoryToTreeNodeCollection(String sCategoryText, String sCategoryName, ref TreeNodeCollection tncTargetTreeNodeCollection, Object oTreeNodeTag) { if (sCategoryName == "") { return; } if (false == tncTargetTreeNodeCollection.ContainsKey(sCategoryName)) { tncTargetTreeNodeCollection.Add(O2Forms.newTreeNode(sCategoryText, sCategoryName, 1, oTreeNodeTag)); } tncTargetTreeNodeCollection = tncTargetTreeNodeCollection[sCategoryName].Nodes; }
public String FindAvailableName(TreeNode parent, String name) { TreeNodeCollection nodes = GetParentNodes(parent); if (!nodes.ContainsKey(name)) { return(name); } String duplicatedName = null; bool foundNewName = false; for (int i = 2; !foundNewName; i++) { duplicatedName = name + " (" + i + ")"; if (!nodes.ContainsKey(duplicatedName)) { foundNewName = true; } } return(duplicatedName); }
private static TreeNode GetOrCreateNode(TreeNodeCollection parentNodes, string key) { TreeNode node = null; if (parentNodes.ContainsKey(key)) { node = parentNodes[key]; } else { node = parentNodes.Add(key, key); } return(node); }
static public TreeNode GetFileTreeNodeByPath(this TreeView trv, string path, bool lastIsFile = true) { string[] elements = path.Split('\\'); TreeNodeCollection current = trv.Nodes; TreeNode currentNode = null; int k = elements.Length; if (lastIsFile) { k--; } string key; for (int i = 0; i < k; i++) { key = 'D' + elements[i]; if (current.ContainsKey(key)) { currentNode = current[key]; current = currentNode.Nodes; } else { return(null); } } if (!lastIsFile) { return(currentNode); } key = 'F' + elements[elements.Length - 1]; if (current.ContainsKey(key)) { return(current[key]); } return(null); }