Add and use more extensions for IDialogParent

This commit is contained in:
YoshiRulz 2020-12-01 05:50:05 +10:00 committed by James Groom
parent b752b09d62
commit 46504b4880
20 changed files with 65 additions and 120 deletions

View File

@ -113,7 +113,7 @@ namespace BizHawk.Client.EmuHawk
public static void Run(IDialogParent parent)
{
var form = new FFmpegDownloaderForm();
parent.DialogController.DoWithTempMute(() => form.ShowDialog(parent.SelfAsHandle));
parent.ShowDialogWithTempMute(form);
}
private void btnDownload_Click(object sender, EventArgs e)

View File

@ -160,8 +160,17 @@ namespace BizHawk.Client.EmuHawk
return ret;
}
public static DialogResult ShowDialogAsChild(this IDialogParent dialogParent, CommonDialog dialog)
=> dialog.ShowDialog(dialogParent.SelfAsHandle);
public static DialogResult ShowDialogAsChild(this IDialogParent dialogParent, Form dialog)
=> dialog.ShowDialog(dialogParent.SelfAsHandle);
public static DialogResult ShowDialogWithTempMute(this IDialogParent dialogParent, CommonDialog dialog)
=> dialogParent.DialogController.DoWithTempMute(() => dialog.ShowDialog(dialogParent.SelfAsHandle));
public static DialogResult ShowDialogWithTempMute(this IDialogParent dialogParent, Form dialog)
=> dialogParent.DialogController.DoWithTempMute(() => dialog.ShowDialog(dialogParent.SelfAsHandle));
}
public static class ListViewExtensions
@ -272,11 +281,7 @@ namespace BizHawk.Client.EmuHawk
RestoreDirectory = true
};
var result = parent.DialogController.DoWithTempMute(() => sfd.ShowDialog(parent.SelfAsHandle));
if (result != DialogResult.OK)
{
return;
}
if (parent.ShowDialogWithTempMute(sfd) != DialogResult.OK) return;
var file = new FileInfo(sfd.FileName);
string extension = file.Extension.ToUpper();

View File

@ -246,10 +246,7 @@ namespace BizHawk.Client.EmuHawk
private void OpenAdvancedMenuItem_Click(object sender, EventArgs e)
{
using var oac = new OpenAdvancedChooser(Config, CreateCoreComm, Game, RunLibretroCoreChooser);
if (this.DoWithTempMute(() => oac.ShowDialog(this)) == DialogResult.Cancel)
{
return;
}
if (this.ShowDialogWithTempMute(oac) == DialogResult.Cancel) return;
if (oac.Result == AdvancedRomLoaderType.LibretroLaunchNoGame)
{
@ -295,11 +292,7 @@ namespace BizHawk.Client.EmuHawk
Title = "Open Advanced"
};
var result = this.DoWithTempMute(() => ofd.ShowDialog(this));
if (!result.IsOk())
{
return;
}
if (!this.ShowDialogWithTempMute(ofd).IsOk()) return;
var file = new FileInfo(ofd.FileName);
Config.PathEntries.LastRomPath = file.DirectoryName;
@ -444,7 +437,7 @@ namespace BizHawk.Client.EmuHawk
RestoreDirectory = false
};
if (this.DoWithTempMute(() => ofd.ShowDialog(this)).IsOk())
if (this.ShowDialogWithTempMute(ofd).IsOk())
{
foreach (var fn in ofd.FileNames)
{
@ -563,7 +556,7 @@ namespace BizHawk.Client.EmuHawk
Filter = FilesystemFilter.PNGs.ToString()
};
if (this.DoWithTempMute(() => sfd.ShowDialog(this)).IsOk())
if (this.ShowDialogWithTempMute(sfd).IsOk())
{
TakeScreenshot(sfd.FileName);
}
@ -1129,7 +1122,7 @@ namespace BizHawk.Client.EmuHawk
Filter = ConfigFileFSFilterString
};
if (this.DoWithTempMute(() => sfd.ShowDialog(this)).IsOk())
if (this.ShowDialogWithTempMute(sfd).IsOk())
{
SaveConfig(sfd.FileName);
AddOnScreenMessage("Copied settings");
@ -1151,7 +1144,7 @@ namespace BizHawk.Client.EmuHawk
Filter = ConfigFileFSFilterString
};
if (this.DoWithTempMute(() => ofd.ShowDialog(this)).IsOk())
if (this.ShowDialogWithTempMute(ofd).IsOk())
{
LoadConfigFile(ofd.FileName);
}
@ -1384,12 +1377,12 @@ namespace BizHawk.Client.EmuHawk
if (Emulator is NES nes && nes.IsVS)
{
using var form = new NesVsSettings(this, nes.GetSyncSettings().Clone());
this.DoWithTempMute(() => form.ShowDialog(this));
this.ShowDialogWithTempMute(form);
}
else if (Emulator is SubNESHawk sub && sub.IsVs)
{
using var form = new NesVsSettings(this, sub.GetSyncSettings().Clone());
this.DoWithTempMute(() => form.ShowDialog(this));
this.ShowDialogWithTempMute(form);
}
}

