dialogs shouldnt be opened without an owner. so give all them an owner. fixes #2420

This commit is contained in:
zeromus 2020-09-21 13:11:28 -04:00
parent fb5a5ed78c
commit c64fb11d0d
26 changed files with 70 additions and 60 deletions

View File

@ -164,11 +164,14 @@ namespace BizHawk.Client.EmuHawk
/// <summary>
/// Handles EmuHawk specific issues before showing a modal dialog
/// </summary>
public static DialogResult ShowHawkDialog(this CommonDialog form)
public static DialogResult ShowHawkDialog(this CommonDialog form, IWin32Window owner)
{
GlobalWin.Sound.StopSound();
using var tempForm = new Form();
var result = form.ShowDialog(tempForm);
DialogResult result;
if(owner != null)
result = form.ShowDialog(owner);
else
result = form.ShowDialog();
GlobalWin.Sound.StartSound();
return result;
}
@ -272,7 +275,7 @@ namespace BizHawk.Client.EmuHawk
Clipboard.SetImage(img);
}
public static void SaveAsFile(this Bitmap bitmap, IGameInfo game, string suffix, string systemId, PathEntryCollection paths)
public static void SaveAsFile(this Bitmap bitmap, IGameInfo game, string suffix, string systemId, PathEntryCollection paths, IWin32Window owner)
{
using var sfd = new SaveFileDialog
{
@ -282,7 +285,7 @@ namespace BizHawk.Client.EmuHawk
RestoreDirectory = true
};
var result = sfd.ShowHawkDialog();
var result = sfd.ShowHawkDialog(owner);
if (result != DialogResult.OK)
{
return;

View File

@ -244,7 +244,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() == DialogResult.Cancel)
if (oac.ShowHawkDialog(this) == DialogResult.Cancel)
{
return;
}
@ -293,7 +293,7 @@ namespace BizHawk.Client.EmuHawk
Title = "Open Advanced"
};
var result = ofd.ShowHawkDialog();
var result = ofd.ShowHawkDialog(this);
if (!result.IsOk())
{
return;
@ -442,7 +442,7 @@ namespace BizHawk.Client.EmuHawk
RestoreDirectory = false
};
if (ofd.ShowHawkDialog().IsOk())
if (ofd.ShowHawkDialog(this).IsOk())
{
foreach (var fn in ofd.FileNames)
{
@ -468,7 +468,9 @@ namespace BizHawk.Client.EmuHawk
filename,
Config.PathEntries.MovieAbsolutePath(),
"Movie Files",
MovieSession.Movie.PreferredExtension);
MovieSession.Movie.PreferredExtension,
this
);
if (file != null)
{
@ -560,7 +562,7 @@ namespace BizHawk.Client.EmuHawk
Filter = FilesystemFilter.PNGs.ToString()
};
if (sfd.ShowHawkDialog().IsOk())
if (sfd.ShowHawkDialog(this).IsOk())
{
TakeScreenshot(sfd.FileName);
}
@ -1110,7 +1112,7 @@ namespace BizHawk.Client.EmuHawk
Filter = ConfigFileFSFilterString
};
if (sfd.ShowHawkDialog().IsOk())
if (sfd.ShowHawkDialog(this).IsOk())
{
SaveConfig(sfd.FileName);
AddOnScreenMessage("Copied settings");
@ -1132,7 +1134,7 @@ namespace BizHawk.Client.EmuHawk
Filter = ConfigFileFSFilterString
};
if (ofd.ShowHawkDialog().IsOk())
if (ofd.ShowHawkDialog(this).IsOk())
{
LoadConfigFile(ofd.FileName);
}
@ -1367,12 +1369,12 @@ namespace BizHawk.Client.EmuHawk
if (Emulator is NES nes && nes.IsVS)
{
using var form = new NesVsSettings(this, nes.GetSyncSettings().Clone());
form.ShowHawkDialog();
form.ShowHawkDialog(this);
}
else if (Emulator is SubNESHawk sub && sub.IsVs)
{
using var form = new NesVsSettings(this, sub.GetSyncSettings().Clone());
form.ShowHawkDialog();
form.ShowHawkDialog(this);
}
}

View File

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

View File

@ -84,7 +84,7 @@ namespace BizHawk.Client.EmuHawk
public void SaveFile()
{
Bmp.SaveAsFile(GlobalWin.Game, "Palettes", GlobalWin.Emulator.SystemId, GlobalWin.Config.PathEntries);
Bmp.SaveAsFile(GlobalWin.Game, "Palettes", GlobalWin.Emulator.SystemId, GlobalWin.Config.PathEntries, this);
}
}
}

View File

