public override void Display() { GUILayout.Label("GIT COMMIT", EditorStyles.boldLabel); #region ///// Header float groupWidth = editorWindow.position.width - 5; GUI.BeginGroup(new Rect(5, 45, groupWidth, 20)); if (GUI.Button(new Rect(0, 0, groupWidth / 3, 20), "Refresh")) { ReloadTree(); } if (GUI.Button(new Rect(groupWidth / 3, 0, groupWidth / 3, 20), "Expand All")) { commitTreeView.ExpandAll(); } if (GUI.Button(new Rect(groupWidth * 2 / 3, 0, groupWidth / 3, 20), "Collapse All")) { commitTreeView.CollapseAll(); } GUI.EndGroup(); #endregion commitTreeView.OnGUI(new Rect(5, 70, editorWindow.position.width - 10, 300)); currentCommitMessage = EditorGUI.TextArea( new Rect(5, 375, editorWindow.position.width - 5, 90), currentCommitMessage); if (GUI.Button(new Rect(5, 475, editorWindow.position.width - 10, 20), "Commit")) { SettingsTab settingsTab = editorWindow.GetSettingsTab(); if (String.IsNullOrEmpty(settingsTab.GetUserUsername()) || String.IsNullOrEmpty(settingsTab.GetUserEmail())) { editorWindow.Close(); editorWindow.credentialsWindow.callback = (username, email) => { settingsTab.SaveNewCredentials(username, email); Commit(); GitEditor.GetWindow().Show(); }; editorWindow.credentialsWindow.Show(true); } else { Commit(); } } if (GUI.Button(new Rect(5, 500, editorWindow.position.width - 10, 20), string.Format("{0} Push", editorWindow.GetHistoryTab().GetAheadBy()))) { editorWindow.Close(); editorWindow.passwordWindow.callback = (password) => { RepositoryManager.Push(editorWindow.GetSettingsTab().GetUserUsername(), password, editorWindow.GetBranchesTab().GetCurrentBranchName()); GitEditor.GetWindow().Show(); }; editorWindow.passwordWindow.Show(true); } }
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(); }