public void LoadStyles()
 {
     styles = new Styles()
     {
         assetIcon = new GUIStyle("NotificationBackground")
         {
             contentOffset = Vector2.zero, alignment = TextAnchor.MiddleCenter, imagePosition = ImagePosition.ImageOnly, padding = new RectOffset(4, 4, 4, 4), border = new RectOffset(12, 12, 12, 12)
         },
         diffElementSelected = "Icon.ClipSelected",
         diffElementSmall    = new GUIStyle("ProjectBrowserHeaderBgTop")
         {
             fixedHeight = 48, margin = new RectOffset(), padding = new RectOffset(4, 4, 4, 4), border = new RectOffset(8, 8, 8, 8)
         },
         diffElementBig = new GUIStyle("ProjectBrowserHeaderBgTop")
         {
             fixedHeight = 60, margin = new RectOffset(), padding = new RectOffset(6, 6, 6, 6), border = new RectOffset(8, 8, 8, 8)
         },
         diffElementName = new GUIStyle(EditorStyles.boldLabel)
         {
             fontSize = 12, onNormal = new GUIStyleState()
             {
                 textColor = Color.white * 0.95f, background = Texture2D.blackTexture
             }
         },
         diffElementPath = new GUIStyle(EditorStyles.label)
         {
             onNormal = new GUIStyleState()
             {
                 textColor = Color.white * 0.9f, background = Texture2D.blackTexture
             }, wordWrap = true, fixedHeight = 0, alignment = TextAnchor.MiddleLeft
         },
         toggle = new GUIStyle("IN Toggle")
         {
             fixedHeight = 32, normal = { background = (Texture2D)GitGUI.IconContentTex("toggle@2x") }, onNormal = { background = (Texture2D)GitGUI.IconContentTex("toggle on@2x") }, active = { background = (Texture2D)GitGUI.IconContentTex("toggle act@2x") }, onActive = { background = (Texture2D)GitGUI.IconContentTex("toggle on act@2x") }, fixedWidth = 0, border = new RectOffset(), padding = new RectOffset(), margin = new RectOffset()
         },
         folderIcon       = EditorGUIUtility.IconContent("Folder Icon").image,
         defaultAssetIcon = EditorGUIUtility.IconContent("DefaultAsset Icon").image
     };
 }
예제 #2
0
        private void DoBranch(Branch branch, BranchCollection branchCollection)
        {
            bool isHead = branch.IsCurrentRepositoryHead;

            GUIContent titleContent = GitGUI.GetTempContent(branch.FriendlyName);

            if (isHead)
            {
                titleContent.text += " (HEAD)";
            }
            if (branch.IsRemote)
            {
                titleContent.image = GitGUI.IconContentTex("ToolHandleGlobal");
            }

            GUILayout.Label(titleContent, isHead ? "IN BigTitle" : "ShurikenModuleTitle", GUILayout.ExpandWidth(true));
            int selectedRemote = Array.FindIndex(remoteCacheList, e => e.Remote == branch.Remote);

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(GitGUI.GetTempContent("Remote"));
            if (remoteNames != null)
            {
                EditorGUI.BeginChangeCheck();
                int newSelectedRemote = EditorGUILayout.Popup(selectedRemote, remoteNames);
                if (EditorGUI.EndChangeCheck() && selectedRemote != newSelectedRemote)
                {
                    branchCollection.Update(branch, (u) =>
                    {
                        u.Remote         = remoteCacheList[newSelectedRemote].Name;
                        u.UpstreamBranch = branch.CanonicalName;
                    });
                }
            }
            else
            {
                GUILayout.Button(GitGUI.GetTempContent("No Remotes"));
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.TextField(GitGUI.GetTempContent("Upstream Branch"), branch.UpstreamBranchCanonicalName);
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUI.enabled = remoteCacheList != null && remoteCacheList.Length < selectedRemote;
            if (GUILayout.Button(GitGUI.GetTempContent("Save", "Send branch changes to selected remote."), EditorStyles.miniButtonLeft))
            {
                branchCollection.Update(branch, (u) =>
                {
                    u.Remote         = remoteCacheList[selectedRemote].Name;
                    u.UpstreamBranch = branch.CanonicalName;
                });
            }
            GUI.enabled = !branch.IsRemote && !isHead;
            Rect switchButtonRect = GUILayoutUtility.GetRect(GitGUI.GetTempContent("Switch"), EditorStyles.miniButtonMid);

            if (GUI.Button(switchButtonRect, GitGUI.GetTempContent("Switch"), EditorStyles.miniButtonMid))
            {
                if (externalManager.TakeSwitch())
                {
                    gitCallbacks.IssueAssetDatabaseRefresh();
                    gitManager.MarkDirty();
                }
                else
                {
                    PopupWindow.Show(switchButtonRect, injectionHelper.CreateInstance <GitCheckoutWindowPopup>(branch));
                }
            }
            GUI.enabled = !isHead;
            if (GUILayout.Button(GitGUI.GetTempContent("Delete", branch.IsCurrentRepositoryHead ? "Can not delete head branch" : ""), EditorStyles.miniButtonMid))
            {
                if (EditorUtility.DisplayDialog("Delete Branch", "Are you sure you want do delete a branch? This action can not be undone.", "Delete", "Cancel"))
                {
                    try
                    {
                        gitManager.Repository.Branches.Remove(branch);
                        gitManager.MarkDirty(true);
                    }
                    catch (Exception e)
                    {
                        logger.LogFormat(LogType.Error, "Could not delete branch: {0}", branch.CanonicalName);
                        logger.LogException(e);
                    }
                }
            }
            GUI.enabled = !branch.IsRemote;
            if (GUILayout.Button(GitGUI.GetTempContent("Reset", "Reset branch properties."), EditorStyles.miniButtonRight))
            {
                branchCollection.Update(branch, (u) =>
                {
                    u.Remote         = "";
                    u.UpstreamBranch = "";
                });
            }
            GUI.enabled = true;
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
        }
예제 #3
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);
        }
예제 #4
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();
        }