示例#1
0
        private void OnFolderTreeViewAfterSelect(object sender, TreeViewEventArgs e)
        {
            FolderTreeItem item = null;

            if (_folderTreeView.SelectedNode != null)
            {
                item = new FolderTreeItem(((FolderTreeNode)_folderTreeView.SelectedNode).Pidl);
            }
            this.SelectedItem = item;
        }
示例#2
0
        private FolderTreeItem ProcessPath(String path, List <FolderTreeItem> parentList, FolderTreeItem parent)
        {
            var idx       = path.IndexOf(Path.DirectorySeparatorChar);
            var directory = idx >= 0 ? path.Substring(0, idx) : path;

            if (!(parentList.FirstOrDefault(item =>
                                            item is FolderTreeItem folder &&
                                            folder.Caption.Equals(directory, StringComparison.InvariantCultureIgnoreCase)) is FolderTreeItem
                  node))
            {
                node = new FolderTreeItem(directory, parent);
                parentList.Add(node);
            }

            if (idx >= 0)
            {
                return(ProcessPath(path.Substring(idx + 1), node.SubFolders, node));
            }

            return(node);
        }
        public override void FetchData()
        {
            // Create root Item
            int depth     = 0;
            var multiRoot = (m_Roots.Count > 1);

            if (multiRoot)
            {
                m_RootItem = new TreeViewItem(-1, depth, null, "Invisible Root Item");
                SetExpanded(m_RootItem, true);
            }
            else
            {
                var rootInstanceID = m_Roots[0].instanceID;
                var displayName    = m_Roots[0].displayName ?? CreateDisplayName(rootInstanceID);
                m_RootItem = new TreeViewItem(rootInstanceID, depth, null, displayName);
                SetExpanded(m_RootItem, true);
            }

            m_Rows = new List <TreeViewItem>(m_Roots.Count * 256);
            Texture2D emptyFolderIcon   = EditorGUIUtility.FindTexture(EditorResources.emptyFolderIconName);
            Texture2D folderIcon        = EditorGUIUtility.FindTexture(EditorResources.folderIconName);
            var       assetsInstanceIDs = AssetDatabase.GetMainAssetOrInProgressProxyInstanceID("Assets");
            var       projectPath       = Path.GetFileName(Directory.GetCurrentDirectory());

            // Fetch root Items
            m_RootsTreeViewItem = new Dictionary <string, TreeViewItem>(m_Roots.Count);
            foreach (var root in m_Roots)
            {
                var rootInstanceID = root.instanceID;
                var displayName    = root.displayName ?? CreateDisplayName(rootInstanceID);
                var rootPath       = root.path ?? AssetDatabase.GetAssetPath(rootInstanceID);

                var property = new HierarchyProperty(rootPath);
                if (!root.skipValidation && !property.Find(rootInstanceID, null))
                {
                    Debug.LogError("Root Asset with id " + rootInstanceID + " not valid!!");
                    continue;
                }

                var          minDepth = property.depth;
                var          subDepth = multiRoot ? 0 : -1;
                TreeViewItem rootItem;
                if (multiRoot)
                {
                    var parentItem = m_RootItem;
                    var rootDepth  = minDepth;
                    rootDepth++;

                    // Find parent treeView item
                    var parentPath = Directory.GetParent(rootPath).Name;
                    if (parentPath != projectPath)
                    {
                        if (!m_RootsTreeViewItem.TryGetValue(parentPath, out parentItem))
                        {
                            Debug.LogError("Cannot find parent for " + rootInstanceID);
                            continue;
                        }

                        rootDepth++;
                        subDepth++;
                    }

                    // Create root item TreeView item
                    if (subDepth > 0)
                    {
                        rootItem = new FolderTreeItem(rootInstanceID, rootDepth, parentItem, displayName);
                    }
                    else
                    {
                        rootItem = new RootTreeItem(rootInstanceID, rootDepth, parentItem, displayName);
                    }
                    rootItem.icon = folderIcon;
                    parentItem.AddChild(rootItem);
                }
                else
                {
                    rootItem = m_RootItem;
                }

                m_RootsTreeViewItem[rootPath] = rootItem;

                var  expandIDs      = GetExpandedIDs();
                var  rows           = new List <TreeViewItem>();
                bool shouldExpandIt = m_ExpandAtFirstTime && (rootItem.id == assetsInstanceIDs);
                if (IsExpanded(rootItem.id) && (rootItem == m_RootItem || IsExpanded(rootItem.parent.id)) || shouldExpandIt)
                {
                    m_ExpandAtFirstTime = false;

                    while (property.NextWithDepthCheck(expandIDs, minDepth))
                    {
                        if (!foldersOnly || property.isFolder)
                        {
                            depth = property.depth - minDepth;
                            TreeViewItem item;
                            if (property.isFolder)
                            {
                                item = new FolderTreeItem(property.instanceID, depth + subDepth, null, property.name);
                            }
                            else
                            {
                                item = new NonFolderTreeItem(property.instanceID, depth + subDepth, null, property.name);
                            }

                            if (property.isFolder && !property.hasChildren)
                            {
                                item.icon = emptyFolderIcon;
                            }
                            else
                            {
                                item.icon = property.icon;
                            }

                            if (property.hasChildren)
                            {
                                item.AddChild(null); // add a dummy child in children list to ensure we show the collapse arrow (because we do not fetch data for collapsed items)
                            }
                            rows.Add(item);
                        }
                    }

                    // Setup reference between child and parent items
                    TreeViewUtility.SetChildParentReferences(rows, rootItem);
                }
                else
                {
                    rootItem.AddChild(null);
                }

                if (shouldExpandIt && !IsExpanded(rootItem))
                {
                    SetExpanded(rootItem, true);
                }

                if (multiRoot && IsExpanded(rootItem.parent.id))
                {
                    m_Rows.Add(rootItem);
                }

                ((List <TreeViewItem>)m_Rows).AddRange(rows);
            }

            if (foldersFirst)
            {
                FoldersFirstRecursive(m_RootItem);
                m_Rows.Clear();
                GetVisibleItemsRecursive(m_RootItem, m_Rows);
            }

            // Must be called before InitSelection (it calls GetVisibleItems)
            m_NeedRefreshRows = false;

            // We want to reset selection on copy/duplication/delete
            bool frameLastSelected = false; // use false because we might just be expanding/collapsing a Item (which would prevent collapsing a Item with a selected child)

            m_TreeView.SetSelection(Selection.instanceIDs, frameLastSelected);
        }
        public override void FetchData()
        {
            int depth = 0;

            base.m_RootItem = new TreeViewItem(this.m_RootInstanceID, depth, null, CreateDisplayName(this.m_RootInstanceID));
            if (!base.showRootNode)
            {
                this.SetExpanded(base.m_RootItem, true);
            }
            IHierarchyProperty property = new HierarchyProperty(HierarchyType.Assets);

            property.Reset();
            if (!property.Find(this.m_RootInstanceID, null))
            {
                Debug.LogError("Root Asset with id " + this.m_RootInstanceID + " not found!!");
            }
            int minDepth = property.depth + (!base.showRootNode ? 1 : 0);

            int[]     expanded = base.expandedIDs.ToArray();
            Texture2D textured = EditorGUIUtility.FindTexture(EditorResourcesUtility.emptyFolderIconName);

            base.m_VisibleRows = new List <TreeViewItem>();
            while (property.NextWithDepthCheck(expanded, minDepth))
            {
                if (!this.foldersOnly || property.isFolder)
                {
                    TreeViewItem item;
                    depth = property.depth - minDepth;
                    if (property.isFolder)
                    {
                        item = new FolderTreeItem(property.instanceID, depth, null, property.name);
                    }
                    else
                    {
                        item = new NonFolderTreeItem(property.instanceID, depth, null, property.name);
                    }
                    if (property.isFolder && !property.hasChildren)
                    {
                        item.icon = textured;
                    }
                    else
                    {
                        item.icon = property.icon;
                    }
                    if (property.hasChildren)
                    {
                        item.AddChild(null);
                    }
                    base.m_VisibleRows.Add(item);
                }
            }
            TreeViewUtility.SetChildParentReferences(base.m_VisibleRows, base.m_RootItem);
            if (this.foldersFirst)
            {
                FoldersFirstRecursive(base.m_RootItem);
                base.m_VisibleRows.Clear();
                base.GetVisibleItemsRecursive(base.m_RootItem, base.m_VisibleRows);
            }
            base.m_NeedRefreshVisibleFolders = false;
            bool revealSelectionAndFrameLastSelected = false;

            base.m_TreeView.SetSelection(Selection.instanceIDs, revealSelectionAndFrameLastSelected);
        }
