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

Commit

Permalink
Fixing context menu displays
Browse files Browse the repository at this point in the history
  • Loading branch information
StanleyGoldman committed Jan 15, 2019
1 parent 6e8ed9a commit 5a2cb01
Showing 1 changed file with 39 additions and 24 deletions.
63 changes: 39 additions & 24 deletions src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ protected void BuildHistoryControl(int loadAhead, List<GitLogEntry> gitLogEntrie
}
}

protected void BuildTree()
protected void BuildTreeChanges()
{
TreeChanges.PathSeparator = Environment.FileSystem.DirectorySeparatorChar.ToString();
TreeChanges.Load(SelectedEntry.changes.Select(entry => new GitStatusEntryTreeData(entry)));
Expand Down Expand Up @@ -371,32 +371,23 @@ 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<GitLogEntry> historyControlRightClick = null,
Action<ChangesTreeNode> changesTreeRightClick = null)
{
var rect = GUILayoutUtility.GetLastRect();
if (HistoryControl != null)
{
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();
Expand All @@ -413,6 +404,7 @@ public override void OnGUI()
{
HistoryControl.ScrollTo(HistoryControl.SelectedIndex);
}

if (GUILayout.Button(ClearSelectionButton, Styles.ToolbarButtonStyle, GUILayout.ExpandWidth(false)))
{
SelectedEntry = GitLogEntry.Default;
Expand All @@ -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)
{
Expand All @@ -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();
Expand Down Expand Up @@ -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; }
Expand All @@ -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]
Expand Down Expand Up @@ -690,6 +700,11 @@ protected override void MaybeUpdateData()
}
}

public override void OnGUI()
{
DoHistoryGui();
}

protected override HistoryControl HistoryControl
{
get { return historyControl; }
Expand Down

0 comments on commit 5a2cb01

Please sign in to comment.