Use `DialogResult.IsOk` extension everywhere and clean up

This commit is contained in:
YoshiRulz 2022-11-07 05:21:01 +10:00
parent 36cb62a792
commit 84cc71e454
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
26 changed files with 111 additions and 163 deletions

View File

@ -96,20 +96,15 @@ namespace BizHawk.Client.EmuHawk
}
dlg.checkBoxASync.Checked = audioSync;
var result = owner.ShowDialogAsChild(dlg);
IVideoWriter ret;
if (result == DialogResult.OK && dlg.listBox1.SelectedIndex != -1)
IVideoWriter ret = null;
if (owner.ShowDialogAsChild(dlg).IsOk()
&& dlg.listBox1.SelectedIndex is not -1)
{
var vwi = (VideoWriterInfo)dlg.listBox1.SelectedItem;
ret = vwi.Create(owner);
config.VideoWriter = vwi.Attribs.ShortName;
}
else
{
ret = null;
}
if (ret != null && dlg.checkBoxResize.Checked)
{

View File

@ -13,7 +13,13 @@ namespace BizHawk.Client.EmuHawk.ToolExtensions
{
public static class ToolExtensions
{
public static ToolStripItem[] RecentMenu(this RecentFiles recent, IMainFormForTools mainForm, Action<string> loadFileCallback, string entrySemantic, bool noAutoload = false, bool romLoading = false)
public static ToolStripItem[] RecentMenu(
this RecentFiles recent,
IDialogParent mainForm,
Action<string> loadFileCallback,
string entrySemantic,
bool noAutoload = false,
bool romLoading = false)
{
var items = new List<ToolStripItem>();
@ -204,13 +210,9 @@ namespace BizHawk.Client.EmuHawk.ToolExtensions
Message = "Number of recent files to track",
InitialValue = recent.MAX_RECENT_FILES.ToString()
};
var result = mainForm.DoWithTempMute(() => prompt.ShowDialog());
if (result == DialogResult.OK)
{
int val = int.Parse(prompt.PromptText);
if (val > 0)
recent.MAX_RECENT_FILES = val;
}
if (!mainForm.ShowDialogWithTempMute(prompt).IsOk()) return;
var val = int.Parse(prompt.PromptText);
if (val > 0) recent.MAX_RECENT_FILES = val;
};
items.Add(settingsItem);

View File

@ -454,18 +454,9 @@ namespace BizHawk.Client.EmuHawk
if (hf.IsArchive)
{
var ac = new ArchiveChooser(new HawkFile(filePath));
int memIdx;
if (!ac.ShowDialog(this).IsOk()) return;
if (ac.ShowDialog(this) == DialogResult.OK)
{
memIdx = ac.SelectedMemberIndex;
}
else
{
return;
}
var insideFile = hf.BindArchiveMember(memIdx);
var insideFile = hf.BindArchiveMember(ac.SelectedMemberIndex);
var fileData = insideFile.ReadAllBytes();
// write to file in the firmwares folder

View File

@ -129,11 +129,8 @@ namespace BizHawk.Client.EmuHawk
{
using var dlg = new CGBColorChooserForm();
dlg.LoadType(s);
var result = parent.ShowDialogAsChild(dlg);
if (result == DialogResult.OK)
{
s.CGBColors = dlg._type;
}
if (!parent.ShowDialogAsChild(dlg).IsOk()) return;
s.CGBColors = dlg._type;
}
}
}

View File

@ -147,15 +147,12 @@ namespace BizHawk.Client.EmuHawk
dlg.CustomColors = customs;
dlg.FullOpen = true;
var result = dlg.ShowDialog(this);
if (!this.ShowDialogAsChild(dlg).IsOk()) return;
if (result == DialogResult.OK)
if (_colors[i] != dlg.Color)
{
if (_colors[i] != dlg.Color)
{
_colors[i] = dlg.Color;
panel.BackColor = _colors[i];
}
_colors[i] = dlg.Color;
panel.BackColor = _colors[i];
}
}

View File

