From 5a2cb01b7c45fc776a102a194ff646c05bbc9c34 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Tue, 15 Jan 2019 10:44:23 -0500 Subject: [PATCH] Fixing context menu displays --- .../Editor/GitHub.Unity/UI/HistoryView.cs | 63 ++++++++++++------- 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs index 6ee1a2cd7..c1c102192 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs @@ -327,7 +327,7 @@ protected void BuildHistoryControl(int loadAhead, List gitLogEntrie } } - protected void BuildTree() + protected void BuildTreeChanges() { TreeChanges.PathSeparator = Environment.FileSystem.DirectorySeparatorChar.ToString(); TreeChanges.Load(SelectedEntry.changes.Select(entry => new GitStatusEntryTreeData(entry))); @@ -371,16 +371,8 @@ protected void HistoryDetailsEntry(GitLogEntry entry) GUILayout.EndVertical(); } - protected GenericMenu CreateChangesTreeContextMenu(ChangesTreeNode node) - { - var genericMenu = new GenericMenu(); - - genericMenu.AddItem(new GUIContent("Show History"), false, () => { }); - - return genericMenu; - } - - public override void OnGUI() + protected void DoHistoryGui(Action historyControlRightClick = null, + Action changesTreeRightClick = null) { var rect = GUILayoutUtility.GetLastRect(); if (HistoryControl != null) @@ -388,15 +380,14 @@ public override void OnGUI() var historyControlRect = new Rect(0f, 0f, Position.width, Position.height - rect.height); var requiresRepaint = HistoryControl.Render(historyControlRect, - entry => { + singleClick: entry => { SelectedEntry = entry; - BuildTree(); + BuildTreeChanges(); + }, + doubleClick: entry => { + }, - entry => { }, entry => { - GenericMenu menu = new GenericMenu(); - menu.AddItem(new GUIContent("Revert"), false, RevertCommit); - menu.ShowAsContext(); - }); + rightClick: historyControlRightClick); if (requiresRepaint) Redraw(); @@ -413,6 +404,7 @@ public override void OnGUI() { HistoryControl.ScrollTo(HistoryControl.SelectedIndex); } + if (GUILayout.Button(ClearSelectionButton, Styles.ToolbarButtonStyle, GUILayout.ExpandWidth(false))) { SelectedEntry = GitLogEntry.Default; @@ -435,7 +427,8 @@ public override void OnGUI() GUILayout.BeginVertical(); { var borderLeft = Styles.Label.margin.left; - var treeControlRect = new Rect(rect.x + borderLeft, rect.y, Position.width - borderLeft * 2, Position.height - rect.height + Styles.CommitAreaPadding); + var treeControlRect = new Rect(rect.x + borderLeft, rect.y, Position.width - borderLeft * 2, + Position.height - rect.height + Styles.CommitAreaPadding); var treeRect = new Rect(0f, 0f, 0f, 0f); if (TreeChanges != null) { @@ -448,11 +441,7 @@ public override void OnGUI() treeRect = TreeChanges.Render(treeControlRect, DetailsScroll, singleClick: node => { }, doubleClick: node => { }, - rightClick: node => { - var menu = CreateChangesTreeContextMenu(node); - menu.ShowAsContext(); - } - ); + rightClick: changesTreeRightClick); if (TreeChanges.RequiresRepaint) Redraw(); @@ -611,6 +600,18 @@ protected override void MaybeUpdateData() } } + public override void OnGUI() + { + DoHistoryGui(entry => { + GenericMenu menu = new GenericMenu(); + menu.AddItem(new GUIContent("Revert"), false, RevertCommit); + menu.ShowAsContext(); + }, node => { + var menu = CreateChangesTreeContextMenu(node); + menu.ShowAsContext(); + }); + } + protected override HistoryControl HistoryControl { get { return historyControl; } @@ -634,6 +635,15 @@ protected override Vector2 DetailsScroll get { return detailsScroll; } set { detailsScroll = value; } } + + private GenericMenu CreateChangesTreeContextMenu(ChangesTreeNode node) + { + var genericMenu = new GenericMenu(); + + genericMenu.AddItem(new GUIContent("Show History"), false, () => { }); + + return genericMenu; + } } [Serializable] @@ -690,6 +700,11 @@ protected override void MaybeUpdateData() } } + public override void OnGUI() + { + DoHistoryGui(); + } + protected override HistoryControl HistoryControl { get { return historyControl; }