Beispiel #1
0
        private static void GetNodeFromName(INavTreeItem rootNode, string fullPathNames, ref INavTreeItem selectedNode)
        {
            // Just setup a call to GetNodeFromNameLocal to do the work

            // note: to copy or not to copy (pointer, content), all seems ok
            selectedNode = null;

            if ((fullPathNames == null) || (fullPathNames == ""))
            {
                return;
            }

            // make a pathArray.
            // Note now it is not anymore [(drive) (folder)] but [(drive) [(drive) (folder)]]
            string[] separator = new string[] { strSeparator };
            string[] pathArray = fullPathNames.Split(separator, StringSplitOptions.RemoveEmptyEntries);
            if (pathArray.Length == 0)
            {
                return;
            }
            ;

            // Get the node holding the Items
            selectedNode = rootNode;

            int iLevel = 0;

            GetNodeFromNameLocal(ref selectedNode, pathArray, iLevel);
        }
Beispiel #2
0
        // Supporting procedure
        private static void GetNodeFromNameLocal(ref INavTreeItem item, string[] pathArray, int iLevel)
        {
            string name;

            // Check children
            name = pathArray[iLevel];
            INavTreeItem child;
            INavTreeItem selected = null;

            for (int i = 0; (i <= item.Children.Count() - 1) && (selected == null); i++)
            {
                child = item.Children[i];
                if (name == child.FullPathName)
                {
                    selected = child;
                }
            }

            item = selected;

            // If we have a hit, step deeper
            iLevel++;
            if ((iLevel <= pathArray.Length - 1) && (item != null))
            {
                GetNodeFromNameLocal(ref item, pathArray, iLevel);
            }
        }
Beispiel #3
0
        private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            var button = (sender as Button);

            if (button != null)
            {
                INavTreeItem selectedItem = (INavTreeItem)((sender as Button).DataContext);
                SingleTree.SelectedPath = selectedItem.FullPathName;
            }
        }
Beispiel #4
0
        // Procedure used in NavTreeVm. First take snapshot, reconstruct new tree, expand items in snapshot
        public static void ExpandSnapShotItems(List <string> SnapShot, INavTreeItem treeRootItem)
        {
            // try to open all old snapshot nodes
            INavTreeItem Selected = null;

            for (int i = 0; i < SnapShot.Count; i++)
            {
                GetNodeFromName(treeRootItem, SnapShot[i], ref Selected);
                if (Selected != null)
                {
                    Selected.IsExpanded = true;
                }
            }
        }
Beispiel #5
0
        private static void VisitExpandedChildrenAndTakeSnapshot
            (INavTreeItem selectedNode, string currentName, ref List <string> snapShot)
        {
            // If node not expanded we do not refresh/repaint rest of the nodes
            if (selectedNode.IsExpanded)
            {
                string newCurrentName = (currentName == strSeparator) ? selectedNode.FullPathName : currentName + strSeparator + selectedNode.FullPathName;
                snapShot.Add(newCurrentName);
                //Console.WriteLine(selectedNode.FullPathName);

                for (int i = 0; i < selectedNode.Children.Count; i++)
                {
                    VisitExpandedChildrenAndTakeSnapshot(selectedNode.Children[i], newCurrentName, ref snapShot);
                }
            }
        }
Beispiel #6
0
        public override ObservableCollection <INavTreeItem> GetMyChildren()
        {
            ObservableCollection <INavTreeItem> childrenList = new ObservableCollection <INavTreeItem>()
            {
            };


            DriveInfo drive = new DriveInfo(this.FullPathName);

            if (!drive.IsReady)
            {
                return(childrenList);
            }

            DirectoryInfo di = new DirectoryInfo(((DriveInfo)drive).RootDirectory.Name);

            if (!di.Exists)
            {
                return(childrenList);
            }

            foreach (DirectoryInfo dir in di.GetDirectories())
            {
                item1 = new FolderItem();
                item1.FullPathName = FullPathName + "\\" + dir.Name;
                item1.FriendlyName = dir.Name;

                item1.BuildTreeCommand    = new AppBase.DelegateCommand(click);
                item1.IncludeFileChildren = true;// this.IncludeFileChildren;
                childrenList.Add(item1);
                item1.test = item1;
            }

            if (this.IncludeFileChildren)
            {
                foreach (FileInfo file in di.GetFiles())
                {
                    item1 = new FileItem();
                    item1.FullPathName = FullPathName + "\\" + file.Name;
                    item1.FriendlyName = file.Name;
                    childrenList.Add(item1);
                }
            }
            return(childrenList);
        }
Beispiel #7
0
        // Procedure used in Treeviewmodel to expand to current folder
        public static void ExpandCurrentFolder(List <string> CurrentFolder, INavTreeItem treeRootItem)
        {
            // try to open all old snapshot nodes
            INavTreeItem Selected = null;

            for (int i = 0; i < CurrentFolder.Count; i++)
            {
                GetNodeFromName(treeRootItem, CurrentFolder[i], ref Selected);
                if (Selected != null)
                {
                    Selected.IsExpanded = true;
                    if (i == CurrentFolder.Count - 1)
                    {
                        Selected.IsSelected = true;
                    }
                }
            }
        }