示例#5
0
        public override void FetchData()
        {
            // Create root Item
            int depth = 0;

            m_RootItem = new TreeViewItem(m_RootInstanceID, depth, null, CreateDisplayName(m_RootInstanceID));
            if (!showRootItem)
            {
                SetExpanded(m_RootItem, true);
            }

            // Find start Item
            var property = new HierarchyProperty(k_HierarchyType, false);

            property.Reset();
            bool found = property.Find(m_RootInstanceID, null);

            if (!found)
            {
                Debug.LogError("Root Asset with id " + m_RootInstanceID + " not found!!");
            }

            int minDepth = property.depth + (showRootItem ? 0 : 1);

            int[]     expanded        = expandedIDs.ToArray();
            Texture2D emptyFolderIcon = EditorGUIUtility.FindTexture(EditorResources.emptyFolderIconName);

            // Fetch visible items
            m_Rows = new List <TreeViewItem>();
            while (property.NextWithDepthCheck(expanded, minDepth))
            {
                if (!foldersOnly || property.isFolder)
                {
                    depth = property.depth - minDepth;
                    TreeViewItem item;
                    if (property.isFolder)
                    {
                        item = new FolderTreeItem(property.instanceID, depth, null, property.name);
                    }
                    else
                    {
                        item = new NonFolderTreeItem(property.instanceID, depth, null, property.name);
                    }

                    if (property.isFolder && !property.hasChildren)
                    {
                        item.icon = emptyFolderIcon;
                    }
                    else
                    {
                        item.icon = property.icon;
                    }

                    if (property.hasChildren)
                    {
                        item.AddChild(null); // add a dummy child in children list to ensure we show the collapse arrow (because we do not fetch data for collapsed items)
                    }
                    m_Rows.Add(item);
                }
            }

            // Setup reference between child and parent items
            TreeViewUtility.SetChildParentReferences(m_Rows, m_RootItem);

            if (foldersFirst)
            {
                FoldersFirstRecursive(m_RootItem);
                m_Rows.Clear();
                GetVisibleItemsRecursive(m_RootItem, m_Rows);
            }

            // Must be called before InitSelection (it calls GetVisibleItems)
            m_NeedRefreshRows = false;

            // We want to reset selection on copy/duplication/delete
            bool frameLastSelected = false; // use false because we might just be expanding/collapsing a Item (which would prevent collapsing a Item with a selected child)

            m_TreeView.SetSelection(Selection.instanceIDs, frameLastSelected);
        }
示例#6
0
		private void OnFolderTreeViewAfterSelect(object sender, TreeViewEventArgs e)
		{
			FolderTreeItem item = null;
			if (_folderTreeView.SelectedNode != null)
			{
				item = new FolderTreeItem(((FolderTreeNode) _folderTreeView.SelectedNode).Pidl);
			}
			this.SelectedItem = item;
		}