コード例 #1
0
        private void RefreshFileTree()
        {
            // Unregisters nodes
            foreach (TreeViewItem node in TreeView_Archive.Items)
            {
                UnregisterNode(node);
            }

            TreeView_Archive.Items.Clear();

            if (manager.Index == null || manager.Definition == null)
            {
                return;
            }

            TreeViewItem root = new TreeViewItem();

            root.Header = manager.Definition.PackageName;
            root.Tag    = manager;
            root.Name   = "_";
            TreeView_Archive.RegisterName("_", root);
            //root.ContextMenu = TreeView_Archive.Resources["CM_Directory"] as ContextMenu;

            TreeViewItem tn = root;

            foreach (Index2Entry entry in manager.Index.Entries)
            {
                tn = root;
                string   currentPath = "";
                string[] splitNames  = ToFilePath(entry).Split('/');

                for (int i = 0; i < splitNames.Length; i++)
                {
                    currentPath += splitNames[i];
                    if (i == (splitNames.Length - 1))
                    {
                        // File entry
                        tn = AddNode(tn, currentPath, splitNames[i], false, entry);
                    }
                    else
                    {
                        // Folder entry
                        currentPath += "/";
                        tn           = AddNode(tn, currentPath, splitNames[i], true, entry);
                    }
                }
            }

            root.Items.SortDescriptions.Clear();
            root.Items.SortDescriptions.Add(new SortDescription("Name", System.ComponentModel.ListSortDirection.Ascending));
            //root.Items.Refresh();

            // Sorts nodes
            foreach (TreeViewItem node in root.Items)
            {
                SortNode(node);
            }

            TreeView_Archive.Items.Add(root);
        }
コード例 #2
0
        private void UnregisterNode(TreeViewItem parent)
        {
            foreach (TreeViewItem child in parent.Items)
            {
                UnregisterNode(child);
            }

            // Unregisters name
            TreeView_Archive.UnregisterName(parent.Name);
        }
コード例 #3
0
        private TreeViewItem AddNode(TreeViewItem parent, string currentPath, string text, bool folder, Index2Entry entry)
        {
            //node.Items.Cast<TreeViewItem>().
            string key    = CreateKey(currentPath, folder);
            object needle = TreeView_Archive.FindName(key);

            if (needle != null)
            {
                return(needle as TreeViewItem);
            }
            else
            {
                //TreeFileEntry temp = new TreeFileEntry();
                TreeViewItem child = new TreeViewItem();
                child.Header = text;
                child.Name   = key;

                child.Selected += (sender, e) =>
                {
                    //this.selectedObject = entry;

                    if (!entry.IsZObject())
                    {
                        selectedObject = null;
                        ListView_Catalog.Items.Clear();
                        return;
                    }

                    var zObject = manager[entry.FilePath];
                    if (zObject is Catalog2 catalog2)
                    {
                        ListView_Catalog.ItemsSource = catalog2.Entries;
                    }
                    else
                    {
                        selectedObject = null;
                        ListView_Catalog.ItemsSource = null;
                    }
                };

                //temp.Path = currentPath;
                TreeView_Archive.RegisterName(key, child);

                int returnIdx = parent.Items.Add(child);
                if (!folder)
                {
                    child.Tag = entry;
                }
                SetNodeProperties(child);

                return(parent.Items[returnIdx] as TreeViewItem);
            }
        }