@ -62,15 +62,10 @@ namespace BizHawk.Client.EmuHawk
dlg.PutSettings(s, ss);
var result = dialogParent.ShowDialogAsChild(dlg);
if (result == DialogResult.OK)
{
dlg.GetSettings(out s, out ss);
settable.PutCoreSettings(s);
if (dlg.SyncSettingsChanged)
{
settable.PutCoreSyncSettings(ss);
}
}
if (!result.IsOk()) return result;
dlg.GetSettings(out s, out ss);
settable.PutCoreSettings(s);
if (dlg.SyncSettingsChanged) settable.PutCoreSyncSettings(ss);
return result;
}
}

View File

@ -110,15 +110,12 @@ namespace BizHawk.Client.EmuHawk
dlg.CustomColors = customs;
dlg.FullOpen = true;
var result = dlg.ShowDialog(this);
if (!this.ShowDialogAsChild(dlg).IsOk()) return;
if (result == DialogResult.OK)
if (_colors[i] != dlg.Color)
{
if (_colors[i] != dlg.Color)
{
_colors[i] = dlg.Color;
panel.BackColor = _colors[i];
}
_colors[i] = dlg.Color;
panel.BackColor = _colors[i];
}
}

View File

@ -164,7 +164,7 @@ namespace BizHawk.Client.EmuHawk
private void ChangeBG()
{
if (BGColorDialog.ShowDialog() == DialogResult.OK)
if (BGColorDialog.ShowDialog().IsOk())
{
SetColorBox();
}

View File

@ -44,33 +44,31 @@ namespace BizHawk.Client.EmuHawk
};
var result = dialogParent.ShowDialogAsChild(dlg);
if (result == DialogResult.OK)
{
s.AlwaysDoubleSize = dlg.AlwaysDoubleSize;
s.CropSGBFrame = dlg.CropSGBFrame;
ss.Entropy = dlg.Entropy;
ss.RegionOverride = dlg.RegionOverride;
ss.Hotfixes = dlg.Hotfixes;
ss.FastPPU = dlg.FastPPU;
ss.FastDSP = dlg.FastDSP;
ss.FastCoprocessors = dlg.FastCoprocessors;
ss.UseSGB2 = dlg.UseSGB2;
s.ShowOBJ_0 = dlg.ShowObj1;
s.ShowOBJ_1 = dlg.ShowObj2;
s.ShowOBJ_2 = dlg.ShowObj3;
s.ShowOBJ_3 = dlg.ShowObj4;
s.ShowBG1_0 = dlg.ShowBg1_0;
s.ShowBG1_1 = dlg.ShowBg1_1;
s.ShowBG2_0 = dlg.ShowBg2_0;
s.ShowBG2_1 = dlg.ShowBg2_1;
s.ShowBG3_0 = dlg.ShowBg3_0;
s.ShowBG3_1 = dlg.ShowBg3_1;
s.ShowBG4_0 = dlg.ShowBg4_0;
s.ShowBG4_1 = dlg.ShowBg4_1;
if (!result.IsOk()) return result;
settable.PutCoreSettings(s);
settable.PutCoreSyncSettings(ss);
}
s.AlwaysDoubleSize = dlg.AlwaysDoubleSize;
s.CropSGBFrame = dlg.CropSGBFrame;
ss.Entropy = dlg.Entropy;
ss.RegionOverride = dlg.RegionOverride;
ss.Hotfixes = dlg.Hotfixes;
ss.FastPPU = dlg.FastPPU;
ss.FastDSP = dlg.FastDSP;
ss.FastCoprocessors = dlg.FastCoprocessors;
ss.UseSGB2 = dlg.UseSGB2;
s.ShowOBJ_0 = dlg.ShowObj1;
s.ShowOBJ_1 = dlg.ShowObj2;
s.ShowOBJ_2 = dlg.ShowObj3;
s.ShowOBJ_3 = dlg.ShowObj4;
s.ShowBG1_0 = dlg.ShowBg1_0;
s.ShowBG1_1 = dlg.ShowBg1_1;
s.ShowBG2_0 = dlg.ShowBg2_0;
s.ShowBG2_1 = dlg.ShowBg2_1;
s.ShowBG3_0 = dlg.ShowBg3_0;
s.ShowBG3_1 = dlg.ShowBg3_1;
s.ShowBG4_0 = dlg.ShowBg4_0;
s.ShowBG4_1 = dlg.ShowBg4_1;
settable.PutCoreSettings(s);
settable.PutCoreSyncSettings(ss);
return result;
}

