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));
        }
Пример #2
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);
        }
        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));
        }