From 0395bd6b57b210294700fe7cb0c033beb9ffeea7 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Tue, 5 Dec 2017 10:27:06 -0500 Subject: [PATCH] Deferring the right click action to the next OnGui In order to allow the node to be selected before showing a context menu. I am storing the right click handler and the node and executing it on the next call to Render --- .../Assets/Editor/GitHub.Unity/UI/TreeControl.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/TreeControl.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/TreeControl.cs index 092f41f2c..71caaef62 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/TreeControl.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/TreeControl.cs @@ -30,6 +30,8 @@ public abstract class Tree [SerializeField] private TreeNodeDictionary folders = new TreeNodeDictionary(); [NonSerialized] private Stack indents = new Stack(); + [NonSerialized] private Action rightClickNextRender; + [NonSerialized] private TreeNode rightClickNextRenderNode; public bool IsInitialized { get { return nodes != null && nodes.Count > 0 && !String.IsNullOrEmpty(nodes[0].Name); } } public bool RequiresRepaint { get; private set; } @@ -134,6 +136,16 @@ public void Load(IEnumerable data, string title) public Rect Render(Rect rect, Vector2 scroll, Action singleClick = null, Action doubleClick = null, Action rightClick = null) { + if (Event.current.type != EventType.Repaint) + { + if (rightClickNextRender != null) + { + rightClickNextRender.Invoke(rightClickNextRenderNode); + rightClickNextRender = null; + rightClickNextRenderNode = null; + } + } + Profiler.BeginSample("TreeControl"); bool visible = true; var availableHeight = rect.y + rect.height; @@ -274,7 +286,8 @@ private bool HandleInput(Rect rect, TreeNode currentNode, int index, Action