View File

@ -2258,11 +2258,7 @@ namespace BizHawk.Client.EmuHawk
FilterIndex = _lastOpenRomFilter
};
var result = this.DoWithTempMute(() => ofd.ShowDialog(this));
if (result != DialogResult.OK)
{
return;
}
if (this.ShowDialogWithTempMute(ofd) != DialogResult.OK) return;
var file = new FileInfo(ofd.FileName);
_lastOpenRomFilter = ofd.FilterIndex;
@ -3270,8 +3266,7 @@ namespace BizHawk.Client.EmuHawk
sfd.Filter = new FilesystemFilterSet(new FilesystemFilter(ext, new[] { ext })).ToString();
var result = this.DoWithTempMute(() => sfd.ShowDialog(this));
if (result == DialogResult.Cancel)
if (this.ShowDialogWithTempMute(sfd) == DialogResult.Cancel)
{
aw.Dispose();
return;
@ -4257,8 +4252,7 @@ namespace BizHawk.Client.EmuHawk
FileName = $"{SaveStatePrefix()}.QuickSave0.State"
};
var result = this.DoWithTempMute(() => sfd.ShowDialog(this));
if (result == DialogResult.OK)
if (this.ShowDialogWithTempMute(sfd) == DialogResult.OK)
{
SaveState(sfd.FileName, sfd.FileName);
}
@ -4289,11 +4283,7 @@ namespace BizHawk.Client.EmuHawk
RestoreDirectory = true
};
var result = this.DoWithTempMute(() => ofd.ShowDialog(this));
if (result != DialogResult.OK)
{
return;
}
if (this.ShowDialogWithTempMute(ofd) != DialogResult.OK) return;
if (!File.Exists(ofd.FileName))
{

View File

@ -517,7 +517,7 @@ namespace BizHawk.Client.EmuHawk
InitialDirectory = _config.PathEntries.MovieAbsolutePath()
};
var result = _mainForm.DoWithTempMute(() => ofd.ShowDialog(this));
var result = this.ShowDialogWithTempMute(ofd);
if (result == DialogResult.OK)
{
var file = new FileInfo(ofd.FileName);

View File

@ -198,7 +198,7 @@ namespace BizHawk.Client.EmuHawk
Filter = new FilesystemFilterSet(new FilesystemFilter("Movie Files", new[] { preferredExt })).ToString()
};
var result = _mainForm.DoWithTempMute(() => sfd.ShowDialog(this));
var result = this.ShowDialogWithTempMute(sfd);
if (result == DialogResult.OK
&& !string.IsNullOrWhiteSpace(sfd.FileName))
{

View File

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

View File

@ -1022,8 +1022,7 @@ namespace BizHawk.Client.EmuHawk
Color = Spriteback
};
var result = MainForm.DoWithTempMute(() => dlg.ShowDialog(this));
if (result.IsOk())
if (this.ShowDialogWithTempMute(dlg).IsOk())
{
Spriteback = dlg.Color;
}

View File

