static bool ShouldExpandCategory(
            IncomingChangesTreeView treeView,
            ChangeCategoryTreeViewItem categoryTreeViewItem,
            int categoriesCount,
            bool expandCategories)
        {
            if (expandCategories)
            {
                if (categoriesCount == 1)
                {
                    return(true);
                }

                if (categoryTreeViewItem.Category.CategoryType
                    == IncomingChangeCategory.Type.Conflicted)
                {
                    return(true);
                }

                if (categoryTreeViewItem.Category.GetChildrenCount()
                    > NODES_TO_EXPAND_CATEGORY)
                {
                    return(false);
                }

                return(true);
            }

            return(treeView.IsExpanded(categoryTreeViewItem.id));
        }
        static void CategoryTreeViewItemGUI(
            Rect rowRect,
            float rowHeight,
            ChangeCategoryTreeViewItem item,
            Action onCheckedNodeChanged,
            int solvedConflictsCount,
            bool isSelected,
            bool isFocused)
        {
            Texture icon      = GetCategoryIcon(item.Category.CategoryType);
            string  label     = item.Category.CategoryName;
            string  infoLabel = item.Category.GetCheckedChangesText();

            bool wasChecked         = item.Category.IsChecked();
            bool hadCheckedChildren = item.Category.GetCheckedChangesCount() > 0;

            DefaultStyles.label = GetCategoryStyle(
                item.Category, solvedConflictsCount, isSelected);

            bool isChecked = DrawTreeViewItem.ForCheckableCategoryItem(
                rowRect,
                rowHeight,
                item.depth,
                icon,
                label,
                infoLabel,
                isSelected,
                isFocused,
                wasChecked,
                hadCheckedChildren);

            DefaultStyles.label = UnityStyles.Tree.Label;

            if (!wasChecked && isChecked)
            {
                item.Category.UpdateCheckedState(true);
                onCheckedNodeChanged();
                return;
            }

            if (wasChecked && !isChecked)
            {
                item.Category.UpdateCheckedState(false);
                onCheckedNodeChanged();
                return;
            }
        }
        static void RegenerateRows(
            UnityIncomingChangesTree incomingChangesTree,
            TreeViewItemIds <IncomingChangeCategory, IncomingChangeInfo> treeViewItemIds,
            IncomingChangesTreeView treeView,
            TreeViewItem rootItem,
            List <TreeViewItem> rows,
            bool expandCategories)
        {
            if (incomingChangesTree == null)
            {
                return;
            }

            ClearRows(rootItem, rows);

            List <IncomingChangeCategory> categories = incomingChangesTree.GetNodes();

            if (categories == null)
            {
                return;
            }

            List <int> categoriesToExpand = new List <int>();

            foreach (IncomingChangeCategory category in categories)
            {
                int categoryId;
                if (!treeViewItemIds.TryGetCategoryItemId(category, out categoryId))
                {
                    categoryId = treeViewItemIds.AddCategoryItem(category);
                }

                ChangeCategoryTreeViewItem categoryTreeViewItem =
                    new ChangeCategoryTreeViewItem(categoryId, category);

                rootItem.AddChild(categoryTreeViewItem);
                rows.Add(categoryTreeViewItem);

                if (!ShouldExpandCategory(
                        treeView, categoryTreeViewItem,
                        categories.Count, expandCategories))
                {
                    continue;
                }

                categoriesToExpand.Add(categoryTreeViewItem.id);

                foreach (IncomingChangeInfo incomingChange in category.GetChanges())
                {
                    int changeId;
                    if (!treeViewItemIds.TryGetInfoItemId(incomingChange, out changeId))
                    {
                        changeId = treeViewItemIds.AddInfoItem(incomingChange);
                    }

                    TreeViewItem changeTreeViewItem =
                        new ChangeTreeViewItem(changeId, incomingChange);

                    categoryTreeViewItem.AddChild(changeTreeViewItem);
                    rows.Add(changeTreeViewItem);
                }
            }

            treeView.state.expandedIDs = categoriesToExpand;
        }