예제 #1
0
        private void DoCommit(Rect rect, Rect scrollRect, CommitInfo commit)
        {
            GitProfilerProxy.BeginSample("Git History Window Commit GUI", this);
            Event current = Event.current;

            if (rect.y > scrollRect.height + historyScroll.y || rect.y + scrollRect.height < historyScroll.y)
            {
                return;
            }

            BranchInfo[] branches = commit.Branches;
            bool         isHead   = commit.IsHead;
            bool         isRemote = commit.IsRemote;

            GUI.Box(new Rect(8, rect.y + 6, 16, 16), GUIContent.none, "AC LeftArrow");
            GUI.Box(new Rect(8, rect.y + 6, 16, 16), GUIContent.none, branches != null && branches.Length > 0 ? isHead ? styles.historyKnobHead : isRemote ? styles.historyKnobRemote : styles.historyKnobOther : styles.historyKnobNormal);

            float y = 8;
            float x = 12;

            if (isHead)
            {
                //GUI.Box(new Rect(commitRect.x + 4, commitRect.y, commitRect.width - 8, commitRect.height - 8), GUIContent.none, "TL SelectionButton PreDropGlow");
            }
            GUI.Box(rect, GUIContent.none, "RegionBg");
            if (isHead || isRemote)
            {
                GUI.Box(new Rect(rect.x + 4, rect.y, rect.width - 8, 5), GUIContent.none, isHead ? styles.commitLineHead : styles.commitLineRemote);
                y += 4;
            }

            if (GitManager.Settings.UseGavatar && Application.internetReachability != NetworkReachability.NotReachable)
            {
                Texture2D avatar = GetProfilePixture(commit.Committer.Email);
                if (avatar != null)
                {
                    GUI.Box(new Rect(rect.x + x, rect.y + y, 32, 32), GitGUI.GetTempContent(avatar), styles.avatar);
                }
                else
                {
                    GUI.Box(new Rect(rect.x + x, rect.y + y, 32, 32), GitManager.icons.loadingIconSmall, styles.avatar);
                }
            }
            else
            {
                UnityEngine.Random.InitState(commit.Committer.Name.GetHashCode());
                GUI.contentColor = UnityEngine.Random.ColorHSV(0, 1, 0.6f, 0.6f, 0.8f, 1, 1, 1);
                GUI.Box(new Rect(rect.x + x, rect.y + y, 32, 32), GitGUI.GetTempContent(commit.Committer.Name.Substring(0, 1).ToUpper()), styles.avatarName);
                GUI.contentColor = Color.white;
            }


            //if (avatar != null)
            //{
            //GUI.DrawTexture(new Rect(rect.x + x, rect.y + y, 32, 32), avatar);
            //}
            x += 38;
            EditorGUI.LabelField(new Rect(rect.x + x, rect.y + y, rect.width - x, EditorGUIUtility.singleLineHeight), GitGUI.GetTempContent(commit.Committer.Name), EditorStyles.boldLabel);
            y += 16;
            EditorGUI.LabelField(new Rect(rect.x + x, rect.y + y, rect.width - x, EditorGUIUtility.singleLineHeight), GitGUI.GetTempContent(FormatRemainningTime(commit.Committer.When.UtcDateTime)));
            y += EditorGUIUtility.singleLineHeight + 3;
            int firstNewLineIndex = commit.Message.IndexOf(Environment.NewLine);

            EditorGUI.LabelField(new Rect(rect.x + x, rect.y + y, rect.width - x - 10, EditorGUIUtility.singleLineHeight + 4), GitGUI.GetTempContent(firstNewLineIndex > 0 ? commit.Message.Substring(0, firstNewLineIndex) : commit.Message), styles.commitMessage);
            y += 8;
            if (branches != null)
            {
                if (branches.Length > 0)
                {
                    y += EditorGUIUtility.singleLineHeight;
                }
                foreach (var branch in branches)
                {
                    GUIStyle   style        = branch.IsRemote ? styles.remoteCommitTag : branch.IsCurrentRepositoryHead ? styles.headCommitTag : styles.otherCommitTag;
                    GUIContent labelContent = GitGUI.GetTempContent(branch.FriendlyName);
                    float      labelWidth   = style.CalcSize(labelContent).x;
                    GUI.Label(new Rect(rect.x + x, rect.y + y, labelWidth, EditorGUIUtility.singleLineHeight), labelContent, style);
                    x += labelWidth + 4;
                }
            }

            x  = 12;
            y += EditorGUIUtility.singleLineHeight * 1.5f;
            GUI.Box(new Rect(rect.x + x, rect.y + y, rect.width - x - x, EditorGUIUtility.singleLineHeight), GUIContent.none, "EyeDropperHorizontalLine");
            y += EditorGUIUtility.singleLineHeight / 3;
            EditorGUI.LabelField(new Rect(rect.x + x, rect.y + y, rect.width - x, EditorGUIUtility.singleLineHeight), GitGUI.GetTempContent(commit.Id.Sha));
            x += GUI.skin.label.CalcSize(GitGUI.GetTempContent(commit.Id.Sha)).x + 8;
            Rect buttonRect = new Rect(rect.x + x, rect.y + y, 64, EditorGUIUtility.singleLineHeight);

            x          += 64;
            GUI.enabled = selectedBranch.IsCurrentRepositoryHead && !isHead;
            if (GUI.Button(buttonRect, GitGUI.GetTempContent("Reset", "Reset changes made up to this commit"), "minibuttonleft"))
            {
                if (GitExternalManager.TakeReset(GitManager.Repository.Lookup <Commit>(commit.Id)))
                {
                    AssetDatabase.Refresh();
                    GitManager.MarkDirty();
                }
                else
                {
                    PopupWindow.Show(buttonRect, new ResetPopupWindow(GitManager.Repository.Lookup <Commit>(commit.Id)));
                }
            }
            GUI.enabled = true;
            buttonRect  = new Rect(rect.x + x, rect.y + y, 64, EditorGUIUtility.singleLineHeight);
            if (GUI.Button(buttonRect, GitGUI.GetTempContent("Details"), "minibuttonright"))
            {
                PopupWindow.Show(buttonRect, new GitCommitDetailsWindow(GitManager.Repository.Lookup <Commit>(commit.Id)));
            }

            if (rect.Contains(current.mousePosition))
            {
                if (current.type == EventType.ContextClick)
                {
                    //GenericMenu commitContexMenu = new GenericMenu();

                    //commitContexMenu.ShowAsContext();
                    current.Use();
                }
            }
            GitProfilerProxy.EndSample();
        }