View File

@ -37,23 +37,21 @@ namespace BizHawk.Client.EmuHawk
};
var result = dialogParent.ShowDialogAsChild(dlg);
if (result == DialogResult.OK)
{
s.AlwaysDoubleSize = dlg.AlwaysDoubleSize;
s.CropSGBFrame = dlg.CropSGBFrame;
ss.RandomizedInitialState = dlg.RandomizedInitialState;
s.ShowOBJ_0 = dlg.ShowObj1;
s.ShowOBJ_1 = dlg.ShowObj2;
s.ShowOBJ_2 = dlg.ShowObj3;
s.ShowOBJ_3 = dlg.ShowObj4;
s.ShowBG1_0 = s.ShowBG1_1 = dlg.ShowBg1;
s.ShowBG2_0 = s.ShowBG2_1 = dlg.ShowBg2;
s.ShowBG3_0 = s.ShowBG3_1 = dlg.ShowBg3;
s.ShowBG4_0 = s.ShowBG4_1 = dlg.ShowBg4;
if (!result.IsOk()) return result;
settable.PutCoreSettings(s);
settable.PutCoreSyncSettings(ss);
}
s.AlwaysDoubleSize = dlg.AlwaysDoubleSize;
s.CropSGBFrame = dlg.CropSGBFrame;
ss.RandomizedInitialState = dlg.RandomizedInitialState;
s.ShowOBJ_0 = dlg.ShowObj1;
s.ShowOBJ_1 = dlg.ShowObj2;
s.ShowOBJ_2 = dlg.ShowObj3;
s.ShowOBJ_3 = dlg.ShowObj4;
s.ShowBG1_0 = s.ShowBG1_1 = dlg.ShowBg1;
s.ShowBG2_0 = s.ShowBG2_1 = dlg.ShowBg2;
s.ShowBG3_0 = s.ShowBG3_1 = dlg.ShowBg3;
s.ShowBG4_0 = s.ShowBG4_1 = dlg.ShowBg4;
settable.PutCoreSettings(s);
settable.PutCoreSyncSettings(ss);
return result;
}

View File

@ -60,7 +60,7 @@ namespace BizHawk.Client.EmuHawk
CustomColors = new[] { customColor }
};
if (dlg.ShowDialog() == DialogResult.OK)
if (dlg.ShowDialog().IsOk())
{
BackgroundPanel.BackColor = dlg.Color;
}
@ -81,7 +81,7 @@ namespace BizHawk.Client.EmuHawk
CustomColors = new[] { customColor }
};
if (dlg.ShowDialog() == DialogResult.OK)
if (dlg.ShowDialog().IsOk())
{
ForeGroundPanel.BackColor = dlg.Color;
}

View File

@ -147,14 +147,10 @@ namespace BizHawk.Client.EmuHawk
cd.Color = c;
if (cd.ShowDialog() == DialogResult.OK)
{
var color = cd.Color;
var col = color.ToArgb();
_bgColor = col;
if (!cd.ShowDialog().IsOk()) return;
SetBtnColor();
}
_bgColor = cd.Color.ToArgb();
SetBtnColor();
}
}
}

View File

@ -196,7 +196,7 @@ namespace BizHawk.Client.EmuHawk
}
using var s = new SubtitleMaker { Sub = GetRow(c[0].Index) };
if (s.ShowDialog() == DialogResult.OK)
if (s.ShowDialog().IsOk())
{
ChangeRow(s.Sub, SubGrid.SelectedRows[0].Index);
}

View File

