public IFileSystemNode GetChild(string path) { var parts = IoHelpers.SplitPath(path); if (children != null && children.TryGetValue(parts[0], out var child)) { if (parts.Length == 1) { return(child); } return(child.GetChild(parts[1])); } return(null); }
internal FileSystemNode GetOrCreateChild([NotNull] string path) { var parts = IoHelpers.SplitPath(path); children = children ?? new ConcurrentDictionary <string, FileSystemNode>(); var child = children.GetOrAdd(parts[0], v => new FileSystemNode() { name = v, parent = this }); if (parts.Length == 1) { return(child); } return(child.GetOrCreateChild(parts[1])); }
public TreeGridNodeViewModel GetChild(string path) { IsExpanded = true; var parts = IoHelpers.SplitPath(path); var child = Children?.Cast <TreeGridNodeViewModel>().FirstOrDefault(n => n.Name == parts[0]); if (child != null) { if (parts.Length == 1) { return(child); } return(child.GetChild(parts[1])); } return(null); }
private void ListViewItem_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { var listViewItem = sender as ListViewItem; if (listViewItem == null) { return; } var topItem = listViewItem.Content as StatisticsItem; if (topItem == null) { return; } var fileNode = ((TreeGridNodeViewModel)TreeGrid.Root).GetChild(IoHelpers.SplitPath(topItem.Path)[1]); if (fileNode == null) { return; } var item = TreeGrid.ItemContainerGenerator.ContainerFromItem(fileNode) as ListViewItem; if (item == null) { return; } TreeGrid.SelectedItems.Clear(); TreeGrid.Focus(); item.Focus(); item.IsSelected = true; Keyboard.Focus(item); TreeGrid.ScrollIntoView(item); }
internal void InsertNode([NotNull] string path, [NotNull] FileSystemNode node) { var parts = IoHelpers.SplitPath(path); if (parts.Length != 2) { return; } var parentNode = GetOrCreateChild(parts[0]); node.name = parts[1]; node.parent = parentNode; parentNode.children.TryAdd(parts[1], node); var t = parentNode; while (t != null) { t.UpdateCounters(node.Size, node.CountDirectories, CountFiles); t = t.parent; } }
internal FileSystemNode RemoveNode([NotNull] string path) { var parts = IoHelpers.SplitPath(path); if (children != null && children.TryGetValue(parts[0], out var child)) { if (parts.Length == 1) { children.TryRemove(parts[0], out child); child.parent = null; return(child); } var deletedNode = child.RemoveNode(parts[1]); if (deletedNode != null) { UpdateCounters(-deletedNode.Size, -deletedNode.CountDirectories, -deletedNode.CountFiles); return(deletedNode); } } return(null); }