Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show context menu on menu key press #3446

Merged
merged 3 commits into from Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions ConsoleUI/Toolkit/ConsolePopupMenu.cs
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
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
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
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
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
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
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
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