@ -52,7 +52,7 @@ namespace BizHawk.Client.EmuHawk
private void ColorPanel_DoubleClick(object sender, EventArgs e)
{
if (colorDialog1.ShowDialog() == DialogResult.OK)
if (colorDialog1.ShowDialog().IsOk())
{
ColorPanel.BackColor = colorDialog1.Color;
}

View File

@ -307,7 +307,7 @@ namespace BizHawk.Client.EmuHawk
}
private void RecentSubMenu_DropDownOpened(object sender, EventArgs e)
=> RecentSubMenu.ReplaceDropDownItems(Settings.RecentBotFiles.RecentMenu(MainForm, LoadFileFromRecent, "Bot Parameters"));
=> RecentSubMenu.ReplaceDropDownItems(Settings.RecentBotFiles.RecentMenu(this, LoadFileFromRecent, "Bot Parameters"));
private void NewMenuItem_Click(object sender, EventArgs e)
{

View File

@ -288,7 +288,7 @@ namespace BizHawk.Client.EmuHawk
}
private void RecentSubMenu_DropDownOpened(object sender, EventArgs e)
=> RecentSubMenu.ReplaceDropDownItems(_recent.RecentMenu(MainForm, LoadFile, "Session"));
=> RecentSubMenu.ReplaceDropDownItems(_recent.RecentMenu(this, LoadFile, "Session"));
private void NewFileLogic()
{

View File

@ -344,7 +344,7 @@ namespace BizHawk.Client.EmuHawk
}
private void RecentSubMenu_DropDownOpened(object sender, EventArgs e)
=> RecentSubMenu.ReplaceDropDownItems(Config!.Cheats.Recent.RecentMenu(MainForm, LoadFileFromRecent, "Cheats"));
=> RecentSubMenu.ReplaceDropDownItems(Config!.Cheats.Recent.RecentMenu(this, LoadFileFromRecent, "Cheats"));
private void NewMenuItem_Click(object sender, EventArgs e)
{

View File

@ -263,7 +263,7 @@ namespace BizHawk.Client.EmuHawk
{
var b = CreateAddBreakpointDialog(BreakpointOperation.Duplicate, breakpoint.Type, breakpoint.Address, breakpoint.AddressMask);
if (this.ShowDialogWithTempMute(b) == DialogResult.OK)
if (this.ShowDialogWithTempMute(b).IsOk())
{
_breakpoints.Add(new Breakpoint(Core, MemoryDomains.SystemBus.Name, breakpoint.Callback, b.Address, b.AddressMask, b.BreakType, breakpoint.Active));
}
@ -282,7 +282,7 @@ namespace BizHawk.Client.EmuHawk
{
var b = CreateAddBreakpointDialog(BreakpointOperation.Edit, breakpoint.Type, breakpoint.Address, breakpoint.AddressMask);
if (this.ShowDialogWithTempMute(b) == DialogResult.OK)
if (this.ShowDialogWithTempMute(b).IsOk())
{
breakpoint.Type = b.BreakType;
breakpoint.Address = b.Address;

View File

@ -1332,7 +1332,7 @@ namespace BizHawk.Client.EmuHawk
}
private void RecentTablesSubMenu_DropDownOpened(object sender, EventArgs e)
=> RecentTablesSubMenu.ReplaceDropDownItems(RecentTables.RecentMenu(MainForm, LoadFileFromRecent, "Session"));
=> RecentTablesSubMenu.ReplaceDropDownItems(RecentTables.RecentMenu(this, LoadFileFromRecent, "Session"));
private void EditMenuItem_DropDownOpened(object sender, EventArgs e)
{
@ -1562,9 +1562,7 @@ namespace BizHawk.Client.EmuHawk
Message = "Enter a hexadecimal value"
};
var result = this.ShowDialogWithTempMute(inputPrompt);
if (result == DialogResult.OK && inputPrompt.PromptText.IsHex())
if (this.ShowDialogWithTempMute(inputPrompt).IsOk() && inputPrompt.PromptText.IsHex())
{
GoToAddress(long.Parse(inputPrompt.PromptText, NumberStyles.HexNumber));
}

View File

@ -761,10 +761,10 @@ namespace BizHawk.Client.EmuHawk
}
private void RecentSessionsSubMenu_DropDownOpened(object sender, EventArgs e)
=> RecentSessionsSubMenu.ReplaceDropDownItems(Config!.RecentLuaSession.RecentMenu(MainForm, LoadSessionFromRecent, "Session"));
=> RecentSessionsSubMenu.ReplaceDropDownItems(Config!.RecentLuaSession.RecentMenu(this, LoadSessionFromRecent, "Session"));
private void RecentScriptsSubMenu_DropDownOpened(object sender, EventArgs e)
=> RecentScriptsSubMenu.ReplaceDropDownItems(Config!.RecentLua.RecentMenu(MainForm, LoadLuaFile, "Script"));
=> RecentScriptsSubMenu.ReplaceDropDownItems(Config!.RecentLua.RecentMenu(this, LoadLuaFile, "Script"));
private void NewSessionMenuItem_Click(object sender, EventArgs e)
{

View File

@ -243,7 +243,7 @@ namespace BizHawk.Client.EmuHawk
}
private void RecentToolStripMenuItem_DropDownOpened(object sender, EventArgs e)
=> RecentToolStripMenuItem.ReplaceDropDownItems(Config!.RecentMacros.RecentMenu(MainForm, DummyLoadMacro, "Macro"));
=> RecentToolStripMenuItem.ReplaceDropDownItems(Config!.RecentMacros.RecentMenu(this, DummyLoadMacro, "Macro"));
private void DummyLoadMacro(string path)
{

View File

@ -254,12 +254,11 @@ namespace BizHawk.Client.EmuHawk
i.Location = point;
}
if (this.ShowDialogWithTempMute(i) == DialogResult.OK)
{
marker.Message = i.PromptText;
UpdateTextColumnWidth();
UpdateValues();
}
if (!this.ShowDialogWithTempMute(i).IsOk()) return;
marker.Message = i.PromptText;
UpdateTextColumnWidth();
UpdateValues();
}
public void EditMarkerFramePopUp(TasMovieMarker marker)

View File

@ -67,7 +67,7 @@ namespace BizHawk.Client.EmuHawk
}
private void RecentSubMenu_DropDownOpened(object sender, EventArgs e)
=> RecentSubMenu.ReplaceDropDownItems(Settings.RecentTas.RecentMenu(MainForm, DummyLoadProject, "Project"));
=> RecentSubMenu.ReplaceDropDownItems(Settings.RecentTas.RecentMenu(this, DummyLoadProject, "Project"));
private void NewTasMenuItem_Click(object sender, EventArgs e)
{
@ -248,7 +248,7 @@ namespace BizHawk.Client.EmuHawk
}
private void RecentMacrosMenuItem_DropDownOpened(object sender, EventArgs e)
=> recentMacrosToolStripMenuItem.ReplaceDropDownItems(Config!.RecentMacros.RecentMenu(MainForm, DummyLoadMacro, "Macro", noAutoload: true));
=> recentMacrosToolStripMenuItem.ReplaceDropDownItems(Config!.RecentMacros.RecentMenu(this, DummyLoadMacro, "Macro", noAutoload: true));
private void ToBk2MenuItem_Click(object sender, EventArgs e)
{
@ -1185,12 +1185,9 @@ namespace BizHawk.Client.EmuHawk
Message = "Frames per tick:",
InitialValue = TasView.ScrollSpeed.ToString()
};
var result = MainForm.DoWithTempMute(() => inputPrompt.ShowDialog());
if (result == DialogResult.OK)
{
TasView.ScrollSpeed = int.Parse(inputPrompt.PromptText);
Settings.ScrollSpeed = TasView.ScrollSpeed;
}
if (!this.ShowDialogWithTempMute(inputPrompt).IsOk()) return;
TasView.ScrollSpeed = int.Parse(inputPrompt.PromptText);
Settings.ScrollSpeed = TasView.ScrollSpeed;
}
private void SetUpToolStripColumns()

