private void AddFolder_Click(object sender, RoutedEventArgs e) { AddTreeFolderDialog dialog = new AddTreeFolderDialog(); if (dialog.ShowDialog().GetValueOrDefault(false)) { TreeViewItem selectedItem = root; if (treeView.SelectedItem != null) { selectedItem = (TreeViewItem)treeView.SelectedItem; } ArchiveProjectEntry entry = new ArchiveProjectEntry { Name = dialog.FolderName }; ((ArchiveProjectEntry)selectedItem.Header).AddChild(entry); TreeViewItem item = new TreeViewItem() { Header = entry }; selectedItem.Items.Add(item); selectedItem.IsExpanded = true; } }
public ArchiveProject() { Root = new ArchiveProjectEntry { Name = "Root" }; }
private void BuildParents(ArchiveProjectEntry entry) { foreach (var child in entry.Children) { child.Parent = entry; BuildParents(child); } }
public void RemoveChild(ArchiveProjectEntry entry) { if (Children.Contains(entry)) { Children.Remove(entry); entry.Parent = null; } }
private void RecursiveFileCapture(ICollection <ArchiveProjectEntry> entries, ArchiveProjectEntry curEntry) { if (curEntry.IsFile) { entries.Add(curEntry); } curEntry.Children.ForEach(child => RecursiveFileCapture(entries, child)); }
private void AddTreeNode(TreeViewItem parent, ArchiveProjectEntry entry) { TreeViewItem node = new TreeViewItem() { Header = entry }; parent.Items.Add(node); entry.Children.ForEach(child => AddTreeNode(node, child)); }
private void TreeViewItem_MouseDoubleClick(object sender, MouseButtonEventArgs e) { if (treeView.SelectedItem != null && treeView.SelectedItem != root) { TreeViewItem item = treeView.SelectedItem as TreeViewItem; AddTreeFolderDialog dialog = new AddTreeFolderDialog { FolderName = item.Header.ToString() }; if (dialog.ShowDialog().GetValueOrDefault(false)) { ArchiveProjectEntry entry = item.Header as ArchiveProjectEntry; entry.Name = dialog.FolderName; // HACK: Must force the Header to change in order for the text to // display correctly in the TreeView. item.Header = null; item.Header = entry; } } }
private void AddNode_Click(object sender, RoutedEventArgs e) { OpenFileDialog dialog = new OpenFileDialog { Title = Resource.add_node_dialog_title, Filter = "All files (*.*)|*.*" }; if (dialog.ShowDialog().GetValueOrDefault(false)) { if (Directory.Exists(dialog.FileName)) { Console.WriteLine(string.Format("{0} is a directory and not a file.", dialog.FileName)); return; } TreeViewItem selectedItem = root; if (treeView.SelectedItem != null) { selectedItem = treeView.SelectedItem as TreeViewItem; } ArchiveProjectEntry entry = new ArchiveProjectEntry { Name = dialog.SafeFileName, Path = dialog.FileName, IsFile = true }; ((ArchiveProjectEntry)selectedItem.Header).AddChild(entry); TreeViewItem item = new TreeViewItem() { Header = entry }; selectedItem.Items.Add(item); selectedItem.IsExpanded = true; } }
private void RemoveNode_Click(object sender, RoutedEventArgs e) { if (treeView.SelectedItem != null) { TreeViewItem selectedItem = treeView.SelectedItem as TreeViewItem; ArchiveProjectEntry entry = selectedItem.Header as ArchiveProjectEntry; if (entry.Parent != null) { entry.Parent.RemoveChild(entry); } else { archiveProject.Root.RemoveChild(entry); } selectedItem.Items.Clear(); if (selectedItem != root) { RecursiveRemoveNode(root, selectedItem); } } }
public void AddChild(ArchiveProjectEntry entry) { entry.Parent = this; Children.Add(entry); }