@ -946,7 +946,7 @@ namespace BizHawk.Client.EmuHawk
: Game.FilesystemSafeName()
};
var result = MainForm.DoWithTempMute(() => sfd.ShowDialog(this));
var result = this.ShowDialogWithTempMute(sfd);
return result == DialogResult.OK ? sfd.FileName : "";
}
@ -962,7 +962,7 @@ namespace BizHawk.Client.EmuHawk
RestoreDirectory = true
};
var result = MainForm.DoWithTempMute(() => sfd.ShowDialog(this));
var result = this.ShowDialogWithTempMute(sfd);
return result == DialogResult.OK ? sfd.FileName : "";
}
@ -1284,12 +1284,8 @@ namespace BizHawk.Client.EmuHawk
RestoreDirectory = true
};
var result = MainForm.DoWithTempMute(() => sfd.ShowDialog(this));
if (result != DialogResult.OK)
{
return;
}
if (this.ShowDialogWithTempMute(sfd) != DialogResult.OK) return;
var path = sfd.FileName;
using var inf = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read);
@ -1338,9 +1334,7 @@ namespace BizHawk.Client.EmuHawk
RestoreDirectory = false
};
var result = MainForm.DoWithTempMute(() => ofd.ShowDialog(this));
if (result == DialogResult.OK)
if (this.ShowDialogWithTempMute(ofd) == DialogResult.OK)
{
LoadTable(ofd.FileName);
RecentTables.Add(ofd.FileName);
@ -1605,7 +1599,7 @@ namespace BizHawk.Client.EmuHawk
Message = "Enter a hexadecimal value"
};
var result = MainForm.DoWithTempMute(() => inputPrompt.ShowDialog(this));
var result = this.ShowDialogWithTempMute(inputPrompt);
if (result == DialogResult.OK && inputPrompt.PromptText.IsHex())
{
@ -1694,7 +1688,7 @@ namespace BizHawk.Client.EmuHawk
ParentTool = this
};
MainForm.DoWithTempMute(() => poke.ShowDialog(this));
this.ShowDialogWithTempMute(poke);
GeneralUpdate();
}
}
@ -1702,7 +1696,7 @@ namespace BizHawk.Client.EmuHawk
private void SetColorsMenuItem_Click(object sender, EventArgs e)
{
using var form = new HexColorsForm(this);
MainForm.DoWithTempMute(() => form.ShowDialog(this));
this.ShowDialogWithTempMute(form);
}
private void ResetColorsToDefaultMenuItem_Click(object sender, EventArgs e)

View File

@ -696,7 +696,7 @@ namespace BizHawk.Client.EmuHawk
sfd.Filter = SessionsFSFilterSet.ToString();
sfd.RestoreDirectory = true;
var result = MainForm.DoWithTempMute(() => sfd.ShowDialog(this));
var result = this.ShowDialogWithTempMute(sfd);
return result.IsOk() ? new FileInfo(sfd.FileName) : null;
}
@ -826,7 +826,7 @@ namespace BizHawk.Client.EmuHawk
Directory.CreateDirectory(ofd.InitialDirectory);
}
var result = MainForm.DoWithTempMute(() => ofd.ShowDialog(this));
var result = this.ShowDialogWithTempMute(ofd);
if (result.IsOk() && !string.IsNullOrWhiteSpace(ofd.FileName))
{
LoadLuaSession(ofd.FileName);
@ -880,7 +880,7 @@ namespace BizHawk.Client.EmuHawk
Filter = new FilesystemFilterSet(FilesystemFilter.LuaScripts).ToString()
};
var result = MainForm.DoWithTempMute(() => sfd.ShowDialog(this));
var result = this.ShowDialogWithTempMute(sfd);
if (result.IsOk() && !string.IsNullOrWhiteSpace(sfd.FileName))
{
string defaultTemplate = "while true do\n\temu.frameadvance();\nend";
@ -912,7 +912,7 @@ namespace BizHawk.Client.EmuHawk
Directory.CreateDirectory(ofd.InitialDirectory);
}
var result = MainForm.DoWithTempMute(() => ofd.ShowDialog(this));
var result = this.ShowDialogWithTempMute(ofd);
if (result.IsOk() && ofd.FileNames != null)
{
foreach (var file in ofd.FileNames)

View File

@ -279,8 +279,7 @@ namespace BizHawk.Client.EmuHawk
create = true;
}
DialogResult result = MainForm.DoWithTempMute(() => dialog.ShowDialog(this));
if (result != DialogResult.OK)
if (this.ShowDialogWithTempMute(dialog) != DialogResult.OK)
{
if (create)
{
@ -303,12 +302,8 @@ namespace BizHawk.Client.EmuHawk
InitialDirectory = SuggestedFolder(),
Filter = MacrosFSFilterSet.ToString()
};
DialogResult result = MainForm.DoWithTempMute(() => dialog.ShowDialog(this));
if (result != DialogResult.OK)
{
return null;
}
if (this.ShowDialogWithTempMute(dialog) != DialogResult.OK) return null;
Config.RecentMacros.Add(dialog.FileName);
return new MovieZone(dialog.FileName, emulator ?? Emulator, MovieSession, tools ?? Tools);

View File

@ -262,8 +262,7 @@ namespace BizHawk.Client.EmuHawk
Filter = new FilesystemFilterSet(new FilesystemFilter("XML Files", new[] { "xml" })).ToString()
};
var result = MainForm.DoWithTempMute(() => sfd.ShowDialog(this));
if (result != DialogResult.Cancel)
if (this.ShowDialogWithTempMute(sfd) != DialogResult.Cancel)
{
NameBox.Text = sfd.FileName;
}

