Skip to content

Commit

Permalink
Merge #3446 Show context menu on menu key press
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Nov 1, 2021
2 parents 988a39e + 8180d8d commit 2564dfb
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file.
- [GUI] Label ordering buttons (#3416 by: HebaruSan; reviewed: DasSkelett)
- [GUI] Suppress incompatibility warning at game launch (#3453 by: HebaruSan; reviewed: DasSkelett)
- [CLI] Options for ckan show to hide sections (#3461 by: HebaruSan; reviewed: DasSkelett)
- [Multiple] Show context menu on menu key press (#3446 by: HebaruSan; reviewed: DasSkelett)

### Bugfixes

Expand Down
1 change: 1 addition & 0 deletions ConsoleUI/Toolkit/ConsolePopupMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public bool Run(ConsoleTheme theme, int right, int top)
break;
case ConsoleKey.F10:
case ConsoleKey.Escape:
case ConsoleKey.Applications:
done = true;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion ConsoleUI/Toolkit/ConsoleScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected ConsoleScreen()
"F10", MenuTip(),
() => mainMenu != null
);
AddBinding(Keys.F10, (object sender, ConsoleTheme theme) => {
AddBinding(new ConsoleKeyInfo[] {Keys.F10, Keys.Apps}, (object sender, ConsoleTheme theme) => {
bool val = true;
if (mainMenu != null) {
DrawSelectedHamburger(theme);
Expand Down
7 changes: 7 additions & 0 deletions ConsoleUI/Toolkit/Keys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ public static class Keys {
(System.Char)0, ConsoleKey.F10, false, false, false
);

/// <summary>
/// Representation of Apps for key bindings
/// </summary>
public static readonly ConsoleKeyInfo Apps = new ConsoleKeyInfo(
(System.Char)0, ConsoleKey.Applications, false, false, false
);

/// <summary>
/// Representation of down arrow for key bindings
/// </summary>
Expand Down
14 changes: 13 additions & 1 deletion ConsoleUI/Toolkit/ScreenContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ public void AddBinding(ConsoleKeyInfo k, KeyAction a)
}
}

/// <summary>
/// Add custom key bindings
/// </summary>
/// <param name="keys">Keys to bind</param>
/// <param name="a">Action to bind to key</param>
public void AddBinding(IEnumerable<ConsoleKeyInfo> keys, KeyAction a)
{
foreach (ConsoleKeyInfo k in keys) {
AddBinding(k, a);
}
}

/// <summary>
/// Add a screen tip to show in the FooterBg
/// </summary>
Expand Down Expand Up @@ -247,7 +259,7 @@ private void Blur(ScreenObject source, bool forward)
} while (!objects[focusIndex].Focusable());
}
}

private bool done = false;

private List<ScreenObject> objects = new List<ScreenObject>();
Expand Down
1 change: 1 addition & 0 deletions GUI/Controls/ManageMods.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 20 additions & 7 deletions GUI/Controls/ManageMods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,11 @@ private void ModList_KeyDown(object sender, KeyEventArgs e)
}
}
break;

case Keys.Apps:
ShowModContextMenu();
e.Handled = true;
break;
}
}

Expand Down Expand Up @@ -908,23 +913,31 @@ private void ModList_MouseDown(object sender, MouseEventArgs e)
{
var rowIndex = ModGrid.HitTest(e.X, e.Y).RowIndex;

// Ignore header column to prevent errors.
// Ignore header column to prevent errors
if (rowIndex != -1 && e.Button == MouseButtons.Right)
{
// Detect the clicked cell and select the row.
// Detect the clicked cell and select the row
ModGrid.ClearSelection();
ModGrid.Rows[rowIndex].Selected = true;

// Show the context menu.
ModListContextMenuStrip.Show(ModGrid, new Point(e.X, e.Y));

// Set the menu options.
var guiMod = (GUIMod)ModGrid.Rows[rowIndex].Tag;
// Show the context menu
ShowModContextMenu();
}
}

private bool ShowModContextMenu()
{
var guiMod = SelectedModule;
if (guiMod != null)
{
ModListContextMenuStrip.Show(Cursor.Position);
// Set the menu options
downloadContentsToolStripMenuItem.Enabled = !guiMod.ToModule().IsMetapackage && !guiMod.IsCached;
purgeContentsToolStripMenuItem.Enabled = !guiMod.ToModule().IsMetapackage && guiMod.IsCached;
reinstallToolStripMenuItem.Enabled = guiMod.IsInstalled && !guiMod.IsAutodetected;
return true;
}
return false;
}

private void ModList_Resize(object sender, EventArgs e)
Expand Down
12 changes: 12 additions & 0 deletions GUI/Controls/ModInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ private void LinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs
Util.HandleLinkClicked((sender as LinkLabel).Text, e);
}

private void LinkLabel_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Apps:
Util.LinkContextMenu((sender as LinkLabel).Text);
e.Handled = true;
break;
}
}

private void UpdateModInfo(GUIMod gui_module)
{
CkanModule module = gui_module.ToModule();
Expand Down Expand Up @@ -254,6 +265,7 @@ private void AddResourceLink(string label, Uri link)
Text = link.ToString(),
};
llbl.LinkClicked += new LinkLabelLinkClickedEventHandler(LinkLabel_LinkClicked);
llbl.KeyDown += new KeyEventHandler(LinkLabel_KeyDown);
int row = MetaDataLowerLayoutPanel.RowCount;
MetaDataLowerLayoutPanel.Controls.Add(lbl, 0, row);
MetaDataLowerLayoutPanel.Controls.Add(llbl, 1, row);
Expand Down
5 changes: 5 additions & 0 deletions GUI/Dialogs/AboutDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions GUI/Dialogs/AboutDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,17 @@ private void linkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs
string url = (sender as LinkLabel).Text;
Util.HandleLinkClicked(url, e);
}

private void linkLabel_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Apps:
Util.LinkContextMenu((sender as LinkLabel).Text);
e.Handled = true;
break;
}
}

}
}
1 change: 1 addition & 0 deletions GUI/Dialogs/ManageGameInstancesDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions GUI/Dialogs/ManageGameInstancesDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,17 @@ private void GameInstancesListView_Click(object sender, MouseEventArgs e)
}
}

private void GameInstancesListView_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Apps:
InstanceListContextMenuStrip.Show(Cursor.Position);
e.Handled = true;
break;
}
}

private void OpenDirectoryMenuItem_Click(object sender, EventArgs e)
{
string path = _manager.Instances[(string) GameInstancesListView.SelectedItems[0].Tag].GameDir();
Expand Down

0 comments on commit 2564dfb

Please sign in to comment.