예제 #2
0
        private void DoCommit(Rect rect, Rect scrollRect, CommitInfo commit)
        {
            GitProfilerProxy.BeginSample("Git History Window Commit GUI", this);
            Event current = Event.current;

            if (rect.y > scrollRect.height + historyScroll.y || rect.y + scrollRect.height < historyScroll.y)
            {
                return;
            }

            BranchInfo[] branches = commit.Branches;
            bool         isHead   = commit.IsHead;
            bool         isRemote = commit.IsRemote;

            Color branchColor = Color.white;

            if (branches != null)
            {
                foreach (var branch in branches)
                {
                    if (branch.IsRemote)
                    {
                        branchColor = remoteColor;
                        break;
                    }
                    if (branch.IsCurrentRepositoryHead)
                    {
                        branchColor = headColor;
                        break;
                    }
                    UnityEngine.Random.InitState(branch.CanonicalName.GetHashCode());
                    branchColor = UnityEngine.Random.ColorHSV(0, 1, 0, 1);
                }
            }

            GUI.backgroundColor = new Color(1, 1, 1, 0.4f);
            GUI.Box(new Rect(24, rect.y + 5, 16, 16), GUIContent.none, "AC LeftArrow");
            GUI.backgroundColor = branchColor;
            GUI.Box(new Rect(9, rect.y + 6, 12, 12), GUIContent.none, styles.historyKnobNormal);
            GUI.backgroundColor = Color.white;

            float y = 8;
            float x = 12;

            if (isHead)
            {
                //GUI.Box(new Rect(commitRect.x + 4, commitRect.y, commitRect.width - 8, commitRect.height - 8), GUIContent.none, "TL SelectionButton PreDropGlow");
            }
            GUI.Box(rect, GUIContent.none, "RegionBg");
            if (isHead || isRemote)
            {
                GUI.Box(new Rect(rect.x + 4, rect.y, rect.width - 8, 5), GUIContent.none, isHead ? styles.commitLineHead : styles.commitLineRemote);
                y += 4;
            }

            if (GitManager.Settings.UseGavatar && Application.internetReachability != NetworkReachability.NotReachable)
            {
                Texture2D avatar = GetProfilePixture(commit.Committer.Email);
                if (avatar != null)
                {
                    GUI.Box(new Rect(rect.x + x, rect.y + y, 32, 32), GitGUI.GetTempContent(avatar), styles.avatar);
                }
                else
                {
                    GUI.Box(new Rect(rect.x + x, rect.y + y, 32, 32), GitOverlay.icons.loadingIconSmall, styles.avatar);
                }
            }
            else
            {
                UnityEngine.Random.InitState(commit.Committer.Name.GetHashCode());
                GUI.contentColor = UnityEngine.Random.ColorHSV(0, 1, 0.6f, 0.6f, 0.8f, 1, 1, 1);
                GUI.Box(new Rect(rect.x + x, rect.y + y, 32, 32), GitGUI.GetTempContent(commit.Committer.Name.Substring(0, 1).ToUpper()), styles.avatarName);
                GUI.contentColor = Color.white;
            }


            //if (avatar != null)
            //{
            //GUI.DrawTexture(new Rect(rect.x + x, rect.y + y, 32, 32), avatar);
            //}
            x += 38;
            EditorGUI.LabelField(new Rect(rect.x + x, rect.y + y, rect.width - x, EditorGUIUtility.singleLineHeight), GitGUI.GetTempContent(commit.Committer.Name), EditorStyles.boldLabel);
            y += 16;
            EditorGUI.LabelField(new Rect(rect.x + x, rect.y + y, rect.width - x, EditorGUIUtility.singleLineHeight), GitGUI.GetTempContent(FormatRemainningTime(commit.Committer.When.UtcDateTime)));
            y += EditorGUIUtility.singleLineHeight + 3;
            int firstNewLineIndex = commit.Message.IndexOf(Environment.NewLine);

            EditorGUI.LabelField(new Rect(rect.x + x, rect.y + y, rect.width - x - 10, EditorGUIUtility.singleLineHeight + 4), GitGUI.GetTempContent(firstNewLineIndex > 0 ? commit.Message.Substring(0, firstNewLineIndex) : commit.Message), styles.commitMessage);
            y += 8;
            if (branches != null)
            {
                if (branches.Length > 0)
                {
                    y += EditorGUIUtility.singleLineHeight;
                }
                foreach (var branch in branches)
                {
                    GUIStyle style = styles.otherCommitTag;
                    if (branch.IsRemote)
                    {
                        GUI.backgroundColor = remoteColor;
                    }
                    else if (branch.IsCurrentRepositoryHead)
                    {
                        GUI.backgroundColor = headColor;
                    }
                    else
                    {
                        UnityEngine.Random.InitState(branch.CanonicalName.GetHashCode());
                        GUI.backgroundColor = UnityEngine.Random.ColorHSV(0, 1, 0, 1);
                    }
                    GUIContent labelContent   = GitGUI.GetTempContent(branch.FriendlyName, branch.CanonicalName);
                    float      labelWidth     = style.CalcSize(labelContent).x;
                    Rect       branchIconRect = new Rect(rect.x + x, rect.y + y, labelWidth, EditorGUIUtility.singleLineHeight);
                    GUI.Label(branchIconRect, labelContent, style);
                    x += labelWidth + 4;
                    GUI.backgroundColor = Color.white;

                    if (Event.current.type == EventType.ContextClick && branchIconRect.Contains(Event.current.mousePosition))
                    {
                        GenericMenu branchContextMenu = new GenericMenu();
                        BranchInfo  b = branch;
                        branchContextMenu.AddItem(new GUIContent("View branch"), false, () => { ViewBranchCallback(b); });
                        if (!b.IsRemote && !b.IsCurrentRepositoryHead)
                        {
                            branchContextMenu.AddItem(new GUIContent("Switch To Branch"), false, () => { SwitchToBranchCallback(b, new Rect(branchIconRect.x - historyScroll.x, branchIconRect.y - historyScroll.y, branchIconRect.width, branchIconRect.height)); });
                        }
                        else
                        {
                            branchContextMenu.AddDisabledItem(new GUIContent("Switch To Branch"));
                        }
                        branchContextMenu.ShowAsContext();
                    }
                }
            }

            x  = 12;
            y += EditorGUIUtility.singleLineHeight * 1.5f;
            GUI.Box(new Rect(rect.x + x, rect.y + y, rect.width - x - x, EditorGUIUtility.singleLineHeight), GUIContent.none, "EyeDropperHorizontalLine");
            y += EditorGUIUtility.singleLineHeight / 3;
            EditorGUI.LabelField(new Rect(rect.x + x, rect.y + y, rect.width - x, EditorGUIUtility.singleLineHeight), GitGUI.GetTempContent(commit.Id.Sha));
            x += GUI.skin.label.CalcSize(GitGUI.GetTempContent(commit.Id.Sha)).x + 8;
            Rect buttonRect = new Rect(rect.x + x, rect.y + y, 64, EditorGUIUtility.singleLineHeight);

            x += 64;
            if (GUI.Button(buttonRect, GitGUI.GetTempContent("Options"), "minibuttonleft"))
            {
                GenericMenu menu = new GenericMenu();

                if (selectedBranch.IsCurrentRepositoryHead && !isHead)
                {
                    menu.AddItem(new GUIContent("Reset"), false, () =>
                    {
                        if (GitExternalManager.TakeReset(GitManager.Repository.Lookup <Commit>(commit.Id)))
                        {
                            AssetDatabase.Refresh();
                            GitManager.MarkDirty();
                        }
                        else
                        {
                            popupsQueue.Enqueue(new KeyValuePair <Rect, PopupWindowContent>(buttonRect, new ResetPopupWindow(GitManager.Repository.Lookup <Commit>(commit.Id))));
                        }
                    });
                }
                else
                {
                    menu.AddDisabledItem(new GUIContent("Reset"));
                }
                menu.AddItem(new GUIContent("Branch Out"), false, () =>
                {
                    popupsQueue.Enqueue(new KeyValuePair <Rect, PopupWindowContent>(buttonRect, new GitCreateBranchWindow(this, GitManager.Repository.Lookup <Commit>(commit.Id), null)));
                });
                menu.DropDown(buttonRect);
            }
            GUI.enabled = true;
            buttonRect  = new Rect(rect.x + x, rect.y + y, 64, EditorGUIUtility.singleLineHeight);
            if (GUI.Button(buttonRect, GitGUI.GetTempContent("Details"), "minibuttonright"))
            {
                PopupWindow.Show(buttonRect, new GitCommitDetailsWindow(GitManager.Repository.Lookup <Commit>(commit.Id)));
            }

            if (rect.Contains(current.mousePosition))
            {
                if (current.type == EventType.ContextClick)
                {
                    //GenericMenu commitContexMenu = new GenericMenu();

                    //commitContexMenu.ShowAsContext();
                    current.Use();
                }
            }
            GitProfilerProxy.EndSample();
        }