From 3ff067d426c3fa26679c7d23855701aaa0f39f94 Mon Sep 17 00:00:00 2001 From: goyuken Date: Tue, 23 Dec 2014 01:01:37 +0000 Subject: [PATCH] IToolFormAutoConfig: add restore defaults --- .../config/ToolDialogSettings.cs | 12 +++++++ BizHawk.Client.EmuHawk/tools/ToolManager.cs | 31 +++++++++++++------ 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/BizHawk.Client.Common/config/ToolDialogSettings.cs b/BizHawk.Client.Common/config/ToolDialogSettings.cs index 5dabf9bdb1..8dd5ed3623 100644 --- a/BizHawk.Client.Common/config/ToolDialogSettings.cs +++ b/BizHawk.Client.Common/config/ToolDialogSettings.cs @@ -14,6 +14,18 @@ namespace BizHawk.Client.Common FloatingWindow = true; } + public void RestoreDefaults() + { + _wndx = null; + _wndy = null; + SaveWindowPosition = true; + FloatingWindow = true; + TopMost = false; + AutoLoad = false; + Width = null; + Height = null; + } + [JsonIgnore] public int? Wndx { diff --git a/BizHawk.Client.EmuHawk/tools/ToolManager.cs b/BizHawk.Client.EmuHawk/tools/ToolManager.cs index c0758e731e..3f5b52e6a4 100644 --- a/BizHawk.Client.EmuHawk/tools/ToolManager.cs +++ b/BizHawk.Client.EmuHawk/tools/ToolManager.cs @@ -110,10 +110,24 @@ namespace BizHawk.Client.EmuHawk } } + private static void RefreshSettings(Form form, ToolStripItemCollection menu, ToolDialogSettings settings, int idx) + { + (menu[idx + 0] as ToolStripMenuItem).Checked = settings.SaveWindowPosition; + (menu[idx + 1] as ToolStripMenuItem).Checked = settings.TopMost; + (menu[idx + 2] as ToolStripMenuItem).Checked = settings.FloatingWindow; + (menu[idx + 3] as ToolStripMenuItem).Checked = settings.AutoLoad; + + form.TopMost = settings.TopMost; + + // do we need to do this OnShown() as well? + form.Owner = settings.FloatingWindow ? null : GlobalWin.MainForm; + } + private static void AttachSettingHooks(IToolFormAutoConfig tool, ToolDialogSettings settings) { var form = (Form)tool; ToolStripItemCollection dest = null; + var oldsize = form.Size; // this should be the right time to grab this size foreach (Control c in form.Controls) { if (c is MenuStrip) @@ -146,17 +160,10 @@ namespace BizHawk.Client.EmuHawk dest.Add("Stay on &Top"); dest.Add("&Float from Parent"); dest.Add("&Autoload"); + dest.Add("Restore &Defaults"); - (dest[idx+0] as ToolStripMenuItem).Checked = settings.SaveWindowPosition; - (dest[idx + 1] as ToolStripMenuItem).Checked = settings.TopMost; - (dest[idx + 2] as ToolStripMenuItem).Checked = settings.FloatingWindow; - (dest[idx + 3] as ToolStripMenuItem).Checked = settings.AutoLoad; + RefreshSettings(form, dest, settings, idx); - form.TopMost = settings.TopMost; - - // do we need to do this OnShown() as well? - form.Owner = settings.FloatingWindow ? null : GlobalWin.MainForm; - if (settings.UseWindowPosition) { form.Location = settings.WindowPosition; @@ -201,6 +208,12 @@ namespace BizHawk.Client.EmuHawk settings.AutoLoad = val; (o as ToolStripMenuItem).Checked = val; }; + dest[idx + 4].Click += (o, e) => + { + settings.RestoreDefaults(); + RefreshSettings(form, dest, settings, idx); + form.Size = oldsize; + }; } private static bool HasCustomConfig(IToolForm tool)