From a9facd895a14ba6dd0acb5a126345bee4329ff00 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Fri, 14 May 2021 13:26:18 +1000 Subject: [PATCH] Fix accelerator on system menu --- src/BizHawk.Client.EmuHawk/MainForm.cs | 44 +++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index 679fe29a7a..9a09766ad7 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -1905,6 +1905,11 @@ namespace BizHawk.Client.EmuHawk private void HandlePlatformMenus() { + if (GenericCoreSubMenu.Visible) + { + var i = GenericCoreSubMenu.Text.IndexOf('&'); + if (i != -1) AvailableAccelerators.Add(GenericCoreSubMenu.Text[i + 1]); + } GenericCoreSubMenu.Visible = false; TI83SubMenu.Visible = false; NESSubMenu.Visible = false; @@ -1989,14 +1994,43 @@ namespace BizHawk.Client.EmuHawk .Where(t => t.GetCustomAttribute() != null) .ToList(); + private ISet _availableAccelerators; + + private ISet AvailableAccelerators + { + get + { + if (_availableAccelerators == null) + { + _availableAccelerators = new HashSet(); + for (var c = 'A'; c <= 'Z'; c++) _availableAccelerators.Add(c); + foreach (ToolStripItem item in MainMenuStrip.Items) + { + if (!item.Visible) continue; + var i = item.Text.IndexOf('&'); + if (i == -1 || i == item.Text.Length - 1) continue; + _availableAccelerators.Remove(char.ToUpperInvariant(item.Text[i + 1])); + } + } + return _availableAccelerators; + } + } + private void DisplayDefaultCoreMenu() { GenericCoreSubMenu.Visible = true; -#if true - GenericCoreSubMenu.Text = Emulator.SystemId; -#else //TODO accelerator; I commented out this naive approach which doesn't work --yoshi - GenericCoreSubMenu.Text = $"&{Emulator.SystemId}"; -#endif + var sysID = Emulator.SystemId; + for (var i = 0; i < sysID.Length; i++) + { + var upper = char.ToUpperInvariant(sysID[i]); + if (AvailableAccelerators.Contains(upper)) + { + AvailableAccelerators.Remove(upper); + sysID = sysID.Insert(i, "&"); + break; + } + } + GenericCoreSubMenu.Text = sysID; GenericCoreSubMenu.DropDownItems.Clear(); var settingsMenuItem = new ToolStripMenuItem { Text = "&Settings" };