Exemplo n.º 1
0
        // Build the base treeview
        private void ExplorerTv_Loaded(object sender, RoutedEventArgs e)
        {
            //create root node "Computer"
            ExplorerTvItem computer = new ExplorerTvItem();

            computer.TV.Header  = "Computer";
            computer.ItemType   = ExplorerTvItem.NodeType.Computer;
            computer.IsExpanded = true;
            ((TreeView)sender).Items.Add(computer);

            //add HDDs to computer treenode
            DriveInfo[] drives = DriveInfo.GetDrives();
            foreach (DriveInfo drive in drives)
            {
                if (drive.DriveType == DriveType.Fixed)
                {
                    ExplorerTvItem hdd = new ExplorerTvItem();
                    hdd.Header   = drive.Name;
                    hdd.Tag      = drive.Name;
                    hdd.ItemType = ExplorerTvItem.NodeType.Hdd;

                    hdd.Items.Add(dummyNode);
                    hdd.Expanded += new RoutedEventHandler(Folder_Expanded);

                    computer.Items.Add(hdd);
                }
            }
        }
Exemplo n.º 2
0
        // store current FilesList to selected TreeView Item
        private void TVItemStoreFiles()
        {
            ExplorerTvItem item = ExplorerTv.SelectedItem as ExplorerTvItem;

            if (NormalMode.IsChecked)
            {
                item.TVItemFiles = new List <ItemDG>();
                foreach (ItemDG items in FilesList)
                {
                    item.TVItemFiles.Add(items);
                }
            }
        }
Exemplo n.º 3
0
        // Get the treeview selected item full path
        private void ExplorerTv_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            try
            {
                // define the new item
                ExplorerTvItem item = (ExplorerTvItem)e.NewValue;
                folderPath = item.Tag.ToString();

                if (NormalMode.IsChecked)
                {
                    // Reset the files list
                    FilesList.Clear();

                    // check if the selected item already contain a file list
                    if (item.TVItemFiles != null)
                    {
                        foreach (ItemDG items in item.TVItemFiles)
                        {
                            FilesList.Add(items);
                        }
                    }
                    else
                    {
                        // create the folder's file list
                        foreach (string s in Directory.GetFiles(folderPath))
                        {
                            string name = System.IO.Path.GetFileNameWithoutExtension(s);
                            string ext  = (System.IO.Path.GetExtension(s)).TrimStart((".").ToCharArray());

                            FilesList.Add(new ItemDG(FilesList.Count + 1, name)
                            {
                                Checked = true, DotExt = ext
                            });
                        }
                    }

                    // fill the Files DG
                    FillFilesDG(0);

                    // Check if the replace textbox text is still valide
                    ReplaceTxtShowWarning();
                }

                //enabled treeview buttons
                else
                {
                    AddFolderBtn.IsEnabled = AddSubFoldersBtn.IsEnabled = true;
                }
            }
            catch (Exception) { }
        }
Exemplo n.º 4
0
        /*private void ExplorerTv_Loaded(object sender, RoutedEventArgs e)
         * {
         *  //add local network computers as root nodes
         *  DirectoryEntry root = new DirectoryEntry("WinNT:");
         *  foreach (DirectoryEntry computers in root.Children)
         *  {
         *      foreach (DirectoryEntry computer in computers.Children)
         *      {
         *          if (computer.Name != "CLEMENT" && computer.Name != "Schema")
         *          {
         *              ExplorerTvItem networkComputer = new ExplorerTvItem();
         *              networkComputer.TV.Header = computer.Name;
         *              networkComputer.ItemType = ExplorerTvItem.NodeType.Computer;
         *              networkComputer.IsExpanded = true;
         *              ((TreeView)sender).Items.Add(networkComputer);
         *
         *              //string _tempstring = @"\\WORKGROUP\" + computer.Name + "\\share";
         *              //Debug.WriteLine(@"\\WORKGROUP\" + computer.Name + "\share");
         *              //var folders = Directory.GetDirectories(@"\\WORKGROUP\" + computer.Name + "\\share");
         *              //foreach (var dir in folders)
         *              //{
         *              //    ExplorerTvItem folder = new ExplorerTvItem();
         *              //    folder.Header = dir.ToString();
         *              //    //folder.Tag = dir.FullName;
         *              //    folder.ItemType = ExplorerTvItem.NodeType.Folder;
         *              //    networkComputer.Items.Add(folder);
         *              //}
         *
         *
         *          }
         *      }
         *  }
         * }*/

        // Dynamically fill the treview
        private void Folder_Expanded(object sender, RoutedEventArgs e)
        {
            ExplorerTvItem item = (ExplorerTvItem)sender;

            if (item.Items.Count == 1 && item.Items[0] == dummyNode)
            {
                item.Items.Clear();
                try
                {
                    // create the unhidden subfolder list
                    var directory = new DirectoryInfo(item.Tag.ToString()).GetDirectories().Where(x => (x.Attributes & FileAttributes.Hidden) == 0);

                    // add the list the the expanded item
                    foreach (var dir in directory)
                    {
                        ExplorerTvItem folder = new ExplorerTvItem();
                        folder.Header   = dir.ToString();
                        folder.Tag      = dir.FullName;
                        folder.ItemType = ExplorerTvItem.NodeType.Folder;
                        item.Items.Add(folder);
                    }

                    // check if folders in the list contains visible subfolders to add them a dummynode
                    foreach (ExplorerTvItem folder in item.Items)
                    {
                        var subDir = new DirectoryInfo(folder.Tag.ToString()).GetDirectories().Where(x => (x.Attributes & FileAttributes.Hidden) == 0);

                        if ((subDir.ToList()).Count > 0)
                        {
                            folder.Items.Add(dummyNode);
                            folder.Expanded += new RoutedEventHandler(Folder_Expanded);
                        }
                    }
                }

                catch (Exception) { }
            }
        }
