From d9e563a655889735d446000ea77d045bb5474c02 Mon Sep 17 00:00:00 2001 From: adelikat Date: Fri, 3 Jul 2020 11:08:40 -0500 Subject: [PATCH] simplify setting the font style of a ToolStripMenuItemEx --- src/BizHawk.Client.EmuHawk/MainForm.Events.cs | 61 ++++--------------- .../tools/Lua/LuaConsole.cs | 12 ++-- .../MenuEx/MenuItemEx.cs | 2 + 3 files changed, 21 insertions(+), 54 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs index 6824b59d72..13ad791460 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs @@ -25,6 +25,7 @@ using BizHawk.Emulation.Cores.Nintendo.NES; using BizHawk.Emulation.Cores.Nintendo.SNES; using BizHawk.Emulation.Cores.Nintendo.SubNESHawk; using BizHawk.Emulation.Cores.Sony.PSX; +using BizHawk.WinForms.Controls; namespace BizHawk.Client.EmuHawk { @@ -69,55 +70,19 @@ namespace BizHawk.Client.EmuHawk private void SaveStateSubMenu_DropDownOpened(object sender, EventArgs e) { - SaveState0MenuItem.Font = new Font( - SaveState0MenuItem.Font.FontFamily, - SaveState0MenuItem.Font.Size, - HasSlot(0) ? (FontStyle.Italic | FontStyle.Bold) : FontStyle.Regular); + void SetSlotFont(ToolStripMenuItemEx menu, int slot) => menu.SetStyle( + HasSlot(slot) ? (FontStyle.Italic | FontStyle.Bold) : FontStyle.Regular); - SaveState1MenuItem.Font = new Font( - SaveState1MenuItem.Font.FontFamily, - SaveState1MenuItem.Font.Size, - HasSlot(1) ? (FontStyle.Italic | FontStyle.Bold) : FontStyle.Regular); - - SaveState2MenuItem.Font = new Font( - SaveState2MenuItem.Font.FontFamily, - SaveState2MenuItem.Font.Size, - HasSlot(2) ? (FontStyle.Italic | FontStyle.Bold) : FontStyle.Regular); - - SaveState3MenuItem.Font = new Font( - SaveState3MenuItem.Font.FontFamily, - SaveState3MenuItem.Font.Size, - HasSlot(3) ? (FontStyle.Italic | FontStyle.Bold) : FontStyle.Regular); - - SaveState4MenuItem.Font = new Font( - SaveState4MenuItem.Font.FontFamily, - SaveState4MenuItem.Font.Size, - HasSlot(4) ? (FontStyle.Italic | FontStyle.Bold) : FontStyle.Regular); - - SaveState5MenuItem.Font = new Font( - SaveState5MenuItem.Font.FontFamily, - SaveState5MenuItem.Font.Size, - HasSlot(5) ? (FontStyle.Italic | FontStyle.Bold) : FontStyle.Regular); - - SaveState6MenuItem.Font = new Font( - SaveState6MenuItem.Font.FontFamily, - SaveState6MenuItem.Font.Size, - HasSlot(6) ? (FontStyle.Italic | FontStyle.Bold) : FontStyle.Regular); - - SaveState7MenuItem.Font = new Font( - SaveState7MenuItem.Font.FontFamily, - SaveState7MenuItem.Font.Size, - HasSlot(7) ? (FontStyle.Italic | FontStyle.Bold) : FontStyle.Regular); - - SaveState8MenuItem.Font = new Font( - SaveState8MenuItem.Font.FontFamily, - SaveState8MenuItem.Font.Size, - HasSlot(8) ? (FontStyle.Italic | FontStyle.Bold) : FontStyle.Regular); - - SaveState9MenuItem.Font = new Font( - SaveState9MenuItem.Font.FontFamily, - SaveState9MenuItem.Font.Size, - HasSlot(9) ? (FontStyle.Italic | FontStyle.Bold) : FontStyle.Regular); + SetSlotFont(SaveState0MenuItem, 0); + SetSlotFont(SaveState1MenuItem, 1); + SetSlotFont(SaveState2MenuItem, 2); + SetSlotFont(SaveState3MenuItem, 3); + SetSlotFont(SaveState4MenuItem, 4); + SetSlotFont(SaveState5MenuItem, 5); + SetSlotFont(SaveState6MenuItem, 6); + SetSlotFont(SaveState7MenuItem, 7); + SetSlotFont(SaveState8MenuItem, 8); + SetSlotFont(SaveState9MenuItem, 9); SaveState1MenuItem.ShortcutKeyDisplayString = Config.HotkeyBindings["Save State 1"].Bindings; SaveState2MenuItem.ShortcutKeyDisplayString = Config.HotkeyBindings["Save State 2"].Bindings; diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs index b91adf8507..52c5624ab4 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs @@ -1203,20 +1203,20 @@ namespace BizHawk.Client.EmuHawk if (_luaAutoInstaller.IsBizLuaRegistered(LuaAutocompleteInstaller.TextEditors.Sublime2)) { RegisterSublimeText2MenuItem.Text = "Sublime Text 2 (installed)"; - RegisterSublimeText2MenuItem.Font = new Font(RegisterSublimeText2MenuItem.Font, FontStyle.Regular); + RegisterSublimeText2MenuItem.SetStyle(FontStyle.Regular); RegisterSublimeText2MenuItem.Image = Resources.GreenCheck; } else { RegisterSublimeText2MenuItem.Text = "Sublime Text 2 (detected)"; - RegisterSublimeText2MenuItem.Font = new Font(RegisterSublimeText2MenuItem.Font, FontStyle.Italic); + RegisterSublimeText2MenuItem.SetStyle(FontStyle.Italic); RegisterSublimeText2MenuItem.Image = null; } } else { RegisterSublimeText2MenuItem.Text = "Sublime Text 2"; - RegisterSublimeText2MenuItem.Font = new Font(RegisterSublimeText2MenuItem.Font, FontStyle.Regular); + RegisterSublimeText2MenuItem.SetStyle(FontStyle.Regular); RegisterSublimeText2MenuItem.Image = null; } @@ -1225,20 +1225,20 @@ namespace BizHawk.Client.EmuHawk if (_luaAutoInstaller.IsBizLuaRegistered(LuaAutocompleteInstaller.TextEditors.NotePad)) { RegisterNotePadMenuItem.Text = "Notepad++ (installed)"; - RegisterNotePadMenuItem.Font = new Font(RegisterNotePadMenuItem.Font, FontStyle.Regular); + RegisterNotePadMenuItem.SetStyle(FontStyle.Regular); RegisterNotePadMenuItem.Image = Resources.GreenCheck; } else { RegisterNotePadMenuItem.Text = "Notepad++ (detected)"; - RegisterNotePadMenuItem.Font = new Font(RegisterNotePadMenuItem.Font, FontStyle.Italic); + RegisterNotePadMenuItem.SetStyle(FontStyle.Italic); RegisterNotePadMenuItem.Image = null; } } else { RegisterNotePadMenuItem.Text = "Notepad++"; - RegisterNotePadMenuItem.Font = new Font(RegisterNotePadMenuItem.Font, FontStyle.Regular); + RegisterNotePadMenuItem.SetStyle(FontStyle.Regular); RegisterNotePadMenuItem.Image = null; } } diff --git a/src/BizHawk.WinForms.Controls/MenuEx/MenuItemEx.cs b/src/BizHawk.WinForms.Controls/MenuEx/MenuItemEx.cs index aa8230c9d7..f0b8e472aa 100644 --- a/src/BizHawk.WinForms.Controls/MenuEx/MenuItemEx.cs +++ b/src/BizHawk.WinForms.Controls/MenuEx/MenuItemEx.cs @@ -12,6 +12,8 @@ namespace BizHawk.WinForms.Controls [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public new string Name => Guid.NewGuid().ToString(); + + public void SetStyle(FontStyle style) => Font = new Font(Font.FontFamily, Font.Size, style); } public class ToolStripSeparatorEx : ToolStripSeparator