private void Render() { listID = GUIUtility.GetControlID(FocusType.Keyboard); GUILayout.BeginHorizontal(); { OnButtonBarGUI(); } GUILayout.EndHorizontal(); var rect = GUILayoutUtility.GetLastRect(); scroll = GUILayout.BeginScrollView(scroll); { OnTreeGUI(new Rect(0f, 0f, Position.width, Position.height - rect.height + Styles.CommitAreaPadding)); } GUILayout.EndScrollView(); if (Event.current.type == EventType.Repaint) { // Effectuating mode switch if (mode != targetMode) { mode = targetMode; Redraw(); } } }
public override void InitializeView(IView parent) { base.InitializeView(parent); targetMode = mode; }
private void OnButtonBarGUI() { if (mode == BranchesMode.Default) { // Delete button // If the current branch is selected, then do not enable the Delete button var disableDelete = selectedNode == null || selectedNode.Type == NodeType.Folder || activeBranchNode == selectedNode; EditorGUI.BeginDisabledGroup(disableDelete); { if (GUILayout.Button(DeleteBranchButton, EditorStyles.miniButton, GUILayout.ExpandWidth(false))) { var selectedBranchName = selectedNode.Name; var dialogMessage = string.Format(DeleteBranchMessageFormatString, selectedBranchName); if (EditorUtility.DisplayDialog(DeleteBranchTitle, dialogMessage, DeleteBranchButton, CancelButtonLabel)) { GitClient.DeleteBranch(selectedBranchName, true).Start(); } } } EditorGUI.EndDisabledGroup(); // Create button GUILayout.FlexibleSpace(); if (GUILayout.Button(CreateBranchButton, EditorStyles.miniButton, GUILayout.ExpandWidth(false))) { targetMode = BranchesMode.Create; } } // Branch name + cancel + create else if (mode == BranchesMode.Create) { GUILayout.BeginHorizontal(); { var createBranch = false; var cancelCreate = false; var cannotCreate = selectedNode == null || selectedNode.Type == NodeType.Folder || !Validation.IsBranchNameValid(newBranchName); // Create on return/enter or cancel on escape var offsetID = GUIUtility.GetControlID(FocusType.Passive); if (Event.current.isKey && GUIUtility.keyboardControl == offsetID + 1) { if (Event.current.keyCode == KeyCode.Escape) { cancelCreate = true; Event.current.Use(); } else if (Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter) { if (cannotCreate) { EditorApplication.Beep(); } else { createBranch = true; } Event.current.Use(); } } newBranchName = EditorGUILayout.TextField(newBranchName); // Create EditorGUI.BeginDisabledGroup(cannotCreate); { if (GUILayout.Button(NewBranchConfirmButton, EditorStyles.miniButtonLeft, GUILayout.ExpandWidth(false))) { createBranch = true; } } EditorGUI.EndDisabledGroup(); // Cancel create if (GUILayout.Button(NewBranchCancelButton, EditorStyles.miniButtonRight, GUILayout.ExpandWidth(false))) { cancelCreate = true; } // Effectuate create if (createBranch) { GitClient.CreateBranch(newBranchName, selectedNode.Name) .FinallyInUI((success, e) => { if (success) { Redraw(); } else { var errorHeader = "fatal: "; var errorMessage = e.Message.StartsWith(errorHeader) ? e.Message.Remove(0, errorHeader.Length) : e.Message; EditorUtility.DisplayDialog(CreateBranchTitle, errorMessage, Localization.Ok); } }) .Start(); } // Cleanup if (createBranch || cancelCreate) { newBranchName = ""; GUIUtility.keyboardControl = -1; targetMode = BranchesMode.Default; } } GUILayout.EndHorizontal(); } }
public void OnEmbeddedGUI() { scroll = GUILayout.BeginScrollView(scroll); { listID = GUIUtility.GetControlID(FocusType.Keyboard); GUILayout.BeginHorizontal(); { OnButtonBarGUI(); } GUILayout.EndHorizontal(); GUILayout.BeginVertical(Styles.CommitFileAreaStyle); { // Local branches and "create branch" button showLocalBranches = EditorGUILayout.Foldout(showLocalBranches, LocalTitle); if (showLocalBranches) { GUILayout.BeginHorizontal(); { GUILayout.BeginVertical(); { OnTreeNodeChildrenGUI(localRoot); } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); } // Remotes showRemoteBranches = EditorGUILayout.Foldout(showRemoteBranches, RemoteTitle); if (showRemoteBranches) { GUILayout.BeginHorizontal(); { GUILayout.BeginVertical(); for (var index = 0; index < remotes.Count; ++index) { var remote = remotes[index]; GUILayout.Label(new GUIContent(remote.Name, Styles.FolderIcon), GUILayout.MaxHeight(EditorGUIUtility.singleLineHeight)); // Branches of the remote GUILayout.BeginHorizontal(); { GUILayout.Space(Styles.TreeIndentation); GUILayout.BeginVertical(); { OnTreeNodeChildrenGUI(remote.Root); } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); GUILayout.Space(Styles.BranchListSeperation); } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); } GUILayout.FlexibleSpace(); } GUILayout.EndVertical(); } GUILayout.EndScrollView(); if (Event.current.type == EventType.Repaint) { // Effectuating selection if (newNodeSelection != null) { selectedNode = newNodeSelection; newNodeSelection = null; GUIUtility.keyboardControl = listID; Redraw(); } // Effectuating mode switch if (mode != targetMode) { mode = targetMode; if (mode == BranchesMode.Create) { selectedNode = activeBranchNode; } Redraw(); } } }
private void OnCreateGUI() { // Create button if (mode == BranchesMode.Default) { GUILayout.FlexibleSpace(); if (GUILayout.Button(CreateBranchButton, EditorStyles.miniButton, GUILayout.ExpandWidth(false))) { targetMode = BranchesMode.Create; } } // Branch name + cancel + create else if (mode == BranchesMode.Create) { GUILayout.BeginHorizontal(); { var createBranch = false; var cancelCreate = false; var cannotCreate = selectedNode == null || selectedNode.Type == NodeType.Folder || newBranchName == null || !Utility.BranchNameRegex.IsMatch(newBranchName); // Create on return/enter or cancel on escape var offsetID = GUIUtility.GetControlID(FocusType.Passive); if (Event.current.isKey && GUIUtility.keyboardControl == offsetID + 1) { if (Event.current.keyCode == KeyCode.Escape) { cancelCreate = true; Event.current.Use(); } else if (Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter) { if (cannotCreate) { EditorApplication.Beep(); } else { createBranch = true; } Event.current.Use(); } } newBranchName = EditorGUILayout.TextField(newBranchName); // Create EditorGUI.BeginDisabledGroup(cannotCreate); { if (GUILayout.Button(NewBranchConfirmButton, EditorStyles.miniButtonLeft, GUILayout.ExpandWidth(false))) { createBranch = true; } } EditorGUI.EndDisabledGroup(); // Cancel create if (GUILayout.Button(NewBranchCancelButton, EditorStyles.miniButtonRight, GUILayout.ExpandWidth(false))) { cancelCreate = true; } // Effectuate create if (createBranch) { GitClient.CreateBranch(newBranchName, selectedNode.Name) .FinallyInUI((success, e) => { if (success) { Refresh(); } }) .Start(); } // Cleanup if (createBranch || cancelCreate) { newBranchName = ""; GUIUtility.keyboardControl = -1; targetMode = BranchesMode.Default; } } GUILayout.EndHorizontal(); } }