View File

@ -79,17 +79,10 @@ namespace BizHawk.Client.EmuHawk
Filter = RomLoader.RomFilter,
RestoreDirectory = true
};
string hawkPath = "";
var result = DialogController.DoWithTempMute(() => ofd.ShowDialog(this));
if (result == DialogResult.OK)
{
hawkPath = ofd.FileName;
}
else
{
return;
}
if (this.ShowDialogWithTempMute(ofd) != DialogResult.OK) return;
var hawkPath = ofd.FileName;
try
{

View File

@ -583,8 +583,7 @@ namespace BizHawk.Client.EmuHawk
i.StartPosition = FormStartPosition.Manual;
i.Location = point;
var result = MainForm.DoWithTempMute(() => i.ShowDialog(this));
if (result.IsOk())
if (this.ShowDialogWithTempMute(i).IsOk())
{
branch.UserText = i.PromptText;
UpdateTextColumnWidth();

View File

@ -202,11 +202,7 @@ namespace BizHawk.Client.EmuHawk
i.StartPosition = FormStartPosition.Manual;
i.Location = point;
var result = Tastudio.MainForm.DoWithTempMute(() => i.ShowDialog(this));
if (!result.IsOk())
{
return;
}
if (!this.ShowDialogWithTempMute(i).IsOk()) return;
UpdateTextColumnWidth();
marker = new TasMovieMarker(frame, i.PromptText);
@ -258,9 +254,7 @@ namespace BizHawk.Client.EmuHawk
i.Location = point;
}
var result = Tastudio.MainForm.DoWithTempMute(() => i.ShowDialog(this));
if (result == DialogResult.OK)
if (this.ShowDialogWithTempMute(i) == DialogResult.OK)
{
marker.Message = i.PromptText;
UpdateTextColumnWidth();

View File

@ -108,8 +108,7 @@ namespace BizHawk.Client.EmuHawk
).ToString()
};
var result = MainForm.DoWithTempMute(() => ofd.ShowDialog(this));
if (result.IsOk())
if (this.ShowDialogWithTempMute(ofd).IsOk())
{
LoadMovieFile(ofd.FileName, false);
}

View File

