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);
        }
Exemplo n.º 2
0
        public static void CreateVCContextMenu(ref GenericMenu menu, string assetPath, Object instance = null)
        {
            if (VCUtility.ValidAssetPath(assetPath))
            {
                bool ready = VCCommands.Instance.Ready;
                if (ready)
                {
                    if (instance && ObjectUtilities.ChangesStoredInScene(instance))
                    {
                        assetPath = SceneManagerUtilities.GetCurrentScenePath();
                    }
                    var validActions = GetValidActions(assetPath, instance);

                    if ((validActions & ValidActions.Diff) != 0)
                    {
                        menu.AddItem(new GUIContent(Terminology.diff), false, () => MergeHandler.DiffWithBase(assetPath));
                    }
                    if ((validActions & ValidActions.Add) != 0)
                    {
                        menu.AddItem(new GUIContent(Terminology.add), false, () => VCCommands.Instance.Add(new[] { assetPath }));
                    }
                    if ((validActions & ValidActions.Open) != 0)
                    {
                        menu.AddItem(new GUIContent(Terminology.getlock), false, () => GetLock(assetPath, instance));
                    }
                    if ((validActions & ValidActions.OpenLocal) != 0)
                    {
                        menu.AddItem(new GUIContent(Terminology.allowLocalEdit), false, () => AllowLocalEdit(assetPath, instance));
                    }
                    if ((validActions & ValidActions.Commit) != 0)
                    {
                        menu.AddItem(new GUIContent(Terminology.commit), false, () => Commit(assetPath, instance));
                    }
                    if ((validActions & ValidActions.Unlock) != 0)
                    {
                        menu.AddItem(new GUIContent(Terminology.unlock), false, () => VCCommands.Instance.ReleaseLock(new[] { assetPath }));
                    }
                    if ((validActions & ValidActions.Delete) != 0)
                    {
                        menu.AddItem(new GUIContent(Terminology.delete), false, () => VCCommands.Instance.Delete(new[] { assetPath }));
                    }
                    if ((validActions & ValidActions.Revert) != 0)
                    {
                        menu.AddItem(new GUIContent(Terminology.revert), false, () => Revert(assetPath, instance));
                    }
                    if ((validActions & ValidActions.UseTheirs) != 0)
                    {
                        menu.AddItem(new GUIContent("Use Theirs"), false, () => VCCommands.Instance.Resolve(new [] { assetPath }, ConflictResolution.Theirs));
                    }
                    if ((validActions & ValidActions.UseMine) != 0)
                    {
                        menu.AddItem(new GUIContent("Use Mine"), false, () => VCCommands.Instance.Resolve(new [] { assetPath }, ConflictResolution.Mine));
                    }
                    if ((validActions & ValidActions.Merge) != 0)
                    {
                        menu.AddItem(new GUIContent("Merge"), false, () => MergeHandler.ResolveConflict(assetPath));
                    }
                    if ((validActions & ValidActions.AddChangeList) != 0)
                    {
                        menu.AddItem(new GUIContent("Add To " + Terminology.changelist), false, () => ChangeListWindow.Open(new [] { assetPath }));
                    }
                    if ((validActions & ValidActions.RemoveChangeList) != 0)
                    {
                        menu.AddItem(new GUIContent("Remove From " + Terminology.changelist), false, () => VCCommands.Instance.ChangeListRemove(new [] { assetPath }));
                    }
                }
                else
                {
                    menu.AddDisabledItem(new GUIContent("..Busy.."));
                }
            }
        }