/// <summary> /// Internally used by the file system watcher entities /// </summary> /// <param name="sParentTreePath"></param> /// <param name="sFullPathToEntry"></param> /// <param name="bIsDirectory"></param> void AddToItem(string sParentTreePath, string sFullPathToEntry, bool bIsDirectory) { var parentItem = GetTreeItemByPath(sParentTreePath, true); // If the item is null, then the entry doesn't exist meaning it is not shown and does not need to be updated if (parentItem != null && parentItem.IsExpanded == true) { var itemToAdd = TreeItemFactory.CreateCustomTreeItemInstance(); // We can safely assume that this is a valid path since only the file system watcher call this method var splitPath = sFullPathToEntry.Split('\\'); itemToAdd.IdentificationName = splitPath[splitPath.Length - 1]; itemToAdd.FullPathToReference = sFullPathToEntry; itemToAdd.IsDirectory = bIsDirectory; if (bIsDirectory) { itemToAdd.Items.Add(CustomTreeItem.CreateNewDummyItem()); } itemToAdd.MakeHeader(); parentItem.Items.Add(itemToAdd); parentItem.RefreshLiveSorting(); parentItem.Items.Refresh(); } }
/// <summary> /// Travels through the tree view and retrieves the first item that matches the path given /// </summary> /// <param name="sPath">Path of the wanted tree view item, separated by backslashes ('\\')</param> /// <param name="bAssumeRoot">If true, first element of the path is assumed to be a root item, meaning it will be searched directly /// inside the TreeView's Item property, else the first item in there is taken and the path will be traveled inside that first item.</param> /// <returns>The item if found, else returns null</returns> public CustomTreeItem GetTreeItemByPath(string sPath, bool bAssumeRoot = false) { var splitPath = sPath.Split('\\'); if (splitPath.Length == 0) { return(null); } CustomTreeItem rootItem = null; if (bAssumeRoot) { foreach (CustomTreeItem item in Items) { if (item.IdentificationName == splitPath[0]) { rootItem = item; break; } } } else { if (Items.Count > 0) { rootItem = Items[0] as CustomTreeItem; } } // If the assumed root doesn't exist the path is invalid if (rootItem == null) { return(null); } // Not neccessary but better for reading CustomTreeItem currentItem = rootItem; for (int i = bAssumeRoot ? 1 : 0; i < splitPath.Length; ++i) { currentItem = currentItem.GetChildByIdentName(splitPath[i]); // If along the way an item can't be found it doesn't exist and therefore the path is invalid if (currentItem == null) { return(null); } } // At this point currentItem is the item we looked for return(currentItem); }
void SearchDirectory() { Items.Clear(); var topLevel = TreeItemFactory.CreateCustomTreeItemInstance(); topLevel.IsDirectory = true; var dirInf = new DirectoryInfo(WatchDir); topLevel.FullPathToReference = WatchDir; topLevel.IdentificationName = dirInf.Name; topLevel.MakeHeader(); topLevel.Items.Add(CustomTreeItem.CreateNewDummyItem()); topLevel.RefreshContextMenu(GlobalContextMenu); Items.Add(topLevel); topLevel.IsExpanded = true; }
public static void ShowThisDialog(CustomTreeItem selectedItem) { if (selectedItem == null) { throw new ArgumentNullException("selectedItem"); } m_selectedItem = selectedItem; var instance = new LinkingDialog(); instance.StartPosition = FormStartPosition.CenterParent; // Buttons for browsing instance.sourceBrowseButton.Text = Properties.Resources.ButtonBrowse; instance.destinationBrowseButton.Text = Properties.Resources.ButtonBrowse; // OK Cancel buttons instance.okButton.Text = Properties.Resources.ButtonOK; instance.cancelButton.Text = Properties.Resources.ButtonCancel; // Browsing destination is the same for both instance.destinationBrowseButton.Click += instance.BrowseDestinationFolder; // Creating the link / junction works the same for both instance.okButton.Click += instance.CreateHardLink; if (selectedItem.IsDirectory) { instance.InitJunctionDialog(); } else { instance.InitHardLinkDialog(); } instance.ShowDialog(); }