Inline ShowHawkDialog

there were 8 unnecessary double-mutes where ShowHawkDialog was called with a
InputPrompt receiver
This commit is contained in:
YoshiRulz 2020-12-01 04:42:26 +10:00 committed by James Groom
parent 9d620116f3
commit f0657b358d
20 changed files with 57 additions and 73 deletions

View File

@ -113,7 +113,7 @@ namespace BizHawk.Client.EmuHawk
public static void Run(IDialogController dialogController, IWin32Window hwnd)
{
var form = new FFmpegDownloaderForm();
form.ShowHawkDialog(dialogController, hwnd);
dialogController.DoWithTempMute(() => form.ShowDialog(hwnd));
}
private void btnDownload_Click(object sender, EventArgs e)

View File

@ -145,27 +145,6 @@ namespace BizHawk.Client.EmuHawk
public static class FormExtensions
{
/// <summary>
/// Handles EmuHawk specific issues before showing a modal dialog
/// </summary>
public static DialogResult ShowHawkDialog(this Form form, IDialogController dialogController, IWin32Window owner, Point position = default)
{
if (position != default)
{
form.StartPosition = FormStartPosition.Manual;
form.Location = position;
}
return dialogController.DoWithTempMute(() => form.ShowDialog(owner));
}
/// <summary>
/// Handles EmuHawk specific issues before showing a modal dialog
/// </summary>
public static DialogResult ShowHawkDialog(this CommonDialog form, IDialogController dialogController, IWin32Window owner)
{
return dialogController.DoWithTempMute(() => form.ShowDialog(owner));
}
public static void DoWithTempMute(this IDialogController dialogController, Action action)
{
dialogController.StopSound();
@ -290,7 +269,7 @@ namespace BizHawk.Client.EmuHawk
RestoreDirectory = true
};
var result = sfd.ShowHawkDialog(dialogController, owner);
var result = dialogController.DoWithTempMute(() => sfd.ShowDialog(owner));
if (result != DialogResult.OK)
{
return;

View File

@ -246,7 +246,7 @@ namespace BizHawk.Client.EmuHawk
private void OpenAdvancedMenuItem_Click(object sender, EventArgs e)
{
using var oac = new OpenAdvancedChooser(Config, CreateCoreComm, Game, RunLibretroCoreChooser);
if (oac.ShowHawkDialog(this, this) == DialogResult.Cancel)
if (this.DoWithTempMute(() => oac.ShowDialog(this)) == DialogResult.Cancel)
{
return;
}
@ -295,7 +295,7 @@ namespace BizHawk.Client.EmuHawk
Title = "Open Advanced"
};
var result = ofd.ShowHawkDialog(this, this);
var result = this.DoWithTempMute(() => ofd.ShowDialog(this));
if (!result.IsOk())
{
return;
@ -444,7 +444,7 @@ namespace BizHawk.Client.EmuHawk
RestoreDirectory = false
};
if (ofd.ShowHawkDialog(this, this).IsOk())
if (this.DoWithTempMute(() => ofd.ShowDialog(this)).IsOk())
{
foreach (var fn in ofd.FileNames)
{
@ -564,7 +564,7 @@ namespace BizHawk.Client.EmuHawk
Filter = FilesystemFilter.PNGs.ToString()
};
if (sfd.ShowHawkDialog(this, this).IsOk())
if (this.DoWithTempMute(() => sfd.ShowDialog(this)).IsOk())
{
TakeScreenshot(sfd.FileName);
}
@ -1130,7 +1130,7 @@ namespace BizHawk.Client.EmuHawk
Filter = ConfigFileFSFilterString
};
if (sfd.ShowHawkDialog(this, this).IsOk())
if (this.DoWithTempMute(() => sfd.ShowDialog(this)).IsOk())
{
SaveConfig(sfd.FileName);
AddOnScreenMessage("Copied settings");
@ -1152,7 +1152,7 @@ namespace BizHawk.Client.EmuHawk
Filter = ConfigFileFSFilterString
};
if (ofd.ShowHawkDialog(this, this).IsOk())
if (this.DoWithTempMute(() => ofd.ShowDialog(this)).IsOk())
{
LoadConfigFile(ofd.FileName);
}
@ -1385,12 +1385,12 @@ namespace BizHawk.Client.EmuHawk
if (Emulator is NES nes && nes.IsVS)
{
using var form = new NesVsSettings(this, nes.GetSyncSettings().Clone());
form.ShowHawkDialog(this, this);
this.DoWithTempMute(() => form.ShowDialog(this));
}
else if (Emulator is SubNESHawk sub && sub.IsVs)
{
using var form = new NesVsSettings(this, sub.GetSyncSettings().Clone());
form.ShowHawkDialog(this, this);
this.DoWithTempMute(() => form.ShowDialog(this));
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -946,7 +946,7 @@ namespace BizHawk.Client.EmuHawk
: Game.FilesystemSafeName()
};
var result = sfd.ShowHawkDialog(MainForm, this);
var result = MainForm.DoWithTempMute(() => sfd.ShowDialog(this));
return result == DialogResult.OK ? sfd.FileName : "";
}
@ -962,7 +962,7 @@ namespace BizHawk.Client.EmuHawk
RestoreDirectory = true
};
var result = sfd.ShowHawkDialog(MainForm, this);
var result = MainForm.DoWithTempMute(() => sfd.ShowDialog(this));
return result == DialogResult.OK ? sfd.FileName : "";
}
@ -1284,7 +1284,7 @@ namespace BizHawk.Client.EmuHawk
RestoreDirectory = true
};
var result = sfd.ShowHawkDialog(MainForm, this);
var result = MainForm.DoWithTempMute(() => sfd.ShowDialog(this));
if (result != DialogResult.OK)
{
return;
@ -1338,7 +1338,7 @@ namespace BizHawk.Client.EmuHawk
RestoreDirectory = false
};
var result = ofd.ShowHawkDialog(MainForm, this);
var result = MainForm.DoWithTempMute(() => ofd.ShowDialog(this));
if (result == DialogResult.OK)
{
@ -1605,7 +1605,7 @@ namespace BizHawk.Client.EmuHawk
Message = "Enter a hexadecimal value"
};
var result = MainForm.DoWithTempMute(() => inputPrompt.ShowHawkDialog(MainForm, this));
var result = MainForm.DoWithTempMute(() => inputPrompt.ShowDialog(this));
if (result == DialogResult.OK && inputPrompt.PromptText.IsHex())
{
@ -1694,7 +1694,7 @@ namespace BizHawk.Client.EmuHawk
ParentTool = this
};
poke.ShowHawkDialog(MainForm, this);
MainForm.DoWithTempMute(() => poke.ShowDialog(this));
GeneralUpdate();
}
}
@ -1702,7 +1702,7 @@ namespace BizHawk.Client.EmuHawk
private void SetColorsMenuItem_Click(object sender, EventArgs e)
{
using var form = new HexColorsForm(this);
form.ShowHawkDialog(MainForm, this);
MainForm.DoWithTempMute(() => form.ShowDialog(this));
}
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 = sfd.ShowHawkDialog(MainForm, this);
var result = MainForm.DoWithTempMute(() => sfd.ShowDialog(this));
return result.IsOk() ? new FileInfo(sfd.FileName) : null;
}
@ -826,7 +826,7 @@ namespace BizHawk.Client.EmuHawk
Directory.CreateDirectory(ofd.InitialDirectory);
}
var result = ofd.ShowHawkDialog(MainForm, this);
var result = MainForm.DoWithTempMute(() => ofd.ShowDialog(this));
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 = sfd.ShowHawkDialog(MainForm, this);
var result = MainForm.DoWithTempMute(() => sfd.ShowDialog(this));
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 = ofd.ShowHawkDialog(MainForm, this);
var result = MainForm.DoWithTempMute(() => ofd.ShowDialog(this));
if (result.IsOk() && ofd.FileNames != null)
{
foreach (var file in ofd.FileNames)

View File

@ -279,7 +279,7 @@ namespace BizHawk.Client.EmuHawk
create = true;
}
DialogResult result = dialog.ShowHawkDialog(MainForm, this);
DialogResult result = MainForm.DoWithTempMute(() => dialog.ShowDialog(this));
if (result != DialogResult.OK)
{
if (create)
@ -304,7 +304,7 @@ namespace BizHawk.Client.EmuHawk
Filter = MacrosFSFilterSet.ToString()
};
DialogResult result = dialog.ShowHawkDialog(MainForm, this);
DialogResult result = MainForm.DoWithTempMute(() => dialog.ShowDialog(this));
if (result != DialogResult.OK)
{
return null;

View File

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

View File

@ -79,7 +79,7 @@ namespace BizHawk.Client.EmuHawk
};
string hawkPath = "";
var result = ofd.ShowHawkDialog(_dialogController, this);
var result = _dialogController.DoWithTempMute(() => ofd.ShowDialog(this));
if (result == DialogResult.OK)
{
hawkPath = ofd.FileName;

View File

@ -576,8 +576,10 @@ namespace BizHawk.Client.EmuHawk
var point = Cursor.Position;
point.Offset(i.Width / -2, i.Height / -2);
i.StartPosition = FormStartPosition.Manual;
i.Location = point;
var result = MainForm.DoWithTempMute(() => i.ShowHawkDialog(Tastudio.MainForm, this, position: point));
var result = MainForm.DoWithTempMute(() => i.ShowDialog(this));
if (result.IsOk())
{
branch.UserText = i.PromptText;

View File

@ -195,8 +195,10 @@ namespace BizHawk.Client.EmuHawk
var point = Cursor.Position;
point.Offset(i.Width / -2, i.Height / -2);
i.StartPosition = FormStartPosition.Manual;
i.Location = point;
var result = Tastudio.MainForm.DoWithTempMute(() => i.ShowHawkDialog(Tastudio.MainForm, this, position: point));
var result = Tastudio.MainForm.DoWithTempMute(() => i.ShowDialog(this));
if (!result.IsOk())
{
return;
@ -233,7 +235,6 @@ namespace BizHawk.Client.EmuHawk
public void EditMarkerPopUp(TasMovieMarker marker, bool followCursor = false)
{
var markerFrame = marker.Frame;
var point = default(Point);
var i = new InputPrompt
{
Text = $"Marker for frame {markerFrame}",
@ -247,11 +248,13 @@ namespace BizHawk.Client.EmuHawk
if (followCursor)
{
point = Cursor.Position;
var point = Cursor.Position;
point.Offset(i.Width / -2, i.Height / -2);
i.StartPosition = FormStartPosition.Manual;
i.Location = point;
}
var result = Tastudio.MainForm.DoWithTempMute(() => i.ShowHawkDialog(Tastudio.MainForm, this, position: point));
var result = Tastudio.MainForm.DoWithTempMute(() => i.ShowDialog(this));
if (result == DialogResult.OK)
{

View File

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

View File

@ -71,7 +71,7 @@ namespace BizHawk.Client.EmuHawk
RestoreDirectory = true
};
var result = ofd.ShowHawkDialog(MainForm, this);
var result = MainForm.DoWithTempMute(() => ofd.ShowDialog(this));
if (result != DialogResult.OK)
{
return null;
@ -95,7 +95,7 @@ namespace BizHawk.Client.EmuHawk
RestoreDirectory = true
};
var result = sfd.ShowHawkDialog(dialogController, owner);
var result = dialogController.DoWithTempMute(() => sfd.ShowDialog(owner));
if (result != DialogResult.OK)
{
return null;

View File

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

View File

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

View File

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