Esempio n. 1
0
 private void OnWizardCreate()
 {
     try
     {
         using (var repository = new Repository(GitManager.RepoPath))
         {
             if (branchNames.Length > 0 && selectedBranch < branchNames.Length)
             {
                 repository.Network.Push(repository.Branches[branchNames[selectedBranch]], pushOptions);
                 GitManager.MarkDirty();
                 var window = GitHistoryWindow.GetWindow(true);
                 window.ShowNotification(new GUIContent("Push Complete"));
             }
             else
             {
                 Debug.LogWarning("No Branch Selected.");
             }
         }
     }
     catch (Exception e)
     {
         if (e is NonFastForwardException)
         {
             GUIContent content = GitGUI.IconContent("console.warnicon", "Could not push changes to remote. Merge changes with remote before pushing.");
             GetWindow <GitHistoryWindow>().ShowNotification(content);
         }
         Debug.LogException(e);
     }
     finally
     {
         EditorUtility.ClearProgressBar();
     }
 }
Esempio n. 2
0
        protected void OnMergeComplete(MergeResult result, string mergeType)
        {
            switch (result.Status)
            {
            case MergeStatus.UpToDate:
                GitHistoryWindow.GetWindow(true).ShowNotification(new GUIContent(string.Format("Everything is Up to date. Nothing to {0}.", mergeType)));
                break;

            case MergeStatus.FastForward:
                GitHistoryWindow.GetWindow(true).ShowNotification(new GUIContent(mergeType + " Complete with Fast Forwarding."));
                break;

            case MergeStatus.NonFastForward:
                GitDiffWindow.GetWindow(true).ShowNotification(new GUIContent("Do a merge commit in order to push changes."));
                GitDiffWindow.GetWindow(false).SetCommitMessage(GitManager.Repository.Info.Message);
                Debug.Log(mergeType + " Complete without Fast Forwarding.");
                break;

            case MergeStatus.Conflicts:
                GUIContent content = GitGUI.IconContent("console.warnicon", "There are merge conflicts!");
                GitDiffWindow.GetWindow(true).ShowNotification(content);
                GitDiffWindow.GetWindow(false).SetCommitMessage(GitManager.Repository.Info.Message);
                break;
            }
            GitManager.MarkDirty();
            Debug.LogFormat("{0} Status: {1}", mergeType, result.Status);
        }
Esempio n. 3
0
        protected void OnMergeComplete(MergeResult result, string mergeType)
        {
            var historyWindow = UniGitLoader.FindWindow <GitHistoryWindow>();
            var diffWindow    = UniGitLoader.FindWindow <GitDiffWindow>();

            switch (result.Status)
            {
            case MergeStatus.UpToDate:
                if (historyWindow != null)
                {
                    historyWindow.ShowNotification(new GUIContent(string.Format("Everything is Up to date. Nothing to {0}.", mergeType)));
                }
                break;

            case MergeStatus.FastForward:
                if (historyWindow != null)
                {
                    historyWindow.ShowNotification(new GUIContent(mergeType + " Complete with Fast Forwarding."));
                }
                break;

            case MergeStatus.NonFastForward:
                if (diffWindow != null)
                {
                    diffWindow.ShowNotification(new GUIContent("Do a merge commit in order to push changes."));
                    diffWindow.SetCommitMessage(gitManager.Repository.Info.Message);
                }
                else
                {
                    GitDiffWindow.SetCommitMessage(gitManager, gitManager.Repository.Info.Message);
                }
                Debug.Log(mergeType + " Complete without Fast Forwarding.");
                break;

            case MergeStatus.Conflicts:
                GUIContent content = GitGUI.IconContent("console.warnicon", "There are merge conflicts!");
                if (diffWindow != null)
                {
                    diffWindow.ShowNotification(content);
                    diffWindow.SetCommitMessage(gitManager.Repository.Info.Message);
                }
                else
                {
                    GitDiffWindow.SetCommitMessage(gitManager, gitManager.Repository.Info.Message);
                }
                break;
            }
            gitManager.MarkDirty();
            Debug.LogFormat("{0} Status: {1}", mergeType, result.Status);
        }
