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

Commit e0aedab

Browse files
Adding a right click handler to Tree.Render(...)
1 parent 658a4a8 commit e0aedab

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,9 @@ private void OnTreeGUI(Rect rect)
282282

283283
var treeHadFocus = treeLocals.SelectedNode != null;
284284

285-
rect = treeLocals.Render(rect, scroll, _ => { }, node =>
285+
rect = treeLocals.Render(rect, scroll,
286+
node =>{ },
287+
node =>
286288
{
287289
if (EditorUtility.DisplayDialog(ConfirmSwitchTitle, String.Format(ConfirmSwitchMessage, node.Name), ConfirmSwitchOK,
288290
ConfirmSwitchCancel))
@@ -302,6 +304,10 @@ private void OnTreeGUI(Rect rect)
302304
}
303305
}).Start();
304306
}
307+
},
308+
node =>
309+
{
310+
Debug.Log("Right Click");
305311
});
306312

307313
if (treeHadFocus && treeLocals.SelectedNode == null)
@@ -316,7 +322,9 @@ private void OnTreeGUI(Rect rect)
316322

317323
rect.y += Styles.TreePadding;
318324

319-
rect = treeRemotes.Render(rect, scroll, _ => {}, selectedNode =>
325+
rect = treeRemotes.Render(rect, scroll,
326+
node => { },
327+
selectedNode =>
320328
{
321329
var indexOfFirstSlash = selectedNode.Name.IndexOf('/');
322330
var originName = selectedNode.Name.Substring(0, indexOfFirstSlash);
@@ -355,6 +363,10 @@ private void OnTreeGUI(Rect rect)
355363
.Start();
356364
}
357365
}
366+
},
367+
node =>
368+
{
369+
Debug.Log("Right Click");
358370
});
359371

360372
if (treeHadFocus && treeRemotes.SelectedNode == null)

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public void Load(IEnumerable<ITreeData> data, string title)
132132
foldersKeys = Folders.Keys.Cast<string>().ToList();
133133
}
134134

135-
public Rect Render(Rect rect, Vector2 scroll, Action<TreeNode> singleClick = null, Action<TreeNode> doubleClick = null)
135+
public Rect Render(Rect rect, Vector2 scroll, Action<TreeNode> singleClick = null, Action<TreeNode> doubleClick = null, Action<TreeNode> rightClick = null)
136136
{
137137
Profiler.BeginSample("TreeControl");
138138
bool visible = true;
@@ -191,7 +191,7 @@ public Rect Render(Rect rect, Vector2 scroll, Action<TreeNode> singleClick = nul
191191
{
192192
if (visible)
193193
{
194-
RequiresRepaint = HandleInput(rect, node, i, singleClick, doubleClick);
194+
RequiresRepaint = HandleInput(rect, node, i, singleClick, doubleClick, rightClick);
195195
}
196196
rect.y += ItemHeight + ItemSpacing;
197197
}
@@ -257,7 +257,7 @@ private int ToggleNodeVisibility(int idx, TreeNode rootNode)
257257
return idx;
258258
}
259259

260-
private bool HandleInput(Rect rect, TreeNode currentNode, int index, Action<TreeNode> singleClick = null, Action<TreeNode> doubleClick = null)
260+
private bool HandleInput(Rect rect, TreeNode currentNode, int index, Action<TreeNode> singleClick = null, Action<TreeNode> doubleClick = null, Action<TreeNode> rightClick = null)
261261
{
262262
bool selectionChanged = false;
263263
var clickRect = new Rect(0f, rect.y, rect.width, rect.height);
@@ -267,14 +267,20 @@ private bool HandleInput(Rect rect, TreeNode currentNode, int index, Action<Tree
267267
SelectedNode = currentNode;
268268
selectionChanged = true;
269269
var clickCount = Event.current.clickCount;
270-
if (clickCount == 1 && singleClick != null)
270+
var mouseButton = Event.current.button;
271+
272+
if (mouseButton == 0 && clickCount == 1 && singleClick != null)
271273
{
272274
singleClick(currentNode);
273275
}
274-
if (clickCount > 1 && doubleClick != null)
276+
if (mouseButton == 0 && clickCount > 1 && doubleClick != null)
275277
{
276278
doubleClick(currentNode);
277279
}
280+
if (mouseButton == 1 && clickCount == 1 && rightClick != null)
281+
{
282+
rightClick(currentNode);
283+
}
278284
}
279285

280286
// Keyboard navigation if this child is the current selection

0 commit comments

Comments
 (0)