@ -513,7 +513,7 @@ namespace BizHawk.Client.EmuHawk
InitialDirectory = _config.PathEntries.MovieAbsolutePath()
};
var result = ofd.ShowHawkDialog();
var result = ofd.ShowHawkDialog(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();
var result = sfd.ShowHawkDialog(this);
if (result == DialogResult.OK
&& !string.IsNullOrWhiteSpace(sfd.FileName))
{

View File

@ -363,7 +363,8 @@ namespace BizHawk.Client.EmuHawk
CurrentFileName,
Config.PathEntries.ToolsAbsolutePath(),
"Bot files",
"bot");
"bot",
this);
if (file != null)
{

View File

@ -388,7 +388,8 @@ namespace BizHawk.Client.EmuHawk
_currentFilename,
Config.PathEntries.LogAbsolutePath(),
"Code Data Logger Files",
"cdl");
"cdl",
this);
if (file == null)
return false;

View File

@ -143,7 +143,8 @@ namespace BizHawk.Client.EmuHawk
MainForm.CheatList.CurrentFileName,
Config.PathEntries.CheatsAbsolutePath(Game.System),
"Cheat Files",
"cht");
"cht",
Owner);
return file != null && MainForm.CheatList.SaveFile(file.FullName);
}

View File

@ -144,7 +144,7 @@ namespace BizHawk.Client.EmuHawk
{
var b = CreateAddBreakpointDialog(BreakpointOperation.Add);
if (b.ShowHawkDialog().IsOk())
if (b.ShowHawkDialog(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() == DialogResult.OK)
if (b.ShowHawkDialog(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() == DialogResult.OK)
if (b.ShowHawkDialog(this) == DialogResult.OK)
{
breakpoint.Type = b.BreakType;
breakpoint.Address = b.Address;

View File

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

View File

@ -179,7 +179,7 @@ namespace BizHawk.Client.EmuHawk
private void SaveAsFile(Bitmap bitmap, string suffix)
{
bitmap.SaveAsFile(Game, suffix, Emu.SystemId, Config.PathEntries);
bitmap.SaveAsFile(Game, suffix, Emu.SystemId, Config.PathEntries, this);
}
private void SaveBGAScreenshotToolStripMenuItem_Click(object sender, EventArgs e)

View File

@ -946,7 +946,7 @@ namespace BizHawk.Client.EmuHawk
: Game.FilesystemSafeName()
};
var result = sfd.ShowHawkDialog();
var result = sfd.ShowHawkDialog(this);
return result == DialogResult.OK ? sfd.FileName : "";
}
@ -962,7 +962,7 @@ namespace BizHawk.Client.EmuHawk
RestoreDirectory = true
};
var result = sfd.ShowHawkDialog();
var result = sfd.ShowHawkDialog(this);
return result == DialogResult.OK ? sfd.FileName : "";
}
@ -1284,7 +1284,7 @@ namespace BizHawk.Client.EmuHawk
RestoreDirectory = true
};
var result = sfd.ShowHawkDialog();
var result = sfd.ShowHawkDialog(this);
if (result != DialogResult.OK)
{
return;
@ -1338,7 +1338,7 @@ namespace BizHawk.Client.EmuHawk
RestoreDirectory = false
};
var result = ofd.ShowHawkDialog();
var result = ofd.ShowHawkDialog(this);
if (result == DialogResult.OK)
{
@ -1605,7 +1605,7 @@ namespace BizHawk.Client.EmuHawk
Message = "Enter a hexadecimal value"
};
var result = inputPrompt.ShowHawkDialog();
var result = inputPrompt.ShowHawkDialog(this);
if (result == DialogResult.OK && inputPrompt.PromptText.IsHex())
{
@ -1694,7 +1694,7 @@ namespace BizHawk.Client.EmuHawk
ParentTool = this
};
poke.ShowHawkDialog();
poke.ShowHawkDialog(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();
form.ShowHawkDialog(this);
}
private void ResetColorsToDefaultMenuItem_Click(object sender, EventArgs e)

View File

