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

Commit 089d010

Browse files
Merge branch 'fixes/branch-delete-button-enabled' into fixes/clone-remote-branch
2 parents 7541813 + a559dfc commit 089d010

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
@@ -27,6 +27,10 @@ class BranchesView : Subview
2727
private const string LocalTitle = "Local branches";
2828
private const string RemoteTitle = "Remote branches";
2929
private const string CreateBranchButton = "New Branch";
30+
private const string DeleteBranchMessageFormatString = "Are you sure you want to delete the branch: {0}?";
31+
private const string DeleteBranchTitle = "Delete Branch?";
32+
private const string DeleteBranchButton = "Delete";
33+
private const string CancelButtonLabel = "Cancel";
3034

3135
private bool showLocalBranches = true;
3236
private bool showRemoteBranches = true;
@@ -151,7 +155,7 @@ public void OnEmbeddedGUI()
151155

152156
GUILayout.BeginHorizontal();
153157
{
154-
OnCreateGUI();
158+
OnButtonBarGUI();
155159
}
156160
GUILayout.EndHorizontal();
157161

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

313317
private void BuildTree(IEnumerable<GitBranch> local, IEnumerable<GitBranch> remote)
314318
{
319+
//Clear the selected node
320+
selectedNode = null;
321+
315322
// Sort
316323
var localBranches = new List<GitBranch>(local);
317324
var remoteBranches = new List<GitBranch>(remote);
@@ -455,28 +462,28 @@ private void SetFavourite(BranchTreeNode branch, bool favourite)
455462
}
456463
}
457464

458-
private void OnCreateGUI()
465+
private void OnButtonBarGUI()
459466
{
460-
// Create button
461467
if (mode == BranchesMode.Default)
462468
{
469+
// Delete button
463470
// If the current branch is selected, then do not enable the Delete button
464-
var disableDelete = activeBranchNode == selectedNode;
471+
var disableDelete = selectedNode == null || selectedNode.Type == NodeType.Folder || activeBranchNode == selectedNode;
465472
EditorGUI.BeginDisabledGroup(disableDelete);
466473
{
467-
if (GUILayout.Button("Delete", EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
474+
if (GUILayout.Button(DeleteBranchButton, EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
468475
{
469476
var selectedBranchName = selectedNode.Name;
470-
var dialogTitle = "Delete Branch: " + selectedBranchName;
471-
var dialogMessage = "Are you sure you want to delete the branch: " + selectedBranchName + "?";
472-
if (EditorUtility.DisplayDialog("Delete Branch?", dialogMessage, "Delete", "Cancel"))
477+
var dialogMessage = string.Format(DeleteBranchMessageFormatString, selectedBranchName);
478+
if (EditorUtility.DisplayDialog(DeleteBranchTitle, dialogMessage, DeleteBranchButton, CancelButtonLabel))
473479
{
474480
GitClient.DeleteBranch(selectedBranchName, true).Start();
475481
}
476482
}
477483
}
478484
EditorGUI.EndDisabledGroup();
479485

486+
// Create button
480487
GUILayout.FlexibleSpace();
481488
if (GUILayout.Button(CreateBranchButton, EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
482489
{

0 commit comments

Comments
 (0)