From da5ddf32176daa7e5ae519864332fffe5181889e Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 3 May 2020 09:52:36 -0500 Subject: [PATCH] put a virtual AskSaveChanges method in ToolFormBase, and only override it when needed, reduces a lot of boilerplate --- src/BizHawk.Client.EmuHawk/LogWindow.cs | 1 - src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs | 2 -- src/BizHawk.Client.EmuHawk/tools/CDL.cs | 2 +- src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs | 5 ----- .../tools/Debugger/GenericDebugger.IToolForm.cs | 2 -- src/BizHawk.Client.EmuHawk/tools/GB/GBGPUView.cs | 1 - src/BizHawk.Client.EmuHawk/tools/GB/GBPrinterView.cs | 2 -- src/BizHawk.Client.EmuHawk/tools/GBA/GBAGPUView.cs | 1 - src/BizHawk.Client.EmuHawk/tools/GameShark.cs | 1 - src/BizHawk.Client.EmuHawk/tools/Genesis/VDPViewer.cs | 2 -- src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs | 2 -- src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs | 2 +- src/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.cs | 2 +- .../tools/MultiDiskBundler/MultiDiskBundler.cs | 2 -- src/BizHawk.Client.EmuHawk/tools/NES/NESMusicRipper.cs | 1 - src/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.cs | 1 - src/BizHawk.Client.EmuHawk/tools/NES/NESPPU.cs | 1 - src/BizHawk.Client.EmuHawk/tools/PCE/PCEBGViewer.cs | 1 - src/BizHawk.Client.EmuHawk/tools/PCE/PCESoundDebugger.cs | 3 --- src/BizHawk.Client.EmuHawk/tools/PCE/PCETileViewer.cs | 2 -- src/BizHawk.Client.EmuHawk/tools/SMS/VDPViewer.cs | 2 -- .../tools/SNES/SNESGraphicsDebugger.cs | 1 - .../tools/TAStudio/TAStudio.IToolForm.cs | 2 +- src/BizHawk.Client.EmuHawk/tools/TI83/TI83KeyPad.cs | 1 - src/BizHawk.Client.EmuHawk/tools/ToolBox.cs | 1 - src/BizHawk.Client.EmuHawk/tools/ToolFormBase.cs | 2 ++ src/BizHawk.Client.EmuHawk/tools/TraceLogger.cs | 2 -- .../tools/VirtualPads/VirtualpadsTool.cs | 1 - src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs | 2 -- src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs | 2 +- 30 files changed, 7 insertions(+), 45 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/LogWindow.cs b/src/BizHawk.Client.EmuHawk/LogWindow.cs index 4943291118..157177ddb0 100644 --- a/src/BizHawk.Client.EmuHawk/LogWindow.cs +++ b/src/BizHawk.Client.EmuHawk/LogWindow.cs @@ -42,7 +42,6 @@ namespace BizHawk.Client.EmuHawk public void Restart() { } - public bool AskSaveChanges() => true; public bool UpdateBefore => true; private void Attach() diff --git a/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs b/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs index 4a4501d624..5829689f76 100644 --- a/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs +++ b/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs @@ -296,8 +296,6 @@ namespace BizHawk.Client.EmuHawk } } - public bool AskSaveChanges() => true; - #endregion #region Control Events diff --git a/src/BizHawk.Client.EmuHawk/tools/CDL.cs b/src/BizHawk.Client.EmuHawk/tools/CDL.cs index 03a67980b7..0ba9fb9bbf 100644 --- a/src/BizHawk.Client.EmuHawk/tools/CDL.cs +++ b/src/BizHawk.Client.EmuHawk/tools/CDL.cs @@ -194,7 +194,7 @@ namespace BizHawk.Client.EmuHawk lvCDL.RowCount = _cdl.Count; } - public bool AskSaveChanges() + public override bool AskSaveChanges() { // nothing to fear: if (_cdl == null) diff --git a/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs b/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs index 041d62b26d..098ccc4ca9 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs @@ -110,11 +110,6 @@ namespace BizHawk.Client.EmuHawk : Path.GetFileName(Global.CheatList.CurrentFileName); } - public bool AskSaveChanges() - { - return true; - } - private void LoadFile(FileSystemInfo file, bool append) { if (file != null) diff --git a/src/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.IToolForm.cs b/src/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.IToolForm.cs index 001e67b6d0..2d53c7b9dd 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.IToolForm.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.IToolForm.cs @@ -156,8 +156,6 @@ namespace BizHawk.Client.EmuHawk EngageDebugger(); } - public bool AskSaveChanges() => true; - public bool UpdateBefore => false; } } diff --git a/src/BizHawk.Client.EmuHawk/tools/GB/GBGPUView.cs b/src/BizHawk.Client.EmuHawk/tools/GB/GBGPUView.cs index 0f19a6a880..e3364ebd5e 100644 --- a/src/BizHawk.Client.EmuHawk/tools/GB/GBGPUView.cs +++ b/src/BizHawk.Client.EmuHawk/tools/GB/GBGPUView.cs @@ -54,7 +54,6 @@ namespace BizHawk.Client.EmuHawk } } - public bool AskSaveChanges() => true; public bool UpdateBefore => true; public GbGpuView() diff --git a/src/BizHawk.Client.EmuHawk/tools/GB/GBPrinterView.cs b/src/BizHawk.Client.EmuHawk/tools/GB/GBPrinterView.cs index cb7c92357b..8904e25111 100644 --- a/src/BizHawk.Client.EmuHawk/tools/GB/GBPrinterView.cs +++ b/src/BizHawk.Client.EmuHawk/tools/GB/GBPrinterView.cs @@ -54,8 +54,6 @@ namespace BizHawk.Client.EmuHawk public bool UpdateBefore => false; - public bool AskSaveChanges() => true; - public void FastUpdate() { } diff --git a/src/BizHawk.Client.EmuHawk/tools/GBA/GBAGPUView.cs b/src/BizHawk.Client.EmuHawk/tools/GBA/GBAGPUView.cs index 95a3ffd901..e003f1511a 100644 --- a/src/BizHawk.Client.EmuHawk/tools/GBA/GBAGPUView.cs +++ b/src/BizHawk.Client.EmuHawk/tools/GBA/GBAGPUView.cs @@ -29,7 +29,6 @@ namespace BizHawk.Client.EmuHawk // MobileDetailView memory; - public bool AskSaveChanges() => true; public bool UpdateBefore => true; public GbaGpuView() diff --git a/src/BizHawk.Client.EmuHawk/tools/GameShark.cs b/src/BizHawk.Client.EmuHawk/tools/GameShark.cs index e6d3beffd5..3f8f5f8a9a 100644 --- a/src/BizHawk.Client.EmuHawk/tools/GameShark.cs +++ b/src/BizHawk.Client.EmuHawk/tools/GameShark.cs @@ -30,7 +30,6 @@ namespace BizHawk.Client.EmuHawk #region IToolForm public bool UpdateBefore => true; - public bool AskSaveChanges() => true; public void FastUpdate() { diff --git a/src/BizHawk.Client.EmuHawk/tools/Genesis/VDPViewer.cs b/src/BizHawk.Client.EmuHawk/tools/Genesis/VDPViewer.cs index d2b6ce29c7..bde647c8d2 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Genesis/VDPViewer.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Genesis/VDPViewer.cs @@ -150,8 +150,6 @@ namespace BizHawk.Client.EmuHawk UpdateValues(); } - public bool AskSaveChanges() => true; - public bool UpdateBefore => true; private void bmpViewPal_MouseClick(object sender, MouseEventArgs e) diff --git a/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs b/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs index 442766e0a8..583cf91273 100644 --- a/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs +++ b/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs @@ -156,8 +156,6 @@ namespace BizHawk.Client.EmuHawk public bool UpdateBefore => false; - public bool AskSaveChanges() => true; - public void NewUpdate(ToolFormUpdateType type) { } public void UpdateValues() diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs index ebef5ad8c0..2592add533 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs @@ -644,7 +644,7 @@ namespace BizHawk.Client.EmuHawk AddFileWatches(); } - public bool AskSaveChanges() + public override bool AskSaveChanges() { if (LuaImp.ScriptList.Changes && !string.IsNullOrEmpty(LuaImp.ScriptList.Filename)) { diff --git a/src/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.cs b/src/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.cs index 2f1fce72c3..43a4897671 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.cs @@ -102,7 +102,7 @@ namespace BizHawk.Client.EmuHawk public bool UpdateBefore => true; - public bool AskSaveChanges() + public override bool AskSaveChanges() { if (_unsavedZones.Count == 0 || IsDisposed) { diff --git a/src/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskBundler.cs b/src/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskBundler.cs index f344885abb..57295cd5fc 100644 --- a/src/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskBundler.cs +++ b/src/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskBundler.cs @@ -77,8 +77,6 @@ namespace BizHawk.Client.EmuHawk { } - public bool AskSaveChanges() => true; - public bool UpdateBefore => true; #endregion diff --git a/src/BizHawk.Client.EmuHawk/tools/NES/NESMusicRipper.cs b/src/BizHawk.Client.EmuHawk/tools/NES/NESMusicRipper.cs index b795aa4739..2d487e5413 100644 --- a/src/BizHawk.Client.EmuHawk/tools/NES/NESMusicRipper.cs +++ b/src/BizHawk.Client.EmuHawk/tools/NES/NESMusicRipper.cs @@ -26,7 +26,6 @@ namespace BizHawk.Client.EmuHawk SyncContents(); } - public bool AskSaveChanges() => true; public bool UpdateBefore => true; public void Restart() diff --git a/src/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.cs b/src/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.cs index dbef147a91..7128ffe8c8 100644 --- a/src/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.cs +++ b/src/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.cs @@ -39,7 +39,6 @@ namespace BizHawk.Client.EmuHawk #region Public API - public bool AskSaveChanges() => true; public bool UpdateBefore => true; public void Restart() diff --git a/src/BizHawk.Client.EmuHawk/tools/NES/NESPPU.cs b/src/BizHawk.Client.EmuHawk/tools/NES/NESPPU.cs index 718e2dfc0e..1fde857cfa 100644 --- a/src/BizHawk.Client.EmuHawk/tools/NES/NESPPU.cs +++ b/src/BizHawk.Client.EmuHawk/tools/NES/NESPPU.cs @@ -59,7 +59,6 @@ namespace BizHawk.Client.EmuHawk #region Public API - public bool AskSaveChanges() => true; public bool UpdateBefore => true; public void NewUpdate(ToolFormUpdateType type) { } diff --git a/src/BizHawk.Client.EmuHawk/tools/PCE/PCEBGViewer.cs b/src/BizHawk.Client.EmuHawk/tools/PCE/PCEBGViewer.cs index 56907cfc5b..762cbb1cca 100644 --- a/src/BizHawk.Client.EmuHawk/tools/PCE/PCEBGViewer.cs +++ b/src/BizHawk.Client.EmuHawk/tools/PCE/PCEBGViewer.cs @@ -32,7 +32,6 @@ namespace BizHawk.Client.EmuHawk #region Public API - public bool AskSaveChanges() => true; public bool UpdateBefore => true; public unsafe void Generate() diff --git a/src/BizHawk.Client.EmuHawk/tools/PCE/PCESoundDebugger.cs b/src/BizHawk.Client.EmuHawk/tools/PCE/PCESoundDebugger.cs index ddc2fb54d3..55894c2414 100644 --- a/src/BizHawk.Client.EmuHawk/tools/PCE/PCESoundDebugger.cs +++ b/src/BizHawk.Client.EmuHawk/tools/PCE/PCESoundDebugger.cs @@ -170,11 +170,8 @@ namespace BizHawk.Client.EmuHawk { } - public bool AskSaveChanges() => true; - public bool UpdateBefore => false; - // 32*16 samples, 16bit, mono, 8khz (but we'll change the sample rate) private static readonly byte[] EmptyWav = { 0x52, 0x49, 0x46, 0x46, 0x24, 0x04, 0x00, 0x00, 0x57, 0x41, 0x56, 0x45, 0x66, 0x6D, 0x74, 0x20, diff --git a/src/BizHawk.Client.EmuHawk/tools/PCE/PCETileViewer.cs b/src/BizHawk.Client.EmuHawk/tools/PCE/PCETileViewer.cs index 618bf598ab..94e9aa9d7a 100644 --- a/src/BizHawk.Client.EmuHawk/tools/PCE/PCETileViewer.cs +++ b/src/BizHawk.Client.EmuHawk/tools/PCE/PCETileViewer.cs @@ -164,8 +164,6 @@ namespace BizHawk.Client.EmuHawk CheckBoxVDC2_CheckedChanged(null, null); } - public bool AskSaveChanges() => true; - public bool UpdateBefore => true; #endregion diff --git a/src/BizHawk.Client.EmuHawk/tools/SMS/VDPViewer.cs b/src/BizHawk.Client.EmuHawk/tools/SMS/VDPViewer.cs index a976718c92..9b5d8054ad 100644 --- a/src/BizHawk.Client.EmuHawk/tools/SMS/VDPViewer.cs +++ b/src/BizHawk.Client.EmuHawk/tools/SMS/VDPViewer.cs @@ -160,8 +160,6 @@ namespace BizHawk.Client.EmuHawk UpdateValues(); } - public bool AskSaveChanges() => true; - public bool UpdateBefore => true; private void bmpViewPalette_MouseClick(object sender, MouseEventArgs e) diff --git a/src/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs b/src/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs index 778eec0422..0d61167506 100644 --- a/src/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs +++ b/src/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs @@ -41,7 +41,6 @@ namespace BizHawk.Client.EmuHawk readonly List displayTypeItems = new List(); public bool UpdateBefore => false; - public bool AskSaveChanges() => true; [RequiredService] private LibsnesCore Emulator { get; set; } diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IToolForm.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IToolForm.cs index 9a09ccb391..772a444ce4 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IToolForm.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IToolForm.cs @@ -96,7 +96,7 @@ namespace BizHawk.Client.EmuHawk } } - public bool AskSaveChanges() + public override bool AskSaveChanges() { if (_suppressAskSave) { diff --git a/src/BizHawk.Client.EmuHawk/tools/TI83/TI83KeyPad.cs b/src/BizHawk.Client.EmuHawk/tools/TI83/TI83KeyPad.cs index 10dd3f6117..62c2f72df8 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TI83/TI83KeyPad.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TI83/TI83KeyPad.cs @@ -35,7 +35,6 @@ namespace BizHawk.Client.EmuHawk #region Public API - public bool AskSaveChanges() => true; public bool UpdateBefore => false; public void NewUpdate(ToolFormUpdateType type) { } diff --git a/src/BizHawk.Client.EmuHawk/tools/ToolBox.cs b/src/BizHawk.Client.EmuHawk/tools/ToolBox.cs index f36589a927..1b120a724a 100644 --- a/src/BizHawk.Client.EmuHawk/tools/ToolBox.cs +++ b/src/BizHawk.Client.EmuHawk/tools/ToolBox.cs @@ -30,7 +30,6 @@ namespace BizHawk.Client.EmuHawk public void NewUpdate(ToolFormUpdateType type) { } - public bool AskSaveChanges() => true; public bool UpdateBefore => false; public void UpdateValues() { } diff --git a/src/BizHawk.Client.EmuHawk/tools/ToolFormBase.cs b/src/BizHawk.Client.EmuHawk/tools/ToolFormBase.cs index c3be8c6675..ae1033089e 100644 --- a/src/BizHawk.Client.EmuHawk/tools/ToolFormBase.cs +++ b/src/BizHawk.Client.EmuHawk/tools/ToolFormBase.cs @@ -16,6 +16,8 @@ namespace BizHawk.Client.EmuHawk public IMovieSession MovieSession { get; set; } + public virtual bool AskSaveChanges() => true; + public static FileInfo OpenFileDialog(string currentFile, string path, string fileType, string fileExt) { if (!Directory.Exists(path)) diff --git a/src/BizHawk.Client.EmuHawk/tools/TraceLogger.cs b/src/BizHawk.Client.EmuHawk/tools/TraceLogger.cs index 169880f25a..1e98f4d898 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TraceLogger.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TraceLogger.cs @@ -95,8 +95,6 @@ namespace BizHawk.Client.EmuHawk public bool UpdateBefore => false; - public bool AskSaveChanges() => true; - private void SaveConfigSettings() { //Tracer.Enabled = LoggingEnabled.Checked; diff --git a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualpadsTool.cs b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualpadsTool.cs index 9eb0f9ad75..26ac7b42b7 100644 --- a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualpadsTool.cs +++ b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualpadsTool.cs @@ -129,7 +129,6 @@ namespace BizHawk.Client.EmuHawk #region IToolForm Implementation - public bool AskSaveChanges() => true; public bool UpdateBefore => false; public void Restart() diff --git a/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs b/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs index 0a54ceee22..b6e1ee8076 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs @@ -71,8 +71,6 @@ namespace BizHawk.Client.EmuHawk [ConfigPersist] public RamSearchSettings Settings { get; set; } - public bool AskSaveChanges() => true; - public bool UpdateBefore => false; private void HardSetDisplayTypeDropDown(Common.DisplayType type) diff --git a/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs b/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs index 8775f00e14..c3b4e65847 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs @@ -112,7 +112,7 @@ namespace BizHawk.Client.EmuHawk Changes(); } - public bool AskSaveChanges() + public override bool AskSaveChanges() { if (_watches.Changes) {