public ProjectBrowserColumnOneTreeViewDataSource(TreeView treeView)
     : base(treeView)
 {
     this.showRootNode      = false;
     this.rootIsCollapsable = false;
     SavedSearchFilters.AddChangeListener(new System.Action(((TreeViewDataSource)this).ReloadData));
 }
Пример #2
0
        protected override void RenameEnded()
        {
            int userData = base.GetRenameOverlay().userData;

            ProjectBrowser.ItemType itemType = ProjectBrowser.GetItemType(userData);
            if (this.m_IsCreatingSavedFilter)
            {
                this.m_IsCreatingSavedFilter = false;
                if (base.GetRenameOverlay().userAcceptedRename)
                {
                    SavedSearchFilters.SetName(userData, base.GetRenameOverlay().name);
                    int[] selectedIDs = new int[] { userData };
                    base.m_TreeView.SetSelection(selectedIDs, true);
                }
                else
                {
                    SavedSearchFilters.RemoveSavedFilter(userData);
                }
            }
            else if (itemType == ProjectBrowser.ItemType.SavedFilter)
            {
                if (base.GetRenameOverlay().userAcceptedRename)
                {
                    SavedSearchFilters.SetName(userData, base.GetRenameOverlay().name);
                }
            }
            else
            {
                base.RenameEnded();
                if (base.GetRenameOverlay().userAcceptedRename)
                {
                    base.m_TreeView.NotifyListenersThatSelectionChanged();
                }
            }
        }
        public override void FetchData()
        {
            this.m_RootItem = new TreeViewItem(int.MaxValue, 0, (TreeViewItem)null, "Invisible Root Item");
            this.SetExpanded(this.m_RootItem, true);
            List <TreeViewItem> treeViewItemList = new List <TreeViewItem>();
            int          folderInstanceId        = ProjectBrowserColumnOneTreeViewDataSource.GetAssetsFolderInstanceID();
            int          depth       = 0;
            string       displayName = "Assets";
            TreeViewItem parent      = new TreeViewItem(folderInstanceId, depth, this.m_RootItem, displayName);

            this.ReadAssetDatabase(parent, depth + 1);
            TreeViewItem treeView = SavedSearchFilters.ConvertToTreeView();

            treeView.parent = this.m_RootItem;
            treeViewItemList.Add(treeView);
            treeViewItemList.Add(parent);
            this.m_RootItem.children = treeViewItemList;
            using (List <TreeViewItem> .Enumerator enumerator = this.m_RootItem.children.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    TreeViewItem current = enumerator.Current;
                    bool         expand  = EditorPrefs.GetBool(ProjectBrowserColumnOneTreeViewDataSource.kProjectBrowserString + current.displayName, true);
                    this.SetExpanded(current, expand);
                }
            }
            this.m_NeedRefreshVisibleFolders = true;
        }
        public override DragAndDropVisualMode DoDrag(TreeViewItem parentItem, TreeViewItem targetItem, bool perform, TreeViewDragging.DropPosition dropPos)
        {
            if (targetItem == null)
            {
                return(DragAndDropVisualMode.None);
            }
            object genericData = DragAndDrop.GetGenericData(ProjectWindowUtil.k_DraggingFavoriteGenericData);

            if (genericData != null)
            {
                int instanceID = (int)genericData;
                if ((targetItem is SearchFilterTreeItem) && (parentItem is SearchFilterTreeItem))
                {
                    bool flag = SavedSearchFilters.CanMoveSavedFilter(instanceID, parentItem.id, targetItem.id, dropPos == TreeViewDragging.DropPosition.Below);
                    if (flag && perform)
                    {
                        SavedSearchFilters.MoveSavedFilter(instanceID, parentItem.id, targetItem.id, dropPos == TreeViewDragging.DropPosition.Below);
                        int[] selectedIDs = new int[] { instanceID };
                        base.m_TreeView.SetSelection(selectedIDs, false);
                        base.m_TreeView.NotifyListenersThatSelectionChanged();
                    }
                    return(!flag ? DragAndDropVisualMode.None : DragAndDropVisualMode.Copy);
                }
                return(DragAndDropVisualMode.None);
            }
            if ((targetItem is SearchFilterTreeItem) && (parentItem is SearchFilterTreeItem))
            {
                string str = DragAndDrop.GetGenericData(ProjectWindowUtil.k_IsFolderGenericData) as string;
                if (str != "isFolder")
                {
                    return(DragAndDropVisualMode.None);
                }
                if (perform)
                {
                    UnityEngine.Object[] objectReferences = DragAndDrop.objectReferences;
                    if (objectReferences.Length > 0)
                    {
                        string assetPath = AssetDatabase.GetAssetPath(objectReferences[0].GetInstanceID());
                        if (!string.IsNullOrEmpty(assetPath))
                        {
                            string       name   = new DirectoryInfo(assetPath).Name;
                            SearchFilter filter = new SearchFilter();
                            filter.folders = new string[] { assetPath };
                            bool  addAsChild       = targetItem == parentItem;
                            float listAreaGridSize = ProjectBrowserColumnOneTreeViewGUI.GetListAreaGridSize();
                            int   num3             = SavedSearchFilters.AddSavedFilterAfterInstanceID(name, filter, listAreaGridSize, targetItem.id, addAsChild);
                            int[] numArray2        = new int[] { num3 };
                            base.m_TreeView.SetSelection(numArray2, false);
                            base.m_TreeView.NotifyListenersThatSelectionChanged();
                        }
                        else
                        {
                            Debug.Log("Could not get asset path from id " + objectReferences[0].GetInstanceID());
                        }
                    }
                }
                return(DragAndDropVisualMode.Copy);
            }
            return(base.DoDrag(parentItem, targetItem, perform, dropPos));
        }
 public override void StartDrag(TreeViewItem draggedItem, List <int> draggedItemIDs)
 {
     if (!SavedSearchFilters.IsSavedFilter(draggedItem.id) || (draggedItem.id != SavedSearchFilters.GetRootInstanceID()))
     {
         ProjectWindowUtil.StartDrag(draggedItem.id, draggedItemIDs);
     }
 }
 public ProjectBrowserColumnOneTreeViewDataSource(TreeViewController treeView, bool skipHidden) : base(treeView)
 {
     showRootItem       = false;
     rootIsCollapsable  = false;
     skipHiddenPackages = skipHidden;
     SavedSearchFilters.AddChangeListener(ReloadData); // We reload on change
 }
 public override bool CanBeParent(TreeViewItem item)
 {
     if (item is SearchFilterTreeItem)
     {
         return(SavedSearchFilters.AllowsHierarchy());
     }
     return(true);
 }
