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();
        }
        private void DoHistoryScrollRect(Rect rect, RepositoryInformation info)
        {
            if (loadingCommits != null && !loadingCommits.IsDone)
            {
                Repaint();
                GitGUI.DrawLoading(rect, new GUIContent("Loading Commit History"));
                return;
            }

            Event current = Event.current;

            GUI.Box(new Rect(14, rect.y + 2, 2, rect.height), GUIContent.none, "AppToolbar");

            //behind,ahead and merge checking

            bool displayWarnningBox = DoWarningBoxValidate(info, selectedBranch);

            //commit layout
            if (current.type == EventType.Layout)
            {
                GitProfilerProxy.BeginSample("Git History Window Scroll Rect GUI Layout", this);
                Rect lastCommitRect = new Rect(32, commitSpacing, Mathf.Max(rect.width - 24, 512) - 32, 0);

                if (displayWarnningBox)
                {
                    warningBoxRect    = new Rect(lastCommitRect.x, lastCommitRect.y, lastCommitRect.width, helpBoxHeight);
                    lastCommitRect.y += helpBoxHeight + commitSpacing;
                }

                for (int i = 0; i < cachedCommits.Length; i++)
                {
                    lastCommitRect = LayoutCommit(lastCommitRect, cachedCommits[i]);
                    if (i < commitRects.Length)
                    {
                        commitRects[i] = lastCommitRect;
                    }
                }

                historyScrollContentsRect         = new Rect(0, 0, lastCommitRect.width + 32, lastCommitRect.y + lastCommitRect.height + commitSpacing * 2);
                historyScrollContentsRect.height += EditorGUIUtility.singleLineHeight * 3;
                GitProfilerProxy.EndSample();
            }
            else
            {
                GitProfilerProxy.BeginSample("Git History Window Scroll Rect GUI Other", this);
                historyScroll = GUI.BeginScrollView(rect, historyScroll, historyScrollContentsRect);

                if (displayWarnningBox)
                {
                    DoWarningBox(warningBoxRect, info, selectedBranch);
                }

                for (int i = 0; i < cachedCommits.Length; i++)
                {
                    if (i < commitRects.Length)
                    {
                        DoCommit(commitRects[i], rect, cachedCommits[i]);
                    }
                }

                Rect commitsCountRect = new Rect(32, historyScrollContentsRect.height - EditorGUIUtility.singleLineHeight * 4, historyScrollContentsRect.width - 64, EditorGUIUtility.singleLineHeight);

                GUI.Label(commitsCountRect, GitGUI.GetTempContent(cachedCommits.Length + " / " + maxCommitsCount), EditorStyles.centeredGreyMiniLabel);

                Rect resetRect    = new Rect(historyScrollContentsRect.width / 2, historyScrollContentsRect.height - EditorGUIUtility.singleLineHeight * 3, 64, EditorGUIUtility.singleLineHeight);
                Rect loadMoreRect = new Rect(historyScrollContentsRect.width / 2 - 64, historyScrollContentsRect.height - EditorGUIUtility.singleLineHeight * 3, 64, EditorGUIUtility.singleLineHeight);
                if (GUI.Button(loadMoreRect, GitGUI.IconContent("ol plus", "More", "Show more commits."), "ButtonLeft"))
                {
                    maxCommitsCount += CommitsPerExpand;
                    StartUpdateChaches(GitManager.LastStatus);
                }
                GitGUI.StartEnable(maxCommitsCount != MaxFirstCommitCount);
                if (GUI.Button(resetRect, GitGUI.GetTempContent("Reset", "Reset the number of commits show."), "ButtonRight"))
                {
                    if (MaxFirstCommitCount < maxCommitsCount)
                    {
                        maxCommitsCount = MaxFirstCommitCount;
                        Array.Resize(ref cachedCommits, maxCommitsCount);
                    }
                    else
                    {
                        maxCommitsCount = MaxFirstCommitCount;
                        StartUpdateChaches(GitManager.LastStatus);
                    }
                }
                GitGUI.EndEnable();
                GUI.EndScrollView();
                GitProfilerProxy.EndSample();
            }
        }
