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

Commit a22725f

Browse files
Adding right click handlers for delete/create branch functionality
1 parent c2a4989 commit a22725f

File tree

1 file changed

+38
-33
lines changed

1 file changed

+38
-33
lines changed

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

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,7 @@ private void OnButtonBarGUI()
163163
{
164164
if (GUILayout.Button(DeleteBranchButton, EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
165165
{
166-
var selectedBranchName = treeLocals.SelectedNode.Name;
167-
var dialogMessage = string.Format(DeleteBranchMessageFormatString, selectedBranchName);
168-
if (EditorUtility.DisplayDialog(DeleteBranchTitle, dialogMessage, DeleteBranchButton, CancelButtonLabel))
169-
{
170-
GitClient.DeleteBranch(selectedBranchName, true).Start();
171-
}
166+
DeleteLocalBranch(treeLocals.SelectedNode.Name);
172167
}
173168
}
174169
EditorGUI.EndDisabledGroup();
@@ -284,29 +279,11 @@ private void OnTreeGUI(Rect rect)
284279

285280
rect = treeLocals.Render(rect, scroll,
286281
node =>{ },
287-
node =>
288-
{
289-
if (EditorUtility.DisplayDialog(ConfirmSwitchTitle, String.Format(ConfirmSwitchMessage, node.Name), ConfirmSwitchOK,
290-
ConfirmSwitchCancel))
291-
{
292-
GitClient.SwitchBranch(node.Name)
293-
.FinallyInUI((success, e) =>
294-
{
295-
if (success)
296-
{
297-
Redraw();
298-
}
299-
else
300-
{
301-
EditorUtility.DisplayDialog(Localization.SwitchBranchTitle,
302-
String.Format(Localization.SwitchBranchFailedDescription, node.Name),
303-
Localization.Ok);
304-
}
305-
}).Start();
306-
}
282+
node => {
283+
SwitchBranch(node.Name);
307284
},
308285
node => {
309-
GenericMenu menu = CreateContextMenuForLocalBranchNode(node);
286+
var menu = CreateContextMenuForLocalBranchNode(node);
310287
menu.ShowAsContext();
311288
});
312289

@@ -399,18 +376,46 @@ private GenericMenu CreateContextMenuForLocalBranchNode(TreeNode node)
399376
}
400377
else
401378
{
402-
genericMenu.AddItem(deleteGuiContent, false, (userData) => {
403-
Debug.Log("Delete Branch");
404-
}, node);
379+
genericMenu.AddItem(deleteGuiContent, false, () => {
380+
DeleteLocalBranch(node.Name);
381+
});
405382

406-
genericMenu.AddItem(switchGuiContent, false, (userData) => {
407-
Debug.Log("Switch Branch");
408-
}, node);
383+
genericMenu.AddItem(switchGuiContent, false, () => {
384+
SwitchBranch(node.Name);
385+
});
409386
}
410387

411388
return genericMenu;
412389
}
413390

391+
private void SwitchBranch(string branchName)
392+
{
393+
if (EditorUtility.DisplayDialog(ConfirmSwitchTitle, String.Format(ConfirmSwitchMessage, branchName), ConfirmSwitchOK,
394+
ConfirmSwitchCancel))
395+
{
396+
GitClient.SwitchBranch(branchName).FinallyInUI((success, e) => {
397+
if (success)
398+
{
399+
Redraw();
400+
}
401+
else
402+
{
403+
EditorUtility.DisplayDialog(Localization.SwitchBranchTitle,
404+
String.Format(Localization.SwitchBranchFailedDescription, branchName), Localization.Ok);
405+
}
406+
}).Start();
407+
}
408+
}
409+
410+
private void DeleteLocalBranch(string branchName)
411+
{
412+
var dialogMessage = string.Format(DeleteBranchMessageFormatString, branchName);
413+
if (EditorUtility.DisplayDialog(DeleteBranchTitle, dialogMessage, DeleteBranchButton, CancelButtonLabel))
414+
{
415+
GitClient.DeleteBranch(branchName, true).Start();
416+
}
417+
}
418+
414419
private GenericMenu CreateContextMenuForRemoteBranchNode(TreeNode node)
415420
{
416421
var genericMenu = new GenericMenu();

0 commit comments

Comments
 (0)