/// <summary> /// Adds a virtual file system item to the tree view. /// </summary> /// <param name="p_tndRoot">The node to which to add the new item.</param> /// <param name="p_strName">The name of the new virtual item to add.</param> /// <returns>The new tree node representing the new virtual file system item.</returns> public FileSystemTreeNode AddVirtualNode(FileSystemTreeNode p_tndRoot, string p_strName) { if ((p_tndRoot != null) && !p_tndRoot.IsDirectory) { return(AddVirtualNode(p_tndRoot.Parent, p_strName)); } FileSystemTreeNode tndFile = null; System.Windows.Forms.TreeNodeCollection tncSiblings = (p_tndRoot == null) ? this.Nodes : p_tndRoot.Nodes; if (!tncSiblings.ContainsKey(p_strName)) { tndFile = (FileSystemTreeNode)tncSiblings[p_strName]; } else { string strName = Path.GetFileName(p_strName); if (String.IsNullOrEmpty(strName)) { strName = p_strName; } tndFile = new FileSystemTreeNode(strName, null); tndFile.Name = p_strName; tncSiblings.Add(tndFile); OnNodeAdded(new NodesChangedEventArgs(tndFile)); } return(tndFile); }
static void CheckNodeIfPathExists(TreeNodeCollection nodes, string path) { var parts = path.Split(new[]{'\\'}, 2); var key = parts[0]; if (!nodes.ContainsKey(key)) return; if (parts.Length == 1) nodes[key].Checked = true; else { nodes[key].Expand(); CheckNodeIfPathExists(nodes[key].Nodes, parts[1]); } }
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 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; }
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); } }
private void checkNodeIfPathExists(TreeNodeCollection nodes, string path) { var parts = path.Split(new char[] { '\\' }, 2); var key = parts[0]; if (nodes.ContainsKey(key)) { if (parts.Length == 1) { nodes[key].Checked = true; } else { nodes[key].Expand(); checkNodeIfPathExists(nodes[key].Nodes, parts[1]); } } }
private void FillSubNodes(TreeNodeCollection nodes, PropertyInfo fileInfo) { // Удаляем из полного пути путь к указанной директории для перебора поддиректорий var nameDirs = fileInfo.FullName.Remove(0, _workDirLength).TrimStart('\\', '/').Split('\\', '/'); if (string.IsNullOrEmpty(nameDirs[0])) { // Игнорируем дерикторию указанную для перебора поддиректорий return; } foreach (var name in nameDirs) { // Если в коллекции узлов нет указанного узла, то добавляем if (!nodes.ContainsKey(name)) { var indexImg = fileInfo.IsFile ? 2 : 0; var indexSelectImg = fileInfo.IsFile ? 3 : 1; TreeNode node = new TreeNode(name, indexImg, indexSelectImg) { Name = name, Tag = fileInfo }; nodes.Add(node); } else // иначе - переходим на дочерний уровень { nodes = nodes[name].Nodes; } } }
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; }
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; }
TreeNode GetNode(string key, TreeNodeCollection nodes) { TreeNode n = null; if (nodes.ContainsKey(key)) n = nodes[key]; else { foreach (TreeNode tn in nodes) { n = GetNode(key, tn.Nodes); if (n != null) break; } } return n; }
private void CreateNodes(TreeNodeCollection treeNodeCollection, string[] parts, int index, ref string parent) { if (!treeNodeCollection.ContainsKey(parts[index])) { string extension = Path.GetExtension(parts[index]); ResourceTreeNode node; switch (extension) { case "": node = new FolderTreeNode(); node.Text = Path.ChangeExtension(parts[index], null); node.Name = parts[index]; string path = string.Empty; for (int i = 0; i <= index; i++) path = Path.Combine(path, parts[i]); node.Path = Path.Combine(parent, path); treeNodeCollection.Add(node); break; case Sunfish.Tag.Path.Extension: node = new ClassTreeNode(); node.Text = Path.ChangeExtension(parts[index], null); node.Name = parts[index]; path = string.Empty; foreach (string s in parts) path = Path.Combine(path, s); node.Path = Path.Combine(parent, path); treeNodeCollection.Add(node); break; } } if (parts.Length > index + 1) CreateNodes(treeNodeCollection[treeNodeCollection.IndexOfKey(parts[index])].Nodes, parts, index + 1, ref parent); }
public TreeNode FindNode(TreeNodeCollection nodes, string key) { if (nodes.ContainsKey(key)) return nodes[key]; else return null; }
/// <summary> /// This adds a file/folder to the source file structure. /// </summary> /// <param name="p_tndRoot">The node to which to add the file/folder.</param> /// <param name="p_strFile">The path to add to the source file structure.</param> public FileSystemTreeNode AddPath(FileSystemTreeNode p_tndRoot, string p_strFile) { if ((p_tndRoot != null) && !p_tndRoot.IsDirectory && (!BrowseIntoArchives || !p_tndRoot.IsArchive)) { return(AddPath(p_tndRoot.Parent, p_strFile)); } Cursor crsOldCursor = Cursor; Cursor = Cursors.WaitCursor; try { if (!Archive.IsArchivePath(p_strFile)) { FileSystemInfo fsiInfo = null; if (Directory.Exists(p_strFile)) { fsiInfo = new DirectoryInfo(p_strFile); } else if (ShowFiles && File.Exists(p_strFile) && !".lnk".Equals(Path.GetExtension(p_strFile), StringComparison.OrdinalIgnoreCase)) { fsiInfo = new FileInfo(p_strFile); } else { return(null); } if (!FileUtil.IsDrivePath(p_strFile) && ((fsiInfo.Attributes & FileAttributes.System) > 0)) { return(null); } } FileSystemTreeNode tndFile = null; System.Windows.Forms.TreeNodeCollection tncSiblings = (p_tndRoot == null) ? this.Nodes : p_tndRoot.Nodes; string strName = Path.GetFileName(p_strFile); if (String.IsNullOrEmpty(strName)) { strName = p_strFile; } if (tncSiblings.ContainsKey(strName)) { tndFile = (FileSystemTreeNode)tncSiblings[strName]; tndFile.AddSource(p_strFile, false); } else { tndFile = new FileSystemTreeNode(strName, p_strFile); tndFile.Name = strName; tncSiblings.Add(tndFile); OnNodeAdded(new NodesChangedEventArgs(tndFile)); } SetNodeImage(tndFile); if (tndFile.IsDirectory) { if (ShouldLoadChildren(tndFile)) { LoadChildren(tndFile); } } else { if (BrowseIntoArchives && tndFile.IsArchive) { if (ShouldLoadChildren(tndFile)) { LoadChildren(tndFile); } } else { tndFile.Sources[p_strFile].IsLoaded = true; } } return(tndFile); } finally { Cursor = crsOldCursor; } }