public override void OnGUI(Rect rect)
 {
     extension = EditorGUILayout.TextField(new GUIContent("Extension"), extension);
     GitGUI.StartEnable(!string.IsNullOrEmpty(extension));
     if (GUILayout.Button(new GUIContent("Track")))
     {
         GitLfsManager.Track(extension);
         focusWindow.Focus();
         focusWindow.ShowNotification(new GUIContent(extension + " now tracked by LFS."));
         GitLfsManager.Update();
     }
     GitGUI.EndEnable();
 }
        public override void OnGUI(Rect rect)
        {
            GUILayout.Label(new GUIContent("Create Branch"), "IN BigTitle", GUILayout.ExpandWidth(true));
            if (commit != null)
            {
                name = EditorGUILayout.TextField(GitGUI.GetTempContent("Name"), name);
                EditorGUILayout.LabelField(GitGUI.GetTempContent("Commit SHA"), new GUIContent(commit.Sha));
            }
            else
            {
                EditorGUILayout.HelpBox("No selected commit.", MessageType.Warning);
            }

            GitGUI.StartEnable(IsValidBranchName(name) && commit != null);
            GUIContent createBranchContent = GitGUI.GetTempContent("Create Branch");

            if (!IsValidBranchName(name))
            {
                createBranchContent.tooltip = "Invalid Branch Name";
            }
            if (GUILayout.Button(createBranchContent))
            {
                try
                {
                    var branch = GitManager.Repository.CreateBranch(name, commit);
                    if (branch != null)
                    {
                        Debug.Log("Branch " + name + " created");
                        editorWindow.Close();
                        if (onCreated != null)
                        {
                            onCreated.Invoke();
                        }
                    }
                    else
                    {
                        Debug.LogError("Could not create branch: " + name);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("Could not create branch!");
                    Debug.LogException(e);
                }
                finally
                {
                    GitManager.MarkDirty(true);
                }
            }
            GitGUI.EndEnable();
        }
        internal void DoFileDiff(Rect rect, StatusListEntry info, bool enabled, bool selected, GitDiffWindow window)
        {
            RectOffset elementPadding = GetElementStyle().padding;
            float      iconSize       = GetElementStyle().fixedHeight - elementPadding.vertical;
            float      toggleSize     = styles.toggle.fixedHeight;

            Event  current     = Event.current;
            string projectPath = gitManager.ToProjectPath(info.LocalPath);
            string fileName    = info.Name;

            GitGUI.StartEnable(enabled);
            Rect  stageToggleRect = new Rect(rect.x + rect.width - toggleSize * 2, rect.y + (rect.height - toggleSize) * 0.5f, toggleSize, toggleSize);
            bool  canUnstage      = GitManager.CanUnstage(info.State);
            bool  canStage        = GitManager.CanStage(info.State);
            float maxPathSize     = rect.width - stageToggleRect.width - toggleSize - 21;

            if (current.type == EventType.Repaint)
            {
                (selected ? styles.diffElementSelected : GetElementStyle()).Draw(rect, false, false, false, false);
            }

            if (canStage && canUnstage)
            {
                maxPathSize -= stageToggleRect.width - 4;
                Rect stageWarnningRect = new Rect(stageToggleRect.x - stageToggleRect.width - 4, stageToggleRect.y, stageToggleRect.width, stageToggleRect.height);
                EditorGUIUtility.AddCursorRect(stageWarnningRect, MouseCursor.Link);
                if (GUI.Button(stageWarnningRect, GitGUI.IconContent("console.warnicon", "", "Unstaged changed pending. Stage to update index."), GUIStyle.none))
                {
                    string[] localPaths = gitManager.GetPathWithMeta(info.LocalPath).ToArray();
                    if (gitManager.Threading.IsFlagSet(GitSettingsJson.ThreadingType.Stage))
                    {
                        gitManager.AsyncStage(localPaths).onComplete += (o) => { window.Repaint(); };
                    }
                    else
                    {
                        GitCommands.Stage(gitManager.Repository, localPaths);
                        gitManager.MarkDirtyAuto(localPaths);
                    }
                    window.Repaint();
                }
            }

            if (current.type == EventType.Repaint)
            {
                Object asset = null;
                if (UniGitPathHelper.IsPathInAssetFolder(projectPath))
                {
                    asset = AssetDatabase.LoadAssetAtPath(UniGitPathHelper.IsMetaPath(projectPath) ? GitManager.AssetPathFromMeta(projectPath) : projectPath, typeof(Object));
                }

                string     extension  = Path.GetExtension(projectPath);
                GUIContent tmpContent = GUIContent.none;
                if (string.IsNullOrEmpty(extension))
                {
                    tmpContent = GitGUI.GetTempContent(styles.folderIcon, "Folder");
                }

                if (tmpContent.image == null)
                {
                    if (asset != null)
                    {
                        tmpContent = GitGUI.GetTempContent(string.Empty, AssetDatabase.GetCachedIcon(projectPath), asset.GetType().Name);
                    }
                    else
                    {
                        tmpContent = GitGUI.GetTempContent(styles.defaultAssetIcon, "Unknown Type");
                    }
                }

                float x = rect.x + elementPadding.left;
                GUI.Box(new Rect(x, rect.y + elementPadding.top, iconSize, iconSize), tmpContent, styles.assetIcon);
                x += iconSize + 8;

                styles.diffElementName.Draw(new Rect(x, rect.y + elementPadding.top + 2, rect.width - elementPadding.right - iconSize - rect.height, EditorGUIUtility.singleLineHeight), GitGUI.GetTempContent(fileName), false, selected, selected, false);

                x = rect.x + elementPadding.left + iconSize + 8;
                foreach (var diffTypeIcon in gitOverlay.GetDiffTypeIcons(info.State, false))
                {
                    GUI.Box(new Rect(x, rect.y + elementPadding.top + EditorGUIUtility.singleLineHeight + 4, 21, 21), diffTypeIcon, GUIStyle.none);
                    x += 25;
                }

                if (info.MetaChange == (MetaChangeEnum.Object | MetaChangeEnum.Meta))
                {
                    GUI.Box(new Rect(x, rect.y + elementPadding.top + EditorGUIUtility.singleLineHeight + 4, 21, 21), GitGUI.GetTempContent(gitOverlay.icons.objectIconSmall.image, "main asset file changed"), GUIStyle.none);
                    x += 25;
                }
                if (info.MetaChange.IsFlagSet(MetaChangeEnum.Meta))
                {
                    GUI.Box(new Rect(x, rect.y + elementPadding.top + EditorGUIUtility.singleLineHeight + 4, 21, 21), GitGUI.GetTempContent(gitOverlay.icons.metaIconSmall.image, ".meta file changed"), GUIStyle.none);
                    x += 25;
                }
                if (info.Flags.IsFlagSet(StatusEntryFlags.IsLfs))
                {
                    GUI.Box(new Rect(x, rect.y + elementPadding.top + EditorGUIUtility.singleLineHeight + 4, 21, 21), GitGUI.GetTempContent(gitOverlay.icons.lfsObjectIconSmall.image, "Lfs Object"), GUIStyle.none);
                    x += 25;
                }
                if (info.Flags.IsFlagSet(StatusEntryFlags.IsSubModule))
                {
                    GUI.Box(new Rect(x, rect.y + elementPadding.top + EditorGUIUtility.singleLineHeight + 4, 21, 21), GitGUI.GetTempContent(gitOverlay.icons.submoduleTagIconSmall.image, "Sub Module"), GUIStyle.none);
                    x += 25;
                }

                Vector2 pathSize = styles.diffElementPath.CalcSize(GitGUI.GetTempContent(projectPath));
                pathSize.x = Mathf.Min(pathSize.x, maxPathSize - x);

                Rect pathRect = new Rect(x, rect.y + elementPadding.top + EditorGUIUtility.singleLineHeight, pathSize.x, EditorGUIUtility.singleLineHeight * 2);

                styles.diffElementPath.Draw(pathRect, GitGUI.GetTempContent(projectPath), false, selected, selected, false);
                x += pathRect.width + 4;

                if (!enabled)
                {
                    GUI.Box(new Rect(x, rect.y + elementPadding.top + EditorGUIUtility.singleLineHeight + 4, 21, 21), GitGUI.GetTempSpinAnimatedTexture(), GUIStyle.none);
                    //spinning animation needs constant repaint
                    if (gitSettings.AnimationType.HasFlag(GitSettingsJson.AnimationTypeEnum.Loading))
                    {
                        window.Repaint();
                    }
                }
            }

            if (canUnstage || canStage)
            {
                EditorGUI.BeginChangeCheck();
                EditorGUIUtility.AddCursorRect(stageToggleRect, MouseCursor.Link);
                EditorGUI.Toggle(stageToggleRect, canUnstage, styles.toggle);
                if (EditorGUI.EndChangeCheck())
                {
                    bool updateFlag = false;
                    if (GitManager.CanStage(info.State))
                    {
                        string[] paths = gitManager.GetPathWithMeta(info.LocalPath).ToArray();
                        if (gitManager.Threading.IsFlagSet(GitSettingsJson.ThreadingType.Stage))
                        {
                            gitManager.AsyncStage(paths).onComplete += (o) => { window.Repaint(); };
                        }
                        else
                        {
                            GitCommands.Stage(gitManager.Repository, paths);
                            gitManager.MarkDirtyAuto(paths);
                        }
                        updateFlag = true;
                    }
                    else if (GitManager.CanUnstage(info.State))
                    {
                        string[] paths = gitManager.GetPathWithMeta(info.LocalPath).ToArray();
                        if (gitManager.Threading.IsFlagSet(GitSettingsJson.ThreadingType.Unstage))
                        {
                            gitManager.AsyncUnstage(paths).onComplete += (o) => { window.Repaint(); };
                        }
                        else
                        {
                            GitCommands.Unstage(gitManager.Repository, paths);
                            gitManager.MarkDirtyAuto(paths);
                        }
                        updateFlag = true;
                    }

                    if (updateFlag)
                    {
                        window.Repaint();
                        current.Use();
                    }
                }
            }
            GitGUI.EndEnable();
        }
        internal void DoCommit(RepositoryInformation repoInfo, GitDiffWindow window, ref Vector2 commitScroll)
        {
            var settings = window.GitDiffSettings;

            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            if (repoInfo.CurrentOperation == CurrentOperation.Merge)
            {
                GUILayout.Label(GitGUI.GetTempContent("Merge"), styles.mergeIndicator);
            }
            window.CommitMaximized = GUILayout.Toggle(window.CommitMaximized, GitGUI.GetTempContent(gitSettings.ReadFromFile ? "File Commit Message: (Read Only)" : "Commit Message: "), styles.commitMessageFoldoud, GUILayout.Width(gitSettings.ReadFromFile ? 210 : 116));
            EditorGUI.BeginDisabledGroup(true);
            if (!window.CommitMaximized)
            {
                if (!gitSettings.ReadFromFile)
                {
                    EditorGUI.BeginChangeCheck();
                    GUI.SetNextControlName("Commit Message Field");
                    settings.commitMessage = EditorGUILayout.TextArea(settings.commitMessage, GUILayout.Height(EditorGUIUtility.singleLineHeight));
                    if (EditorGUI.EndChangeCheck())
                    {
                        window.SaveCommitMessage();
                    }
                }
                else
                {
                    GUILayout.Label(GitGUI.GetTempContent(settings.commitMessageFromFile), GUI.skin.textArea, GUILayout.Height(EditorGUIUtility.singleLineHeight));
                }
            }
            EditorGUI.EndDisabledGroup();
            EditorGUILayout.EndHorizontal();
            if (window.CommitMaximized)
            {
                commitScroll = EditorGUILayout.BeginScrollView(commitScroll, GUILayout.Height(window.CalculateCommitTextHeight()));
                if (!gitSettings.ReadFromFile)
                {
                    EditorGUI.BeginChangeCheck();
                    GUI.SetNextControlName("Commit Message Field");
                    string newCommitMessage = EditorGUILayout.TextArea(settings.commitMessage, GUILayout.ExpandHeight(true));
                    if (EditorGUI.EndChangeCheck())
                    {
                        if ((Event.current.character == ' ' || Event.current.character == '\0') && !(commitMessageLastChar == ' ' || commitMessageLastChar == '\0'))
                        {
                            if (Undo.GetCurrentGroupName() == GitDiffWindow.CommitMessageUndoGroup)
                            {
                                Undo.IncrementCurrentGroup();
                            }
                        }
                        commitMessageLastChar = Event.current.character;
                        Undo.RecordObject(window, GitDiffWindow.CommitMessageUndoGroup);
                        settings.commitMessage = newCommitMessage;
                        window.SaveCommitMessage();
                    }
                }
                else
                {
                    GUILayout.Label(GitGUI.GetTempContent(settings.commitMessageFromFile), GUI.skin.textArea, GUILayout.ExpandHeight(true));
                }
                EditorGUILayout.EndScrollView();
            }

            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button(GitGUI.GetTempContent("Commit"), styles.commitButton))
            {
                GenericMenu commitMenu = new GenericMenu();
                BuildCommitMenu(commitMenu, window);
                commitMenu.ShowAsContext();
            }
            GitGUI.StartEnable(!gitSettings.ExternalsType.IsFlagSet(GitSettingsJson.ExternalsTypeEnum.Commit));
            settings.emptyCommit = GUILayout.Toggle(settings.emptyCommit, GitGUI.GetTempContent("Empty Commit", "Commit the message only without changes"));
            EditorGUI.BeginChangeCheck();
            settings.amendCommit = GUILayout.Toggle(settings.amendCommit, GitGUI.GetTempContent("Amend Commit", "Amend previous commit."));
            if (EditorGUI.EndChangeCheck())
            {
                if (settings.amendCommit)
                {
                    window.AmmendCommit();
                }
            }
            settings.prettify = GUILayout.Toggle(settings.prettify, GitGUI.GetTempContent("Prettify", "Prettify the commit message"));
            GitGUI.EndEnable();
            GUILayout.FlexibleSpace();
            if (GitGUI.LinkButtonLayout(gitOverlay.icons.donateSmall, GitGUI.Styles.IconButton))
            {
                GitLinks.GoTo(GitLinks.Donate);
            }
            if (GitGUI.LinkButtonLayout(GitGUI.Contents.Help, GitGUI.Styles.IconButton))
            {
                GitLinks.GoTo(GitLinks.DiffWindowHelp);
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();
        }
Пример #5
0
        private void DoHistoryScrollRect(Rect rect, RepositoryInformation info)
        {
            if (loadingCommits != null && !loadingCommits.IsDone)
            {
                Repaint();
                GitGUI.DrawLoading(rect, GitGUI.GetTempContent("Loading Commit History"));
                return;
            }

            Event current = Event.current;

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

            //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."), styles.loadMoreCommitsBtn))
                {
                    maxCommitsCount += CommitsPerExpand;
                    StartUpdateChaches(cachedStatus);
                }
                GitGUI.StartEnable(maxCommitsCount != MaxFirstCommitCount);
                if (GUI.Button(resetRect, GitGUI.GetTempContent("Reset", "Reset the number of commits show."), styles.resetCommitsBtn))
                {
                    if (MaxFirstCommitCount < maxCommitsCount)
                    {
                        maxCommitsCount = MaxFirstCommitCount;
                        Array.Resize(ref cachedCommits, maxCommitsCount);
                    }
                    else
                    {
                        maxCommitsCount = MaxFirstCommitCount;
                        StartUpdateChaches(cachedStatus);
                    }
                }
                GitGUI.EndEnable();
                GUI.EndScrollView();
                GitProfilerProxy.EndSample();
            }
        }