Exemplo n.º 5
0
        /*private void ExplorerTv_Loaded(object sender, RoutedEventArgs e)
        {
            //add local network computers as root nodes
            DirectoryEntry root = new DirectoryEntry("WinNT:");
            foreach (DirectoryEntry computers in root.Children)
            {
                foreach (DirectoryEntry computer in computers.Children)
                {
                    if (computer.Name != "CLEMENT" && computer.Name != "Schema")
                    {
                        ExplorerTvItem networkComputer = new ExplorerTvItem();
                        networkComputer.TV.Header = computer.Name;
                        networkComputer.ItemType = ExplorerTvItem.NodeType.Computer;
                        networkComputer.IsExpanded = true;
                        ((TreeView)sender).Items.Add(networkComputer);

                        //string _tempstring = @"\\WORKGROUP\" + computer.Name + "\\share";
                        //Debug.WriteLine(@"\\WORKGROUP\" + computer.Name + "\share");
                        //var folders = Directory.GetDirectories(@"\\WORKGROUP\" + computer.Name + "\\share");
                        //foreach (var dir in folders)
                        //{
                        //    ExplorerTvItem folder = new ExplorerTvItem();
                        //    folder.Header = dir.ToString();
                        //    //folder.Tag = dir.FullName;
                        //    folder.ItemType = ExplorerTvItem.NodeType.Folder;
                        //    networkComputer.Items.Add(folder);
                        //}


                    }
                }
            }
        }*/

        // Dynamically fill the treview
        private void Folder_Expanded(object sender, RoutedEventArgs e)
        {
            ExplorerTvItem item = (ExplorerTvItem)sender;

            if (item.Items.Count == 1 && item.Items[0] == dummyNode)
            {
                item.Items.Clear();
                try
                {
                    // create the unhidden subfolder list
                    var directory = new DirectoryInfo(item.Tag.ToString()).GetDirectories().Where(x => (x.Attributes & FileAttributes.Hidden) == 0);

                    // add the list the the expanded item
                    foreach (var dir in directory)
                    {
                        ExplorerTvItem folder = new ExplorerTvItem();
                        folder.Header = dir.ToString();
                        folder.Tag = dir.FullName;
                        folder.ItemType = ExplorerTvItem.NodeType.Folder;
                        item.Items.Add(folder);
                    }

                    // check if folders in the list contains visible subfolders to add them a dummynode
                    foreach (ExplorerTvItem folder in item.Items)
                    {
                        var subDir = new DirectoryInfo(folder.Tag.ToString()).GetDirectories().Where(x => (x.Attributes & FileAttributes.Hidden) == 0);

                        if ((subDir.ToList()).Count > 0)
                        {
                            folder.Items.Add(dummyNode);
                            folder.Expanded += new RoutedEventHandler(Folder_Expanded);
                        }
                    }

                }

                catch (Exception) { }

            }



        }
Exemplo n.º 6
0
        // Build the base treeview 
        private void ExplorerTv_Loaded(object sender, RoutedEventArgs e)
        {
            //create root node "Computer"
            ExplorerTvItem computer = new ExplorerTvItem();
            computer.TV.Header = "Computer";
            computer.ItemType = ExplorerTvItem.NodeType.Computer;
            computer.IsExpanded = true;
            ((TreeView)sender).Items.Add(computer);

            //add HDDs to computer treenode
            DriveInfo[] drives = DriveInfo.GetDrives();
            foreach (DriveInfo drive in drives)
            {
                if (drive.DriveType == DriveType.Fixed)
                {
                    ExplorerTvItem hdd = new ExplorerTvItem();
                    hdd.Header = drive.Name;
                    hdd.Tag = drive.Name;
                    hdd.ItemType = ExplorerTvItem.NodeType.Hdd;

                    hdd.Items.Add(dummyNode);
                    hdd.Expanded += new RoutedEventHandler(Folder_Expanded);

                    computer.Items.Add(hdd);

                }

            }

        }