Esempio n. 4
0
 private void OnWizardCreate()
 {
     try
     {
         using (var repository = new Repository(gitManager.GetCurrentRepoPath()))
         {
             if (branchNames.Length > 0 && selectedBranch < branchNames.Length)
             {
                 repository.Network.Push(repository.Branches[branchNames[selectedBranch]], pushOptions);
                 gitManager.MarkDirty();
                 var window = UniGitLoader.FindWindow <GitHistoryWindow>();
                 if (window != null)
                 {
                     window.ShowNotification(new GUIContent("Push Complete"));
                 }
             }
             else
             {
                 logger.Log(LogType.Warning, "No Branch Selected.");
             }
         }
     }
     catch (Exception e)
     {
         if (e is NonFastForwardException)
         {
             GUIContent content = GitGUI.IconContent("console.warnicon", "Could not push changes to remote. Merge changes with remote before pushing.");
             if (focusedWindow != null)
             {
                 focusedWindow.ShowNotification(content);
             }
             else
             {
                 GitGUI.ShowNotificationOnWindow <GitHistoryWindow>(content, false);
             }
         }
         logger.LogException(e);
     }
     finally
     {
         EditorUtility.ClearProgressBar();
     }
 }
        internal override void OnGUI()
        {
            var branches = gitManager.Repository.Branches;

            DoBranch(gitManager.Repository.Head, branches);

            EditorGUILayout.Space();
            GUILayout.Label(GUIContent.none, "sv_iconselector_sep");
            EditorGUILayout.Space();

            scroll = EditorGUILayout.BeginScrollView(scroll);
            if (branches != null)
            {
                foreach (var branch in branches)
                {
                    if (branch.IsCurrentRepositoryHead)
                    {
                        continue;
                    }
                    DoBranch(branch, branches);
                }
            }
            EditorGUILayout.EndScrollView();

            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            Rect createBranchRect = GUILayoutUtility.GetRect(GitGUI.GetTempContent("Create Branch"), GitGUI.Styles.AddComponentBtn);

            if (GUI.Button(createBranchRect, GitGUI.IconContent("ol plus", "Create Branch"), GitGUI.Styles.AddComponentBtn))
            {
                PopupWindow.Show(createBranchRect, injectionHelper.CreateInstance <GitCreateBranchWindow>(gitManager.Repository.Commits.FirstOrDefault(), (Action)(() =>
                {
                    branches = null;
                })));
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
        }
Esempio n. 6
0
 private void InitStyles()
 {
     if (styles == null)
     {
         styles = new Styles()
         {
             consoleBox               = "CN Box",
             entryInfoStyle           = "CN EntryInfo",
             entryInfoStyleSmall      = "CN EntryInfoSmall",
             entryStyleEven           = "CN EntryBackEven",
             entryStyleOdd            = "CN EntryBackOdd",
             entryError               = "CN EntryErrorIcon",
             entryLog                 = "CN EntryInfoIcon",
             entryWarning             = "CN EntryWarnIcon",
             logIconSmall             = GitGUI.IconContent("console.infoicon.sml"),
             warningIconSmall         = GitGUI.IconContent("console.warnicon.sml"),
             warningIconSmallInactive = GitGUI.IconContent("console.warnicon.inactive.sml"),
             errorIconSmall           = GitGUI.IconContent("console.erroricon.sml"),
             errorIconSmallInactive   = GitGUI.IconContent("console.erroricon.inactive.sml")
         };
     }
 }
Esempio n. 7
0
        internal override void OnGUI(Rect rect, Event current)
        {
            var branches = GitManager.Repository.Branches;

            DoBranch(GitManager.Repository.Head, branches);

            EditorGUILayout.Space();
            GUILayout.Label(GUIContent.none, "sv_iconselector_sep");
            EditorGUILayout.Space();

            scroll = EditorGUILayout.BeginScrollView(scroll);
            if (branches != null)
            {
                foreach (var branch in branches)
                {
                    if (branch.IsCurrentRepositoryHead)
                    {
                        continue;
                    }
                    DoBranch(branch, branches);
                }
            }
            EditorGUILayout.EndScrollView();

            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            Rect createBranchRect = GUILayoutUtility.GetRect(GitGUI.GetTempContent("Create Branch"), "AC Button");

            if (GUI.Button(createBranchRect, GitGUI.IconContent("ol plus", "Create Branch"), "AC Button"))
            {
                PopupWindow.Show(createBranchRect, new GitCreateBranchWindow(settingsWindow, GitManager.Repository.Commits.FirstOrDefault(), () =>
                {
                    branches = null;
                }));
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
        }
Esempio n. 8
0
        internal override void OnGUI(Rect rect, Event current)
        {
            GitSettingsJson settings = GitManager.Settings;

            scroll = EditorGUILayout.BeginScrollView(scroll);
            //todo cache general settings to reduce lookup
            GUILayout.Box(GitGUI.IconContent("SceneAsset Icon", "Unity Settings"), "IN BigTitle", GUILayout.ExpandWidth(true), GUILayout.Height(EditorGUIUtility.singleLineHeight * 1.6f));

            if (settings != null)
            {
                bool save = false;

                EditorGUI.BeginChangeCheck();
                settings.AutoStage = EditorGUILayout.Toggle(GitGUI.GetTempContent("Auto Stage", "Auto stage changes for committing when an asset is modified"), settings.AutoStage);
                settings.AutoFetch = EditorGUILayout.Toggle(GitGUI.GetTempContent("Auto Fetch", "Auto fetch repository changes when possible. This will tell you about changes to the remote repository without having to pull. This only works with the Credentials Manager."), settings.AutoFetch);
                save = EditorGUI.EndChangeCheck();
                EditorGUI.BeginChangeCheck();
                settings.ProjectStatusOverlayDepth = EditorGUILayout.DelayedIntField(GitGUI.GetTempContent("Project Status Overlay Depth", "The maximum depth at which overlays will be shown in the Project Window. This means that folders at levels higher than this will not be marked as changed. -1 indicates no limit"), settings.ProjectStatusOverlayDepth);
                settings.ShowEmptyFolders          = EditorGUILayout.Toggle(new GUIContent("Show Empty Folders", "Show status for empty folder meta files and auto stage them, if 'Auto stage' option is enabled."), settings.ShowEmptyFolders);
                settings.GitStatusMultithreaded    = EditorGUILayout.Toggle(GitGUI.GetTempContent("Git Status Multithreaded", "Should Git status retrieval be multithreaded."), settings.GitStatusMultithreaded);
                settings.UseGavatar            = EditorGUILayout.Toggle(GitGUI.GetTempContent("Use Gavatar", "Load Gavatars based on the committer's email address."), settings.UseGavatar);
                settings.MaxCommitTextAreaSize = EditorGUILayout.DelayedFloatField(GitGUI.GetTempContent("Max Commit Text Area Size", "The maximum height the commit text area can expand to."), settings.MaxCommitTextAreaSize);
                settings.DetectRenames         = EditorGUILayout.Toggle(GitGUI.GetTempContent("Detect Renames", "Detect Renames. This will make UniGit detect rename changes of files. Note that this feature is not always working as expected do the the modular updating and how Git itself works."), settings.DetectRenames);
                settings.UseSimpleContextMenus = EditorGUILayout.Toggle(GitGUI.GetTempContent("Use Simple Context Menus", "Use Unity's default context menu on Diff window, instead of the UniGit one (with icons)"), settings.UseSimpleContextMenus);
                if (EditorGUI.EndChangeCheck())
                {
                    save = true;
                    GitManager.MarkDirty();
                }

                if (save)
                {
                    settings.MarkDirty();
                }
            }

            GUILayout.Box(GitGUI.IconContent("ListIcon", "Git Settings"), "IN BigTitle", GUILayout.ExpandWidth(true), GUILayout.Height(EditorGUIUtility.singleLineHeight * 1.6f));

            EditorGUILayout.LabelField(GitGUI.GetTempContent("User"), EditorStyles.boldLabel);
            EditorGUI.indentLevel = 1;
            GitGUI.DoConfigStringField(GitGUI.GetTempContent("Name", "Your full name to be recorded in any newly created commits."), "user.name", "");
            GitGUI.DoConfigStringField(GitGUI.GetTempContent("Email", "Your email address to be recorded in any newly created commits."), "user.email", "");
            EditorGUI.indentLevel = 0;

            EditorGUILayout.LabelField(GitGUI.GetTempContent("Core"), EditorStyles.boldLabel);
            EditorGUI.indentLevel = 1;
            GitGUI.DoConfigToggle(GitGUI.GetTempContent("Auto LF line endings", "Setting this variable to 'true' is the same as setting the text attribute to 'auto' on all files and core.eol to 'crlf'. Set to true if you want to have CRLF line endings in your working directory and the repository has LF line endings. "), "core.autocrlf", true);
            GitGUI.DoConfigToggle(GitGUI.GetTempContent("Bare", "If true this repository is assumed to be bare and has no working directory associated with it. If this is the case a number of commands that require a working directory will be disabled, such as git-add[1] or git-merge[1]."), "core.bare", false);
            GitGUI.DoConfigToggle(GitGUI.GetTempContent("Symlinks", "If false, symbolic links are checked out as small plain files that contain the link text. git-update-index[1] and git-add[1] will not change the recorded type to regular file. Useful on filesystems like FAT that do not support symbolic links."), "core.symlinks", false);
            GitGUI.DoConfigToggle(GitGUI.GetTempContent("Ignore Case", "If true, this option enables various workarounds to enable Git to work better on filesystems that are not case sensitive, like FAT. For example, if a directory listing finds 'makefile' when Git expects 'Makefile', Git will assume it is really the same file, and continue to remember it as 'Makefile'."), "core.ignorecase", true);
            GitGUI.DoConfigToggle(GitGUI.GetTempContent("Logal Reference Updates", "Enable the reflog."), "core.logallrefupdates", true);
            GitGUI.DoConfigIntSlider(GitGUI.GetTempContent("Compression", "An integer -1..9, indicating a default compression level. -1 is the zlib default. 0 means no compression, and 1..9 are various speed/size tradeoffs, 9 being slowest."), -1, 9, "core.compression", -1);
            GitGUI.DoConfigStringField(GitGUI.GetTempContent("Big File Threshold", "Files larger than this size are stored deflated, without attempting delta compression. Storing large files without delta compression avoids excessive memory usage, at the slight expense of increased disk usage. Additionally files larger than this size are always treated as binary."), "core.bigFileThreshold", "512m");
            EditorGUI.indentLevel = 0;

            EditorGUILayout.LabelField(GitGUI.GetTempContent("Branch"), EditorStyles.boldLabel);
            EditorGUI.indentLevel = 1;
            GitGUI.DoConfigStringsField(GitGUI.GetTempContent("Auto Setup Rebase", "When a new branch is created with git branch or git checkout that tracks another branch, this variable tells Git to set up pull to rebase instead of merge."), "branch.autoSetupRebase", autoRebaseOptions, "never");
            EditorGUI.indentLevel = 0;

            EditorGUILayout.LabelField(GitGUI.GetTempContent("Diff"), EditorStyles.boldLabel);
            EditorGUI.indentLevel = 1;
            GitGUI.DoConfigToggle(GitGUI.GetTempContent("Renames", "Whether and how Git detects renames. If set to 'false', rename detection is disabled. If set to 'true', basic rename detection is enabled. "), "diff.renames", true);
            GitGUI.DoConfigIntField(GitGUI.GetTempContent("Rename Limit", "The number of files to consider when performing the copy/rename detection. Use -1 for unlimited"), "diff.renameLimit", -1);
            EditorGUI.indentLevel = 0;

            EditorGUILayout.LabelField(GitGUI.GetTempContent("HTTP"), EditorStyles.boldLabel);
            EditorGUI.indentLevel = 1;
            GitGUI.DoConfigToggle(GitGUI.GetTempContent("Verify SSL Crtificate", "Whether to verify the SSL certificate when fetching or pushing over HTTPS."), "http.sslVerify", true);
            string oldPath = GitManager.Repository.Config.GetValueOrDefault <string>("http.sslCAInfo");

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(GitGUI.GetTempContent("SSL Certificate File", "File containing the certificates to verify the peer with when fetching or pushing over HTTPS."));
            if (GUILayout.Button(GitGUI.GetTempContent(oldPath), "TE ToolbarDropDown"))
            {
                EditorGUI.BeginChangeCheck();
                string newPath = EditorUtility.OpenFilePanelWithFilters("Certificate", string.IsNullOrEmpty(oldPath) ? Application.dataPath : Path.GetFullPath(oldPath), new string[] { "", "cer", "", "pom", "", "crt" });
                if (oldPath != newPath)
                {
                    GitManager.Repository.Config.Set("http.sslCAInfo", newPath);
                }
            }
            EditorGUILayout.EndHorizontal();
            EditorGUI.indentLevel = 0;

            GUILayout.Box(GitGUI.IconContent("IN LockButton on", "Git Ignore"), "IN BigTitle", GUILayout.ExpandWidth(true), GUILayout.Height(EditorGUIUtility.singleLineHeight * 1.6f));

            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button(GitGUI.IconContent("IN LockButton on", "Open Git Ignore File")))
            {
                OpenGitIgnore();
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndScrollView();
        }
Esempio n. 9
0
        internal override void OnGUI()
        {
            EditorGUILayout.BeginHorizontal();
            if (gitSettings != null)
            {
                EditorGUI.BeginChangeCheck();
                int newSelectedIndex = EditorGUILayout.Popup(GitGUI.GetTempContent("Credentials Manager", "The name of the External program to use"), credentialsManager.SelectedAdapterIndex, credentialsManager.AdapterNames);
                gitSettings.CredentialsManager = newSelectedIndex >= 0 && newSelectedIndex < credentialsManager.AdapterIds.Length ? credentialsManager.AdapterIds[newSelectedIndex] : "";
                if (EditorGUI.EndChangeCheck())
                {
                    credentialsManager.SetSelectedAdapter(newSelectedIndex, false);

                    gitSettings.MarkDirty();
                }
                GUI.enabled = newSelectedIndex >= 0;
            }
            if (GUILayout.Button(GitGUI.GetTempContent("Remove"), EditorStyles.miniButton, GUILayout.Width(64)))
            {
                int choice = EditorUtility.DisplayDialogComplex("Remove Credentials Manager", "Disable the current external manager only or delete passwords win external manager.", "Disable Only", "Cancel", "Disable and Delete");
                if (choice == 0)
                {
                    credentialsManager.SetSelectedAdapter(-1, false);
                }
                else if (choice == 2)
                {
                    credentialsManager.SetSelectedAdapter(-1, true);
                }
            }
            GUI.enabled = true;
            EditorGUILayout.EndHorizontal();

            if (credentialsManager.GitCredentials == null)
            {
                EditorGUILayout.HelpBox("No Git Credentials", MessageType.Warning);
                return;
            }

            scroll = EditorGUILayout.BeginScrollView(scroll);
            foreach (var gitCredential in credentialsManager.GitCredentials)
            {
                bool   hasPassword     = credentialsManager.HasPassword(gitCredential);
                string currentusername = credentialsManager.LoadUsername(gitCredential);

                Texture nameIcon    = null;
                string  nameTooltip = "";

                if (data.RepositoryStatus.SubModuleEntries.Any(m => m.Url == gitCredential.URL))
                {
                    nameIcon    = gitOverlay.icons.submoduleIconSmall.image;
                    nameTooltip = "These credentials are automatically used by a sub module";
                }
                else if (data.RepositoryStatus.RemoteEntries.Any(r => r.Url == gitCredential.URL))
                {
                    nameIcon    = GitGUI.IconContentTex("ToolHandleGlobal");
                    nameTooltip = "These credentials are automatically used when dealing with a remote";
                }

                GUILayout.Label(GitGUI.GetTempContent(gitCredential.Name, nameIcon, nameTooltip), GitGUI.Styles.ShurikenModuleTitle);
                EditorGUILayout.Space();
                EditorGUILayout.BeginVertical(GitGUI.Styles.ShurikenModuleBg);
                EditorGUI.BeginChangeCheck();
                GUI.SetNextControlName(gitCredential.URL + " Credential Name");
                gitCredential.Name = EditorGUILayout.TextField(GitGUI.GetTempContent("Name", "Display name. Serves no purpose other then visual."), gitCredential.Name);
                if (credentialsManager.IsAdapterSelected)
                {
                    GUIContent managerUrlContent = GitGUI.GetTempContent("Manager URL");
                    if (!hasPassword)
                    {
                        managerUrlContent.image   = GitGUI.Textures.WarrningIconSmall;
                        managerUrlContent.tooltip = "No credentials with specified url found in external manager.";
                    }
                    EditorGUILayout.BeginHorizontal();
                    gitCredential.ManagerUrl = EditorGUILayout.TextField(managerUrlContent, gitCredential.ManagerUrl);
                    if (GUILayout.Button(GitGUI.IconContent("UnityEditor.SceneHierarchyWindow", string.Empty, "Options"), GitGUI.Styles.IconButton, GUILayout.Width(20)))
                    {
                        var         c           = gitCredential;
                        GenericMenu genericMenu = new GenericMenu();
                        genericMenu.AddItem(new GUIContent("Automatic fill"), false, () =>
                        {
                            c.ManagerUrl = credentialsManager.GetFormatedUrl(c.URL);
                            credentialsManager.GitCredentials.MarkDirty();
                        });
                        genericMenu.AddItem(new GUIContent("Clear"), false, () =>
                        {
                            c.ManagerUrl = "";
                            credentialsManager.GitCredentials.MarkDirty();
                        });
                        genericMenu.ShowAsContext();
                    }
                    EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);
                    EditorGUILayout.EndHorizontal();
                }

                EditorGUILayout.Space();
                GUILayout.Label(GUIContent.none, "sv_iconselector_sep");
                EditorGUILayout.Space();
                bool newIsToken = gitCredential.IsToken;

                if (credentialsManager.IsAdapterSelected)
                {
                    GUI.enabled = false;
                    EditorGUILayout.TextField(GitGUI.GetTempContent(newIsToken ? "Manager Token" : "Manager Username"), currentusername);
                    GUI.enabled = true;
                }
                else
                {
                    GUI.enabled = false;
                    EditorGUILayout.TextField(GitGUI.GetTempContent(newIsToken ? "Current Token" : "Current Username"), currentusername);
                    GUI.enabled = true;
                }

                newIsToken = EditorGUILayout.Toggle(GitGUI.GetTempContent("Is Token", "Are credentials used as a token, like in GitHub."), newIsToken);
                if (newIsToken != gitCredential.IsToken)
                {
                    gitCredential.IsToken = newIsToken;
                    if (gitCredential.IsToken)
                    {
                        credentialsManager.ClearCredentialPassword(gitCredential);
                    }
                }

                GUI.SetNextControlName(gitCredential.URL + " Credential username");
                gitCredential.NewUsername = EditorGUILayout.DelayedTextField(newIsToken ? GitGUI.GetTempContent("New Token") : GitGUI.GetTempContent("New Username"), gitCredential.NewUsername);

                if (!gitCredential.IsToken)
                {
                    GUI.SetNextControlName(gitCredential.URL + " Credential New Password");
                    GitGUI.SecurePasswordFieldLayout(GitGUI.GetTempContent("New Password"), gitCredential.NewPassword);
                    if (credentialsManager.IsAdapterSelected && GUI.GetNameOfFocusedControl() == gitCredential.URL + " Credential New Password")
                    {
                        EditorGUILayout.HelpBox("Password will be set in the current credentials manager: " + credentialsManager.SelectedAdapterName, MessageType.Info);
                    }
                }

                if (EditorGUI.EndChangeCheck())
                {
                    credentialsManager.GitCredentials.MarkDirty();
                }

                EditorGUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                GUI.enabled = !string.IsNullOrEmpty(gitCredential.NewUsername) && (!credentialsManager.IsAdapterSelected || hasPassword);
                if (GUILayout.Button(GitGUI.GetTempContent("Set Username"), EditorStyles.miniButtonLeft))
                {
                    credentialsManager.SetNewUsername(gitCredential, gitCredential.NewUsername);
                    gitCredential.NewUsername = "";
                    EditorUtility.DisplayDialog("Username Changed", "Username successfully changed", "Ok");
                }

                GUI.enabled = gitCredential.NewPassword != null && gitCredential.NewPassword.Length > 0 && (!credentialsManager.IsAdapterSelected || hasPassword);
                if (GUILayout.Button(GitGUI.GetTempContent("Set Password"), EditorStyles.miniButtonMid))
                {
                    credentialsManager.SetNewPassword(gitCredential, gitCredential.NewPassword);
                    gitCredential.NewPassword.Dispose();
                    gitCredential.NewPassword = new SecureString();
                    GUI.FocusControl("");
                    EditorUtility.DisplayDialog("Password Changed", "Password successfully changed", "Ok");
                }

                if (credentialsManager.IsAdapterSelected)
                {
                    GUI.enabled = !hasPassword && !string.IsNullOrEmpty(gitCredential.ManagerUrl) && !string.IsNullOrEmpty(gitCredential.NewUsername) && gitCredential.NewPassword != null && gitCredential.NewPassword.Length > 0;

                    if (GUILayout.Button(GitGUI.GetTempContent("New External", "Create new entry in external password manager with provided new password, username and url."), EditorStyles.miniButtonMid))
                    {
                        credentialsManager.CreateNewExternal(gitCredential.ManagerUrl, gitCredential.NewUsername, gitCredential.NewPassword);
                        gitCredential.NewUsername = "";
                        gitCredential.NewPassword.Dispose();
                        gitCredential.NewPassword = new SecureString();
                    }

                    GUI.enabled = true;
                }
                else
                {
                    GUI.enabled = hasPassword;
                    if (GUILayout.Button(GitGUI.GetTempContent("Clear Password"), EditorStyles.miniButtonMid))
                    {
                        if (EditorUtility.DisplayDialog("Are you sure?", "Are you sure you want to clear the stored password.", "Clear", "Cancel"))
                        {
                            credentialsManager.ClearCredentialPassword(gitCredential);
                        }
                    }
                    GUI.enabled = true;
                }

                if (GUILayout.Button(GitGUI.GetTempContent("Remove"), EditorStyles.miniButtonRight))
                {
                    int choise = EditorUtility.DisplayDialogComplex("Remove Credential Entry", "Removing credential from UniGit only or from external manager as well?", "Remove From UniGit", "Cancel", "Remove From Both");
                    if (choise == 0)
                    {
                        credentialsManager.RemoveCredentials(gitCredential, false);
                    }
                    else if (choise == 1)
                    {
                        credentialsManager.RemoveCredentials(gitCredential, true);
                    }

                    credentialsManager.GitCredentials.MarkDirty();
                    GUIUtility.ExitGUI();
                }
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.EndScrollView();
            GUILayout.FlexibleSpace();
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button(GitGUI.IconContent("ol plus", "Add Credentials"), GitGUI.Styles.AddComponentBtn))
            {
                PopupWindow.Show(addCredentialsRect, new AddCredentialPopup(credentialsManager));
            }
            if (Event.current.type == EventType.Repaint)
            {
                addCredentialsRect = GUILayoutUtility.GetLastRect();
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.HelpBox("UniGit does encrypts passwords but, a Security Credentials Manager is always recommended. As it provides more security.", MessageType.Info);
        }
Esempio n. 10
0
        private void OnGUI()
        {
            InitStyles();

            int logCount     = 0;
            int warningCount = 0;
            int errorCount   = 0;

            int visibleCount = 0;

            for (int i = 0; i < gitLog.Count; i++)
            {
                var logType = gitLog[i].LogType;
                switch (logType)
                {
                case LogType.Error:
                case LogType.Exception:
                case LogType.Assert:
                    errorCount++;
                    if (showError)
                    {
                        visibleCount++;
                    }
                    break;

                case LogType.Warning:
                    warningCount++;
                    if (showWarnings)
                    {
                        visibleCount++;
                    }
                    break;

                case LogType.Log:
                    logCount++;
                    if (showLog)
                    {
                        visibleCount++;
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException("logType", logType, null);
                }
            }

            EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
            if (GUILayout.Button(GitGUI.GetTempContent("Clear"), EditorStyles.toolbarButton))
            {
                gitLog.Clear();
            }

            /*if (GUILayout.Button(GitGUI.GetTempContent("Test"),EditorStyles.toolbarButton))
             * {
             *      var enumNames = Enum.GetNames(typeof(LogType));
             *      for (int i = 0; i < enumNames.Length; i++)
             *      {
             *              logger.Log((LogType)i,"Test " + enumNames[i]);
             *      }
             * }*/

            GUILayout.FlexibleSpace();
            showLog      = GUILayout.Toggle(showLog, GitGUI.GetTempContent(logCount.ToString(), styles.logIconSmall.image), EditorStyles.toolbarButton);
            showWarnings = GUILayout.Toggle(showWarnings, GitGUI.GetTempContent(warningCount.ToString(), warningCount > 0 ? styles.warningIconSmall.image : styles.warningIconSmallInactive.image), EditorStyles.toolbarButton);
            showError    = GUILayout.Toggle(showError, GitGUI.GetTempContent(errorCount.ToString(), errorCount > 0 ? styles.errorIconSmall.image : styles.errorIconSmallInactive.image), EditorStyles.toolbarButton);
            EditorGUILayout.EndHorizontal();

            Rect toolbarRect = new Rect(0, 0, position.width, EditorStyles.toolbarButton.fixedHeight);
            Rect logInfoRect = new Rect(0, position.height - 100, position.width, 100);
            Rect scrollPos   = new Rect(0, toolbarRect.height, position.width, position.height - toolbarRect.height - logInfoRect.height);

            float entryHeight = styles.entryInfoStyle.fixedHeight;

            Rect viewRect = new Rect(0, 0, position.width, visibleCount * entryHeight);

            GUI.Box(scrollPos, GUIContent.none, styles.consoleBox);
            scroll = GUI.BeginScrollView(scrollPos, scroll, viewRect, GUI.skin.horizontalScrollbar, GUIStyle.none);
            Event current = Event.current;
            float lastY   = 0;

            for (int i = 0; i < gitLog.Count; i++)
            {
                var entry = gitLog[i];
                if (IsLogTypeShown(entry.LogType))
                {
                    var  entryStyle         = i % 2 == 1 ? styles.entryStyleEven : styles.entryStyleOdd;
                    var  entryInfoIconStyle = GetLogTypeStyle(entry.LogType);
                    Rect rect = new Rect(0, lastY, viewRect.width, entryHeight);
                    if (rect.y <= scrollPos.height + scroll.y && rect.y + rect.height > scroll.y)
                    {
                        if (current.type == EventType.Repaint)
                        {
                            bool selectedFlag = i == selected;
                            entryStyle.Draw(rect, GUIContent.none, false, selectedFlag, selectedFlag, false);

                            styles.entryInfoStyle.Draw(new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight), GitGUI.GetTempContent(entry.Message), selectedFlag, selectedFlag, selectedFlag, selectedFlag);
                            styles.entryInfoStyle.Draw(new Rect(rect.x, rect.y + 12, rect.width, EditorGUIUtility.singleLineHeight), GitGUI.GetTempContent(GitGUI.FormatRemainningTime(entry.Time)), selectedFlag, selectedFlag, selectedFlag, selectedFlag);

                            entryInfoIconStyle.Draw(rect, GitGUI.GetTempContent(entry.Message), selectedFlag, selectedFlag, selectedFlag, selectedFlag);
                        }
                    }

                    if (current.button == 0 && rect.Contains(current.mousePosition))
                    {
                        if (current.type == EventType.MouseUp)
                        {
                            selected = i;
                            GUI.FocusControl(null);
                            Repaint();
                        }
                        else if (current.type == EventType.MouseDown && current.clickCount == 2)
                        {
                            gitLog.OpenLine(entry.StackTrace, 2);
                        }
                    }

                    lastY += entryHeight;
                }
            }

            GUI.EndScrollView();

            GUI.Box(logInfoRect, GUIContent.none, styles.consoleBox);

            if (selected < gitLog.Count)
            {
                var      selectedEntry = gitLog[selected];
                string   finalMsg      = selectedEntry.Message + "\n" + selectedEntry.StackTrace;
                string[] lines         = finalMsg.Split('\n');

                float maxLineWidth = 0;
                for (int i = 0; i < lines.Length; i++)
                {
                    GUIContent content = GitGUI.GetTempContent(lines[i]);
                    maxLineWidth = Mathf.Max(maxLineWidth, EditorStyles.label.CalcSize(content).x);
                }

                Rect logInfoViewRect = new Rect(0, 0, maxLineWidth, lines.Length * EditorGUIUtility.singleLineHeight);
                infoScroll = GUI.BeginScrollView(logInfoRect, infoScroll, logInfoViewRect);

                for (int i = 0; i < lines.Length; i++)
                {
                    var line = lines[i];
                    if (gitLog.CanOpenLine(line))
                    {
                        Rect buttonRect = new Rect(0, i * EditorGUIUtility.singleLineHeight + 1, 21, 21);
                        if (GUI.Button(buttonRect, GitGUI.IconContent("TimelineContinue"), GitGUI.Styles.IconButton))
                        {
                            gitLog.OpenLine(line);
                        }
                        EditorGUIUtility.AddCursorRect(buttonRect, MouseCursor.Link);
                        Rect labelPos = new Rect(16, i * EditorGUIUtility.singleLineHeight, viewRect.width - 16, EditorGUIUtility.singleLineHeight);
                        EditorGUI.SelectableLabel(labelPos, line);
                    }
                    else
                    {
                        Rect labelPos = new Rect(0, i * EditorGUIUtility.singleLineHeight, viewRect.width, EditorGUIUtility.singleLineHeight);
                        EditorGUI.SelectableLabel(labelPos, line);
                    }
                }
                GUI.EndScrollView();
            }
        }
Esempio n. 11
0
 private void OnEnable()
 {
     titleContent = GitGUI.IconContent("UnityEditor.ConsoleWindow", "GitLog");
     GitWindows.AddWindow(this);
 }
Esempio n. 12
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();
            }
        }
        internal override void OnGUI(Rect rect, Event current)
        {
            if (remotes == null)
            {
                return;
            }
            int remoteCount = remotes.Count();

            if (remoteCount <= 0)
            {
                EditorGUILayout.HelpBox("No Remotes", MessageType.Info);
            }

            scroll = EditorGUILayout.BeginScrollView(scroll);
            foreach (var remote in remoteCacheList)
            {
                GUILayout.Label(GitGUI.GetTempContent(remote.Name), "ShurikenModuleTitle");
                EditorGUILayout.Space();
                EditorGUILayout.BeginVertical();
                EditorGUI.BeginChangeCheck();
                GUI.enabled = false;
                GUI.SetNextControlName(remote.GetHashCode() + " Remote Name");
                EditorGUILayout.TextField(GitGUI.GetTempContent("Name"), remote.Name);
                GUI.enabled = true;
                GUI.SetNextControlName(remote.GetHashCode() + " Remote URL");
                remote.Url = EditorGUILayout.DelayedTextField(GitGUI.GetTempContent("URL"), remote.Url);
                //remote.PushUrl = EditorGUILayout.DelayedTextField(new GUIContent("Push URL"), remote.PushUrl, "ShurikenValue");
                remote.TagFetchMode = (TagFetchMode)EditorGUILayout.EnumPopup(GitGUI.GetTempContent("Tag Fetch Mode"), remote.TagFetchMode);
                EditorGUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                if (GUILayout.Button(GitGUI.GetTempContent("Save"), "minibuttonleft"))
                {
                    remote.Update(remotes);
                    UpdateRemotes();
                    GUI.FocusControl("");
                }
                if (GUILayout.Button(GitGUI.GetTempContent("Open", "Show the repository in browser."), "minibuttonmid"))
                {
                    Application.OpenURL(remote.Url);
                }
                if (GUILayout.Button(GitGUI.GetTempContent("Remove"), "minibuttonright"))
                {
                    remotes.Remove(remote.Name);
                    UpdateRemotes();
                    GUI.FocusControl("");
                }
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.EndScrollView();

            GUILayout.FlexibleSpace();
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button(GitGUI.IconContent("ol plus", "Add Remote"), "AC Button"))
            {
                PopupWindow.Show(addRepositoryButtonRect, new AddRepositoryPopup(remotes));
            }
            if (current.type == EventType.Repaint)
            {
                addRepositoryButtonRect = GUILayoutUtility.GetLastRect();
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
        }
Esempio n. 14
0
        private void OnGUI()
        {
            if (!GitManager.IsValidRepo)
            {
                GitHistoryWindow.InvalidRepoGUI();
                return;
            }

            Event current = Event.current;

            EditorGUILayout.BeginHorizontal("Toolbar");
            EditorGUI.BeginChangeCheck();
            bool value = GUILayout.Toggle(tab == SettingTabEnum.General, GitGUI.GetTempContent("General"), "toolbarbutton");

            if (value)
            {
                tab = SettingTabEnum.General;
            }
            value = GUILayout.Toggle(tab == SettingTabEnum.Externals, GitGUI.GetTempContent("Externals", "External Programs Helpers"), "toolbarbutton");
            if (value)
            {
                tab = SettingTabEnum.Externals;
            }
            value = GUILayout.Toggle(tab == SettingTabEnum.Remotes, GitGUI.GetTempContent("Remotes", "Remote Repositories"), "toolbarbutton");
            if (value)
            {
                tab = SettingTabEnum.Remotes;
            }
            value = GUILayout.Toggle(tab == SettingTabEnum.Branches, GitGUI.GetTempContent("Branches"), "toolbarbutton");
            if (value)
            {
                tab = SettingTabEnum.Branches;
            }
            value = GUILayout.Toggle(tab == SettingTabEnum.LFS, GitGUI.GetTempContent("LFS", "Git Large File Storage (beta)"), "toolbarbutton");
            if (value)
            {
                tab = SettingTabEnum.LFS;
            }
            value = GUILayout.Toggle(tab == SettingTabEnum.Security, GitGUI.GetTempContent("Security"), "toolbarbutton");
            if (value)
            {
                tab = SettingTabEnum.Security;
            }
            if (EditorGUI.EndChangeCheck())
            {
                LoseFocus();
                if (currentTab != null)
                {
                    currentTab.OnFocus();
                }
            }
            GUILayout.FlexibleSpace();
            if (GUILayout.Button(GitGUI.IconContent("_Help"), "IconButton"))
            {
                GoToHelp();
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();
            if (GitManager.Repository != null)
            {
                Rect localRect = new Rect(0, 0, position.width, position.height - EditorGUIUtility.singleLineHeight * 1.6f);
                if (currentTab != null)
                {
                    currentTab.OnGUI(localRect, current);
                }
            }
            EditorGUILayout.Space();

            if (current.type == EventType.MouseDown)
            {
                LoseFocus();
            }
        }
        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();
        }
Esempio n. 16
0
        internal override void OnGUI()
        {
            scroll = EditorGUILayout.BeginScrollView(scroll);
            //todo cache general settings to reduce lookup
            GUILayout.BeginHorizontal(GitGUI.Styles.BigTitle, GUILayout.ExpandWidth(true));
            GUILayout.FlexibleSpace();
            GUILayout.Label(GitGUI.IconContent("SceneAsset Icon", "Unity Settings"), GUILayout.Height(18));
            GUILayout.FlexibleSpace();
            if (GUILayout.Button(GitGUI.Contents.Help, GitGUI.Styles.IconButton))
            {
                GitLinks.GoTo(GitLinks.SettingsUniGitSettings);
            }
            EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);
            GUILayout.EndHorizontal();


            if (gitSettings != null)
            {
                bool save      = false;
                bool updateGit = false;

                EditorGUI.BeginChangeCheck();
                gitSettings.AutoStage = EditorGUILayout.Toggle(GitGUI.GetTempContent("Auto Stage", "Auto stage changes for committing when an asset is modified"), gitSettings.AutoStage);
                gitSettings.AutoFetch = EditorGUILayout.Toggle(GitGUI.GetTempContent("Auto Fetch", "Auto fetch repository changes when possible. This will tell you about changes to the remote repository without having to pull. This only works with the Credentials Manager."), gitSettings.AutoFetch);
                save |= EditorGUI.EndChangeCheck();

                EditorGUI.BeginChangeCheck();
                gitSettings.ProjectStatusOverlayDepth = EditorGUILayout.DelayedIntField(GitGUI.GetTempContent("Project Status Overlay Depth", "The maximum depth at which overlays will be shown in the Project Window. This means that folders at levels higher than this will not be marked as changed. -1 indicates no limit"), gitSettings.ProjectStatusOverlayDepth);
                gitSettings.ShowEmptyFolders          = EditorGUILayout.Toggle(GitGUI.GetTempContent("Show Empty Folders", "Show status for empty folder meta files and auto stage them, if 'Auto stage' option is enabled."), gitSettings.ShowEmptyFolders);
                GUIContent threadingContent = GitGUI.GetTempContent("Use Threading", "When Should Threading be used. In staging, unstaging or status retrival.");
                if ((gitSettings.Threading.IsFlagSet(GitSettingsJson.ThreadingType.Stage) || gitSettings.Threading.IsFlagSet(GitSettingsJson.ThreadingType.Unstage)) && lfsManager.Installed && lfsManager.CheckInitialized())
                {
                    threadingContent.image   = GitGUI.Textures.WarrningIconSmall;
                    threadingContent.tooltip = "Threaded 'Stage' and 'Unstage' are disabled when Git LFS is enabled.";
                }
                gitSettings.Threading = (GitSettingsJson.ThreadingType)EditorGUILayout.EnumFlagsField(threadingContent, gitSettings.Threading);

                gitSettings.UseGavatar            = EditorGUILayout.Toggle(GitGUI.GetTempContent("Use Gavatar", "Load Gavatars based on the committer's email address."), gitSettings.UseGavatar);
                gitSettings.MaxCommitTextAreaSize = EditorGUILayout.DelayedFloatField(GitGUI.GetTempContent("Max Commit Text Area Size", "The maximum height the commit text area can expand to."), gitSettings.MaxCommitTextAreaSize);
                GUIContent detectRenamesContent = GitGUI.GetTempContent("Detect Renames", "Detect Renames. This will make UniGit detect rename changes of files. Note that this feature is not always working as expected do the the modular updating and how Git itself works.");
                if (gitSettings.LazyMode)
                {
                    detectRenamesContent.image   = GitGUI.Textures.WarrningIconSmall;
                    detectRenamesContent.tooltip = "Rename Detection will not work properly in preview with lazy update, altho they WILL still be detected by Git internally.";
                }
                gitSettings.DetectRenames = (GitSettingsJson.RenameTypeEnum)EditorGUILayout.EnumFlagsField(detectRenamesContent, gitSettings.DetectRenames);
                if (EditorGUI.EndChangeCheck())
                {
                    save      = true;
                    updateGit = true;
                }

                EditorGUI.BeginChangeCheck();
                gitSettings.UseSimpleContextMenus = EditorGUILayout.Toggle(GitGUI.GetTempContent("Use Simple Context Menus", "Use Unity's default context menu on Diff window, instead of the UniGit one (with icons and animations)."), gitSettings.UseSimpleContextMenus);
                gitSettings.LazyMode                     = EditorGUILayout.Toggle(GitGUI.GetTempContent("Lazy Update Mode", "Without lazy mode, git status is updated on each assembly reload, leaving and entering play mode, staging, unstaging and any asset change."), gitSettings.LazyMode);
                gitSettings.TrackSystemFiles             = EditorGUILayout.Toggle(GitGUI.GetTempContent("Track System Files", "Should files and folders be tracked that are outside the 'Assets' folder? This should definitely be used if lazy mode is on."), gitSettings.TrackSystemFiles);
                gitSettings.UseUnityConsole              = EditorGUILayout.Toggle(GitGUI.GetTempContent("Use Unity's Console", "Show Info, Warning and Error messages in Unity's builtin console instead of the Git Log."), gitSettings.UseUnityConsole);
                gitSettings.AnimationType                = (GitSettingsJson.AnimationTypeEnum)EditorGUILayout.EnumFlagsField(GitGUI.GetTempContent("Animation Types", "Which animation are allowed?"), gitSettings.AnimationType);
                gitSettings.CreateFoldersForDriftingMeta = EditorGUILayout.Toggle(GitGUI.GetTempContent("Create Missing Meta Folders", "Create Missing Folders for .meta files. If a .meta folder is merged but the folder is not present, create it."), gitSettings.CreateFoldersForDriftingMeta);

                save |= EditorGUI.EndChangeCheck();

                if (save)
                {
                    gitSettings.MarkDirty();
                }
                if (updateGit)
                {
                    gitManager.MarkDirty();
                }
            }

            GUILayout.BeginHorizontal(GitGUI.Styles.BigTitle, GUILayout.ExpandWidth(true));
            GUILayout.FlexibleSpace();
            GUILayout.Label(GitGUI.IconContent("UnityEditor.SceneHierarchyWindow", "Git Settings"), GUILayout.Height(18));
            GUILayout.FlexibleSpace();
            if (GUILayout.Button(GitGUI.Contents.Help, GitGUI.Styles.IconButton))
            {
                GitLinks.GoTo(GitLinks.SettingsGitSettings);
            }
            EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);
            GUILayout.EndHorizontal();

            EditorGUI.BeginDisabledGroup(true);
            EditorGUILayout.TextField(new GUIContent("Repository Path"), paths.RepoPath);
            EditorGUI.EndDisabledGroup();

            GUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(GitGUI.GetTempContent("Main Path"));
            if (GUILayout.Button("Select Main Repository Path", EditorStyles.miniButton))
            {
                settingsManager.ShowChooseMainRepositoryPathPopup(settingsWindow);
                GUIUtility.ExitGUI();
            }
            GUILayout.EndHorizontal();

            string currentConfigFolder = gitManager.GetCurrentDotGitFolder();

            if (Directory.Exists(currentConfigFolder))
            {
                using (Configuration c = Configuration.BuildFrom(currentConfigFolder))
                {
                    EditorGUILayout.LabelField(GitGUI.GetTempContent("User"), EditorStyles.boldLabel);
                    EditorGUI.indentLevel = 1;
                    GitGUI.DoConfigStringField(c, GitGUI.GetTempContent("Name", "Your full name to be recorded in any newly created commits."), "user.name", "");
                    GitGUI.DoConfigStringField(c, GitGUI.GetTempContent("Email", "Your email address to be recorded in any newly created commits."), "user.email", "");
                    EditorGUI.indentLevel = 0;

                    EditorGUILayout.LabelField(GitGUI.GetTempContent("Core"), EditorStyles.boldLabel);
                    EditorGUI.indentLevel = 1;
                    GitGUI.DoConfigToggle(c, GitGUI.GetTempContent("Auto LF line endings", "Setting this variable to 'true' is the same as setting the text attribute to 'auto' on all files and core.eol to 'crlf'. Set to true if you want to have CRLF line endings in your working directory and the repository has LF line endings. "), "core.autocrlf", true);
                    GitGUI.DoConfigToggle(c, GitGUI.GetTempContent("Bare", "If true this repository is assumed to be bare and has no working directory associated with it. If this is the case a number of commands that require a working directory will be disabled, such as git-add[1] or git-merge[1]."), "core.bare", false);
                    GitGUI.DoConfigToggle(c, GitGUI.GetTempContent("Symlinks", "If false, symbolic links are checked out as small plain files that contain the link text. git-update-index[1] and git-add[1] will not change the recorded type to regular file. Useful on filesystems like FAT that do not support symbolic links."), "core.symlinks", false);
                    GitGUI.DoConfigToggle(c, GitGUI.GetTempContent("Ignore Case", "If true, this option enables various workarounds to enable Git to work better on filesystems that are not case sensitive, like FAT. For example, if a directory listing finds 'makefile' when Git expects 'Makefile', Git will assume it is really the same file, and continue to remember it as 'Makefile'."), "core.ignorecase", true);
                    GitGUI.DoConfigToggle(c, GitGUI.GetTempContent("Logal Reference Updates", "Enable the reflog."), "core.logallrefupdates", true);
                    GitGUI.DoConfigIntSlider(c, GitGUI.GetTempContent("Compression", "An integer -1..9, indicating a default compression level. -1 is the zlib default. 0 means no compression, and 1..9 are various speed/size tradeoffs, 9 being slowest."), -1, 9, "core.compression", -1);
                    GitGUI.DoConfigStringField(c, GitGUI.GetTempContent("Big File Threshold", "Files larger than this size are stored deflated, without attempting delta compression. Storing large files without delta compression avoids excessive memory usage, at the slight expense of increased disk usage. Additionally files larger than this size are always treated as binary."), "core.bigFileThreshold", "512m");
                    EditorGUI.indentLevel = 0;

                    EditorGUILayout.LabelField(GitGUI.GetTempContent("Branch"), EditorStyles.boldLabel);
                    EditorGUI.indentLevel = 1;
                    GitGUI.DoConfigStringsField(c, GitGUI.GetTempContent("Auto Setup Rebase", "When a new branch is created with git branch or git checkout that tracks another branch, this variable tells Git to set up pull to rebase instead of merge."), "branch.autoSetupRebase", autoRebaseOptions, "never");
                    EditorGUI.indentLevel = 0;

                    EditorGUILayout.LabelField(GitGUI.GetTempContent("Diff"), EditorStyles.boldLabel);
                    EditorGUI.indentLevel = 1;
                    GitGUI.DoConfigToggle(c, GitGUI.GetTempContent("Renames", "Whether and how Git detects renames. If set to 'false', rename detection is disabled. If set to 'true', basic rename detection is enabled. "), "diff.renames", true);
                    GitGUI.DoConfigIntField(c, GitGUI.GetTempContent("Rename Limit", "The number of files to consider when performing the copy/rename detection. Use -1 for unlimited"), "diff.renameLimit", -1);
                    EditorGUI.indentLevel = 0;

                    EditorGUILayout.LabelField(GitGUI.GetTempContent("HTTP"), EditorStyles.boldLabel);
                    EditorGUI.indentLevel = 1;
                    GitGUI.DoConfigToggle(c, GitGUI.GetTempContent("Verify SSL Crtificate", "Whether to verify the SSL certificate when fetching or pushing over HTTPS."), "http.sslVerify", true);
                    string oldPath = c.GetValueOrDefault <string>("http.sslCAInfo");
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.PrefixLabel(GitGUI.GetTempContent("SSL Certificate File", "File containing the certificates to verify the peer with when fetching or pushing over HTTPS."));
                    if (GUILayout.Button(GitGUI.GetTempContent(oldPath), "TE ToolbarDropDown"))
                    {
                        EditorGUI.BeginChangeCheck();
                        string newPath = EditorUtility.OpenFilePanelWithFilters("Certificate", string.IsNullOrEmpty(oldPath) ? Application.dataPath : Path.GetFullPath(oldPath), new string[] { "", "cer", "", "pom", "", "crt" });
                        if (oldPath != newPath)
                        {
                            c.Set("http.sslCAInfo", newPath);
                        }
                    }

                    EditorGUILayout.EndHorizontal();
                    EditorGUI.indentLevel = 0;
                }
            }

            GUILayout.BeginHorizontal(GitGUI.Styles.BigTitle, GUILayout.ExpandWidth(true));
            GUILayout.FlexibleSpace();
            GUILayout.Label(GitGUI.IconContent("IN LockButton on", "Git Ignore"), GUILayout.Height(18));
            GUILayout.FlexibleSpace();
            if (GUILayout.Button(GitGUI.Contents.Help, GitGUI.Styles.IconButton))
            {
                GitLinks.GoTo(GitLinks.SettingsGitIgnoreHelp);
            }
            EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);
            GUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button(GitGUI.IconContent("IN LockButton on", "Open Git Ignore File")))
            {
                OpenGitIgnore();
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndScrollView();
        }
