private void Initialize()
        {
            baseFilter = s => false;
            guiFilter  = s => true;

            columnSelection  = new MultiColumnState.Column(new GUIContent("[]"), data => new GUIContent(masterSelection.Contains(data) ? " ☑" : " ☐"));
            columnAssetPath  = new MultiColumnState.Column(new GUIContent("AssetPath"), data => new GUIContent(data.assetPath.Compose()));
            columnOwner      = new MultiColumnState.Column(new GUIContent("Owner"), data => new GUIContent(data.owner, data.lockToken));
            columnFileStatus = new MultiColumnState.Column(new GUIContent("Status"), GetFileStatusContent);
            columnMetaStatus = new MultiColumnState.Column(new GUIContent("Meta"), data => GetFileStatusContent(data.MetaStatus()));
            columnFileType   = new MultiColumnState.Column(new GUIContent("Type"), data => new GUIContent(GetFileType(data.assetPath.Compose())));
            columnConflict   = new MultiColumnState.Column(new GUIContent("Conflict"), data => new GUIContent(data.treeConflictStatus.ToString()));
            columnChangelist = new MultiColumnState.Column(new GUIContent("ChangeList"), data => new GUIContent(data.changelist.Compose()));

            var guiSkin = EditorGUIUtility.GetBuiltinSkin(EditorGUIUtility.isProSkin ? EditorSkin.Scene : EditorSkin.Inspector);

            multiColumnState = new MultiColumnState();

            multiColumnState.Comparer = (r1, r2, c) =>
            {
                var r1Text = c.GetContent(r1.data).text;
                var r2Text = c.GetContent(r2.data).text;
                if (r1Text == null)
                {
                    r1Text = "";
                }
                if (r2Text == null)
                {
                    r2Text = "";
                }
                //D.Log("Comparing: " + r1Text + " with " + r2Text + " : " + r1Text.CompareTo(r2Text));
                return(String.CompareOrdinal(r1Text, r2Text));
            };

            Func <MultiColumnState.Row, MultiColumnState.Column, GenericMenu> rowRightClickMenu = (row, column) =>
            {
                var selected = multiColumnState.GetSelected().Select(status => status.assetPath.Compose()).ToList();
                if (!selected.Any())
                {
                    return(new GenericMenu());
                }
                GenericMenu menu = new GenericMenu();
                if (selected.Count() == 1)
                {
                    VCGUIControls.CreateVCContextMenu(ref menu, selected.First());
                }
                else
                {
                    VCGUIControls.CreateVCContextMenu(ref menu, selected);
                }
                var selectedObjs = selected.Select(a => AssetDatabase.LoadMainAssetAtPath(a)).ToArray();
                menu.AddSeparator("");
                menu.AddItem(new GUIContent("Show in Project"), false, () =>
                {
                    Selection.objects = selectedObjs;
                    EditorGUIUtility.PingObject(Selection.activeObject);
                });
                menu.AddItem(new GUIContent("Show on Harddisk"), false, () =>
                {
                    foreach (string item in selected)
                    {
                        EditorUtility.RevealInFinder(item);
                    }
                });
                return(menu);
            };

            Func <MultiColumnState.Column, GenericMenu> headerRightClickMenu = column =>
            {
                var menu = new GenericMenu();
                //menu.AddItem(new GUIContent("Remove"), false, () => { ToggleColumn(column); });
                return(menu);
            };

            // Return value of true steals the click from normal selection, false does not.
            Func <MultiColumnState.Row, MultiColumnState.Column, bool> cellClickAction = (row, column) =>
            {
                GUI.FocusControl("");
                if (column == columnSelection)
                {
                    var currentSelection = multiColumnState.GetSelected();
                    if (currentSelection.Contains(row.data))
                    {
                        bool currentRowSelection = masterSelection.Contains(row.data);
                        foreach (var selectionIt in currentSelection)
                        {
                            if (currentRowSelection)
                            {
                                masterSelection.Remove(selectionIt);
                            }
                            else
                            {
                                masterSelection.Add(selectionIt);
                            }
                        }
                    }
                    else
                    {
                        if (masterSelection.Contains(row.data))
                        {
                            masterSelection.Remove(row.data);
                        }
                        else
                        {
                            masterSelection.Add(row.data);
                        }
                    }
                    return(true);
                }
                return(false);
                //D.Log(row.data.assetPath.Compose() + " : "  + column.GetContent(row.data).text);
            };

            options = new MultiColumnViewOption
            {
                headerStyle          = new GUIStyle(guiSkin.button),
                rowStyle             = new GUIStyle(guiSkin.label),
                rowRightClickMenu    = rowRightClickMenu,
                headerRightClickMenu = headerRightClickMenu,
                cellClickAction      = cellClickAction,
                widths            = new float[] { 200 },
                doubleClickAction = status =>
                {
                    if (MergeHandler.IsDiffableAsset(status.assetPath) && VCUtility.ManagedByRepository(status) && status.fileStatus == VCFileStatus.Conflicted)
                    {
                        var assetPath = status.assetPath.Compose();
                        VCCommands.Instance.GetConflict(assetPath, out var basePath, out var yours, out var theirs);
                        MergeHandler.ResolveConflict(assetPath, basePath, theirs, yours);
                    }
                    else if (MergeHandler.IsDiffableAsset(status.assetPath) && VCUtility.ManagedByRepository(status) && status.fileStatus == VCFileStatus.Modified)
                    {
                        MergeHandler.DiffWithBase(status.assetPath.Compose());
                    }
                    else
                    {
                        string path = status.assetPath.Compose();
                        var    obj  = AssetDatabase.LoadMainAssetAtPath(path);

                        if (path.StartsWith("Assets"))
                        {
                            if (AssetDatabase.IsValidFolder(path) || obj == null)
                            {
                                EditorUtility.RevealInFinder(path);
                            }
                            else
                            {
                                bool result = AssetDatabase.OpenAsset(obj);
                                if (!result)
                                {
                                    EditorUtility.RevealInFinder(path);
                                }
                            }
                        }
                        else
                        {
                            EditorUtility.RevealInFinder(path);
                        }
                    }
                }
            };

            options.headerStyle.fixedHeight      = 20.0f;
            options.rowStyle.onNormal.background = IconUtils.CreateSquareTexture(4, 1, new Color(0.24f, 0.5f, 0.87f, 0.75f));
            options.rowStyle.margin  = new RectOffset(2, 2, 2, 1);
            options.rowStyle.border  = new RectOffset(0, 0, 0, 0);
            options.rowStyle.padding = new RectOffset(0, 0, 0, 0);

            if (showMasterSelection)
            {
                multiColumnState.AddColumn(columnSelection);
                options.widthTable.Add(columnSelection.GetHeader().text, 25);
            }

            multiColumnState.AddColumn(columnAssetPath);
            options.widthTable.Add(columnAssetPath.GetHeader().text, 500);

            multiColumnState.AddColumn(columnFileStatus);
            options.widthTable.Add(columnFileStatus.GetHeader().text, 90);

            multiColumnState.AddColumn(columnMetaStatus);
            options.widthTable.Add(columnMetaStatus.GetHeader().text, 100);

            multiColumnState.AddColumn(columnFileType);
            options.widthTable.Add(columnFileType.GetHeader().text, 80);

            multiColumnState.AddColumn(columnOwner);
            options.widthTable.Add(columnOwner.GetHeader().text, 60);

            multiColumnState.AddColumn(columnChangelist);
            options.widthTable.Add(columnChangelist.GetHeader().text, 120);

            //columnConflictState.AddColumn(columnConflict);
            options.widthTable.Add(columnConflict.GetHeader().text, 80);
        }