Пример #8
0
        public override DragAndDropVisualMode DoDrag(TreeViewItem parentItem, TreeViewItem targetItem, bool perform, TreeViewDragging.DropPosition dropPos)
        {
            if (targetItem == null)
            {
                return(DragAndDropVisualMode.None);
            }
            object genericData = DragAndDrop.GetGenericData(ProjectWindowUtil.k_DraggingFavoriteGenericData);

            if (genericData != null)
            {
                int instanceID = (int)genericData;
                if (!(targetItem is SearchFilterTreeItem) || !(parentItem is SearchFilterTreeItem))
                {
                    return(DragAndDropVisualMode.None);
                }
                bool flag = SavedSearchFilters.CanMoveSavedFilter(instanceID, parentItem.id, targetItem.id, true);
                if (flag && perform)
                {
                    SavedSearchFilters.MoveSavedFilter(instanceID, parentItem.id, targetItem.id, true);
                }
                return(!flag ? DragAndDropVisualMode.None : DragAndDropVisualMode.Copy);
            }
            if (!(targetItem is SearchFilterTreeItem) || !(parentItem is SearchFilterTreeItem))
            {
                return(base.DoDrag(parentItem, targetItem, perform, dropPos));
            }
            string str = DragAndDrop.GetGenericData(ProjectWindowUtil.k_IsFolderGenericData) as string;

            if (!(str == "isFolder"))
            {
                return(DragAndDropVisualMode.None);
            }
            if (perform)
            {
                UnityEngine.Object[] objectReferences = DragAndDrop.objectReferences;
                if (objectReferences.Length > 0)
                {
                    HierarchyProperty property = new HierarchyProperty(HierarchyType.Assets);
                    if (property.Find(objectReferences[0].GetInstanceID(), null))
                    {
                        SearchFilter filter    = new SearchFilter();
                        string       assetPath = AssetDatabase.GetAssetPath(property.instanceID);
                        if (!string.IsNullOrEmpty(assetPath))
                        {
                            filter.folders = new string[] { assetPath };
                            bool  addAsChild       = targetItem == parentItem;
                            float listAreaGridSize = ProjectBrowserColumnOneTreeViewGUI.GetListAreaGridSize();
                            Selection.activeInstanceID = SavedSearchFilters.AddSavedFilterAfterInstanceID(property.name, filter, listAreaGridSize, targetItem.id, addAsChild);
                        }
                        else
                        {
                            Debug.Log("Could not get asset path from id " + property.name);
                        }
                    }
                }
            }
            return(DragAndDropVisualMode.Copy);
        }
