IToolFormAutoConfig: add restore defaults

This commit is contained in:
goyuken 2014-12-23 01:01:37 +00:00
parent 2a771791d0
commit 3ff067d426
2 changed files with 34 additions and 9 deletions

View File

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

View File

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