Esempio n. 17
0
        public override void OnGUI(Rect rect)
        {
            if (Event.current.type == EventType.MouseMove)
            {
                editorWindow.Repaint();
            }
            EditorGUILayout.Space();
            scroll = EditorGUILayout.BeginScrollView(scroll);
            foreach (var entry in data.RepositoryStatus.SubModuleEntries)
            {
                string path = entry.Path;
                float  elementTextHeight = EditorStyles.label.CalcHeight(GitGUI.GetTempContent(path), rect.width);
                Rect   elementRect       = GUILayoutUtility.GetRect(GUIContent.none, moduleStyle, GUILayout.MinHeight(elementTextHeight + EditorGUIUtility.singleLineHeight + 24));

                if (Event.current.type == EventType.Repaint)
                {
                    moduleStyle.Draw(elementRect, GUIContent.none, 0);
                }

                var innerRect = new Rect(elementRect.x + 4, elementRect.y + 2, elementRect.width - 8, elementRect.height - 4);

                Rect nameRect = new Rect(innerRect.x, innerRect.y, innerRect.width - 24, elementTextHeight);
                GUI.Label(nameRect, GitGUI.GetTempContent(path));
                Rect hashRect = new Rect(innerRect.x, innerRect.y + elementTextHeight, innerRect.width - 24, EditorGUIUtility.singleLineHeight);
                GUI.Label(hashRect, GitGUI.GetTempContent(entry.WorkDirId), EditorStyles.miniLabel);
                Rect iconRect = new Rect(innerRect.x, innerRect.y + elementTextHeight + EditorGUIUtility.singleLineHeight, 21, 21);

                bool initActive = false;
                if (entry.Status == SubmoduleStatus.InConfig)
                {
                    GUI.Label(iconRect, GitGUI.GetTempContent(GitGUI.Textures.WarrningIconSmall, "Module is only in config."), GitGUI.Styles.IconButton);
                    initActive  = true;
                    iconRect.x += EditorGUIUtility.singleLineHeight;
                }
                else if (entry.Status.HasFlag(SubmoduleStatus.WorkDirUninitialized))
                {
                    GUI.Label(iconRect, GitGUI.GetTempContent(GitGUI.Textures.WarrningIconSmall, "Module is uninitialized."), GitGUI.Styles.IconButton);
                    initActive  = true;
                    iconRect.x += EditorGUIUtility.singleLineHeight;
                }
                else if (entry.Status.HasFlag(SubmoduleStatus.IndexAdded))
                {
                    GUI.Label(iconRect, GitGUI.GetTempContent(gitOverlay.icons.addedIconSmall.image, "Sub Module is in index but not in head. Commit changes to add module to head."), GitGUI.Styles.IconButton);
                    iconRect.x += EditorGUIUtility.singleLineHeight;
                }
                else if (entry.Status.HasFlag(SubmoduleStatus.WorkDirModified))
                {
                    GUI.Label(iconRect, GitGUI.GetTempContent(GitGUI.Textures.CollabPush, "Sub Module in index and in working directory don't match. Stage module or update it."), GitGUI.Styles.IconButton);
                    iconRect.x += EditorGUIUtility.singleLineHeight;
                }

                if (entry.Status.HasFlag(SubmoduleStatus.WorkDirFilesModified))
                {
                    GUI.Label(iconRect, GitGUI.GetTempContent(gitOverlay.icons.modifiedIconSmall.image, "Sub Module has modified files."), GitGUI.Styles.IconButton);
                    iconRect.x += EditorGUIUtility.singleLineHeight;
                }

                if (entry.Status.HasFlag(SubmoduleStatus.WorkDirFilesUntracked))
                {
                    GUI.Label(iconRect, GitGUI.GetTempContent(gitOverlay.icons.untrackedIconSmall.image, "Sub Module has untracked files."), GitGUI.Styles.IconButton);
                    iconRect.x += EditorGUIUtility.singleLineHeight;
                }

                if (entry.Status.HasFlag(SubmoduleStatus.WorkDirFilesIndexDirty))
                {
                    GUI.Label(iconRect, GitGUI.GetTempContent(gitOverlay.icons.addedIconSmall.image, "Sub Module has added files to index."), GitGUI.Styles.IconButton);
                    iconRect.x += EditorGUIUtility.singleLineHeight;
                }

                GUIContent switchContent = GitGUI.GetTempContent(GitGUI.Textures.OrbitTool, "Explore");
                Rect       switchRect    = new Rect(innerRect.x + innerRect.width - 24, innerRect.y, 24, 24);
                EditorGUIUtility.AddCursorRect(switchRect, MouseCursor.Link);
                if (GUI.Button(switchRect, switchContent, GitGUI.Styles.IconButton))
                {
                    gitManager.SwitchToSubModule(entry.Path);
                    editorWindow.Close();
                }
                Rect optionsRect = new Rect(innerRect.x + innerRect.width - 24, innerRect.y + 24, 24, 24);
                EditorGUIUtility.AddCursorRect(optionsRect, MouseCursor.Link);
                if (GUI.Button(optionsRect, GitGUI.IconContent("UnityEditor.SceneHierarchyWindow", string.Empty, "Options"), GitGUI.Styles.IconButton))
                {
                    GenericMenu menu = new GenericMenu();
                    BuildOptions(menu, path, initActive);
                    menu.DropDown(optionsRect);
                }

                if (Event.current.type == EventType.ContextClick && elementRect.Contains(Event.current.mousePosition))
                {
                    GenericMenu menu = new GenericMenu();
                    BuildOptions(menu, path, initActive);
                    menu.ShowAsContext();
                }
            }
            EditorGUILayout.EndScrollView();
            if (gitManager.InSubModule)
            {
                if (GUILayout.Button(GitGUI.GetTempContent("Return")))
                {
                    gitManager.SwitchToMainRepository();
                }
            }
        }
        internal override void OnGUI(Rect rect, Event current)
        {
            EditorGUILayout.BeginHorizontal();
            GitSettingsJson settings = gitManager.Settings;

            if (settings != null)
            {
                EditorGUI.BeginChangeCheck();
                int newSelectedIndex = EditorGUILayout.Popup(GitGUI.GetTempContent("Credentials Manager", "The name of the External program to use"), credentialsManager.SelectedAdapterIndex, credentialsManager.AdapterNames);
                settings.CredentialsManager = newSelectedIndex >= 0 && newSelectedIndex < credentialsManager.AdapterIds.Length ? credentialsManager.AdapterIds[newSelectedIndex] : "";
                if (EditorGUI.EndChangeCheck())
                {
                    credentialsManager.SetSelectedAdapter(newSelectedIndex);

                    settings.MarkDirty();
                }
                GUI.enabled = newSelectedIndex >= 0;
            }
            if (GUILayout.Button(GitGUI.GetTempContent("Remove"), EditorStyles.miniButton, GUILayout.Width(64)))
            {
                if (EditorUtility.DisplayDialog("Remove Credentials Manager", "This will remove all stored passwords in the Manager. Usernames and URLs will be kept in Unity", "Remove", "Cancel"))
                {
                    credentialsManager.SetSelectedAdapter(-1);
                }
            }
            GUI.enabled = true;
            EditorGUILayout.EndHorizontal();

            if (credentialsManager.GitCredentials == null)
            {
                EditorGUILayout.HelpBox("No Git Credentials", MessageType.Warning);
                return;
            }

            scroll = EditorGUILayout.BeginScrollView(scroll);
            foreach (var gitCredential in credentialsManager.GitCredentials)
            {
                GUILayout.Label(GitGUI.GetTempContent(gitCredential.Name), GitGUI.Styles.ShurikenModuleTitle);
                EditorGUILayout.Space();
                EditorGUILayout.BeginVertical(GitGUI.Styles.ShurikenModuleBg);
                EditorGUI.BeginChangeCheck();
                GUI.SetNextControlName(gitCredential.URL + " Credential Name");
                gitCredential.Name = EditorGUILayout.TextField(GitGUI.GetTempContent("Name"), gitCredential.Name);
                GUI.enabled        = false;
                GUI.SetNextControlName(gitCredential.URL + " Credential URL");
                EditorGUILayout.TextField(GitGUI.GetTempContent("URL"), gitCredential.URL);
                GUI.enabled = true;
                EditorGUILayout.Space();
                GUILayout.Label(GUIContent.none, "sv_iconselector_sep");
                EditorGUILayout.Space();
                bool newIsToken = gitCredential.IsToken;
                newIsToken = EditorGUILayout.Toggle(GitGUI.GetTempContent("Is Token", "Are credentials used as a token, like in GitHub."), newIsToken);
                if (newIsToken != gitCredential.IsToken)
                {
                    gitCredential.IsToken = newIsToken;
                    if (gitCredential.IsToken)
                    {
                        credentialsManager.ClearCredentialPassword(gitCredential.URL);
                    }
                }

                if (gitCredential.IsToken)
                {
                    GUI.SetNextControlName(gitCredential.URL + " Credential Token");
                    string newUsername = EditorGUILayout.DelayedTextField(GitGUI.GetTempContent("Token"), gitCredential.Username);
                    if (newUsername != gitCredential.Username)
                    {
                        credentialsManager.SetNewUsername(gitCredential.URL, newUsername);
                    }
                }
                else
                {
                    GUI.SetNextControlName(gitCredential.URL + " Credential username");
                    string newUsername = EditorGUILayout.DelayedTextField(GitGUI.GetTempContent("Username"), gitCredential.Username);
                    if (newUsername != gitCredential.Username)
                    {
                        credentialsManager.SetNewUsername(gitCredential.URL, newUsername);
                    }
                    GUI.SetNextControlName(gitCredential.URL + " Credential New Password");
                    gitCredential.NewPassword = EditorGUILayout.PasswordField(GitGUI.GetTempContent("New Password"), gitCredential.NewPassword);
                    if (credentialsManager.IsAdapterSelected && GUI.GetNameOfFocusedControl() == gitCredential.URL + " Credential New Password")
                    {
                        EditorGUILayout.HelpBox("Password will be set in the current credentials manager: " + credentialsManager.SelectedAdapterName, MessageType.Info);
                    }

                    if (!gitCredential.HasPassword && !credentialsManager.IsAdapterSelected)
                    {
                        EditorGUILayout.HelpBox("Credential has no set Password", MessageType.Warning);
                    }
                }

                if (EditorGUI.EndChangeCheck())
                {
                    credentialsManager.GitCredentials.MarkDirty();
                }

                GUI.enabled = !string.IsNullOrEmpty(gitCredential.NewPassword);
                EditorGUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                if (GUILayout.Button(GitGUI.GetTempContent("Set Password"), EditorStyles.miniButtonLeft))
                {
                    credentialsManager.SetNewPassword(gitCredential.URL, gitCredential.Username, gitCredential.NewPassword);
                    gitCredential.NewPassword = "";
                    credentialsManager.GitCredentials.MarkDirty();
                    GUI.FocusControl("");
                    EditorUtility.DisplayDialog("Password Changed", "Password successfully changed", "Ok");
                }
                GUI.enabled = gitCredential.HasPassword;
                if (GUILayout.Button(GitGUI.GetTempContent("Clear Password"), EditorStyles.miniButtonMid))
                {
                    credentialsManager.ClearCredentialPassword(gitCredential.URL);
                    credentialsManager.GitCredentials.MarkDirty();
                }
                GUI.enabled = true;
                if (GUILayout.Button(GitGUI.GetTempContent("Save"), EditorStyles.miniButtonMid))
                {
                    credentialsManager.GitCredentials.MarkDirty();
                }
                if (GUILayout.Button(GitGUI.GetTempContent("Remove"), EditorStyles.miniButtonRight))
                {
                    credentialsManager.GitCredentials.MarkDirty();
                    GUIUtility.ExitGUI();
                }
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.EndScrollView();

            GUILayout.FlexibleSpace();
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button(GitGUI.IconContent("ol plus", "Add Credentials"), GitGUI.Styles.AddComponentBtn))
            {
                PopupWindow.Show(addCredentialsRect, new AddCredentialPopup(credentialsManager));
            }
            if (current.type == EventType.Repaint)
            {
                addCredentialsRect = GUILayoutUtility.GetLastRect();
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.HelpBox("UniGit does encrypts passwords but, a Security Credentials Manager is always recommended. As it provides more security.", MessageType.Info);
        }
Esempio n. 19
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();
        }
Esempio n. 20
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();
            }
        }