Пример #9
0
        internal virtual void BeginCreateSavedFilter(SearchFilter filter)
        {
            string displayName = "New Saved Search";

            this.m_IsCreatingSavedFilter = true;
            int id = SavedSearchFilters.AddSavedFilter(displayName, filter, GetListAreaGridSize());

            base.m_TreeView.Frame(id, true, false);
            base.m_TreeView.state.renameOverlay.BeginRename(displayName, id, 0f);
        }
Пример #10
0
        internal virtual void BeginCreateSavedFilter(SearchFilter filter)
        {
            string text = "New Saved Search";

            this.m_IsCreatingSavedFilter = true;
            int num = SavedSearchFilters.AddSavedFilter(text, filter, ProjectBrowserColumnOneTreeViewGUI.GetListAreaGridSize());

            this.m_TreeView.Frame(num, true, false);
            this.m_TreeView.state.renameOverlay.BeginRename(text, num, 0f);
        }
        virtual internal void BeginCreateSavedFilter(SearchFilter filter)
        {
            string savedFilterName = "New Saved Search";

            m_IsCreatingSavedFilter = true;
            int instanceID = SavedSearchFilters.AddSavedFilter(savedFilterName, filter, GetListAreaGridSize());

            m_TreeView.Frame(instanceID, true, false);

            // Start naming the asset
            m_TreeView.state.renameOverlay.BeginRename(savedFilterName, instanceID, 0f);
        }
        public override void FetchData()
        {
            m_RootItem = new TreeViewItem(System.Int32.MaxValue, 0, null, "Invisible Root Item");
            SetExpanded(m_RootItem, true); // ensure always visible

            // We want three roots: Favorites, Assets, and Saved Filters
            List <TreeViewItem> visibleRoots = new List <TreeViewItem>();

            // Fetch asset folders
            int          assetsFolderInstanceID = GetAssetsFolderInstanceID();
            int          depth         = 0;
            string       displayName   = "Assets"; //CreateDisplayName (assetsFolderInstanceID);
            TreeViewItem assetRootItem = new TreeViewItem(assetsFolderInstanceID, depth, m_RootItem, displayName);

            ReadAssetDatabase(HierarchyType.Assets, assetRootItem, depth + 1);

            // Fetch packages
            TreeViewItem packagesRootItem = null;

            if (Unsupported.IsDeveloperMode() && EditorPrefs.GetBool("ShowPackagesFolder"))
            {
                var    packagesFolderInstanceID = AssetDatabase.GetMainAssetOrInProgressProxyInstanceID(AssetDatabase.GetPackagesMountPoint());
                string packagesDisplayName      = AssetDatabase.GetPackagesMountPoint();
                packagesRootItem = new TreeViewItem(packagesFolderInstanceID, depth, m_RootItem, packagesDisplayName);
                ReadAssetDatabase(HierarchyType.Packages, packagesRootItem, depth + 1);
            }

            // Fetch saved filters
            TreeViewItem savedFiltersRootItem = SavedSearchFilters.ConvertToTreeView();

            savedFiltersRootItem.parent = m_RootItem;

            // Order
            visibleRoots.Add(savedFiltersRootItem);
            visibleRoots.Add(assetRootItem);

            if (packagesRootItem != null)
            {
                visibleRoots.Add(packagesRootItem);
            }

            m_RootItem.children = visibleRoots;

            // Get global expanded state of roots
            foreach (TreeViewItem item in m_RootItem.children)
            {
                bool expanded = EditorPrefs.GetBool(kProjectBrowserString + item.displayName, true);
                SetExpanded(item, expanded);
            }

            m_NeedRefreshRows = true;
        }
        public override void StartDrag(TreeViewItem draggedItem, List <int> draggedItemIDs)
        {
            if (SavedSearchFilters.IsSavedFilter(draggedItem.id))
            {
                // Root Filters Item is not allowed to be dragged
                if (draggedItem.id == SavedSearchFilters.GetRootInstanceID())
                {
                    return;
                }
            }

            ProjectWindowUtil.StartDrag(draggedItem.id, draggedItemIDs);
        }
 protected override void GetParentsAbove(int id, HashSet <int> parentsAbove)
 {
     if (SavedSearchFilters.IsSavedFilter(id))
     {
         parentsAbove.Add(SavedSearchFilters.GetRootInstanceID());
     }
     else
     {
         // AssetDatabase folders (in Assets or Packages)
         var path = AssetDatabase.GetAssetPath(id);
         if (Directory.Exists(path))
         {
             parentsAbove.UnionWith(ProjectWindowUtil.GetAncestors(id));
         }
     }
 }
        override protected void RenameEnded()
        {
            int instanceID = GetRenameOverlay().userData;

            ProjectBrowser.ItemType type = ProjectBrowser.GetItemType(instanceID);

            if (m_IsCreatingSavedFilter)
            {
                // Create saved filter
                m_IsCreatingSavedFilter = false;

                if (GetRenameOverlay().userAcceptedRename)
                {
                    SavedSearchFilters.SetName(instanceID, GetRenameOverlay().name);
                    m_TreeView.SetSelection(new[] { instanceID }, true);
                }
                else
                {
                    SavedSearchFilters.RemoveSavedFilter(instanceID);
                }
            }
            else if (type == ProjectBrowser.ItemType.SavedFilter)
            {
                // Renamed saved filter
                if (GetRenameOverlay().userAcceptedRename)
                {
                    SavedSearchFilters.SetName(instanceID, GetRenameOverlay().name);
                }
            }
            else
            {
                // Let base handle renaming of folders
                base.RenameEnded();

                // Ensure to sync filter to new folder name (so we still show the contents of the folder)
                if (GetRenameOverlay().userAcceptedRename)
                {
                    m_TreeView.NotifyListenersThatSelectionChanged();
                }
            }
        }
 public override void FetchData()
 {
     base.m_RootItem = new TreeViewItem(0x7fffffff, 0, null, "Invisible Root Item");
     this.SetExpanded(base.m_RootItem, true);
     List<TreeViewItem> list = new List<TreeViewItem>();
     int assetsFolderInstanceID = GetAssetsFolderInstanceID();
     int depth = 0;
     string displayName = "Assets";
     TreeViewItem parent = new TreeViewItem(assetsFolderInstanceID, depth, base.m_RootItem, displayName);
     this.ReadAssetDatabase(parent, depth + 1);
     TreeViewItem item = SavedSearchFilters.ConvertToTreeView();
     item.parent = base.m_RootItem;
     list.Add(item);
     list.Add(parent);
     base.m_RootItem.children = list;
     foreach (TreeViewItem item3 in base.m_RootItem.children)
     {
         bool @bool = EditorPrefs.GetBool(kProjectBrowserString + item3.displayName, true);
         this.SetExpanded(item3, @bool);
     }
     base.m_NeedRefreshVisibleFolders = true;
 }