Example #3
0
 public override Vector2 GetWindowSize()
 {
     return(new Vector2(360, EditorStyles.wordWrappedLabel.CalcHeight(GitGUI.GetTempContent(commit.Message), 360) + EditorGUIUtility.singleLineHeight * 5));
 }
        private void DoToolbar(Rect rect, RepositoryInformation info)
        {
            Branch branch = selectedBranch.LoadBranch();

            if (branch == null)
            {
                EditorGUILayout.HelpBox(string.Format("Invalid Branch: '{0}'", selectedBranch.CanonicalName), MessageType.Warning, true);
                return;
            }

            GitGUI.StartEnable();
            GitProfilerProxy.BeginSample("Git History Window Toolbar GUI", this);
            GUI.Box(rect, GUIContent.none, "Toolbar");
            Rect       btRect            = new Rect(rect.x, rect.y, 64, rect.height);
            GUIContent pushButtonContent = GitGUI.GetTempContent(EditorGUIUtility.FindTexture("CollabPush"), "Push", "Push local changes to a remote repository.");

            if (info.CurrentOperation == CurrentOperation.Merge)
            {
                GUI.enabled = false;
                pushButtonContent.tooltip = "Do a Merge commit before pushing.";
            }
            else if (hasConflicts)
            {
                GUI.enabled = false;
                pushButtonContent.tooltip = "Resolve conflicts before pushing.";
            }
            else if (selectedBranch == null)
            {
                GUI.enabled = false;
                pushButtonContent.tooltip = "No Selected branch. Create a new branch or create atleast one commit.";
            }
            if (GUI.Button(btRect, pushButtonContent, "toolbarbutton"))
            {
                GoToPush();
            }
            btRect      = new Rect(btRect.x + 64, btRect.y, 64, btRect.height);
            GUI.enabled = !hasConflicts;
            if (GUI.Button(btRect, GitGUI.IconContent("CollabPull", "Pull", hasConflicts ? "Must resolve conflicts before pulling" : "Pull changes from remote repository by fetching them and then merging them. This is the same as calling Fetch then Merge."), "toolbarbutton"))
            {
                GoToPull();
            }
            btRect = new Rect(btRect.x + 70, btRect.y, 64, btRect.height);
            GUIContent fetchContent = new GUIContent("Fetch", GitOverlay.icons.fetch.image, "Get changes from remote repository but do not merge them.");

            if (branch.Remote == null)
            {
                fetchContent.tooltip = "Branch does not have a remote.";
                GUI.enabled          = false;
            }
            if (GUI.Button(btRect, fetchContent, "toolbarbutton"))
            {
                GoToFetch();
            }
            GUI.enabled = true;
            btRect      = new Rect(btRect.x + 64, btRect.y, 64, btRect.height);
            if (GUI.Button(btRect, GitGUI.GetTempContent(GitOverlay.icons.merge.image, "Merge", hasConflicts ? "Must Resolve conflict before merging" : "Merge fetched changes from remote repository. Changes from the latest fetch will be merged."), "toolbarbutton"))
            {
                GoToMerge();
            }
            GUI.enabled = GitManager.IsValidRepo;
            btRect      = new Rect(btRect.x + 64, btRect.y, 64, btRect.height);
            if (GUI.Button(btRect, GitGUI.GetTempContent(GitOverlay.icons.stashIcon.image, "Stash"), "toolbarbutton"))
            {
                PopupWindow.Show(btRect, new GitStashWindow());
            }
            GUI.enabled = true;

            GUIContent branchNameContent = GitGUI.GetTempContent(string.IsNullOrEmpty(selectedBranchName) ? "Branch" : selectedBranch.FriendlyName);

            if (selectedBranch.IsRemote)
            {
                branchNameContent.image = GitGUI.IconContentTex("ToolHandleGlobal");
            }
            else if (!selectedBranch.IsCurrentRepositoryHead)
            {
                branchNameContent.image = GitGUI.IconContentTex("IN LockButton on");
            }

            float branchNameWidth = ((GUIStyle)"ToolbarDropDown").CalcSize(branchNameContent).x;

            btRect = new Rect(rect.x + rect.width - branchNameWidth, btRect.y, branchNameWidth, btRect.height);
            if (GUI.Button(btRect, branchNameContent, "ToolbarDropDown"))
            {
                GenericMenu selectBranchMenu = new GenericMenu();
                foreach (var cachedBranch in cachedBranches)
                {
                    selectBranchMenu.AddItem(new GUIContent(cachedBranch.FriendlyName), selectedBranchName == cachedBranch.CanonicalName, (b) =>
                    {
                        SetSelectedBranch((string)b);
                        StartUpdateChaches(GitManager.LastStatus);
                    }, cachedBranch.CanonicalName);
                }
                selectBranchMenu.ShowAsContext();
            }
            GitGUI.EndEnable();
            btRect = new Rect(btRect.x - 64, btRect.y, 64, btRect.height);
            GitGUI.StartEnable(GitManager.Settings.ExternalsType.HasFlag(GitSettings.ExternalsTypeEnum.Switch) || (!selectedBranch.IsRemote && !selectedBranch.IsCurrentRepositoryHead));
            if (GUI.Button(btRect, GitGUI.GetTempContent(GitOverlay.icons.checkout.image, "Switch", selectedBranch.IsRemote ? "Cannot switch to remote branches." : selectedBranch.IsCurrentRepositoryHead ? "This branch is the active one" : "Switch to another branch"), "toolbarbutton"))
            {
                if (GitExternalManager.TakeSwitch())
                {
                    AssetDatabase.Refresh();
                    GitManager.MarkDirty();
                }
                else
                {
                    PopupWindow.Show(btRect, new GitCheckoutWindowPopup(selectedBranch.LoadBranch()));
                }
            }
            GitGUI.EndEnable();
            btRect = new Rect(btRect.x - 21, btRect.y + 1, 21, btRect.height);
            if (GUI.Button(btRect, GitGUI.IconContent("_Help"), "IconButton"))
            {
                GoToHelp();
            }
            GitProfilerProxy.EndSample();
        }
