simplify setting the font style of a ToolStripMenuItemEx

This commit is contained in:
adelikat 2020-07-03 11:08:40 -05:00
parent 715e457a4e
commit d9e563a655
3 changed files with 21 additions and 54 deletions

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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