Пример #6
0
        private void DoToolbar(Rect rect, RepositoryInformation info)
        {
            Branch branch = selectedBranch.LoadBranch(gitManager);

            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, EditorStyles.toolbar);
            Rect       btRect            = new Rect(rect.x, rect.y, 64, rect.height);
            GUIContent pushButtonContent = GitGUI.GetTempContent("Push", GitGUI.Textures.CollabPush, "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, EditorStyles.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."), EditorStyles.toolbarButton))
            {
                GoToPull();
            }
            btRect = new Rect(btRect.x + 70, btRect.y, 64, btRect.height);
            GUIContent fetchContent = GitGUI.GetTempContent("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, EditorStyles.toolbarButton))
            {
                GoToFetch();
            }
            GUI.enabled = true;
            btRect      = new Rect(btRect.x + 64, btRect.y, 64, btRect.height);
            if (GUI.Button(btRect, GitGUI.GetTempContent("Merge", GitOverlay.icons.merge.image, hasConflicts ? "Must Resolve conflict before merging" : "Merge fetched changes from remote repository. Changes from the latest fetch will be merged."), EditorStyles.toolbarButton))
            {
                GoToMerge();
            }
            GUI.enabled = gitManager.IsValidRepo;
            btRect      = new Rect(btRect.x + 64, btRect.y, 64, btRect.height);
            if (GUI.Button(btRect, GitGUI.GetTempContent("Stash", GitOverlay.icons.stashIcon.image), EditorStyles.toolbarButton))
            {
                PopupWindow.Show(btRect, new GitStashWindow(gitManager));
            }
            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 = EditorStyles.toolbarDropDown.CalcSize(branchNameContent).x;

            btRect = new Rect(rect.x + rect.width - branchNameWidth, btRect.y, branchNameWidth, btRect.height);
            if (GUI.Button(btRect, branchNameContent, EditorStyles.toolbarDropDown))
            {
                GenericMenu selectBranchMenu = new GenericMenu();
                foreach (var cachedBranch in cachedBranches)
                {
                    selectBranchMenu.AddItem(new GUIContent(cachedBranch.FriendlyName), selectedBranchName == cachedBranch.CanonicalName, (b) =>
                    {
                        SetSelectedBranch((string)b);
                        StartUpdateChaches(cachedStatus);
                    }, cachedBranch.CanonicalName);
                }
                selectBranchMenu.ShowAsContext();
            }
            GitGUI.EndEnable();
            btRect = new Rect(btRect.x - 64, btRect.y, 64, btRect.height);
            GitGUI.StartEnable(gitManager.Settings.ExternalsType.IsFlagSet(GitSettingsJson.ExternalsTypeEnum.Switch) || (!selectedBranch.IsRemote && !selectedBranch.IsCurrentRepositoryHead));
            if (GUI.Button(btRect, GitGUI.GetTempContent("Switch", GitOverlay.icons.checkout.image, selectedBranch.IsRemote ? "Cannot switch to remote branches." : selectedBranch.IsCurrentRepositoryHead ? "This branch is the active one" : "Switch to another branch"), EditorStyles.toolbarButton))
            {
                if (externalManager.TakeSwitch())
                {
                    gitManager.Callbacks.IssueAssetDatabaseRefresh();
                    gitManager.MarkDirty();
                }
                else
                {
                    PopupWindow.Show(btRect, new GitCheckoutWindowPopup(gitManager, selectedBranch.LoadBranch(gitManager)));
                }
            }
            GitGUI.EndEnable();
            btRect = new Rect(btRect.x - 21, btRect.y + 1, 21, btRect.height);
            EditorGUIUtility.AddCursorRect(btRect, MouseCursor.Link);
            if (GUI.Button(btRect, GitGUI.Contents.Help, GitGUI.Styles.IconButton))
            {
                GitLinks.GoTo(GitLinks.HistoryWindowHelp);
            }
            GitProfilerProxy.EndSample();
        }