@ -75,13 +75,8 @@ namespace BizHawk.Client.EmuHawk
RestoreDirectory = true
};
var result = MainForm.DoWithTempMute(() => ofd.ShowDialog(this));
if (result != DialogResult.OK)
{
return null;
}
return new FileInfo(ofd.FileName);
var result = this.ShowDialogWithTempMute(ofd);
return result.IsOk() ? new FileInfo(ofd.FileName) : null;
}
public static FileInfo SaveFileDialog(string currentFile, string path, string fileType, string fileExt, IDialogParent parent)
@ -99,13 +94,8 @@ namespace BizHawk.Client.EmuHawk
RestoreDirectory = true
};
var result = parent.DialogController.DoWithTempMute(() => sfd.ShowDialog(parent.SelfAsHandle));
if (result != DialogResult.OK)
{
return null;
}
return new FileInfo(sfd.FileName);
var result = parent.ShowDialogWithTempMute(sfd);
return result.IsOk() ? new FileInfo(sfd.FileName) : null;
}
public FileInfo GetWatchFileFromUser(string currentFile)

View File

@ -302,7 +302,7 @@ namespace BizHawk.Client.EmuHawk
FilesystemFilter.TextFiles
).ToString();
sfd.RestoreDirectory = true;
var result = MainForm.DoWithTempMute(() => sfd.ShowDialog(this));
var result = this.ShowDialogWithTempMute(sfd);
return result.IsOk() ? new FileInfo(sfd.FileName) : null;
}
@ -351,8 +351,7 @@ namespace BizHawk.Client.EmuHawk
InitialValue = MaxLines.ToString()
};
var result = MainForm.DoWithTempMute(() => prompt.ShowDialog(this));
if (result == DialogResult.OK)
if (this.ShowDialogWithTempMute(prompt) == DialogResult.OK)
{
var max = int.Parse(prompt.PromptText);
if (max > 0)
@ -372,8 +371,7 @@ namespace BizHawk.Client.EmuHawk
InitialValue = FileSizeCap.ToString()
};
var result = MainForm.DoWithTempMute(() => prompt.ShowDialog(this));
if (result == DialogResult.OK)
if (this.ShowDialogWithTempMute(prompt) == DialogResult.OK)
{
FileSizeCap = int.Parse(prompt.PromptText);
_splitFile = FileSizeCap != 0;

View File

@ -868,7 +868,7 @@ namespace BizHawk.Client.EmuHawk
InitialLocation = this.ChildPointToScreen(WatchListView)
};
MainForm.DoWithTempMute(() => poke.ShowDialog(this));
this.ShowDialogWithTempMute(poke);
UpdateList();
}
}
@ -898,7 +898,7 @@ namespace BizHawk.Client.EmuHawk
Message = "Enter a hexadecimal value"
};
var result = MainForm.DoWithTempMute(() => prompt.ShowDialog(this));
var result = this.ShowDialogWithTempMute(prompt);
while (result.IsOk())
{
try

View File

@ -395,8 +395,7 @@ namespace BizHawk.Client.EmuHawk
we.SetWatch(SelectedWatches.First().Domain, SelectedWatches, duplicate ? WatchEditor.Mode.Duplicate : WatchEditor.Mode.Edit);
var result = MainForm.DoWithTempMute(() => we.ShowDialog(this));
if (result == DialogResult.OK)
if (this.ShowDialogWithTempMute(we) == DialogResult.OK)
{
if (duplicate)
{
@ -426,9 +425,7 @@ namespace BizHawk.Client.EmuHawk
TextInputType = InputPrompt.InputType.Text
};
var result = MainForm.DoWithTempMute(() => inputPrompt.ShowDialog(this));
if (result == DialogResult.OK)
if (this.ShowDialogWithTempMute(inputPrompt) == DialogResult.OK)
{
Changes();
@ -732,7 +729,7 @@ namespace BizHawk.Client.EmuHawk
MemoryDomains = MemoryDomains
};
we.SetWatch(CurrentDomain);
MainForm.DoWithTempMute(() => we.ShowDialog(this));
this.ShowDialogWithTempMute(we);
if (we.DialogResult == DialogResult.OK)
{
_watches.Add(we.Watches[0]);
@ -779,7 +776,7 @@ namespace BizHawk.Client.EmuHawk
InitialLocation = this.ChildPointToScreen(WatchListView)
};
if (MainForm.DoWithTempMute(() => poke.ShowDialog(this)).IsOk())
if (this.ShowDialogWithTempMute(poke).IsOk())
{
GeneralUpdate();
}