private void DoToolbar(Rect rect, RepositoryInformation info) { GitProfilerProxy.BeginSample("Git History Window Toolbar GUI", this); GUI.Box(rect, GUIContent.none, "Toolbar"); Rect btRect = new Rect(rect.x, rect.y, 64, rect.height); GUIContent pushButtonContent = GitGUI.GetTempContent(EditorGUIUtility.FindTexture("CollabPush"), "Push", "Push local changes to a remote repository."); if (info.CurrentOperation == CurrentOperation.Merge) { GUI.enabled = false; pushButtonContent.tooltip = "Do a Merge commit before pushing."; } else if (hasConflicts) { GUI.enabled = false; pushButtonContent.tooltip = "Resolve conflicts before pushing."; } if (GUI.Button(btRect, pushButtonContent, "toolbarbutton")) { if (GitExternalManager.TakePush()) { GitManager.MarkDirty(); } else { ScriptableWizard.DisplayWizard <GitPushWizard>("Push", "Push").Init(selectedBranch.LoadBranch()); } } btRect = new Rect(btRect.x + 64, btRect.y, 64, btRect.height); GUI.enabled = !hasConflicts; if (GUI.Button(btRect, GitGUI.GetTempContent(EditorGUIUtility.IconContent("CollabPull").image, "Pull", hasConflicts ? "Must resolve conflicts before pulling" : "Pull changes from remote repository by fetching them and then merging them. This is the same as calling Fetch then Merge."), "toolbarbutton")) { Branch branch = selectedBranch.LoadBranch(); if (branch != null) { if (GitExternalManager.TakePull()) { AssetDatabase.Refresh(); GitManager.MarkDirty(); } else { ScriptableWizard.DisplayWizard <GitPullWizard>("Pull", "Pull").Init(branch); } } else { Debug.LogError("Could Not Load Branch"); } } btRect = new Rect(btRect.x + 70, btRect.y, 64, btRect.height); if (GUI.Button(btRect, GitGUI.GetTempContent(EditorGUIUtility.IconContent("UniGit/GitFetch").image, "Fetch", "Get changes from remote repository but do not merge them."), "toolbarbutton")) { Branch branch = selectedBranch.LoadBranch(); if (branch != null) { if (branch.Remote != null) { if (GitExternalManager.TakeFetch(branch.Remote.Name)) { GitManager.MarkDirty(); } else { ScriptableWizard.DisplayWizard <GitFetchWizard>("Fetch", "Fetch").Init(branch); } } else { Debug.LogError("Branch does not have a remote"); } } else { Debug.LogError("Could not Load Branch"); } } btRect = new Rect(btRect.x + 64, btRect.y, 64, btRect.height); if (GUI.Button(btRect, GitGUI.GetTempContent(EditorGUIUtility.IconContent("UniGit/GitMerge").image, "Merge", hasConflicts ? "Must Resolve conflict before merging" : "Merge fetched changes from remote repository. Changes from the latest fetch will be merged."), "toolbarbutton")) { if (GitExternalManager.TakeMerge()) { GitManager.MarkDirty(); } else { ScriptableWizard.DisplayWizard <GitMergeWizard>("Merge", "Merge"); } } GUI.enabled = true; btRect = new Rect(rect.x + rect.width - 64, btRect.y, 64, btRect.height); if (GUI.Button(btRect, GitGUI.GetTempContent(string.IsNullOrEmpty(selectedBranchName) ? "Branch" : selectedBranch.FriendlyName), "ToolbarDropDown")) { GenericMenu selectBranchMenu = new GenericMenu(); foreach (var branch in cachedBranches) { selectBranchMenu.AddItem(new GUIContent(branch.FriendlyName), false, (b) => { selectedBranchName = (string)b; UpdateSelectedBranch(); }, branch.FriendlyName); } selectBranchMenu.ShowAsContext(); } btRect = new Rect(btRect.x - 64, btRect.y, 64, btRect.height); GUI.enabled = GitManager.Settings.ExternalsType.HasFlag(GitSettings.ExternalsTypeEnum.Switch) || (!selectedBranch.IsRemote && !selectedBranch.IsCurrentRepositoryHead); if (GUI.Button(btRect, GitGUI.GetTempContent(EditorGUIUtility.IconContent("UniGit/GitCheckout").image, "Switch", selectedBranch.IsRemote ? "Cannot switch to remote branches." : selectedBranch.IsCurrentRepositoryHead ? "This branch is the active one" : "Switch to another branch"), "toolbarbutton")) { if (GitExternalManager.TakeSwitch()) { AssetDatabase.Refresh(); GitManager.MarkDirty(); } //todo Implement native switching } GUI.enabled = true; GitProfilerProxy.EndSample(); }
private void DoToolbar(Rect rect, RepositoryInformation info) { Branch branch = selectedBranch.LoadBranch(); if (branch == null) { EditorGUILayout.HelpBox(string.Format("Invalid Branch: '{0}'", selectedBranch.CanonicalName), MessageType.Warning, true); return; } GitGUI.StartEnable(); GitProfilerProxy.BeginSample("Git History Window Toolbar GUI", this); GUI.Box(rect, GUIContent.none, "Toolbar"); Rect btRect = new Rect(rect.x, rect.y, 64, rect.height); GUIContent pushButtonContent = GitGUI.GetTempContent(EditorGUIUtility.FindTexture("CollabPush"), "Push", "Push local changes to a remote repository."); if (info.CurrentOperation == CurrentOperation.Merge) { GUI.enabled = false; pushButtonContent.tooltip = "Do a Merge commit before pushing."; } else if (hasConflicts) { GUI.enabled = false; pushButtonContent.tooltip = "Resolve conflicts before pushing."; } else if (selectedBranch == null) { GUI.enabled = false; pushButtonContent.tooltip = "No Selected branch. Create a new branch or create atleast one commit."; } if (GUI.Button(btRect, pushButtonContent, "toolbarbutton")) { GoToPush(); } btRect = new Rect(btRect.x + 64, btRect.y, 64, btRect.height); GUI.enabled = !hasConflicts; if (GUI.Button(btRect, GitGUI.IconContent("CollabPull", "Pull", hasConflicts ? "Must resolve conflicts before pulling" : "Pull changes from remote repository by fetching them and then merging them. This is the same as calling Fetch then Merge."), "toolbarbutton")) { GoToPull(); } btRect = new Rect(btRect.x + 70, btRect.y, 64, btRect.height); GUIContent fetchContent = new GUIContent("Fetch", GitOverlay.icons.fetch.image, "Get changes from remote repository but do not merge them."); if (branch.Remote == null) { fetchContent.tooltip = "Branch does not have a remote."; GUI.enabled = false; } if (GUI.Button(btRect, fetchContent, "toolbarbutton")) { GoToFetch(); } GUI.enabled = true; btRect = new Rect(btRect.x + 64, btRect.y, 64, btRect.height); if (GUI.Button(btRect, GitGUI.GetTempContent(GitOverlay.icons.merge.image, "Merge", hasConflicts ? "Must Resolve conflict before merging" : "Merge fetched changes from remote repository. Changes from the latest fetch will be merged."), "toolbarbutton")) { GoToMerge(); } GUI.enabled = GitManager.IsValidRepo; btRect = new Rect(btRect.x + 64, btRect.y, 64, btRect.height); if (GUI.Button(btRect, GitGUI.GetTempContent(GitOverlay.icons.stashIcon.image, "Stash"), "toolbarbutton")) { PopupWindow.Show(btRect, new GitStashWindow()); } GUI.enabled = true; GUIContent branchNameContent = GitGUI.GetTempContent(string.IsNullOrEmpty(selectedBranchName) ? "Branch" : selectedBranch.FriendlyName); if (selectedBranch.IsRemote) { branchNameContent.image = GitGUI.IconContentTex("ToolHandleGlobal"); } else if (!selectedBranch.IsCurrentRepositoryHead) { branchNameContent.image = GitGUI.IconContentTex("IN LockButton on"); } float branchNameWidth = ((GUIStyle)"ToolbarDropDown").CalcSize(branchNameContent).x; btRect = new Rect(rect.x + rect.width - branchNameWidth, btRect.y, branchNameWidth, btRect.height); if (GUI.Button(btRect, branchNameContent, "ToolbarDropDown")) { GenericMenu selectBranchMenu = new GenericMenu(); foreach (var cachedBranch in cachedBranches) { selectBranchMenu.AddItem(new GUIContent(cachedBranch.FriendlyName), selectedBranchName == cachedBranch.CanonicalName, (b) => { SetSelectedBranch((string)b); StartUpdateChaches(GitManager.LastStatus); }, cachedBranch.CanonicalName); } selectBranchMenu.ShowAsContext(); } GitGUI.EndEnable(); btRect = new Rect(btRect.x - 64, btRect.y, 64, btRect.height); GitGUI.StartEnable(GitManager.Settings.ExternalsType.HasFlag(GitSettings.ExternalsTypeEnum.Switch) || (!selectedBranch.IsRemote && !selectedBranch.IsCurrentRepositoryHead)); if (GUI.Button(btRect, GitGUI.GetTempContent(GitOverlay.icons.checkout.image, "Switch", selectedBranch.IsRemote ? "Cannot switch to remote branches." : selectedBranch.IsCurrentRepositoryHead ? "This branch is the active one" : "Switch to another branch"), "toolbarbutton")) { if (GitExternalManager.TakeSwitch()) { AssetDatabase.Refresh(); GitManager.MarkDirty(); } else { PopupWindow.Show(btRect, new GitCheckoutWindowPopup(selectedBranch.LoadBranch())); } } GitGUI.EndEnable(); btRect = new Rect(btRect.x - 21, btRect.y + 1, 21, btRect.height); if (GUI.Button(btRect, GitGUI.IconContent("_Help"), "IconButton")) { GoToHelp(); } GitProfilerProxy.EndSample(); }