示例#1
0
        private static MyTreeViewItem RecursiveSubdirectoriesPrinter(FileSystemInfo analysed, MyTreeViewItem parent = null)
        {
            if ((analysed.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
            {
                MyTreeViewItem toReturn = new MyTreeViewItem();
                if (((DirectoryInfo)analysed).GetFileSystemInfos().Any())
                {
                    foreach (var item in ((DirectoryInfo)analysed).GetFileSystemInfos())
                    {
                        toReturn.Items.Add(RecursiveSubdirectoriesPrinter(item));
                    }
                }
                toReturn.Header   = analysed.Name;
                toReturn.LinkPath = analysed.FullName;
                toReturn.Tag      = "Directory";

                return(toReturn);
            }

            else
            {
                return(new MyTreeViewItem()
                {
                    Header = analysed.Name, LinkPath = analysed.FullName, Tag = "File"
                });
            }
        }
示例#2
0
        //private void AddFile(object sender, RoutedEventArgs e)
        //{
        //    MyTreeViewItem SelectedItem = treeView.SelectedItem as MyTreeViewItem;
        //    string prefix = SelectedItem.LinkPath;

        //    using (SaveFileDialog fdb = new SaveFileDialog())
        //    {
        //        if (fdb.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        //        {
        //            (this.treeView.SelectedItem as MyTreeViewItem).Items.Add(new MyTreeViewItem { Header = System.IO.Path.GetFileName(fdb.FileName), Tag= "File", LinkPath= fdb.FileName });
        //            File.Create(prefix + "\\" + System.IO.Path.GetFileName(fdb.FileName));
        //        }
        //        if (fdb.FileName == string.Empty)
        //        {
        //            System.Windows.MessageBox.Show("No file name given!", "Error", MessageBoxButton.OK);
        //        }
        //    }

        //    treeView.Items.Refresh();
        //}


        private void AddFile(object sender, RoutedEventArgs e)
        {
            MyTreeViewItem SelectedItem = treeView.SelectedItem as MyTreeViewItem;
            string         prefix       = SelectedItem.LinkPath;

            this.AddGrid.Visibility = Visibility.Visible;
        }
示例#3
0
        private void RemoveFile(object sender, RoutedEventArgs e)
        {
            MyTreeViewItem SelectedItem = treeView.SelectedItem as MyTreeViewItem;

            string pathToFile = SelectedItem.LinkPath;

            this.treeView.Items.Remove(SelectedItem);

            File.Delete(pathToFile);
            this.treeView.Items.Refresh();
        }
示例#4
0
 private void CreateFile(object sender, RoutedEventArgs e)
 {
     if (nameInput.Text == string.Empty)
     {
         System.Windows.MessageBox.Show("No file name given!", "Error", MessageBoxButton.OK);
     }
     else
     {
         string         prefix = (this.treeView.SelectedItem as MyTreeViewItem).LinkPath + "\\";
         MyTreeViewItem toAdd  = new MyTreeViewItem {
             Header = nameInput.Text, Tag = "File", LinkPath = prefix + nameInput.Text
         };
         (this.treeView.SelectedItem as MyTreeViewItem).Items.Add(toAdd);
         File.Create(toAdd.LinkPath);
     }
     this.nameInput.Text     = string.Empty;
     this.AddGrid.Visibility = Visibility.Collapsed;
 }