Пример #17
0
        protected override void RenameEnded()
        {
            int userData = this.GetRenameOverlay().userData;

            ProjectBrowser.ItemType itemType = ProjectBrowser.GetItemType(userData);
            if (this.m_IsCreatingSavedFilter)
            {
                this.m_IsCreatingSavedFilter = false;
                if (this.GetRenameOverlay().userAcceptedRename)
                {
                    SavedSearchFilters.SetName(userData, this.GetRenameOverlay().name);
                    this.m_TreeView.SetSelection(new int[1] {
                        userData
                    }, 1 != 0);
                }
                else
                {
                    SavedSearchFilters.RemoveSavedFilter(userData);
                }
            }
            else if (itemType == ProjectBrowser.ItemType.SavedFilter)
            {
                if (!this.GetRenameOverlay().userAcceptedRename)
                {
                    return;
                }
                SavedSearchFilters.SetName(userData, this.GetRenameOverlay().name);
            }
            else
            {
                base.RenameEnded();
                if (!this.GetRenameOverlay().userAcceptedRename)
                {
                    return;
                }
                this.m_TreeView.NotifyListenersThatSelectionChanged();
            }
        }
        public override void FetchData()
        {
            this.m_RootItem = new TreeViewItem(2147483647, 0, null, "Invisible Root Item");
            this.SetExpanded(this.m_RootItem, true);
            List <TreeViewItem> list            = new List <TreeViewItem>();
            int          assetsFolderInstanceID = ProjectBrowserColumnOneTreeViewDataSource.GetAssetsFolderInstanceID();
            int          num          = 0;
            string       displayName  = "Assets";
            TreeViewItem treeViewItem = new TreeViewItem(assetsFolderInstanceID, num, this.m_RootItem, displayName);

            this.ReadAssetDatabase(HierarchyType.Assets, treeViewItem, num + 1);
            TreeViewItem treeViewItem2 = null;

            if (Unsupported.IsDeveloperMode() && EditorPrefs.GetBool("ShowPackagesFolder"))
            {
                int    mainAssetOrInProgressProxyInstanceID = AssetDatabase.GetMainAssetOrInProgressProxyInstanceID(AssetDatabase.GetPackagesMountPoint());
                string packagesMountPoint = AssetDatabase.GetPackagesMountPoint();
                treeViewItem2 = new TreeViewItem(mainAssetOrInProgressProxyInstanceID, num, this.m_RootItem, packagesMountPoint);
                this.ReadAssetDatabase(HierarchyType.Packages, treeViewItem2, num + 1);
            }
            TreeViewItem treeViewItem3 = SavedSearchFilters.ConvertToTreeView();

            treeViewItem3.parent = this.m_RootItem;
            list.Add(treeViewItem3);
            list.Add(treeViewItem);
            if (treeViewItem2 != null)
            {
                list.Add(treeViewItem2);
            }
            this.m_RootItem.children = list;
            foreach (TreeViewItem current in this.m_RootItem.children)
            {
                bool @bool = EditorPrefs.GetBool(ProjectBrowserColumnOneTreeViewDataSource.kProjectBrowserString + current.displayName, true);
                this.SetExpanded(current, @bool);
            }
            this.m_NeedRefreshRows = true;
        }
        public override void FetchData()
        {
            this.m_RootItem = new TreeViewItem(2147483647, 0, null, "Invisible Root Item");
            this.SetExpanded(this.m_RootItem, true);
            List <TreeViewItem> list            = new List <TreeViewItem>();
            int          assetsFolderInstanceID = ProjectBrowserColumnOneTreeViewDataSource.GetAssetsFolderInstanceID();
            int          num          = 0;
            string       displayName  = "Assets";
            TreeViewItem treeViewItem = new TreeViewItem(assetsFolderInstanceID, num, this.m_RootItem, displayName);

            this.ReadAssetDatabase(treeViewItem, num + 1);
            TreeViewItem treeViewItem2 = SavedSearchFilters.ConvertToTreeView();

            treeViewItem2.parent = this.m_RootItem;
            list.Add(treeViewItem2);
            list.Add(treeViewItem);
            this.m_RootItem.children = list;
            foreach (TreeViewItem current in this.m_RootItem.children)
            {
                bool @bool = EditorPrefs.GetBool(ProjectBrowserColumnOneTreeViewDataSource.kProjectBrowserString + current.displayName, true);
                this.SetExpanded(current, @bool);
            }
            this.m_NeedRefreshVisibleFolders = true;
        }
        public override void FetchData()
        {
            m_RootItem = new TreeViewItem(0, 0, null, "Invisible Root Item");
            SetExpanded(m_RootItem, true); // ensure always visible

            Texture2D folderIcon = EditorGUIUtility.FindTexture(EditorResources.folderIconName);

            // We want three roots: Favorites, Assets, and Saved Filters
            List <TreeViewItem> visibleRoots = new List <TreeViewItem>();

            // Fetch asset folders
            int    assetsFolderInstanceID = AssetDatabase.GetMainAssetOrInProgressProxyInstanceID("Assets");
            int    depth       = 0;
            string displayName = "Assets"; //CreateDisplayName (assetsFolderInstanceID);

            AssetsTreeViewDataSource.RootTreeItem assetRootItem = new AssetsTreeViewDataSource.RootTreeItem(assetsFolderInstanceID, depth, m_RootItem, displayName);
            assetRootItem.icon = folderIcon;
            ReadAssetDatabase("Assets", assetRootItem, depth + 1);

            // Fetch packages folder
            displayName = PackageManager.Folders.GetPackagesPath();
            AssetsTreeViewDataSource.RootTreeItem packagesRootItem = new AssetsTreeViewDataSource.RootTreeItem(ProjectBrowser.kPackagesFolderInstanceId, depth, m_RootItem, displayName);
            depth++;

            packagesRootItem.icon = folderIcon;

            var packages = PackageManagerUtilityInternal.GetAllVisiblePackages(skipHiddenPackages);

            foreach (var package in packages)
            {
                var packageFolderInstanceId = AssetDatabase.GetMainAssetOrInProgressProxyInstanceID(package.assetPath);

                displayName = !string.IsNullOrEmpty(package.displayName) ? package.displayName : package.name;
                AssetsTreeViewDataSource.PackageTreeItem packageItem = new AssetsTreeViewDataSource.PackageTreeItem(packageFolderInstanceId, depth, packagesRootItem, displayName);
                packageItem.icon = folderIcon;
                packagesRootItem.AddChild(packageItem);
                ReadAssetDatabase(package.assetPath, packageItem, depth + 1);
            }

            // Fetch saved filters
            TreeViewItem savedFiltersRootItem = SavedSearchFilters.ConvertToTreeView();

            savedFiltersRootItem.parent = m_RootItem;

            // Order
            visibleRoots.Add(savedFiltersRootItem);
            visibleRoots.Add(assetRootItem);
            visibleRoots.Add(packagesRootItem);

            m_RootItem.children = visibleRoots;

            // Get global expanded state of roots
            foreach (TreeViewItem item in m_RootItem.children)
            {
                // Do not expand Packages root item
                if (item.id == ProjectBrowser.kPackagesFolderInstanceId)
                {
                    continue;
                }
                bool expanded = EditorPrefs.GetBool(kProjectBrowserString + item.displayName, true);
                SetExpanded(item, expanded);
            }

            m_NeedRefreshRows = true;
        }
        public override void FetchData()
        {
            bool firstInitialize = !isInitialized;

            m_RootItem = new TreeViewItem(0, 0, null, "Invisible Root Item");
            SetExpanded(m_RootItem, true); // ensure always visible

            // We want three roots: Favorites, Assets, and Packages
            List <TreeViewItem> visibleRoots = new List <TreeViewItem>();

            // Favorites root
            TreeViewItem savedFiltersRootItem = SavedSearchFilters.ConvertToTreeView();

            visibleRoots.Add(savedFiltersRootItem);

            // Assets root
            int    assetsFolderInstanceID = AssetDatabase.GetMainAssetOrInProgressProxyInstanceID("Assets");
            int    depth       = 0;
            string displayName = "Assets";

            AssetsTreeViewDataSource.RootTreeItem assetRootItem = new AssetsTreeViewDataSource.RootTreeItem(assetsFolderInstanceID, depth, m_RootItem, displayName);
            assetRootItem.icon = s_FolderIcon;
            visibleRoots.Add(assetRootItem);

            // Packages root
            displayName = PackageManager.Folders.GetPackagesPath();
            AssetsTreeViewDataSource.RootTreeItem packagesRootItem = new AssetsTreeViewDataSource.RootTreeItem(ProjectBrowser.kPackagesFolderInstanceId, depth, m_RootItem, displayName);
            packagesRootItem.icon = s_FolderIcon;
            visibleRoots.Add(packagesRootItem);

            m_RootItem.children = visibleRoots;

            // Set global expanded state for roots from EditorPrefs (must be before building the rows)
            if (firstInitialize)
            {
                foreach (TreeViewItem item in m_RootItem.children)
                {
                    bool expanded = EditorPrefs.GetBool(kProjectBrowserString + item.displayName, true);
                    SetExpanded(item, expanded);
                }
            }

            // Build rows
            //-----------
            m_Rows = new List <TreeViewItem>(100);

            // Favorites
            savedFiltersRootItem.parent = m_RootItem;
            m_Rows.Add(savedFiltersRootItem);
            if (IsExpanded(savedFiltersRootItem))
            {
                foreach (var f in savedFiltersRootItem.children)
                {
                    m_Rows.Add(f);
                }
            }
            else
            {
                savedFiltersRootItem.children = CreateChildListForCollapsedParent();
            }

            // Asset folders
            m_Rows.Add(assetRootItem);
            ReadAssetDatabase("Assets", assetRootItem, depth + 1, m_Rows);

            // Individual Package folders (under the Packages root item)
            m_Rows.Add(packagesRootItem);
            var packages = PackageManagerUtilityInternal.GetAllVisiblePackages(skipHiddenPackages);

            if (IsExpanded(packagesRootItem))
            {
                depth++;
                foreach (var package in packages)
                {
                    var packageFolderInstanceId = AssetDatabase.GetMainAssetOrInProgressProxyInstanceID(package.assetPath);

                    displayName = !string.IsNullOrEmpty(package.displayName) ? package.displayName : package.name;
                    AssetsTreeViewDataSource.PackageTreeItem packageItem = new AssetsTreeViewDataSource.PackageTreeItem(packageFolderInstanceId, depth, packagesRootItem, displayName);
                    packageItem.icon = s_FolderIcon;
                    packagesRootItem.AddChild(packageItem);
                    m_Rows.Add(packageItem);
                    ReadAssetDatabase(package.assetPath, packageItem, depth + 1, m_Rows);
                }
            }
            else
            {
                if (packages.Length > 0)
                {
                    packagesRootItem.children = CreateChildListForCollapsedParent();
                }
            }

            m_NeedRefreshRows = false;
        }
        public override DragAndDropVisualMode DoDrag(TreeViewItem parentItem, TreeViewItem targetItem, bool perform, DropPosition dropPos)
        {
            if (targetItem == null)
            {
                return(DragAndDropVisualMode.None);
            }

            object savedFilterData = DragAndDrop.GetGenericData(ProjectWindowUtil.k_DraggingFavoriteGenericData);

            // Dragging saved filter
            if (savedFilterData != null)
            {
                int instanceID = (int)savedFilterData;
                if (targetItem is SearchFilterTreeItem && parentItem is SearchFilterTreeItem)// && targetItem.id != draggedInstanceID && parentItem.id != draggedInstanceID)
                {
                    bool validMove = SavedSearchFilters.CanMoveSavedFilter(instanceID, parentItem.id, targetItem.id, dropPos == DropPosition.Below);
                    if (validMove && perform)
                    {
                        SavedSearchFilters.MoveSavedFilter(instanceID, parentItem.id, targetItem.id, dropPos == DropPosition.Below);
                        m_TreeView.SetSelection(new[] { instanceID }, false);
                        m_TreeView.NotifyListenersThatSelectionChanged();
                    }
                    return(validMove ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.None);
                }
                return(DragAndDropVisualMode.None);
            }
            // Dragging of folders into filters
            else
            {
                // Check if we are dragging a single folder
                if (targetItem is SearchFilterTreeItem && parentItem is SearchFilterTreeItem)
                {
                    string genericData = DragAndDrop.GetGenericData(ProjectWindowUtil.k_IsFolderGenericData) as string;
                    if (genericData == "isFolder")
                    {
                        if (perform)
                        {
                            Object[] objs = DragAndDrop.objectReferences;
                            if (objs.Length > 0)
                            {
                                string path = AssetDatabase.GetAssetPath(objs[0].GetInstanceID());
                                if (!string.IsNullOrEmpty(path))
                                {
                                    // TODO: Fix with new AssetDatabase API when it is ready (GetName)
                                    string       folderName   = new DirectoryInfo(path).Name;
                                    SearchFilter searchFilter = new SearchFilter();
                                    searchFilter.folders = new[] { path };
                                    bool addAsChild = targetItem == parentItem;

                                    float previewSize = ProjectBrowserColumnOneTreeViewGUI.GetListAreaGridSize();
                                    int   instanceID  = SavedSearchFilters.AddSavedFilterAfterInstanceID(folderName, searchFilter, previewSize, targetItem.id, addAsChild);
                                    m_TreeView.SetSelection(new[] { instanceID }, false);
                                    m_TreeView.NotifyListenersThatSelectionChanged();
                                }
                                else
                                {
                                    Debug.Log("Could not get asset path from id " + objs[0].GetInstanceID());
                                }
                            }
                        }
                        return(DragAndDropVisualMode.Copy); // Allow dragging folders to filters
                    }
                    return(DragAndDropVisualMode.None);     // Assets that are not folders are not allowed to be dragged to filters
                }
            }
            //  Assets are handled by base
            return(base.DoDrag(parentItem, targetItem, perform, dropPos));
        }
 public ProjectBrowserColumnOneTreeViewDataSource(TreeViewController treeView) : base(treeView)
 {
     base.showRootItem      = false;
     base.rootIsCollapsable = false;
     SavedSearchFilters.AddChangeListener(new System.Action(this.ReloadData));
 }
 public override bool CanBeParent(TreeViewItem item) =>
 (!(item is SearchFilterTreeItem) || SavedSearchFilters.AllowsHierarchy());
