From ef4ee26218ca1554baddcca0ae3075abc5dd4ec3 Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Sat, 4 Sep 2021 22:00:10 +0000 Subject: [PATCH] Show mod context menu on menu key press --- GUI/Controls/ManageMods.cs | 27 ++++++++++++++----- GUI/Controls/ModInfo.cs | 12 +++++++++ GUI/Dialogs/AboutDialog.Designer.cs | 5 ++++ GUI/Dialogs/AboutDialog.cs | 12 +++++++++ .../ManageGameInstancesDialog.Designer.cs | 1 + GUI/Dialogs/ManageGameInstancesDialog.cs | 11 ++++++++ 6 files changed, 61 insertions(+), 7 deletions(-) diff --git a/GUI/Controls/ManageMods.cs b/GUI/Controls/ManageMods.cs index 189f898bcd..60f68497f7 100644 --- a/GUI/Controls/ManageMods.cs +++ b/GUI/Controls/ManageMods.cs @@ -643,6 +643,11 @@ private void ModList_KeyDown(object sender, KeyEventArgs e) } } break; + + case Keys.Apps: + ShowModContextMenu(); + e.Handled = true; + break; } } @@ -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) diff --git a/GUI/Controls/ModInfo.cs b/GUI/Controls/ModInfo.cs index 9f81b41372..f22d32b687 100644 --- a/GUI/Controls/ModInfo.cs +++ b/GUI/Controls/ModInfo.cs @@ -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(); @@ -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); diff --git a/GUI/Dialogs/AboutDialog.Designer.cs b/GUI/Dialogs/AboutDialog.Designer.cs index 528c12ba04..1e21bce130 100644 --- a/GUI/Dialogs/AboutDialog.Designer.cs +++ b/GUI/Dialogs/AboutDialog.Designer.cs @@ -87,6 +87,7 @@ private void InitializeComponent() this.licenseLinkLabel.TextAlign = System.Drawing.ContentAlignment.TopLeft; this.licenseLinkLabel.UseCompatibleTextRendering = true; this.licenseLinkLabel.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel_LinkClicked); + this.licenseLinkLabel.KeyDown += new System.Windows.Forms.KeyEventHandler(this.linkLabel_KeyDown); // // authorsLabel // @@ -108,6 +109,7 @@ private void InitializeComponent() this.authorsLinkLabel.TabStop = true; this.authorsLinkLabel.TextAlign = System.Drawing.ContentAlignment.TopLeft; this.authorsLinkLabel.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel_LinkClicked); + this.authorsLinkLabel.KeyDown += new System.Windows.Forms.KeyEventHandler(this.linkLabel_KeyDown); // // sourceLabel // @@ -129,6 +131,7 @@ private void InitializeComponent() this.sourceLinkLabel.TabStop = true; this.sourceLinkLabel.TextAlign = System.Drawing.ContentAlignment.TopLeft; this.sourceLinkLabel.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel_LinkClicked); + this.sourceLinkLabel.KeyDown += new System.Windows.Forms.KeyEventHandler(this.linkLabel_KeyDown); // // forumthreadLabel // @@ -151,6 +154,7 @@ private void InitializeComponent() this.forumthreadLinkLabel.TextAlign = System.Drawing.ContentAlignment.TopLeft; this.forumthreadLinkLabel.UseCompatibleTextRendering = true; this.forumthreadLinkLabel.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel_LinkClicked); + this.forumthreadLinkLabel.KeyDown += new System.Windows.Forms.KeyEventHandler(this.linkLabel_KeyDown); // // homepageLabel // @@ -172,6 +176,7 @@ private void InitializeComponent() this.homepageLinkLabel.TabStop = true; this.homepageLinkLabel.TextAlign = System.Drawing.ContentAlignment.TopLeft; this.homepageLinkLabel.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel_LinkClicked); + this.homepageLinkLabel.KeyDown += new System.Windows.Forms.KeyEventHandler(this.linkLabel_KeyDown); // // AboutDialog // diff --git a/GUI/Dialogs/AboutDialog.cs b/GUI/Dialogs/AboutDialog.cs index 9e74d64d94..ce09e36761 100644 --- a/GUI/Dialogs/AboutDialog.cs +++ b/GUI/Dialogs/AboutDialog.cs @@ -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; + } + } + } } diff --git a/GUI/Dialogs/ManageGameInstancesDialog.Designer.cs b/GUI/Dialogs/ManageGameInstancesDialog.Designer.cs index f97c61dbfb..3dd123bf05 100644 --- a/GUI/Dialogs/ManageGameInstancesDialog.Designer.cs +++ b/GUI/Dialogs/ManageGameInstancesDialog.Designer.cs @@ -77,6 +77,7 @@ private void InitializeComponent() this.GameInstancesListView.SelectedIndexChanged += new System.EventHandler(this.GameInstancesListView_SelectedIndexChanged); this.GameInstancesListView.DoubleClick += new System.EventHandler(this.GameInstancesListView_DoubleClick); this.GameInstancesListView.MouseClick += new System.Windows.Forms.MouseEventHandler(this.GameInstancesListView_Click); + this.GameInstancesListView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.GameInstancesListView_KeyDown); // // InstanceListContextMenuStrip // diff --git a/GUI/Dialogs/ManageGameInstancesDialog.cs b/GUI/Dialogs/ManageGameInstancesDialog.cs index 59dacd0b03..e49cd63db9 100644 --- a/GUI/Dialogs/ManageGameInstancesDialog.cs +++ b/GUI/Dialogs/ManageGameInstancesDialog.cs @@ -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();