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

Commit c2a4989

Browse files
Creating a context menu for local and remote branch nodes
1 parent e0aedab commit c2a4989

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

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

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,9 @@ private void OnTreeGUI(Rect rect)
305305
}).Start();
306306
}
307307
},
308-
node =>
309-
{
310-
Debug.Log("Right Click");
308+
node => {
309+
GenericMenu menu = CreateContextMenuForLocalBranchNode(node);
310+
menu.ShowAsContext();
311311
});
312312

313313
if (treeHadFocus && treeLocals.SelectedNode == null)
@@ -364,9 +364,9 @@ private void OnTreeGUI(Rect rect)
364364
}
365365
}
366366
},
367-
node =>
368-
{
369-
Debug.Log("Right Click");
367+
node => {
368+
GenericMenu menu = CreateContextMenuForRemoteBranchNode(node);
369+
menu.ShowAsContext();
370370
});
371371

372372
if (treeHadFocus && treeRemotes.SelectedNode == null)
@@ -385,6 +385,39 @@ private void OnTreeGUI(Rect rect)
385385
GUILayout.Space(rect.y - initialRect.y);
386386
}
387387

388+
private GenericMenu CreateContextMenuForLocalBranchNode(TreeNode node)
389+
{
390+
var genericMenu = new GenericMenu();
391+
392+
var deleteGuiContent = new GUIContent("Delete");
393+
var switchGuiContent = new GUIContent("Switch");
394+
395+
if (node.IsActive)
396+
{
397+
genericMenu.AddDisabledItem(deleteGuiContent);
398+
genericMenu.AddDisabledItem(switchGuiContent);
399+
}
400+
else
401+
{
402+
genericMenu.AddItem(deleteGuiContent, false, (userData) => {
403+
Debug.Log("Delete Branch");
404+
}, node);
405+
406+
genericMenu.AddItem(switchGuiContent, false, (userData) => {
407+
Debug.Log("Switch Branch");
408+
}, node);
409+
}
410+
411+
return genericMenu;
412+
}
413+
414+
private GenericMenu CreateContextMenuForRemoteBranchNode(TreeNode node)
415+
{
416+
var genericMenu = new GenericMenu();
417+
418+
return genericMenu;
419+
}
420+
388421
private int CompareBranches(GitBranch a, GitBranch b)
389422
{
390423
//if (IsFavorite(a.Name))

0 commit comments

Comments
 (0)