EnabledState GetFolderChildrenEnabledState(PackageExportTreeViewItem folder)
        {
            if (!folder.isFolder)
            {
                Debug.LogError("Should be a folder item!");
            }

            if (!folder.hasChildren)
            {
                return(EnabledState.None);
            }

            EnabledState amount = EnabledState.NotSet;

            var          firstChild = folder.children[0] as PackageExportTreeViewItem;
            EnabledState initial    = firstChild.enabledState;

            for (int i = 1; i < folder.children.Count; ++i)
            {
                var child = folder.children[i] as PackageExportTreeViewItem;
                if (initial != child.enabledState)
                {
                    amount = EnabledState.Mixed;
                    break;
                }
            }

            if (amount == EnabledState.NotSet)
            {
                amount = initial == EnabledState.All ? EnabledState.All : EnabledState.None;
            }

            return(amount);
        }
 private void RecursiveComputeEnabledStateForFolders(PackageExportTreeViewItem pitem, HashSet <PackageExportTreeViewItem> done)
 {
     if (pitem.isFolder)
     {
         if (pitem.hasChildren)
         {
             foreach (TreeViewItem item in pitem.children)
             {
                 this.RecursiveComputeEnabledStateForFolders(item as PackageExportTreeViewItem, done);
             }
         }
         if (!done.Contains(pitem))
         {
             EnabledState folderChildrenEnabledState = this.GetFolderChildrenEnabledState(pitem);
             pitem.enabledState = folderChildrenEnabledState;
             if (folderChildrenEnabledState == EnabledState.Mixed)
             {
                 done.Add(pitem);
                 for (PackageExportTreeViewItem item2 = pitem.parent as PackageExportTreeViewItem; item2 != null; item2 = item2.parent as PackageExportTreeViewItem)
                 {
                     if (!done.Contains(item2))
                     {
                         item2.enabledState = EnabledState.Mixed;
                         done.Add(item2);
                     }
                 }
             }
         }
     }
 }
        private EnabledState GetFolderChildrenEnabledState(PackageExportTreeViewItem folder)
        {
            ExportPackageItem item = folder.item;

            if ((item != null) && !item.isFolder)
            {
                Debug.LogError("Should be a folder item!");
            }
            if (!folder.hasChildren)
            {
                return(EnabledState.None);
            }
            EnabledState notSet             = EnabledState.NotSet;
            PackageExportTreeViewItem item2 = folder.children[0] as PackageExportTreeViewItem;
            ExportPackageItem         item3 = item2.item;
            int num = (item3 != null) ? item3.enabledStatus : 1;

            for (int i = 1; i < folder.children.Count; i++)
            {
                item3 = (folder.children[i] as PackageExportTreeViewItem).item;
                if (num != item3.enabledStatus)
                {
                    notSet = EnabledState.Mixed;
                    break;
                }
            }
            if (notSet == EnabledState.NotSet)
            {
                notSet = (num != 1) ? EnabledState.None : EnabledState.All;
            }
            return(notSet);
        }
        private EnabledState GetFolderChildrenEnabledState(PackageExportTreeViewItem folder)
        {
            if (!folder.isFolder)
            {
                UnityEngine.Debug.LogError("Should be a folder item!");
            }
            if (!folder.hasChildren)
            {
                return(EnabledState.None);
            }
            EnabledState notSet            = EnabledState.NotSet;
            PackageExportTreeViewItem item = folder.children[0] as PackageExportTreeViewItem;
            EnabledState enabledState      = item.enabledState;

            for (int i = 1; i < folder.children.Count; i++)
            {
                PackageExportTreeViewItem item2 = folder.children[i] as PackageExportTreeViewItem;
                if (enabledState != item2.enabledState)
                {
                    notSet = EnabledState.Mixed;
                    break;
                }
            }
            if (notSet == EnabledState.NotSet)
            {
                notSet = (enabledState != EnabledState.All) ? EnabledState.None : EnabledState.All;
            }
            return(notSet);
        }
 private EnabledState GetFolderChildrenEnabledState(PackageExportTreeViewItem folder)
 {
     if (!folder.isFolder)
     {
         Debug.LogError("Should be a folder item!");
     }
     if (!folder.hasChildren)
     {
         return EnabledState.None;
     }
     EnabledState notSet = EnabledState.NotSet;
     PackageExportTreeViewItem item = folder.children[0] as PackageExportTreeViewItem;
     EnabledState enabledState = item.enabledState;
     for (int i = 1; i < folder.children.Count; i++)
     {
         PackageExportTreeViewItem item2 = folder.children[i] as PackageExportTreeViewItem;
         if (enabledState != item2.enabledState)
         {
             notSet = EnabledState.Mixed;
             break;
         }
     }
     if (notSet == EnabledState.NotSet)
     {
         notSet = (enabledState != EnabledState.All) ? EnabledState.None : EnabledState.All;
     }
     return notSet;
 }
        private void RecursiveComputeEnabledStateForFolders(PackageExportTreeViewItem pitem, HashSet <PackageExportTreeViewItem> done)
        {
            ExportPackageItem item = pitem.item;

            if ((item == null) || item.isFolder)
            {
                if (pitem.hasChildren)
                {
                    foreach (TreeViewItem item2 in pitem.children)
                    {
                        this.RecursiveComputeEnabledStateForFolders(item2 as PackageExportTreeViewItem, done);
                    }
                }
                if ((item != null) && !done.Contains(pitem))
                {
                    EnabledState folderChildrenEnabledState = this.GetFolderChildrenEnabledState(pitem);
                    item.enabledStatus = (int)folderChildrenEnabledState;
                    if (folderChildrenEnabledState == EnabledState.Mixed)
                    {
                        done.Add(pitem);
                        for (PackageExportTreeViewItem item3 = pitem.parent as PackageExportTreeViewItem; item3 != null; item3 = item3.parent as PackageExportTreeViewItem)
                        {
                            ExportPackageItem item4 = item3.item;
                            if ((item4 != null) && !done.Contains(item3))
                            {
                                item4.enabledStatus = 2;
                                done.Add(item3);
                            }
                        }
                    }
                }
            }
        }
            public override void FetchData()
            {
                int rootDepth = -1; // -1 so its children will have 0 depth

                m_RootItem = new PackageExportTreeViewItem(null, "Assets".GetHashCode(), rootDepth, null, "InvisibleAssetsFolder");

                bool initExpandedState = true;

                if (initExpandedState)
                {
                    m_TreeView.state.expandedIDs.Add(m_RootItem.id);
                }

                ExportPackageItem[] items = m_PackageExportView.items;

                Dictionary <string, PackageExportTreeViewItem> treeViewFolders = new Dictionary <string, PackageExportTreeViewItem>();

                for (int i = 0; i < items.Length; i++)
                {
                    var item = items[i];

                    if (PackageImport.HasInvalidCharInFilePath(item.assetPath))
                    {
                        continue; // Do not add invalid paths (we already warn the user with a dialog in PackageImport.cs)
                    }
                    string filename   = Path.GetFileName(item.assetPath).ConvertSeparatorsToUnity();
                    string folderPath = Path.GetDirectoryName(item.assetPath).ConvertSeparatorsToUnity();

                    // Ensure folders. This is for when installed packages have been moved to other folders.
                    TreeViewItem targetFolder = EnsureFolderPath(folderPath, treeViewFolders, initExpandedState);

                    // Add file to folder
                    if (targetFolder != null)
                    {
                        int id      = item.assetPath.GetHashCode();
                        var newItem = new PackageExportTreeViewItem(item, id, targetFolder.depth + 1, targetFolder, filename);
                        targetFolder.AddChild(newItem);

                        if (initExpandedState)
                        {
                            m_TreeView.state.expandedIDs.Add(id);
                        }

                        // We need to ensure that the folder is available for
                        // EnsureFolderPath on subsequent iterations.
                        if (item.isFolder)
                        {
                            treeViewFolders[item.assetPath] = newItem;
                        }
                    }
                }

                if (initExpandedState)
                {
                    m_TreeView.state.expandedIDs.Sort();
                }
            }
        private void ComputeEnabledStateForFolders()
        {
            PackageExportTreeViewItem           root = this.m_TreeView.data.root as PackageExportTreeViewItem;
            HashSet <PackageExportTreeViewItem> done = new HashSet <PackageExportTreeViewItem> {
                root
            };

            this.RecursiveComputeEnabledStateForFolders(root, done);
        }
 private void EnableChildrenRecursive(TreeViewItem parentItem, EnabledState enabled)
 {
     if (parentItem.hasChildren)
     {
         foreach (TreeViewItem item in parentItem.children)
         {
             PackageExportTreeViewItem item2 = item as PackageExportTreeViewItem;
             item2.enabledState = enabled;
             this.EnableChildrenRecursive(item2, enabled);
         }
     }
 }
 void DoIconAndText(PackageExportTreeViewItem item, Rect contentRect, bool selected, bool focused)
 {
     EditorGUIUtility.SetIconSize(new Vector2(k_IconWidth, k_IconWidth)); // If not set we see icons scaling down if text is being cropped
     lineStyle = Styles.lineStyle;
     lineStyle.padding.left = 0;                                          // padding could have been set by other tree views
     contentRect.height    += 5;                                          // with the default row height, underscore and lower parts of characters like g, p, etc. were not visible
     if (Event.current.type == EventType.Repaint)
     {
         lineStyle.Draw(contentRect, GUIContent.Temp(item.displayName, GetIconForItem(item)), false, false, selected, focused);
     }
     EditorGUIUtility.SetIconSize(Vector2.zero);
 }
 private void ItemWasToggled(PackageExportTreeViewItem pitem)
 {
     if (this.m_Selection.Count <= 1)
     {
         this.EnableChildrenRecursive(pitem, pitem.enabledState);
     }
     else
     {
         foreach (PackageExportTreeViewItem item in this.m_Selection)
         {
             item.enabledState = pitem.enabledState;
         }
     }
     this.ComputeEnabledStateForFolders();
 }
 private void ItemWasToggled(PackageExportTreeViewItem pitem)
 {
     if (this.m_Selection.Count <= 1)
     {
         this.EnableChildrenRecursive(pitem, pitem.enabledState);
     }
     else
     {
         foreach (PackageExportTreeViewItem item in this.m_Selection)
         {
             item.enabledState = pitem.enabledState;
         }
     }
     this.ComputeEnabledStateForFolders();
 }
 private void SelectionChanged(int[] selectedIDs)
 {
     this.m_Selection = new List <PackageExportTreeViewItem>();
     foreach (TreeViewItem item in this.m_TreeView.data.GetRows())
     {
         if (selectedIDs.Contains <int>(item.id))
         {
             PackageExportTreeViewItem item2 = item as PackageExportTreeViewItem;
             if (item2 != null)
             {
                 this.m_Selection.Add(item2);
             }
         }
     }
 }
 private void EnableChildrenRecursive(TreeViewItem parentItem, int enabled)
 {
     if (parentItem.hasChildren)
     {
         foreach (TreeViewItem item in parentItem.children)
         {
             PackageExportTreeViewItem item2 = item as PackageExportTreeViewItem;
             ExportPackageItem         item3 = item2.item;
             if (item3 != null)
             {
                 item3.enabledStatus = enabled;
             }
             this.EnableChildrenRecursive(item2, enabled);
         }
     }
 }
        void ItemWasToggled(PackageExportTreeViewItem pitem)
        {
            if (m_Selection.Count <= 1)
            {
                EnableChildrenRecursive(pitem, pitem.enabledState);
            }
            else
            {
                foreach (var i in m_Selection)
                {
                    i.enabledState = pitem.enabledState;
                }
            }

            ComputeEnabledStateForFolders();
        }
            static void Toggle(ExportPackageItem[] items, PackageExportTreeViewItem pitem, Rect toggleRect)
            {
                bool enabled = pitem.enabledState > EnabledState.None;

                GUIStyle style    = EditorStyles.toggle;
                bool     setMixed = pitem.isFolder && (pitem.enabledState == EnabledState.Mixed);

                if (setMixed)
                {
                    style = EditorStyles.toggleMixed;
                }

                bool newEnabled = GUI.Toggle(toggleRect, enabled, GUIContent.none, style);

                if (newEnabled != enabled)
                {
                    pitem.enabledState = newEnabled ? EnabledState.All : EnabledState.None;
                }
            }
        private void ItemWasToggled(PackageExportTreeViewItem pitem)
        {
            ExportPackageItem item = pitem.item;

            if (item != null)
            {
                if (this.m_Selection.Count <= 1)
                {
                    this.EnableChildrenRecursive(pitem, item.enabledStatus);
                }
                else
                {
                    foreach (PackageExportTreeViewItem item2 in this.m_Selection)
                    {
                        item2.item.enabledStatus = item.enabledStatus;
                    }
                }
                this.ComputeEnabledStateForFolders();
            }
        }
 void DoToggle(PackageExportTreeViewItem pitem, Rect toggleRect)
 {
     // Toggle on/off
     EditorGUI.BeginChangeCheck();
     Toggle(m_PackageExportView.items, pitem, toggleRect);
     if (EditorGUI.EndChangeCheck())
     {
         // Only change selection if we already have single selection (Keep multi-selection when toggling)
         if (m_TreeView.GetSelection().Length <= 1 || !m_TreeView.GetSelection().Contains(pitem.id))
         {
             m_TreeView.SetSelection(new int[] { pitem.id }, false);
             m_TreeView.NotifyListenersThatSelectionChanged();
         }
         if (itemWasToggled != null)
         {
             itemWasToggled(pitem);
         }
         Event.current.Use();
     }
 }
        void RecursiveComputeEnabledStateForFolders(PackageExportTreeViewItem pitem, HashSet <PackageExportTreeViewItem> done)
        {
            if (!pitem.isFolder)
            {
                return;
            }

            // Depth first recursion to allow parent folders be dependant on child folders

            // Recurse
            if (pitem.hasChildren)
            {
                foreach (var child in pitem.children)
                {
                    RecursiveComputeEnabledStateForFolders(child as PackageExportTreeViewItem, done);
                }
            }

            // Now do logic
            if (!done.Contains(pitem))
            {
                EnabledState enabledState = GetFolderChildrenEnabledState(pitem);
                pitem.enabledState = enabledState;

                // If 'item' is mixed then all of its parents will also be mixed
                if (enabledState == EnabledState.Mixed)
                {
                    done.Add(pitem);
                    var current = pitem.parent as PackageExportTreeViewItem;
                    while (current != null)
                    {
                        if (!done.Contains(current))
                        {
                            current.enabledState = EnabledState.Mixed;
                            done.Add(current);
                        }
                        current = current.parent as PackageExportTreeViewItem;
                    }
                }
            }
        }
 private void RecursiveComputeEnabledStateForFolders(PackageExportTreeViewItem pitem, HashSet<PackageExportTreeViewItem> done)
 {
     if (pitem.isFolder)
     {
         if (pitem.hasChildren)
         {
             foreach (TreeViewItem item in pitem.children)
             {
                 this.RecursiveComputeEnabledStateForFolders(item as PackageExportTreeViewItem, done);
             }
         }
         if (!done.Contains(pitem))
         {
             EnabledState folderChildrenEnabledState = this.GetFolderChildrenEnabledState(pitem);
             pitem.enabledState = folderChildrenEnabledState;
             if (folderChildrenEnabledState == EnabledState.Mixed)
             {
                 done.Add(pitem);
                 for (PackageExportTreeViewItem item2 = pitem.parent as PackageExportTreeViewItem; item2 != null; item2 = item2.parent as PackageExportTreeViewItem)
                 {
                     if (!done.Contains(item2))
                     {
                         item2.enabledState = EnabledState.Mixed;
                         done.Add(item2);
                     }
                 }
             }
         }
     }
 }
            TreeViewItem EnsureFolderPath(string folderPath, Dictionary <string, PackageExportTreeViewItem> treeViewFolders, bool initExpandedState)
            {
                // We're in the root folder, so just return the root item as the parent.
                if (folderPath == "")
                {
                    return(m_RootItem);
                }

                // Does folder path exist?
                int          id   = folderPath.GetHashCode();
                TreeViewItem item = TreeViewUtility.FindItem(id, m_RootItem);

                if (item != null)
                {
                    return(item);
                }

                // Add folders as needed
                string[]     splitPath   = folderPath.Split('/');
                string       currentPath = "";
                TreeViewItem currentItem = m_RootItem;
                int          folderDepth = -1; // Will be incremented to the right depth in the loop.

                for (int depth = 0; depth < splitPath.Length; ++depth)
                {
                    string folder = splitPath[depth];
                    if (currentPath != "")
                    {
                        currentPath += '/';
                    }

                    currentPath += folder;

                    // Dont create a 'Assets' folder (we already have that as a hidden root)
                    if (depth == 0 && currentPath == "Assets")
                    {
                        continue;
                    }

                    // Only increment the folder depth if we are past the root "Assets" folder.
                    ++folderDepth;

                    id = currentPath.GetHashCode();

                    PackageExportTreeViewItem foundItem;
                    if (treeViewFolders.TryGetValue(currentPath, out foundItem))
                    {
                        currentItem = foundItem;
                    }
                    else
                    {
                        // If we do not have a tree view item for this folder we create one
                        var folderItem = new PackageExportTreeViewItem(null, id, folderDepth, currentItem, folder);

                        // Add to children array of the parent
                        currentItem.AddChild(folderItem);
                        currentItem = folderItem;

                        // Auto expand all folder items
                        if (initExpandedState)
                        {
                            m_TreeView.state.expandedIDs.Add(id);
                        }

                        // For faster finding of folders
                        treeViewFolders[currentPath] = folderItem;
                    }
                }

                return(currentItem);
            }