private string BuildDrivesTreeView() { DrivesTreeView.BeginUpdate(); // Store all the bookmark nodes var bookmarks = new List <TreeNode>(); if (DrivesTreeView.Nodes.Count > 0) { foreach (TreeNode node in DrivesTreeView.Nodes[0].Nodes) { if (node.Tag is BookmarkTag) { bookmarks.Add(node); } } DrivesTreeView.Nodes.Clear(); } TreeNode root = DrivesTreeView.Nodes.Add("Computer"); root.Tag = new RootTag(); root.ImageIndex = m_iconListManager.AddStockIcon(StockIconID.DesktopPC); string firstReadyDrivePath = null; foreach (var drive in DriveInfo.GetDrives()) { if (drive.IsReady) { firstReadyDrivePath = firstReadyDrivePath ?? drive.RootDirectory.FullName; AddDriveToTree(root, drive); } } // Add the recycle bin /* * int recycleBinIconIndex = m_iconListManager.AddStockIcon(StockIconID.Recycler); * * root.Nodes.Add(new TreeNode($"Recycle Bin", recycleBinIconIndex, recycleBinIconIndex) * { * Tag = new RecycleBinTag() * }); */ // Re-add the bookmarks foreach (var bookmark in bookmarks) { root.Nodes.Add(bookmark); } root.Expand(); DrivesTreeView.EndUpdate(); return(firstReadyDrivePath); }
private string BuildDrivesTreeView() { DrivesTreeView.BeginUpdate(); TreeNode root = DrivesTreeView.Nodes.Add("Computer"); root.ImageIndex = m_iconListManager.AddStockIcon(StockIconID.DesktopPC); string firstReadyDrivePath = null; foreach (var drive in DriveInfo.GetDrives()) { if (drive.IsReady) { firstReadyDrivePath = firstReadyDrivePath ?? drive.RootDirectory.FullName; AddDriveToTree(root, drive); } } root.Expand(); DrivesTreeView.EndUpdate(); return(firstReadyDrivePath); }
private void UpdateDrivesTreeView() { // Refresh if files have been deleted or added. Dictionary <string, TreeNode> drivesInView = new Dictionary <string, TreeNode>(); List <DriveInfo> drivesToAdd = new List <DriveInfo>(); // Build up a list of items in the view // Then run through all of the drives nulling out the items that we find // Anything left in the list of view items must have been deleted foreach (TreeNode node in DrivesTreeView.Nodes[0].Nodes) { if (node.Tag is LazyDirectoryTag) { drivesInView.Add((node.Tag as LazyDirectoryTag).Path.ToLower(), node); } else if (node.Tag is DirectoryTag) { drivesInView.Add((node.Tag as DirectoryTag).Path.ToLower(), node); } } foreach (var drive in DriveInfo.GetDrives()) { if (drive.IsReady) { string key = drive.RootDirectory.FullName.ToLower(); if (!drivesInView.ContainsKey(key)) { // New directory to add drivesToAdd.Add(drive); } else { // Mark as still present on disk by setting the ListViewItem to null drivesInView[key] = null; } } } // Find all of the items that have been deleted List <TreeNode> itemsToDelete = drivesInView.Where(x => x.Value != null).Select(x => x.Value).ToList(); DrivesTreeView.BeginUpdate(); DrivesTreeView.SuspendLayout(); foreach (TreeNode item in itemsToDelete) { item.Remove(); } foreach (var drive in drivesToAdd) { AddDriveToTree(DrivesTreeView.Nodes[0], drive); } DrivesTreeView.EndUpdate(); DrivesTreeView.ResumeLayout(); }
private void DrivesTreeView_MouseClick(object sender, MouseEventArgs e) { TreeViewHitTestInfo info = DrivesTreeView.HitTest(e.X, e.Y); if (info.Node != null) { if (e.Button == MouseButtons.Left) { // If the selection is different we'll call the event handler anyway. Only need // to force the event handler call if the node is the same as the currently selected one. if (DrivesTreeView.SelectedNode == info.Node) { DrivesTreeView_AfterSelect(sender, new TreeViewEventArgs(info.Node)); } } else { m_preventDirectoryChangeEventOnTreeNodeSelect = true; DrivesTreeView.SelectedNode = info.Node; m_preventDirectoryChangeEventOnTreeNodeSelect = false; } } }