public override void Display() { GUILayout.Label("GIT BRANCH", EditorStyles.boldLabel); int newBranchIndex = EditorGUILayout.Popup(currentBranchIndex, branches.ToArray()); if (newBranchIndex != currentBranchIndex) { RepositoryManager.CheckoutBranch(branches[newBranchIndex]); currentBranchIndex = newBranchIndex; } WindowHelper.DrawUILine(Color.black, width: editorWindow.position.width - 15); #region //// Merge EditorGUILayout.LabelField("Merge"); GUILayout.BeginHorizontal(); int newFromBranchIndex = EditorGUILayout.Popup(fromBranchIndex, branches.ToArray()); if (newFromBranchIndex != fromBranchIndex) { toBranchList = new List <string>(branches); toBranchList.Remove(branches[newFromBranchIndex]); fromBranchIndex = newFromBranchIndex; } EditorGUILayout.LabelField(" => ", GUILayout.Width(60)); int newToBranchIndex = EditorGUILayout.Popup(toBranchIndex, toBranchList.ToArray()); if (newToBranchIndex < toBranchList.Count) { toBranchIndex = newToBranchIndex; } else { toBranchIndex = toBranchList.Count - 1; } GUILayout.EndHorizontal(); if (GUILayout.Button("Merge", GUILayout.Width(editorWindow.position.width - 15))) { SettingsTab settingsTab = editorWindow.GetSettingsTab(); RepositoryManager.CheckoutBranch(toBranchList[toBranchIndex]); RepositoryManager.Merge(settingsTab.GetUserUsername(), settingsTab.GetUserEmail(), branches[fromBranchIndex]); editorWindow.GetHistoryTab().RefreshHistory(); } #endregion }
public override void Display() { GUILayout.Label("GIT HISTORY", EditorStyles.boldLabel); #region ///// Header GUILayout.BeginHorizontal(); if (GUILayout.Button("Refresh")) { RefreshHistory(); } if (GUILayout.Button(string.Format("{0} Pull", behindBy))) { editorWindow.Close(); editorWindow.passwordWindow.callback = (password) => { SettingsTab settingsTab = editorWindow.GetSettingsTab(); RepositoryManager.Pull(settingsTab.GetUserUsername(), settingsTab.GetUserEmail(), password); GitEditor.GetWindow().Show(); }; editorWindow.passwordWindow.Show(true); } if (GUILayout.Button("Checkout current branch")) { RepositoryManager.CheckoutBranch(editorWindow.GetBranchesTab().GetCurrentBranchName()); } GUILayout.EndHorizontal(); #endregion /// Compute the total height of the scroll view float height = 0; historyCommits.ForEach((elt) => { // GUI Button, rule, space heght + status, id, message, changes height height += 70 + (elt.changes.Count + 2 + (elt.onlyLocal || elt.onlyRemote ? 1 : 0)) * EditorGUIUtility.singleLineHeight * 1.5f; }); historyScrollPos = GUILayout.BeginScrollView(historyScrollPos, false, true); #region ////// Display the scroll view GUI.BeginGroup(new Rect(0, 5, editorWindow.position.width - 15, height)); string currentCommitID = editorWindow.GetCommitTab().GetCurrentCommitID(); int historyCommitsCount = historyCommits.Count; for (int commitIdx = currentPage * 10; commitIdx < (currentPage + 1) * 10 && commitIdx < historyCommitsCount; commitIdx++) { HistoryCommit com = historyCommits[commitIdx]; if (com.onlyLocal) { GUI.backgroundColor = Color.green; } else if (com.onlyRemote) { GUI.backgroundColor = Color.red; } else if (com.id == currentCommitID) { GUI.backgroundColor = Color.blue; } #region ////// Display Box GUILayout.BeginVertical(new GUIStyle("Box")); #region ////// Display status if (com.onlyLocal || com.onlyRemote) { string status = ""; if (com.onlyLocal) { status = "Ready to be pushed"; } else if (com.onlyRemote) { status = "Ready to be pulled"; } else if (com.id == currentCommitID) { status = "Current deteched head"; } GUILayout.BeginHorizontal(); GUILayout.Label("Status : ", EditorStyles.boldLabel, GUILayout.Width(60)); GUILayout.Label(status, EditorStyles.boldLabel); GUILayout.EndHorizontal(); } #endregion GUILayout.Space(10); GUILayout.BeginHorizontal(); GUILayout.Label("ID : ", GUILayout.Width(60)); GUILayout.Label(com.id); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Author : ", GUILayout.Width(60)); GUILayout.Label(com.author); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Message : ", GUILayout.Width(60)); GUILayout.Label(com.message); GUILayout.EndHorizontal(); GUILayout.Space(10); foreach (string change in com.changes) { GUILayout.Label(change); } if (!com.onlyLocal && !com.onlyRemote) { if (GUILayout.Button("Revert to", GUILayout.Width(editorWindow.position.width - 30))) { RepositoryManager.Revert(com.id); } } GUILayout.EndVertical(); #endregion GUI.backgroundColor = Color.white; } GUI.EndGroup(); #endregion GUILayout.EndScrollView(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Prev page")) { if (currentPage > 0) { currentPage--; } } GUILayout.Label(string.Format("{0}/{1}", currentPage + 1, maxPage + 1)); if (GUILayout.Button("Next page")) { if (currentPage < maxPage - 1) { currentPage++; } } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); }