Example #5
0
        protected void OnGUI()
        {
            if (styles == null)
            {
                InitGUI();
            }

            if (!string.IsNullOrEmpty(invalidMessage))
            {
                EditorGUILayout.HelpBox(invalidMessage, MessageType.Error, true);
                if (GUILayout.Button(GitGUI.GetTempContent("Close")))
                {
                    Close();
                }
                return;
            }

            if (Event.current.type == EventType.MouseMove)
            {
                Repaint();
            }

            if (blameHunk == null)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                GUILayout.Label(GitGUI.IconContent("WaitSpin00"));
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.LabelField(GitGUI.GetTempContent("Checking Blame..."), EditorStyles.centeredGreyMiniLabel);
            }
            else
            {
                Rect scrollRect = new Rect(0, 0, position.width, position.height - commitsWindowHeight);
                Rect viewRect   = new Rect(0, 0, 0, lines.Length * EditorGUIUtility.singleLineHeight);
                for (int i = 0; i < lines.Length; i++)
                {
                    viewRect.width = Mathf.Max(viewRect.width, styles.lineStyle.CalcSize(GitGUI.GetTempContent(lines[i])).x);
                }
                viewRect.width += 32;
                linesScroll     = GUI.BeginScrollView(scrollRect, linesScroll, viewRect);
                for (int i = 0; i < lines.Length; i++)
                {
                    GUIContent lineContent = GitGUI.GetTempContent(lines[i]);
                    Rect       lineRect    = new Rect(32, i * EditorGUIUtility.singleLineHeight, viewRect.width - 32, EditorGUIUtility.singleLineHeight);
                    if (lineRect.y < linesScroll.y + scrollRect.height && lineRect.y + lineRect.height > linesScroll.y)
                    {
                        bool isFromHunk = blameHunk.Any(hunk => hunk.ContainsLine(i) && hunk.FinalCommit.Sha == selectedCommit);
                        if (Event.current.type == EventType.Repaint)
                        {
                            styles.lineNumStyle.Draw(new Rect(0, i * EditorGUIUtility.singleLineHeight, 32, EditorGUIUtility.singleLineHeight), i.ToString(), false, false, false, false);
                            styles.lineStyle.Draw(lineRect, lineContent, false, false, isFromHunk, false);
                        }
                        else if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && lineRect.Contains(Event.current.mousePosition))
                        {
                            foreach (var hunk in blameHunk)
                            {
                                if (hunk.ContainsLine(i))
                                {
                                    selectedCommit = hunk.FinalCommit.Sha;
                                    MoveToCommit(selectedCommit);
                                    Repaint();
                                    break;
                                }
                            }
                        }
                    }
                }
                GUI.EndScrollView();

                DoCommitsResize(new Rect(0, position.height - commitsWindowHeight, position.width, 4));

                int   hunkCount    = 0;
                float hunkMaxWidth = 0;
                foreach (var entry in commitLog)
                {
                    Vector2 hunkSize = styles.hunkStyle.CalcSize(GitGUI.GetTempContent(entry.Commit.MessageShort));
                    hunkMaxWidth = Mathf.Max(hunkMaxWidth, hunkSize.x);
                    hunkCount++;
                }
                viewRect    = new Rect(0, 0, hunkMaxWidth, hunkCount * CommitLineHeight);
                scrollRect  = new Rect(0, position.height - commitsWindowHeight + 4, position.width, commitsWindowHeight - 4);
                hunksScroll = GUI.BeginScrollView(scrollRect, hunksScroll, viewRect);

                int hunkId = 0;
                foreach (var entry in commitLog)
                {
                    GUIContent commitContent  = GitGUI.GetTempContent(entry.Commit.MessageShort);
                    Rect       commitRect     = new Rect(0, hunkId * CommitLineHeight, hunkMaxWidth, CommitLineHeight);
                    Rect       commitInfoRect = new Rect(commitRect.x, commitRect.y, 24, commitRect.height);
                    EditorGUIUtility.AddCursorRect(commitInfoRect, MouseCursor.Link);
                    if (Event.current.type == EventType.Repaint)
                    {
                        int controlId = GUIUtility.GetControlID(commitContent, FocusType.Passive, commitRect);
                        styles.hunkStyle.Draw(commitRect, commitContent, controlId, selectedCommit == entry.Commit.Sha);
                        GUIStyle.none.Draw(commitInfoRect, GitGUI.IconContent("SubAssetCollapseButton"), false, false, false, false);
                    }
                    else if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
                    {
                        if (commitInfoRect.Contains(Event.current.mousePosition))
                        {
                            PopupWindow.Show(commitInfoRect, new CommitInfoPopupContent(entry.Commit));
                            Event.current.Use();
                        }
                        else if (commitRect.Contains(Event.current.mousePosition))
                        {
                            selectedCommit = entry.Commit.Sha;
                            MoveToLineFromCommit(selectedCommit);
                            Repaint();
                            Event.current.Use();
                        }
                    }
                    hunkId++;
                }

                GUI.EndScrollView();
            }
        }