From 36cb62a79229b6de5f22ee884ed3b8c5a08736d0 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Mon, 7 Nov 2022 05:55:28 +1000 Subject: [PATCH] Create and use `ToolStripDropDownItem.ReplaceDropDownItems` extension --- .../Extensions/ControlExtensions.cs | 6 ++++++ src/BizHawk.Client.EmuHawk/MainForm.Events.cs | 10 ++-------- .../tools/BasicBot/BasicBot.cs | 12 ++---------- src/BizHawk.Client.EmuHawk/tools/CDL.cs | 5 +---- src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs | 5 +---- .../tools/HexEditor/HexEditor.cs | 10 ++-------- src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs | 10 ++-------- .../tools/Macros/MacroInput.cs | 5 +---- .../tools/TAStudio/TAStudio.MenuItems.cs | 10 ++-------- src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs | 12 ++---------- src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs | 12 ++---------- 11 files changed, 23 insertions(+), 74 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs b/src/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs index 9466491ff5..74d86322a9 100644 --- a/src/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs +++ b/src/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs @@ -133,6 +133,12 @@ namespace BizHawk.Client.EmuHawk { return tabControl.TabPages.Cast(); } + + public static void ReplaceDropDownItems(this ToolStripDropDownItem menu, params ToolStripItem[] items) + { + menu.DropDownItems.Clear(); + menu.DropDownItems.AddRange(items); + } } public static class ListViewExtensions diff --git a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs index 67837eefcf..460153584a 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs @@ -115,10 +115,7 @@ namespace BizHawk.Client.EmuHawk } private void RecentRomMenuItem_DropDownOpened(object sender, EventArgs e) - { - RecentRomSubMenu.DropDownItems.Clear(); - RecentRomSubMenu.DropDownItems.AddRange(Config.RecentRoms.RecentMenu(this, LoadRomFromRecent, "ROM", romLoading: true)); - } + => RecentRomSubMenu.ReplaceDropDownItems(Config.RecentRoms.RecentMenu(this, LoadRomFromRecent, "ROM", romLoading: true)); private bool HasSlot(int slot) => _stateSlots.HasSlot(Emulator, MovieSession.Movie, slot, SaveStatePrefix()); @@ -248,10 +245,7 @@ namespace BizHawk.Client.EmuHawk } private void RecentMovieSubMenu_DropDownOpened(object sender, EventArgs e) - { - RecentMovieSubMenu.DropDownItems.Clear(); - RecentMovieSubMenu.DropDownItems.AddRange(Config.RecentMovies.RecentMenu(this, LoadMoviesFromRecent, "Movie")); - } + => RecentMovieSubMenu.ReplaceDropDownItems(Config.RecentMovies.RecentMenu(this, LoadMoviesFromRecent, "Movie")); private void MovieEndSubMenu_DropDownOpened(object sender, EventArgs e) { diff --git a/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs b/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs index 7bba1e8bff..07e58d1f6b 100644 --- a/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs +++ b/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs @@ -307,10 +307,7 @@ namespace BizHawk.Client.EmuHawk } private void RecentSubMenu_DropDownOpened(object sender, EventArgs e) - { - RecentSubMenu.DropDownItems.Clear(); - RecentSubMenu.DropDownItems.AddRange(Settings.RecentBotFiles.RecentMenu(MainForm, LoadFileFromRecent, "Bot Parameters")); - } + => RecentSubMenu.ReplaceDropDownItems(Settings.RecentBotFiles.RecentMenu(MainForm, LoadFileFromRecent, "Bot Parameters")); private void NewMenuItem_Click(object sender, EventArgs e) { @@ -394,12 +391,7 @@ namespace BizHawk.Client.EmuHawk } private void MemoryDomainsMenuItem_DropDownOpened(object sender, EventArgs e) - { - MemoryDomainsMenuItem.DropDownItems.Clear(); - MemoryDomainsMenuItem.DropDownItems.AddRange( - MemoryDomains.MenuItems(SetMemoryDomain, _currentDomain.Name) - .ToArray()); - } + => MemoryDomainsMenuItem.ReplaceDropDownItems(MemoryDomains.MenuItems(SetMemoryDomain, _currentDomain.Name).ToArray()); private void BigEndianMenuItem_Click(object sender, EventArgs e) { diff --git a/src/BizHawk.Client.EmuHawk/tools/CDL.cs b/src/BizHawk.Client.EmuHawk/tools/CDL.cs index 385a7895c7..480a458343 100644 --- a/src/BizHawk.Client.EmuHawk/tools/CDL.cs +++ b/src/BizHawk.Client.EmuHawk/tools/CDL.cs @@ -288,10 +288,7 @@ namespace BizHawk.Client.EmuHawk } private void RecentSubMenu_DropDownOpened(object sender, EventArgs e) - { - RecentSubMenu.DropDownItems.Clear(); - RecentSubMenu.DropDownItems.AddRange(_recent.RecentMenu(MainForm, LoadFile, "Session")); - } + => RecentSubMenu.ReplaceDropDownItems(_recent.RecentMenu(MainForm, LoadFile, "Session")); private void NewFileLogic() { diff --git a/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs b/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs index 592eaa6087..583de2baf2 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs @@ -344,10 +344,7 @@ namespace BizHawk.Client.EmuHawk } private void RecentSubMenu_DropDownOpened(object sender, EventArgs e) - { - RecentSubMenu.DropDownItems.Clear(); - RecentSubMenu.DropDownItems.AddRange(Config.Cheats.Recent.RecentMenu(MainForm, LoadFileFromRecent, "Cheats")); - } + => RecentSubMenu.ReplaceDropDownItems(Config!.Cheats.Recent.RecentMenu(MainForm, LoadFileFromRecent, "Cheats")); private void NewMenuItem_Click(object sender, EventArgs e) { diff --git a/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs b/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs index a916cc07ac..f5331632f6 100644 --- a/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs +++ b/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs @@ -1332,10 +1332,7 @@ namespace BizHawk.Client.EmuHawk } private void RecentTablesSubMenu_DropDownOpened(object sender, EventArgs e) - { - RecentTablesSubMenu.DropDownItems.Clear(); - RecentTablesSubMenu.DropDownItems.AddRange(RecentTables.RecentMenu(MainForm, LoadFileFromRecent, "Session")); - } + => RecentTablesSubMenu.ReplaceDropDownItems(RecentTables.RecentMenu(MainForm, LoadFileFromRecent, "Session")); private void EditMenuItem_DropDownOpened(object sender, EventArgs e) { @@ -1518,10 +1515,7 @@ namespace BizHawk.Client.EmuHawk private void MemoryDomainsMenuItem_DropDownOpened(object sender, EventArgs e) { - MemoryDomainsMenuItem.DropDownItems.Clear(); - MemoryDomainsMenuItem.DropDownItems.AddRange( - MemoryDomains.MenuItems(SetMemoryDomain, _domain.Name) - .ToArray()); + MemoryDomainsMenuItem.ReplaceDropDownItems(MemoryDomains.MenuItems(SetMemoryDomain, _domain.Name).ToArray()); if (_romDomain != null) { diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs index 566d619637..e9bdae10fe 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs @@ -761,16 +761,10 @@ namespace BizHawk.Client.EmuHawk } private void RecentSessionsSubMenu_DropDownOpened(object sender, EventArgs e) - { - RecentSessionsSubMenu.DropDownItems.Clear(); - RecentSessionsSubMenu.DropDownItems.AddRange(Config.RecentLuaSession.RecentMenu(MainForm, LoadSessionFromRecent, "Session")); - } + => RecentSessionsSubMenu.ReplaceDropDownItems(Config!.RecentLuaSession.RecentMenu(MainForm, LoadSessionFromRecent, "Session")); private void RecentScriptsSubMenu_DropDownOpened(object sender, EventArgs e) - { - RecentScriptsSubMenu.DropDownItems.Clear(); - RecentScriptsSubMenu.DropDownItems.AddRange(Config.RecentLua.RecentMenu(MainForm, LoadLuaFile, "Script")); - } + => RecentScriptsSubMenu.ReplaceDropDownItems(Config!.RecentLua.RecentMenu(MainForm, LoadLuaFile, "Script")); private void NewSessionMenuItem_Click(object sender, EventArgs e) { diff --git a/src/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.cs b/src/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.cs index bc8af317ac..9da99f8a5c 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.cs @@ -243,10 +243,7 @@ namespace BizHawk.Client.EmuHawk } private void RecentToolStripMenuItem_DropDownOpened(object sender, EventArgs e) - { - RecentToolStripMenuItem.DropDownItems.Clear(); - RecentToolStripMenuItem.DropDownItems.AddRange(Config.RecentMacros.RecentMenu(MainForm, DummyLoadMacro, "Macro")); - } + => RecentToolStripMenuItem.ReplaceDropDownItems(Config!.RecentMacros.RecentMenu(MainForm, DummyLoadMacro, "Macro")); private void DummyLoadMacro(string path) { diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs index 1bb81312cc..6e6e5e5875 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs @@ -67,10 +67,7 @@ namespace BizHawk.Client.EmuHawk } private void RecentSubMenu_DropDownOpened(object sender, EventArgs e) - { - RecentSubMenu.DropDownItems.Clear(); - RecentSubMenu.DropDownItems.AddRange(Settings.RecentTas.RecentMenu(MainForm, DummyLoadProject, "Project")); - } + => RecentSubMenu.ReplaceDropDownItems(Settings.RecentTas.RecentMenu(MainForm, DummyLoadProject, "Project")); private void NewTasMenuItem_Click(object sender, EventArgs e) { @@ -251,10 +248,7 @@ namespace BizHawk.Client.EmuHawk } private void RecentMacrosMenuItem_DropDownOpened(object sender, EventArgs e) - { - recentMacrosToolStripMenuItem.DropDownItems.Clear(); - recentMacrosToolStripMenuItem.DropDownItems.AddRange(Config.RecentMacros.RecentMenu(MainForm, DummyLoadMacro, "Macro", noAutoload: true)); - } + => recentMacrosToolStripMenuItem.ReplaceDropDownItems(Config!.RecentMacros.RecentMenu(MainForm, DummyLoadMacro, "Macro", noAutoload: true)); private void ToBk2MenuItem_Click(object sender, EventArgs e) { diff --git a/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs b/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs index d8d60596a0..fca6a629e4 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs @@ -971,10 +971,7 @@ namespace BizHawk.Client.EmuHawk } private void RecentSubMenu_DropDownOpened(object sender, EventArgs e) - { - RecentSubMenu.DropDownItems.Clear(); - RecentSubMenu.DropDownItems.AddRange(Settings.RecentSearches.RecentMenu(MainForm, LoadFileFromRecent, "Search", noAutoload: true)); - } + => RecentSubMenu.ReplaceDropDownItems(Settings.RecentSearches.RecentMenu(MainForm, LoadFileFromRecent, "Search", noAutoload: true)); private void OpenMenuItem_Click(object sender, EventArgs e) { @@ -1051,12 +1048,7 @@ namespace BizHawk.Client.EmuHawk } private void MemoryDomainsSubMenu_DropDownOpened(object sender, EventArgs e) - { - MemoryDomainsSubMenu.DropDownItems.Clear(); - MemoryDomainsSubMenu.DropDownItems.AddRange( - MemoryDomains.MenuItems(SetMemoryDomain, _searches.Domain.Name, MaxSupportedSize) - .ToArray()); - } + => MemoryDomainsSubMenu.ReplaceDropDownItems(MemoryDomains.MenuItems(SetMemoryDomain, _searches.Domain.Name, MaxSupportedSize).ToArray()); private void SizeSubMenu_DropDownOpened(object sender, EventArgs e) { diff --git a/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs b/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs index 9dac2dddcf..368eb87119 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs @@ -692,10 +692,7 @@ namespace BizHawk.Client.EmuHawk } private void RecentSubMenu_DropDownOpened(object sender, EventArgs e) - { - RecentSubMenu.DropDownItems.Clear(); - RecentSubMenu.DropDownItems.AddRange(Config.RecentWatches.RecentMenu(MainForm, LoadFileFromRecent, "Watches")); - } + => RecentSubMenu.ReplaceDropDownItems(Config!.RecentWatches.RecentMenu(MainForm, LoadFileFromRecent, "Watches")); private void WatchesSubMenu_DropDownOpened(object sender, EventArgs e) { @@ -725,12 +722,7 @@ namespace BizHawk.Client.EmuHawk } private void MemoryDomainsSubMenu_DropDownOpened(object sender, EventArgs e) - { - MemoryDomainsSubMenu.DropDownItems.Clear(); - MemoryDomainsSubMenu.DropDownItems.AddRange( - MemoryDomains.MenuItems(SetMemoryDomain, CurrentDomain.Name) - .ToArray()); - } + => MemoryDomainsSubMenu.ReplaceDropDownItems(MemoryDomains.MenuItems(SetMemoryDomain, CurrentDomain.Name).ToArray()); private void NewWatchMenuItem_Click(object sender, EventArgs e) {