View File

@ -350,15 +350,9 @@ namespace BizHawk.Client.EmuHawk
Message = "Max lines to display in the window",
InitialValue = MaxLines.ToString()
};
if (this.ShowDialogWithTempMute(prompt) == DialogResult.OK)
{
var max = int.Parse(prompt.PromptText);
if (max > 0)
{
MaxLines = max;
}
}
if (!this.ShowDialogWithTempMute(prompt).IsOk()) return;
var max = int.Parse(prompt.PromptText);
if (max > 0) MaxLines = max;
}
private void SegmentSizeMenuItem_Click(object sender, EventArgs e)
@ -370,12 +364,9 @@ namespace BizHawk.Client.EmuHawk
Message = "Log file segment size in megabytes\nSetting 0 disables segmentation",
InitialValue = FileSizeCap.ToString()
};
if (this.ShowDialogWithTempMute(prompt) == DialogResult.OK)
{
FileSizeCap = int.Parse(prompt.PromptText);
_splitFile = FileSizeCap != 0;
}
if (!this.ShowDialogWithTempMute(prompt).IsOk()) return;
FileSizeCap = int.Parse(prompt.PromptText);
_splitFile = FileSizeCap != 0;
}
private void LoggingEnabled_CheckedChanged(object sender, EventArgs e)