예제 #2
0
        public static ValidActions GetValidActions(string assetPath, Object instance = null)
        {
            using (sceneviewUpdateMarker.Auto())
            {
                if (!VCCommands.Active || string.IsNullOrEmpty(assetPath))
                {
                    return(noAction);
                }

                var assetStatus = VCCommands.Instance.GetAssetStatus(assetPath);

                bool isPrefab              = instance != null && PrefabHelper.IsPrefab(instance);
                bool isPrefabParent        = isPrefab && PrefabHelper.IsPrefabParent(instance);
                bool isFolder              = AssetDatabase.IsValidFolder(assetPath);
                bool diffableAsset         = MergeHandler.IsDiffableAsset(assetPath);
                bool mergableAsset         = MergeHandler.IsMergableAsset(assetPath);
                bool modifiedDiffableAsset = diffableAsset && assetStatus.fileStatus != VCFileStatus.Normal;
                bool modifiedMeta          = assetStatus.MetaStatus().fileStatus != VCFileStatus.Normal;
                bool lockedMeta            = assetStatus.MetaStatus().lockStatus == VCLockStatus.LockedHere;
                bool modified              = assetStatus.fileStatus == VCFileStatus.Modified;
                bool localOnly             = assetStatus.localOnly;
                bool deleted        = assetStatus.fileStatus == VCFileStatus.Deleted;
                bool added          = assetStatus.fileStatus == VCFileStatus.Added;
                bool unversioned    = assetStatus.fileStatus == VCFileStatus.Unversioned;
                bool ignored        = assetStatus.fileStatus == VCFileStatus.Ignored;
                bool replaced       = assetStatus.fileStatus == VCFileStatus.Replaced;
                bool lockedByOther  = assetStatus.lockStatus == VCLockStatus.LockedOther;
                bool managedByRep   = VCUtility.ManagedByRepository(assetStatus);
                bool haveControl    = VCUtility.HaveAssetControl(assetStatus);
                bool haveLock       = VCUtility.HaveVCLock(assetStatus);
                bool allowLocalEdit = assetStatus.LocalEditAllowed();
                bool pending        = assetStatus.reflectionLevel == VCReflectionLevel.Pending;
                bool mergeinfo      = assetStatus.property == VCProperty.Modified;
                bool conflicted     = assetStatus.fileStatus == VCFileStatus.Conflicted;
                bool hasChangeSet   = !ComposedString.IsNullOrEmpty(assetStatus.changelist);

                bool showAdd    = !pending && !ignored && unversioned;
                bool showOpen   = !pending && !showAdd && !added && !haveLock && !deleted && !isFolder && !mergableAsset && ((!lockedByOther && !localOnly) || allowLocalEdit);
                bool showDiff   = !pending && !ignored && !deleted && modifiedDiffableAsset && managedByRep;
                bool showCommit = !pending && !ignored && !allowLocalEdit && !localOnly && (haveLock || added || deleted || modifiedDiffableAsset || modifiedMeta || mergeinfo);
                bool showRevert = !pending && !ignored && !unversioned &&
                                  (haveControl || modified || added || deleted || replaced || modifiedDiffableAsset || modifiedMeta || lockedMeta || mergeinfo);
                bool showDelete           = !pending && !ignored && !deleted && !lockedByOther;
                bool showOpenLocal        = !pending && !ignored && !deleted && !isFolder && !allowLocalEdit && !unversioned && !added && !haveLock && !mergableAsset && !localOnly;
                bool showUnlock           = !pending && !ignored && !allowLocalEdit && haveLock;
                bool showUpdate           = !pending && !ignored && !added && managedByRep && instance != null;
                bool showUseTheirs        = !pending && !ignored && conflicted;
                bool showUseMine          = !pending && !ignored && conflicted;
                bool showMerge            = !pending && !ignored && conflicted && mergableAsset;
                bool showAddChangeList    = !pending && !ignored && !unversioned;
                bool showRemoveChangeList = !pending && !ignored && hasChangeSet;

                ValidActions validActions = 0;
                if (showAdd)
                {
                    validActions |= ValidActions.Add;
                }
                if (showOpen)
                {
                    validActions |= ValidActions.Open;
                }
                if (showDiff)
                {
                    validActions |= ValidActions.Diff;
                }
                if (showCommit)
                {
                    validActions |= ValidActions.Commit;
                }
                if (showRevert)
                {
                    validActions |= ValidActions.Revert;
                }
                if (showDelete)
                {
                    validActions |= ValidActions.Delete;
                }
                if (showOpenLocal)
                {
                    validActions |= ValidActions.OpenLocal;
                }
                if (showUnlock)
                {
                    validActions |= ValidActions.Unlock;
                }
                if (showUpdate)
                {
                    validActions |= ValidActions.Update;
                }
                if (showUseTheirs)
                {
                    validActions |= ValidActions.UseTheirs;
                }
                if (showUseMine)
                {
                    validActions |= ValidActions.UseMine;
                }
                if (showMerge)
                {
                    validActions |= ValidActions.Merge;
                }
                if (showAddChangeList)
                {
                    validActions |= ValidActions.AddChangeList;
                }
                if (showRemoveChangeList)
                {
                    validActions |= ValidActions.RemoveChangeList;
                }

                return(validActions);
            }
        }