Exemplo n.º 1
0
        // This method adds all images to expanded node
        // And since node already contains it's subfolders, it adds subfolders to subfolders
        //public void ExpandNode(string name)
        //{
        //    TreeBranch ExpandedNode = null;
        //    foreach (var drive in Children)
        //    {
        //        ExpandedNode = drive.Find(name, true) as TreeBranch;
        //        if (ExpandedNode != null)
        //            break;
        //    }

        //    AddImagesTo(ExpandedNode);
        //    foreach (TreeBranch child in ExpandedNode.Children)
        //        AddFoldersTo(child);
        //}

        // This method adds all images to expanded node
        // And since node already contains it's subfolders, it adds subfolders to subfolders
        public void ExpandNode(TreeBranch argBranch)
        {
            foreach (TreeItem child in argBranch.Children)
            {
                if (child is TreeBranch)
                {
                    AddImagesTo(child as TreeBranch);
                    AddFoldersTo(child as TreeBranch);
                }
            }
        }
Exemplo n.º 2
0
 // In constructor:
 // Create branch for each found drive and add it to root
 // Create branch for each folder in each drive and add them to corresponding drives
 public LocalTree()
 {
     Children = new List <TreeBranch>();
     string[] drives = Directory.GetLogicalDrives();
     foreach (var d in drives)
     {
         TreeBranch Drive = new TreeBranch(d, d, this);
         Children.Add(Drive);
         AddFoldersTo(Drive);
         AddImagesTo(Drive);
     }
 }
Exemplo n.º 3
0
 // Method finding all subfolders in corresponing folder of given TreeBranch and adding them as new TreeBranch
 private void AddFoldersTo(TreeBranch root)
 {
     try
     {
         string[] folders = Directory.GetDirectories(root.Fullpath);
         foreach (var f in folders)
         {
             if (root.Children.Find(x => x.Fullpath == f) == null)
             {
                 root.Children.Add(new TreeBranch(Path.GetFileName(f), f, this));
             }
         }
     }
     catch (UnauthorizedAccessException) { }
 }
        private TreeBranchViewModel(TreeBranch branch, TreeBranchViewModel parent, iTreeViewModel governor)
            : base(branch, parent, governor)
        {
            _modelBranch = branch;

            Children = new ObservableCollection <TreeItemViewModel>();
            foreach (var child in _modelBranch.Children)
            {
                if (child is TreeBranch)
                {
                    Children.Add(new TreeBranchViewModel(child as TreeBranch, _governor));
                }
                else if (child is TreeLeaf)
                {
                    Children.Add(new TreeLeafViewModel(child as TreeLeaf, _governor));
                }
            }
        }
Exemplo n.º 5
0
        // Method to find first occurence of TreeItem with given name
        // Second parameter define will children be searched or not
        public TreeItem Find(string name, bool searchChildren)
        {
            TreeItem found = Children.Find(x => x.Name == name);

            if (found == null && searchChildren)
            {
                foreach (var child in Children)
                {
                    if (child is TreeBranch)
                    {
                        TreeBranch childBranch = child as TreeBranch;
                        childBranch.Find(name, searchChildren);
                    }
                }
            }

            return(found);
        }
Exemplo n.º 6
0
 // Method finding all images in corresponing folder of given TreeBranch and adding them as new TreeLeaf
 private void AddImagesTo(TreeBranch root)
 {
     try
     {
         string[] files = Directory.GetFiles(root.Fullpath);
         foreach (var f in files)
         {
             if (Path.GetExtension(f) != ".png" &&
                 Path.GetExtension(f) != ".gif" &&
                 Path.GetExtension(f) != ".jpg" &&
                 Path.GetExtension(f) != ".bmp" &&
                 Path.GetExtension(f) != ".jpeg")
             {
                 continue;
             }
             if (root.Children.Find(x => x.Fullpath == f) == null)
             {
                 root.Children.Add(new TreeLeaf(Path.GetFileName(f), f, this));
             }
         }
     }
     catch (UnauthorizedAccessException) { }
 }
Exemplo n.º 7
0
 private void ExpanderInstance_NodeExpanded(TreeBranch argBranch)
 {
     ExpandNode(argBranch);
 }
 public TreeBranchViewModel(TreeBranch branch, iTreeViewModel governor)
     : this(branch, null, governor)
 {
 }