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 <GenericMenu> rowRightClickMenu = () =>
            {
                var selected = multiColumnState.GetSelected().Select(status => status.assetPath.Compose());
                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, () =>
                {
                    Selection.objects = selectedObjs;
                    EditorApplication.ExecuteMenuItem((Application.platform == RuntimePlatform.OSXEditor ? "Assets/Reveal in Finder" : "Assets/Show in Explorer"));
                });
                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 (VCUtility.IsDiffableAsset(status.assetPath) && VCUtility.ManagedByRepository(status) && status.fileStatus == VCFileStatus.Modified)
                    {
                        VCUtility.DiffWithBase(status.assetPath.Compose());
                    }
                    else
                    {
                        AssetDatabase.OpenAsset(AssetDatabase.LoadMainAssetAtPath(status.assetPath.Compose()));
                    }
                }
            };

            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);
        }
Ejemplo n.º 2
0
            private void Initialize()
            {
                columnActive     = new MultiColumnState.Column(new GUIContent("", "Active Branch"), data => currentBranch == data.name ?  activeBranch : emptyGUIContent);
                columnPath       = new MultiColumnState.Column(new GUIContent("Path"), data => new GUIContent(data.name));
                columnAuthor     = new MultiColumnState.Column(new GUIContent("Author"), data => new GUIContent(data.author));
                columnRevision   = new MultiColumnState.Column(new GUIContent("Revision"), data => new GUIContent(data.revision.ToString()));
                columnDate       = new MultiColumnState.Column(new GUIContent("Date"), data => new GUIContent(data.date.ToString("yyyy-MM-dd HH:mm:ss")));
                multiColumnState = new MultiColumnState();

                Func <MultiColumnState.Row, MultiColumnState.Column, bool> cellClickAction = (row, column) =>
                {
                    GUI.FocusControl("");
                    DebugLog.Log(row.data + " : " + column.GetContent(row.data).text);
                    return(false);
                };

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

                Func <MultiColumnState.Row, MultiColumnState.Column, GenericMenu> rowRightClickMenu = (row, column) =>
                {
                    GenericMenu menu = new GenericMenu();
                    menu.AddItem(new GUIContent("Switch"), false, () => Switch(row.data.name));
                    menu.AddItem(new GUIContent("Merge"), false, () => MergeWithConfirm(row.data.name));
                    return(menu);
                };

                Func <MultiColumnState.Column, GenericMenu> headerRightClickMenu = column =>
                {
                    GenericMenu menu = new GenericMenu();
                    return(menu);
                };


                options = new MultiColumnViewOption
                {
                    headerStyle          = new GUIStyle(guiSkin.button),
                    rowStyle             = new GUIStyle(guiSkin.label),
                    rowRightClickMenu    = rowRightClickMenu,
                    headerRightClickMenu = headerRightClickMenu,
                    cellClickAction      = cellClickAction,
                    widths            = new float[] { 200 },
                    doubleClickAction = path =>
                    {
                        //DebugLog.Log(path.name);
                    }
                };

                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);

                multiColumnState.AddColumn(columnActive);
                options.widthTable.Add(columnActive.GetHeader().text, 25);

                multiColumnState.AddColumn(columnPath);
                options.widthTable.Add(columnPath.GetHeader().text, 350);

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

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

                multiColumnState.AddColumn(columnDate);
                options.widthTable.Add(columnDate.GetHeader().text, 150);
            }