private void BuildOptions(GenericMenu menu, string path, bool initActive) { if (initActive) { menu.AddItem(new GUIContent("Init/Init"), false, () => { gitManager.Repository.Submodules.Init(path, false); gitManager.MarkDirty(true); }); } else { menu.AddDisabledItem(new GUIContent("Init/Init")); } menu.AddItem(new GUIContent("Init/Force"), false, () => { gitManager.Repository.Submodules.Init(path, true); gitManager.MarkDirty(true); }); menu.AddItem(new GUIContent("Update\\Info"), false, () => { var window = UniGitLoader.GetWindow <GitSubModuleOptionsWizard>(true); window.Init(path); }); }
private static void Revet() { var paths = Selection.assetGUIDs.Select(AssetDatabase.GUIDToAssetPath).SelectMany(GitManager.GetPathWithMeta).ToArray(); if (externalManager.TakeRevert(paths)) { gitManager.Callbacks.IssueAssetDatabaseRefresh(); gitManager.MarkDirty(paths); return; } try { gitManager.Repository.CheckoutPaths("HEAD", paths, new CheckoutOptions() { CheckoutModifiers = CheckoutModifiers.Force, OnCheckoutProgress = OnRevertProgress }); } finally { EditorUtility.ClearProgressBar(); } gitManager.Callbacks.IssueAssetDatabaseRefresh(); gitManager.MarkDirty(paths); }
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).commitMessage = GitManager.Repository.Info.Message; Debug.Log(mergeType + " Complete without Fast Forwarding."); break; case MergeStatus.Conflicts: GUIContent content = EditorGUIUtility.IconContent("console.warnicon"); content.text = "There are merge conflicts!"; GitDiffWindow.GetWindow(true).ShowNotification(content); GitDiffWindow.GetWindow(false).commitMessage = GitManager.Repository.Info.Message; break; } GitManager.MarkDirty(); Debug.LogFormat("{0} Status: {1}", mergeType, result.Status); }
public override void OnGUI(Rect rect) { EditorGUILayout.Space(); resetMode = (ResetMode)EditorGUILayout.EnumPopup(GitGUI.GetTempContent("Reset Type"), resetMode); switch (resetMode) { case ResetMode.Soft: EditorGUILayout.HelpBox("Leave working tree and index untouched", MessageType.Info); break; case ResetMode.Mixed: EditorGUILayout.HelpBox("Leave working tree untouched,reset index (Default)", MessageType.Info); break; case ResetMode.Hard: EditorGUILayout.HelpBox("Reset working tree and index (Will delete all files)", MessageType.Error); break; } GUILayout.FlexibleSpace(); if (GUILayout.Button("Reset")) { if (EditorUtility.DisplayDialog("Reset", "Are you sure you want to reset to the selected commit", "Reset", "Cancel")) { GitProfilerProxy.BeginSample("Git Reset Popup", editorWindow); GitManager.Repository.Reset(resetMode, commit, checkoutOptions); GitManager.MarkDirty(true); editorWindow.Close(); GitProfilerProxy.EndSample(); AssetDatabase.Refresh(); } } EditorGUILayout.Space(); }
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(); } }
private void GoToPush() { if (GitExternalManager.TakePush()) { GitManager.MarkDirty(); } else { ScriptableWizard.DisplayWizard <GitPushWizard>("Push", "Push").Init(selectedBranch.LoadBranch()); } }
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { if (EditorPrefs.GetBool("UniGit_DisablePostprocess")) { return; } if (GitManager.Repository != null) { if (GitManager.Settings != null && GitManager.Settings.AutoStage) { if (importedAssets != null && importedAssets.Length > 0) { string[] importedAssetsToStage = importedAssets.Where(a => !GitManager.IsEmptyFolder(a)).SelectMany(g => GitManager.GetPathWithMeta(g)).Where(g => GitManager.CanStage(GitManager.Repository.RetrieveStatus(g))).ToArray(); if (importedAssetsToStage.Length > 0) { GitManager.Repository.Stage(importedAssetsToStage); GitManager.MarkDirty(importedAssetsToStage); } } if (movedAssets != null && movedAssets.Length > 0) { string[] movedAssetsFinal = movedAssets.Where(a => !GitManager.IsEmptyFolder(a)).SelectMany(g => GitManager.GetPathWithMeta(g)).Where(g => GitManager.CanStage(GitManager.Repository.RetrieveStatus(g))).ToArray(); if (movedAssetsFinal.Length > 0) { GitManager.Repository.Stage(movedAssetsFinal); GitManager.MarkDirty(movedAssetsFinal); } } } //automatic deletion of previously moved asset is necessary even if AutoStage is off if (movedFromAssetPaths != null && movedFromAssetPaths.Length > 0) { string[] movedFromAssetPathsFinal = movedFromAssetPaths.SelectMany(g => GitManager.GetPathWithMeta(g)).Where(g => GitManager.CanUnstage(GitManager.Repository.RetrieveStatus(g))).ToArray(); if (movedFromAssetPathsFinal.Length > 0) { GitManager.Repository.Unstage(movedFromAssetPathsFinal); GitManager.MarkDirty(movedFromAssetPathsFinal); } } //automatic deletion is necessary even if AutoStage is off if (deletedAssets != null && deletedAssets.Length > 0) { string[] deletedAssetsFinal = deletedAssets.SelectMany(g => GitManager.GetPathWithMeta(g)).Where(g => GitManager.CanUnstage(GitManager.Repository.RetrieveStatus(g))).ToArray(); if (deletedAssetsFinal.Length > 0) { GitManager.Repository.Unstage(deletedAssetsFinal); GitManager.MarkDirty(deletedAssetsFinal); } } } }
private void GoToMerge() { if (GitExternalManager.TakeMerge()) { GitManager.MarkDirty(); } else { ScriptableWizard.DisplayWizard <GitMergeWizard>("Merge", "Merge"); } }
private void GoToPull() { if (GitExternalManager.TakePull()) { AssetDatabase.Refresh(); GitManager.MarkDirty(); } else { ScriptableWizard.DisplayWizard <GitPullWizard>("Pull", "Pull").Init(selectedBranch.LoadBranch()); } }
private static void OnRevertProgress(string path, int currentSteps, int totalSteps) { float percent = (float)currentSteps / totalSteps; EditorUtility.DisplayProgressBar("Reverting File", string.Format("Reverting file {0} {1}%", path, (percent * 100).ToString("####")), percent); if (currentSteps >= totalSteps) { GitManager.MarkDirty(); Type type = typeof(EditorWindow).Assembly.GetType("UnityEditor.ProjectBrowser"); EditorWindow.GetWindow(type).ShowNotification(new GUIContent("Revert Complete!")); } }
private void GoToFetch() { var branch = selectedBranch.LoadBranch(); if (GitExternalManager.TakeFetch(branch.Remote.Name)) { GitManager.MarkDirty(); } else { ScriptableWizard.DisplayWizard <GitFetchWizard>("Fetch", "Fetch").Init(branch); } }
public override void OnGUI(Rect rect) { GUILayout.Label(new GUIContent("Create Branch"), "IN BigTitle", GUILayout.ExpandWidth(true)); if (commit != null) { name = EditorGUILayout.TextField(GitGUI.GetTempContent("Name"), name); EditorGUILayout.LabelField(GitGUI.GetTempContent("Commit SHA"), new GUIContent(commit.Sha)); } else { EditorGUILayout.HelpBox("No selected commit.", MessageType.Warning); } GitGUI.StartEnable(IsValidBranchName(name) && commit != null); GUIContent createBranchContent = GitGUI.GetTempContent("Create Branch"); if (!IsValidBranchName(name)) { createBranchContent.tooltip = "Invalid Branch Name"; } if (GUILayout.Button(createBranchContent)) { try { var branch = GitManager.Repository.CreateBranch(name, commit); if (branch != null) { Debug.Log("Branch " + name + " created"); editorWindow.Close(); if (onCreated != null) { onCreated.Invoke(); } } else { Debug.LogError("Could not create branch: " + name); } } catch (Exception e) { Debug.LogError("Could not create branch!"); Debug.LogException(e); } finally { GitManager.MarkDirty(true); } } GitGUI.EndEnable(); }
public override void OnGUI(Rect rect) { EditorGUILayout.Space(); name = EditorGUILayout.TextField(GitGUI.GetTempContent("Name"), name); url = EditorGUILayout.TextField(GitGUI.GetTempContent("URL"), url); GUI.enabled = !string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(url); if (GUILayout.Button(GitGUI.GetTempContent("Add Remote"))) { remoteCollection.Add(name, url); GitManager.MarkDirty(); GetWindow <GitSettingsWindow>().Focus(); } GUI.enabled = true; EditorGUILayout.Space(); }
internal static void InvalidRepoGUI() { EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Box(GitGUI.GetTempContent("Not a GIT Repository"), "NotificationBackground"); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button(GitGUI.GetTempContent("Create"), "LargeButton", GUILayout.Height(32), GUILayout.Width(128))) { if (EditorUtility.DisplayDialog("Initialize Repository", "Are you sure you want to initialize a Repository for your project", "Yes", "Cancel")) { Repository.Init(Application.dataPath.Replace("/Assets", "")); TextAsset textAsset = EditorGUIUtility.Load("UniGit/gitignore.txt") as TextAsset; if (textAsset != null) { string textAssetPath = AssetDatabase.GetAssetPath(textAsset).Replace("Assets/", ""); string newGitIgnoreFile = Path.Combine(Application.dataPath.Replace("Assets", "").Replace("Contents", ""), ".gitignore"); if (!File.Exists(newGitIgnoreFile)) { File.Copy(Path.Combine(Application.dataPath, textAssetPath), newGitIgnoreFile); } else { #if UNITY_EDITOR Debug.Log("Git Ignore file already present"); #endif } } else { Debug.LogError("Missing default gitignore.txt in resources"); } AssetDatabase.Refresh(); AssetDatabase.SaveAssets(); GitManager.Initlize(); GitManager.MarkDirty(); GUIUtility.ExitGUI(); return; } } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); }
private static string[] OnWillSaveAssets(string[] paths) { if (EditorPrefs.GetBool("UniGit_DisablePostprocess")) { return(paths); } if (GitManager.Settings != null && GitManager.Settings.AutoStage && GitManager.Repository != null && paths != null && paths.Length > 0) { string[] pathsFinal = paths.SelectMany(g => GitManager.GetPathWithMeta(g)).Where(g => GitManager.CanStage(GitManager.Repository.RetrieveStatus(g))).ToArray(); if (pathsFinal.Length > 0) { GitManager.Repository.Stage(pathsFinal); GitManager.MarkDirty(pathsFinal); } } return(paths); }
private static void Revet() { var paths = Selection.assetGUIDs.Select(e => AssetDatabase.GUIDToAssetPath(e)).SelectMany(e => GitManager.GetPathWithMeta(e)).ToArray(); if (GitExternalManager.TakeRevert(paths)) { AssetDatabase.Refresh(); GitManager.MarkDirty(paths); return; } GitManager.Repository.CheckoutPaths("HEAD", paths, new CheckoutOptions() { CheckoutModifiers = CheckoutModifiers.Force, OnCheckoutProgress = OnRevertProgress }); EditorUtility.ClearProgressBar(); AssetDatabase.Refresh(); GitManager.MarkDirty(paths); }
private void OnWizardCreate() { try { MergeResult result = GitManager.Repository.MergeFetchedRefs(GitManager.Signature, mergeOptions); GitHistoryWindow.GetWindow(true); OnMergeComplete(result, "Merge"); GitManager.MarkDirty(); AssetDatabase.Refresh(); } catch (CheckoutConflictException e) { Debug.LogException(e); } finally { EditorUtility.ClearProgressBar(); } }
public override void OnGUI(Rect rect) { GUILayout.Label(new GUIContent("Switch to: " + branch.FriendlyName), "IN BigTitle", GUILayout.ExpandWidth(true)); force = EditorGUILayout.Toggle(GitGUI.GetTempContent("Force", "Override working tree changes"), force); if (GUILayout.Button(new GUIContent("Siwtch"))) { CheckoutOptions checkoutOptions = new CheckoutOptions() { OnCheckoutNotify = OnCheckoutNotify, OnCheckoutProgress = OnCheckoutProgress }; if (force) { checkoutOptions.CheckoutModifiers = CheckoutModifiers.Force; } if (branch != null) { try { GitManager.Repository.Checkout(branch, checkoutOptions); Debug.Log("Switched to branch: " + branch.FriendlyName); } catch (Exception e) { Debug.LogError("There was a problem while switching to branch: " + branch.CanonicalName); Debug.LogException(e); } finally { AssetDatabase.Refresh(); GitManager.MarkDirty(true); } } else { Debug.LogError("Trying to switch to null branch"); } } }
private void OnWizardCreate() { try { GitManager.Repository.Network.Fetch(remotes[selectedRemote], fetchOptions); #if UNITY_EDITOR Debug.Log("Fetch Complete"); #endif var window = GitHistoryWindow.GetWindow(true); window.ShowNotification(new GUIContent("Fetch Complete")); GitManager.MarkDirty(true); } catch (Exception e) { Debug.LogException(e); } finally { EditorUtility.ClearProgressBar(); } }
public override void OnGUI(Rect rect) { GUILayout.Label(GitGUI.GetTempContent("Switch to: " + branch.FriendlyName), GitGUI.Styles.BigTitle, GUILayout.ExpandWidth(true)); force = EditorGUILayout.Toggle(GitGUI.GetTempContent("Force", "Override working tree changes"), force); if (GUILayout.Button(GitGUI.GetTempContent("Siwtch"))) { CheckoutOptions checkoutOptions = new CheckoutOptions() { OnCheckoutNotify = OnCheckoutNotify, OnCheckoutProgress = OnCheckoutProgress }; if (force) { checkoutOptions.CheckoutModifiers = CheckoutModifiers.Force; } if (branch != null) { try { GitCommands.Checkout(gitManager.Repository, branch, checkoutOptions); } catch (Exception e) { logger.LogFormat(LogType.Error, "There was a problem while switching to branch: {0}", branch.CanonicalName); logger.LogException(e); } finally { gitCallbacks.IssueAssetDatabaseRefresh(); gitManager.MarkDirty(true); } } else { logger.Log(LogType.Error, "Trying to switch to null branch"); } } }
private void DoGeneral(Event current) { //todo cache general settings to reduce lookup GUILayout.Box(new GUIContent("Unity Settings"), "ProjectBrowserHeaderBgTop"); if (serializedSettings != null) { EditorGUILayout.PropertyField(serializedSettings.FindProperty("AutoStage")); EditorGUILayout.PropertyField(serializedSettings.FindProperty("AutoFetch")); serializedSettings.ApplyModifiedProperties(); EditorGUILayout.PropertyField(serializedSettings.FindProperty("MaxCommits")); EditorGUILayout.PropertyField(serializedSettings.FindProperty("ProjectStatusOverlayDepth")); EditorGUILayout.PropertyField(serializedSettings.FindProperty("ShowEmptyFolders")); EditorGUILayout.PropertyField(serializedSettings.FindProperty("GitStatusMultithreaded")); EditorGUILayout.PropertyField(serializedSettings.FindProperty("UseGavatar")); EditorGUILayout.PropertyField(serializedSettings.FindProperty("MaxCommitTextAreaSize")); if (serializedSettings.ApplyModifiedProperties()) { GitManager.MarkDirty(); } } GUILayout.Box(GitGUI.GetTempContent("Git Settings"), "ProjectBrowserHeaderBgMiddle"); EditorGUILayout.LabelField(GitGUI.GetTempContent("User"), EditorStyles.boldLabel); EditorGUI.indentLevel = 1; DoConfigStringField(GitGUI.GetTempContent("Name"), "user.name", ""); DoConfigStringField(GitGUI.GetTempContent("Email"), "user.email", ""); EditorGUI.indentLevel = 0; EditorGUILayout.LabelField(GitGUI.GetTempContent("Core"), EditorStyles.boldLabel); EditorGUI.indentLevel = 1; DoConfigToggle(GitGUI.GetTempContent("Auto LF line endings"), "core.autocrlf", true); DoConfigToggle(GitGUI.GetTempContent("Bare"), "core.bare", false); DoConfigToggle(GitGUI.GetTempContent("Symlinks"), "core.symlinks", false); DoConfigToggle(GitGUI.GetTempContent("Ignore Case"), "core.ignorecase", true); DoConfigToggle(GitGUI.GetTempContent("Logal Reference Updates"), "core.logallrefupdates", true); DoConfigIntSlider(GitGUI.GetTempContent("Compression"), -1, 9, "core.compression", -1); DoConfigStringField(GitGUI.GetTempContent("Big File Threshold"), "core.bigFileThreshold", "512m"); EditorGUI.indentLevel = 0; EditorGUILayout.LabelField(GitGUI.GetTempContent("Branch"), EditorStyles.boldLabel); EditorGUI.indentLevel = 1; DoConfigStringsField(GitGUI.GetTempContent("Auto Setup Rebase"), "branch.autoSetupRebase", autoRebaseOptions, "never"); EditorGUI.indentLevel = 0; EditorGUILayout.LabelField(GitGUI.GetTempContent("Diff"), EditorStyles.boldLabel); EditorGUI.indentLevel = 1; DoConfigToggle(GitGUI.GetTempContent("Renames"), "diff.renames", true); DoConfigIntField(GitGUI.GetTempContent("Rename Limit"), "diff.renameLimit", -1); EditorGUI.indentLevel = 0; EditorGUILayout.LabelField(GitGUI.GetTempContent("HTTP"), EditorStyles.boldLabel); EditorGUI.indentLevel = 1; DoConfigToggle(GitGUI.GetTempContent("Verify SSL Crtificate"), "http.sslVerify", true); string oldPath = GitManager.Repository.Config.GetValueOrDefault <string>("http.sslCAInfo"); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(GitGUI.GetTempContent("SSL Certificate File")); 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; }
private void OnWizardCreate() { gitManager.Repository.Stashes.Add(gitManager.Signature, stashMessage, stashModifiers); gitManager.MarkDirty(true); }
private static void RemoveSelected() { string[] paths = Selection.assetGUIDs.Select(g => AssetDatabase.GUIDToAssetPath(g)).SelectMany(g => GitManager.GetPathWithMeta(g)).ToArray(); GitManager.Repository.Unstage(paths); GitManager.MarkDirty(paths); }
private void DoCommit(Rect rect, Rect scrollRect, CommitInfo commit) { GitProfilerProxy.BeginSample("Git History Window Commit GUI", this); Event current = Event.current; if (rect.y > scrollRect.height + historyScroll.y || rect.y + scrollRect.height < historyScroll.y) { return; } BranchInfo[] branches = commit.Branches; bool isHead = commit.IsHead; bool isRemote = commit.IsRemote; Color branchColor = Color.white; if (branches != null) { foreach (var branch in branches) { if (branch.IsRemote) { branchColor = remoteColor; break; } if (branch.IsCurrentRepositoryHead) { branchColor = headColor; break; } UnityEngine.Random.InitState(branch.CanonicalName.GetHashCode()); branchColor = UnityEngine.Random.ColorHSV(0, 1, 0, 1); } } GUI.backgroundColor = new Color(1, 1, 1, 0.4f); GUI.Box(new Rect(24, rect.y + 5, 16, 16), GUIContent.none, "AC LeftArrow"); GUI.backgroundColor = branchColor; GUI.Box(new Rect(9, rect.y + 6, 12, 12), GUIContent.none, styles.historyKnobNormal); GUI.backgroundColor = Color.white; float y = 8; float x = 12; if (isHead) { //GUI.Box(new Rect(commitRect.x + 4, commitRect.y, commitRect.width - 8, commitRect.height - 8), GUIContent.none, "TL SelectionButton PreDropGlow"); } GUI.Box(rect, GUIContent.none, "RegionBg"); if (isHead || isRemote) { GUI.Box(new Rect(rect.x + 4, rect.y, rect.width - 8, 5), GUIContent.none, isHead ? styles.commitLineHead : styles.commitLineRemote); y += 4; } if (GitManager.Settings.UseGavatar && Application.internetReachability != NetworkReachability.NotReachable) { Texture2D avatar = GetProfilePixture(commit.Committer.Email); if (avatar != null) { GUI.Box(new Rect(rect.x + x, rect.y + y, 32, 32), GitGUI.GetTempContent(avatar), styles.avatar); } else { GUI.Box(new Rect(rect.x + x, rect.y + y, 32, 32), GitOverlay.icons.loadingIconSmall, styles.avatar); } } else { UnityEngine.Random.InitState(commit.Committer.Name.GetHashCode()); GUI.contentColor = UnityEngine.Random.ColorHSV(0, 1, 0.6f, 0.6f, 0.8f, 1, 1, 1); GUI.Box(new Rect(rect.x + x, rect.y + y, 32, 32), GitGUI.GetTempContent(commit.Committer.Name.Substring(0, 1).ToUpper()), styles.avatarName); GUI.contentColor = Color.white; } //if (avatar != null) //{ //GUI.DrawTexture(new Rect(rect.x + x, rect.y + y, 32, 32), avatar); //} x += 38; EditorGUI.LabelField(new Rect(rect.x + x, rect.y + y, rect.width - x, EditorGUIUtility.singleLineHeight), GitGUI.GetTempContent(commit.Committer.Name), EditorStyles.boldLabel); y += 16; EditorGUI.LabelField(new Rect(rect.x + x, rect.y + y, rect.width - x, EditorGUIUtility.singleLineHeight), GitGUI.GetTempContent(FormatRemainningTime(commit.Committer.When.UtcDateTime))); y += EditorGUIUtility.singleLineHeight + 3; int firstNewLineIndex = commit.Message.IndexOf(Environment.NewLine); EditorGUI.LabelField(new Rect(rect.x + x, rect.y + y, rect.width - x - 10, EditorGUIUtility.singleLineHeight + 4), GitGUI.GetTempContent(firstNewLineIndex > 0 ? commit.Message.Substring(0, firstNewLineIndex) : commit.Message), styles.commitMessage); y += 8; if (branches != null) { if (branches.Length > 0) { y += EditorGUIUtility.singleLineHeight; } foreach (var branch in branches) { GUIStyle style = styles.otherCommitTag; if (branch.IsRemote) { GUI.backgroundColor = remoteColor; } else if (branch.IsCurrentRepositoryHead) { GUI.backgroundColor = headColor; } else { UnityEngine.Random.InitState(branch.CanonicalName.GetHashCode()); GUI.backgroundColor = UnityEngine.Random.ColorHSV(0, 1, 0, 1); } GUIContent labelContent = GitGUI.GetTempContent(branch.FriendlyName, branch.CanonicalName); float labelWidth = style.CalcSize(labelContent).x; Rect branchIconRect = new Rect(rect.x + x, rect.y + y, labelWidth, EditorGUIUtility.singleLineHeight); GUI.Label(branchIconRect, labelContent, style); x += labelWidth + 4; GUI.backgroundColor = Color.white; if (Event.current.type == EventType.ContextClick && branchIconRect.Contains(Event.current.mousePosition)) { GenericMenu branchContextMenu = new GenericMenu(); BranchInfo b = branch; branchContextMenu.AddItem(new GUIContent("View branch"), false, () => { ViewBranchCallback(b); }); if (!b.IsRemote && !b.IsCurrentRepositoryHead) { branchContextMenu.AddItem(new GUIContent("Switch To Branch"), false, () => { SwitchToBranchCallback(b, new Rect(branchIconRect.x - historyScroll.x, branchIconRect.y - historyScroll.y, branchIconRect.width, branchIconRect.height)); }); } else { branchContextMenu.AddDisabledItem(new GUIContent("Switch To Branch")); } branchContextMenu.ShowAsContext(); } } } x = 12; y += EditorGUIUtility.singleLineHeight * 1.5f; GUI.Box(new Rect(rect.x + x, rect.y + y, rect.width - x - x, EditorGUIUtility.singleLineHeight), GUIContent.none, "EyeDropperHorizontalLine"); y += EditorGUIUtility.singleLineHeight / 3; EditorGUI.LabelField(new Rect(rect.x + x, rect.y + y, rect.width - x, EditorGUIUtility.singleLineHeight), GitGUI.GetTempContent(commit.Id.Sha)); x += GUI.skin.label.CalcSize(GitGUI.GetTempContent(commit.Id.Sha)).x + 8; Rect buttonRect = new Rect(rect.x + x, rect.y + y, 64, EditorGUIUtility.singleLineHeight); x += 64; if (GUI.Button(buttonRect, GitGUI.GetTempContent("Options"), "minibuttonleft")) { GenericMenu menu = new GenericMenu(); if (selectedBranch.IsCurrentRepositoryHead && !isHead) { menu.AddItem(new GUIContent("Reset"), false, () => { if (GitExternalManager.TakeReset(GitManager.Repository.Lookup <Commit>(commit.Id))) { AssetDatabase.Refresh(); GitManager.MarkDirty(); } else { popupsQueue.Enqueue(new KeyValuePair <Rect, PopupWindowContent>(buttonRect, new ResetPopupWindow(GitManager.Repository.Lookup <Commit>(commit.Id)))); } }); } else { menu.AddDisabledItem(new GUIContent("Reset")); } menu.AddItem(new GUIContent("Branch Out"), false, () => { popupsQueue.Enqueue(new KeyValuePair <Rect, PopupWindowContent>(buttonRect, new GitCreateBranchWindow(this, GitManager.Repository.Lookup <Commit>(commit.Id), null))); }); menu.DropDown(buttonRect); } GUI.enabled = true; buttonRect = new Rect(rect.x + x, rect.y + y, 64, EditorGUIUtility.singleLineHeight); if (GUI.Button(buttonRect, GitGUI.GetTempContent("Details"), "minibuttonright")) { PopupWindow.Show(buttonRect, new GitCommitDetailsWindow(GitManager.Repository.Lookup <Commit>(commit.Id))); } if (rect.Contains(current.mousePosition)) { if (current.type == EventType.ContextClick) { //GenericMenu commitContexMenu = new GenericMenu(); //commitContexMenu.ShowAsContext(); current.Use(); } } GitProfilerProxy.EndSample(); }
public override void OnGUI(Rect rect) { if (Event.current.type == EventType.MouseMove) { editorWindow.Repaint(); } int stashCount = stashCollection.Count(); EditorGUILayout.BeginHorizontal("IN BigTitle"); if (GUILayout.Button(GitGUI.GetTempContent("Stash Save", gitOverlay.icons.stashIcon.image, "Save changes in working directory to stash."))) { UniGitLoader.GetWindow <GitStashSaveWizard>(true); } EditorGUILayout.EndHorizontal(); GUI.enabled = true; stashScroll = EditorGUILayout.BeginScrollView(stashScroll, GUILayout.ExpandHeight(true)); int stashId = 0; foreach (var stash in stashCollection) { string msg = stash.Message; GUIContent stashContent = GitGUI.GetTempContent(msg); Rect stastRect = GUILayoutUtility.GetRect(stashContent, stashStyle); if (Event.current.type == EventType.Repaint) { stashStyle.Draw(stastRect, stashContent, stastRect.Contains(Event.current.mousePosition) || stashId == selectedStash, false, false, false); } else if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && stastRect.Contains(Event.current.mousePosition)) { selectedStash = stashId; } stashId++; } GUILayout.FlexibleSpace(); EditorGUILayout.EndScrollView(); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal("ProjectBrowserBottomBarBg"); GUI.enabled = stashCount > 0; if (GUILayout.Button(GitGUI.GetTempContent("Apply", "Apply stash to working directory."), EditorStyles.miniButtonLeft)) { if (EditorUtility.DisplayDialog("Apply Stash: " + selectedStash, "Are you sure you want to apply stash ? This will override your current working directory!", "Apply", "Cancel")) { stashCollection.Apply(selectedStash); gitManager.MarkDirty(true); gitCallbacks.IssueAssetDatabaseRefresh(); } } if (GUILayout.Button(GitGUI.GetTempContent("Pop", "Remove and apply stash to working directory."), EditorStyles.miniButtonMid)) { if (EditorUtility.DisplayDialog("Pop Stash: " + selectedStash, "Are you sure you want to pop the stash ? This will override your current working directory and remove the stash from the list.", "Pop and Apply", "Cancel")) { stashCollection.Pop(selectedStash); gitManager.MarkDirty(true); gitCallbacks.IssueAssetDatabaseRefresh(); } } if (GUILayout.Button(GitGUI.GetTempContent("Remove", "Remove stash from list"), EditorStyles.miniButtonRight)) { if (EditorUtility.DisplayDialog("Remove Stash: " + selectedStash, "Are you sure you want to remove the stash ? This action cannot be undone!", "Remove", "Cancel")) { stashCollection.Remove(selectedStash); } } GUI.enabled = true; EditorGUILayout.EndHorizontal(); }
private void DoCommit(Rect rect, Rect scrollRect, CommitInfo commit) { GitProfilerProxy.BeginSample("Git History Window Commit GUI", this); Event current = Event.current; if (rect.y > scrollRect.height + historyScroll.y || rect.y + scrollRect.height < historyScroll.y) { return; } BranchInfo[] branches = commit.Branches; bool isHead = commit.IsHead; bool isRemote = commit.IsRemote; GUI.Box(new Rect(8, rect.y + 6, 16, 16), GUIContent.none, "AC LeftArrow"); GUI.Box(new Rect(8, rect.y + 6, 16, 16), GUIContent.none, branches != null && branches.Length > 0 ? isHead ? styles.historyKnobHead : isRemote ? styles.historyKnobRemote : styles.historyKnobOther : styles.historyKnobNormal); float y = 8; float x = 12; if (isHead) { //GUI.Box(new Rect(commitRect.x + 4, commitRect.y, commitRect.width - 8, commitRect.height - 8), GUIContent.none, "TL SelectionButton PreDropGlow"); } GUI.Box(rect, GUIContent.none, "RegionBg"); if (isHead || isRemote) { GUI.Box(new Rect(rect.x + 4, rect.y, rect.width - 8, 5), GUIContent.none, isHead ? styles.commitLineHead : styles.commitLineRemote); y += 4; } if (GitManager.Settings.UseGavatar && Application.internetReachability != NetworkReachability.NotReachable) { Texture2D avatar = GetProfilePixture(commit.Committer.Email); if (avatar != null) { GUI.Box(new Rect(rect.x + x, rect.y + y, 32, 32), GitGUI.GetTempContent(avatar), styles.avatar); } else { GUI.Box(new Rect(rect.x + x, rect.y + y, 32, 32), GitManager.icons.loadingIconSmall, styles.avatar); } } else { UnityEngine.Random.InitState(commit.Committer.Name.GetHashCode()); GUI.contentColor = UnityEngine.Random.ColorHSV(0, 1, 0.6f, 0.6f, 0.8f, 1, 1, 1); GUI.Box(new Rect(rect.x + x, rect.y + y, 32, 32), GitGUI.GetTempContent(commit.Committer.Name.Substring(0, 1).ToUpper()), styles.avatarName); GUI.contentColor = Color.white; } //if (avatar != null) //{ //GUI.DrawTexture(new Rect(rect.x + x, rect.y + y, 32, 32), avatar); //} x += 38; EditorGUI.LabelField(new Rect(rect.x + x, rect.y + y, rect.width - x, EditorGUIUtility.singleLineHeight), GitGUI.GetTempContent(commit.Committer.Name), EditorStyles.boldLabel); y += 16; EditorGUI.LabelField(new Rect(rect.x + x, rect.y + y, rect.width - x, EditorGUIUtility.singleLineHeight), GitGUI.GetTempContent(FormatRemainningTime(commit.Committer.When.UtcDateTime))); y += EditorGUIUtility.singleLineHeight + 3; int firstNewLineIndex = commit.Message.IndexOf(Environment.NewLine); EditorGUI.LabelField(new Rect(rect.x + x, rect.y + y, rect.width - x - 10, EditorGUIUtility.singleLineHeight + 4), GitGUI.GetTempContent(firstNewLineIndex > 0 ? commit.Message.Substring(0, firstNewLineIndex) : commit.Message), styles.commitMessage); y += 8; if (branches != null) { if (branches.Length > 0) { y += EditorGUIUtility.singleLineHeight; } foreach (var branch in branches) { GUIStyle style = branch.IsRemote ? styles.remoteCommitTag : branch.IsCurrentRepositoryHead ? styles.headCommitTag : styles.otherCommitTag; GUIContent labelContent = GitGUI.GetTempContent(branch.FriendlyName); float labelWidth = style.CalcSize(labelContent).x; GUI.Label(new Rect(rect.x + x, rect.y + y, labelWidth, EditorGUIUtility.singleLineHeight), labelContent, style); x += labelWidth + 4; } } x = 12; y += EditorGUIUtility.singleLineHeight * 1.5f; GUI.Box(new Rect(rect.x + x, rect.y + y, rect.width - x - x, EditorGUIUtility.singleLineHeight), GUIContent.none, "EyeDropperHorizontalLine"); y += EditorGUIUtility.singleLineHeight / 3; EditorGUI.LabelField(new Rect(rect.x + x, rect.y + y, rect.width - x, EditorGUIUtility.singleLineHeight), GitGUI.GetTempContent(commit.Id.Sha)); x += GUI.skin.label.CalcSize(GitGUI.GetTempContent(commit.Id.Sha)).x + 8; Rect buttonRect = new Rect(rect.x + x, rect.y + y, 64, EditorGUIUtility.singleLineHeight); x += 64; GUI.enabled = selectedBranch.IsCurrentRepositoryHead && !isHead; if (GUI.Button(buttonRect, GitGUI.GetTempContent("Reset", "Reset changes made up to this commit"), "minibuttonleft")) { if (GitExternalManager.TakeReset(GitManager.Repository.Lookup <Commit>(commit.Id))) { AssetDatabase.Refresh(); GitManager.MarkDirty(); } else { PopupWindow.Show(buttonRect, new ResetPopupWindow(GitManager.Repository.Lookup <Commit>(commit.Id))); } } GUI.enabled = true; buttonRect = new Rect(rect.x + x, rect.y + y, 64, EditorGUIUtility.singleLineHeight); if (GUI.Button(buttonRect, GitGUI.GetTempContent("Details"), "minibuttonright")) { PopupWindow.Show(buttonRect, new GitCommitDetailsWindow(GitManager.Repository.Lookup <Commit>(commit.Id))); } if (rect.Contains(current.mousePosition)) { if (current.type == EventType.ContextClick) { //GenericMenu commitContexMenu = new GenericMenu(); //commitContexMenu.ShowAsContext(); current.Use(); } } GitProfilerProxy.EndSample(); }
private void 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(); }