Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 57da18f

Browse files
Merge branch 'master' into fixes/gui_enabled
2 parents e66dfc4 + 61c24f1 commit 57da18f

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ class BranchesView : Subview
2323
private const string LocalTitle = "Local branches";
2424
private const string RemoteTitle = "Remote branches";
2525
private const string CreateBranchButton = "New Branch";
26+
private const string DeleteBranchMessageFormatString = "Are you sure you want to delete the branch: {0}?";
27+
private const string DeleteBranchTitle = "Delete Branch?";
28+
private const string DeleteBranchButton = "Delete";
29+
private const string CancelButtonLabel = "Cancel";
2630

2731
private bool showLocalBranches = true;
2832
private bool showRemoteBranches = true;
@@ -147,7 +151,7 @@ public void OnEmbeddedGUI()
147151

148152
GUILayout.BeginHorizontal();
149153
{
150-
OnCreateGUI();
154+
OnButtonBarGUI();
151155
}
152156
GUILayout.EndHorizontal();
153157

@@ -308,6 +312,9 @@ private void OnRemoteBranchesUpdate(IEnumerable<GitBranch> list)
308312

309313
private void BuildTree(IEnumerable<GitBranch> local, IEnumerable<GitBranch> remote)
310314
{
315+
//Clear the selected node
316+
selectedNode = null;
317+
311318
// Sort
312319
var localBranches = new List<GitBranch>(local);
313320
var remoteBranches = new List<GitBranch>(remote);
@@ -451,28 +458,28 @@ private void SetFavourite(BranchTreeNode branch, bool favourite)
451458
}
452459
}
453460

454-
private void OnCreateGUI()
461+
private void OnButtonBarGUI()
455462
{
456-
// Create button
457463
if (mode == BranchesMode.Default)
458464
{
465+
// Delete button
459466
// If the current branch is selected, then do not enable the Delete button
460-
var disableDelete = activeBranchNode == selectedNode;
467+
var disableDelete = selectedNode == null || selectedNode.Type == NodeType.Folder || activeBranchNode == selectedNode;
461468
EditorGUI.BeginDisabledGroup(disableDelete);
462469
{
463-
if (GUILayout.Button("Delete", EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
470+
if (GUILayout.Button(DeleteBranchButton, EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
464471
{
465472
var selectedBranchName = selectedNode.Name;
466-
var dialogTitle = "Delete Branch: " + selectedBranchName;
467-
var dialogMessage = "Are you sure you want to delete the branch: " + selectedBranchName + "?";
468-
if (EditorUtility.DisplayDialog("Delete Branch?", dialogMessage, "Delete", "Cancel"))
473+
var dialogMessage = string.Format(DeleteBranchMessageFormatString, selectedBranchName);
474+
if (EditorUtility.DisplayDialog(DeleteBranchTitle, dialogMessage, DeleteBranchButton, CancelButtonLabel))
469475
{
470476
GitClient.DeleteBranch(selectedBranchName, true).Start();
471477
}
472478
}
473479
}
474480
EditorGUI.EndDisabledGroup();
475481

482+
// Create button
476483
GUILayout.FlexibleSpace();
477484
if (GUILayout.Button(CreateBranchButton, EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
478485
{

0 commit comments

Comments
 (0)