View File

@ -971,7 +971,7 @@ namespace BizHawk.Client.EmuHawk
}
private void RecentSubMenu_DropDownOpened(object sender, EventArgs e)
=> RecentSubMenu.ReplaceDropDownItems(Settings.RecentSearches.RecentMenu(MainForm, LoadFileFromRecent, "Search", noAutoload: true));
=> RecentSubMenu.ReplaceDropDownItems(Settings.RecentSearches.RecentMenu(this, LoadFileFromRecent, "Search", noAutoload: true));
private void OpenMenuItem_Click(object sender, EventArgs e)
{

View File

@ -404,7 +404,7 @@ namespace BizHawk.Client.EmuHawk
we.SetWatch(SelectedWatches.First().Domain, SelectedWatches, duplicate ? WatchEditor.Mode.Duplicate : WatchEditor.Mode.Edit);
if (this.ShowDialogWithTempMute(we) == DialogResult.OK)
if (this.ShowDialogWithTempMute(we).IsOk())
{
if (duplicate)
{
@ -434,7 +434,7 @@ namespace BizHawk.Client.EmuHawk
TextInputType = InputPrompt.InputType.Text
};
if (this.ShowDialogWithTempMute(inputPrompt) == DialogResult.OK)
if (this.ShowDialogWithTempMute(inputPrompt).IsOk())
{
Changes();
@ -692,7 +692,7 @@ namespace BizHawk.Client.EmuHawk
}
private void RecentSubMenu_DropDownOpened(object sender, EventArgs e)
=> RecentSubMenu.ReplaceDropDownItems(Config!.RecentWatches.RecentMenu(MainForm, LoadFileFromRecent, "Watches"));
=> RecentSubMenu.ReplaceDropDownItems(Config!.RecentWatches.RecentMenu(this, LoadFileFromRecent, "Watches"));
private void WatchesSubMenu_DropDownOpened(object sender, EventArgs e)
{
@ -732,15 +732,12 @@ namespace BizHawk.Client.EmuHawk
MemoryDomains = MemoryDomains
};
we.SetWatch(CurrentDomain);
this.ShowDialogWithTempMute(we);
if (we.DialogResult == DialogResult.OK)
{
_watches.Add(we.Watches[0]);
Changes();
UpdateWatchCount();
WatchListView.RowCount = _watches.Count;
GeneralUpdate();
}
if (!this.ShowDialogWithTempMute(we).IsOk()) return;
_watches.Add(we.Watches[0]);
Changes();
UpdateWatchCount();
WatchListView.RowCount = _watches.Count;
GeneralUpdate();
}
private void EditWatchMenuItem_Click(object sender, EventArgs e)