示例#1
0
        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;
            }
        }
示例#2
0
 public ArchiveProject()
 {
     Root = new ArchiveProjectEntry
     {
         Name = "Root"
     };
 }
示例#3
0
 private void BuildParents(ArchiveProjectEntry entry)
 {
     foreach (var child in entry.Children)
     {
         child.Parent = entry;
         BuildParents(child);
     }
 }
示例#4
0
 public void RemoveChild(ArchiveProjectEntry entry)
 {
     if (Children.Contains(entry))
     {
         Children.Remove(entry);
         entry.Parent = null;
     }
 }
示例#5
0
        private void RecursiveFileCapture(ICollection <ArchiveProjectEntry> entries, ArchiveProjectEntry curEntry)
        {
            if (curEntry.IsFile)
            {
                entries.Add(curEntry);
            }

            curEntry.Children.ForEach(child => RecursiveFileCapture(entries, child));
        }
示例#6
0
        private void AddTreeNode(TreeViewItem parent, ArchiveProjectEntry entry)
        {
            TreeViewItem node = new TreeViewItem()
            {
                Header = entry
            };

            parent.Items.Add(node);

            entry.Children.ForEach(child => AddTreeNode(node, child));
        }
示例#7
0
        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;
                }
            }
        }
示例#8
0
        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;
            }
        }
示例#9
0
        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);
                }
            }
        }
示例#10
0
 public void AddChild(ArchiveProjectEntry entry)
 {
     entry.Parent = this;
     Children.Add(entry);
 }