@ -694,7 +694,7 @@ namespace BizHawk.Client.EmuHawk
sfd.Filter = SessionsFSFilterSet.ToString();
sfd.RestoreDirectory = true;
var result = sfd.ShowHawkDialog();
var result = sfd.ShowHawkDialog(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();
var result = ofd.ShowHawkDialog(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();
var result = sfd.ShowHawkDialog(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();
var result = ofd.ShowHawkDialog(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();
DialogResult result = dialog.ShowHawkDialog(this);
if (result != DialogResult.OK)
{
if (create)
@ -304,7 +304,7 @@ namespace BizHawk.Client.EmuHawk
Filter = MacrosFSFilterSet.ToString()
};
DialogResult result = dialog.ShowHawkDialog();
DialogResult result = dialog.ShowHawkDialog(this);
if (result != DialogResult.OK)
{
return null;

View File

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

View File

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

View File

@ -188,7 +188,7 @@ namespace BizHawk.Client.EmuHawk
{
NameTableView
.ToBitMap()
.SaveAsFile(Game, "Nametables", "NES", Config.PathEntries);
.SaveAsFile(Game, "Nametables", "NES", Config.PathEntries, this);
}
private void ScreenshotToClipboardMenuItem_Click(object sender, EventArgs e)

View File

@ -314,7 +314,7 @@ namespace BizHawk.Client.EmuHawk
private void Screenshot(Bitmap b, string suffix)
{
b.SaveAsFile(Game, suffix, "NES", Config.PathEntries);
b.SaveAsFile(Game, suffix, "NES", Config.PathEntries, this);
}
private void SavePaletteScreenshotMenuItem_Click(object sender, EventArgs e)

View File

@ -581,7 +581,7 @@ namespace BizHawk.Client.EmuHawk
var point = Cursor.Position;
point.Offset(i.Width / -2, i.Height / -2);
var result = i.ShowHawkDialog(position: point);
var result = i.ShowHawkDialog(this, position: point);
if (result.IsOk())
{
branch.UserText = i.PromptText;

View File

@ -197,7 +197,7 @@ namespace BizHawk.Client.EmuHawk
var point = Cursor.Position;
point.Offset(i.Width / -2, i.Height / -2);
var result = i.ShowHawkDialog(position: point);
var result = i.ShowHawkDialog(this, position: point);
if (result.IsOk())
{
Markers.Add(new TasMovieMarker(frame, i.PromptText));
@ -249,7 +249,7 @@ namespace BizHawk.Client.EmuHawk
point.Offset(i.Width / -2, i.Height / -2);
}
var result = i.ShowHawkDialog(position: point);
var result = i.ShowHawkDialog(this, position: point);
if (result == DialogResult.OK)
{

View File

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

View File

@ -801,7 +801,9 @@ namespace BizHawk.Client.EmuHawk
filename,
Config.PathEntries.MovieAbsolutePath(),
"Tas Project Files",
"tasproj");
"tasproj",
this
);
if (file != null)
{

View File

@ -68,7 +68,7 @@ namespace BizHawk.Client.EmuHawk
RestoreDirectory = true
};
var result = ofd.ShowHawkDialog();
var result = ofd.ShowHawkDialog(this);
if (result != DialogResult.OK)
{
return null;
@ -77,7 +77,7 @@ namespace BizHawk.Client.EmuHawk
return new FileInfo(ofd.FileName);
}
public static FileInfo SaveFileDialog(string currentFile, string path, string fileType, string fileExt)
public static FileInfo SaveFileDialog(string currentFile, string path, string fileType, string fileExt, IWin32Window owner)
{
if (!Directory.Exists(path))
{
@ -94,7 +94,7 @@ namespace BizHawk.Client.EmuHawk
RestoreDirectory = true
};
var result = sfd.ShowHawkDialog();
var result = sfd.ShowHawkDialog(owner);
if (result != DialogResult.OK)
{
return null;
@ -110,7 +110,7 @@ namespace BizHawk.Client.EmuHawk
public FileInfo GetWatchSaveFileFromUser(string currentFile)
{
return SaveFileDialog(currentFile, Config.PathEntries.WatchAbsolutePath(), "Watch Files", "wch");
return SaveFileDialog(currentFile, Config.PathEntries.WatchAbsolutePath(), "Watch Files", "wch", this);
}
public void ViewInHexEditor(MemoryDomain domain, IEnumerable<long> addresses, WatchSize size)

View File

@ -302,7 +302,7 @@ namespace BizHawk.Client.EmuHawk
FilesystemFilter.TextFiles
).ToString();
sfd.RestoreDirectory = true;
var result = sfd.ShowHawkDialog();
var result = sfd.ShowHawkDialog(this);
return result.IsOk() ? new FileInfo(sfd.FileName) : null;
}
@ -351,7 +351,7 @@ namespace BizHawk.Client.EmuHawk
InitialValue = MaxLines.ToString()
};
var result = prompt.ShowHawkDialog();
var result = prompt.ShowHawkDialog(this);
if (result == DialogResult.OK)
{
var max = int.Parse(prompt.PromptText);
@ -372,7 +372,7 @@ namespace BizHawk.Client.EmuHawk
InitialValue = FileSizeCap.ToString()
};
var result = prompt.ShowHawkDialog();
var result = prompt.ShowHawkDialog(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();
poke.ShowHawkDialog(this);
UpdateList();
}
}
@ -898,7 +898,7 @@ namespace BizHawk.Client.EmuHawk
Message = "Enter a hexadecimal value"
};
while (prompt.ShowHawkDialog().IsOk())
while (prompt.ShowHawkDialog(this).IsOk())
{
try
{