Пример #25
0
        public override void FetchData()
        {
            m_RootItem = new TreeViewItem(System.Int32.MaxValue, 0, null, "Invisible Root Item");
            SetExpanded(m_RootItem, true); // ensure always visible

            // We want three roots: Favorites, Assets, and Saved Filters
            List <TreeViewItem> visibleRoots = new List <TreeViewItem>();

            // Fetch asset folders
            int          assetsFolderInstanceID = GetAssetsFolderInstanceID();
            int          depth         = 0;
            string       displayName   = "Assets"; //CreateDisplayName (assetsFolderInstanceID);
            TreeViewItem assetRootItem = new TreeViewItem(assetsFolderInstanceID, depth, m_RootItem, displayName);

            ReadAssetDatabase("Assets", assetRootItem, depth + 1);

            TreeViewItem packagesRootItem = new TreeViewItem(0, depth, m_RootItem, "Packages");

            depth++;

            Texture2D folderIcon      = EditorGUIUtility.FindTexture(EditorResources.folderIconName);
            Texture2D emptyFolderIcon = EditorGUIUtility.FindTexture(EditorResources.emptyFolderIconName);

            packagesRootItem.icon = emptyFolderIcon;

            var packages = PackageManager.Packages.GetAll();

            foreach (var package in packages)
            {
                if (package.source == PackageManager.PackageSource.BuiltIn)
                {
                    continue;
                }

                var packagePath             = Path.Combine(PackageManager.Folders.GetPackagesMountPoint(), package.name);
                var packageFolderInstanceId = AssetDatabase.GetMainAssetOrInProgressProxyInstanceID(packagePath);

                displayName = !string.IsNullOrEmpty(package.displayName) ? package.displayName : CultureInfo.InvariantCulture.TextInfo.ToTitleCase(package.name.Replace("com.unity.", ""));
                TreeViewItem packageItem = new TreeViewItem(packageFolderInstanceId, depth, null, displayName);
                packagesRootItem.AddChild(packageItem);
                ReadAssetDatabase(packagePath, packageItem, depth + 1);
                packagesRootItem.icon = folderIcon;
            }

            // Fetch saved filters
            TreeViewItem savedFiltersRootItem = SavedSearchFilters.ConvertToTreeView();

            savedFiltersRootItem.parent = m_RootItem;

            // Order
            visibleRoots.Add(savedFiltersRootItem);
            visibleRoots.Add(assetRootItem);

            if (packagesRootItem != null)
            {
                visibleRoots.Add(packagesRootItem);
            }

            m_RootItem.children = visibleRoots;

            // Get global expanded state of roots
            foreach (TreeViewItem item in m_RootItem.children)
            {
                bool expanded = EditorPrefs.GetBool(kProjectBrowserString + item.displayName, true);
                SetExpanded(item, expanded);
            }

            m_NeedRefreshRows = true;
        }