1
0
mirror of https://github.com/fadden/6502bench.git synced 2024-11-30 01:50:10 +00:00

Set Owner for all modal dialogs

This turns out to be really important.  Otherwise the modal dialog
doesn't stay on top of the application's window stack, which can
make things awkward when ShowInTaskbar is set to false.  The easiest
way to ensure this is getting done is to make it part of the
constructor arguments.

The code now passes the parent window in explicitly.  WPF MessageBox
avoids this by calling UnsafeNativeMethods.GetActiveWindow(), but
that feels weird.  We could assume Application.Current.MainWindow
is the parent, but that seems like it could go quietly and horribly
wrong.
This commit is contained in:
Andy McFadden 2019-06-16 16:46:40 -07:00
parent 61ecb28d60
commit f32135e2c7
5 changed files with 14 additions and 14 deletions

View File

@ -402,7 +402,7 @@ namespace SourceGenWPF {
string messages = mProject.LoadExternalFiles();
if (messages.Length != 0) {
// ProjectLoadIssues isn't quite the right dialog, but it'll do.
ProjectLoadIssues dlg = new ProjectLoadIssues(messages,
ProjectLoadIssues dlg = new ProjectLoadIssues(mMainWin, messages,
ProjectLoadIssues.Buttons.Continue);
dlg.ShowDialog();
}
@ -711,7 +711,7 @@ namespace SourceGenWPF {
// Should probably use a less-busy dialog for something simple like
// "permission denied", but the open file dialog handles most simple
// stuff directly.
ProjectLoadIssues dlg = new ProjectLoadIssues(report.Format(),
ProjectLoadIssues dlg = new ProjectLoadIssues(mMainWin, report.Format(),
ProjectLoadIssues.Buttons.Cancel);
dlg.ShowDialog();
// ignore dlg.DialogResult
@ -741,7 +741,7 @@ namespace SourceGenWPF {
// If there were warnings, notify the user and give the a chance to cancel.
if (report.Count != 0) {
ProjectLoadIssues dlg = new ProjectLoadIssues(report.Format(),
ProjectLoadIssues dlg = new ProjectLoadIssues(mMainWin, report.Format(),
ProjectLoadIssues.Buttons.ContinueOrCancel);
bool? ok = dlg.ShowDialog();
@ -818,7 +818,7 @@ namespace SourceGenWPF {
/// <param name="errorMsg">Message to display in the message box.</param>
/// <returns>Full path of file to open.</returns>
private string ChooseDataFile(string origPath, string errorMsg) {
DataFileLoadIssue dlg = new DataFileLoadIssue(origPath, errorMsg);
DataFileLoadIssue dlg = new DataFileLoadIssue(mMainWin, origPath, errorMsg);
bool? ok = dlg.ShowDialog();
if (ok != true) {
return null;
@ -909,7 +909,7 @@ namespace SourceGenWPF {
Debug.WriteLine("ProjectView.DoClose() - dirty=" +
(mProject == null ? "N/A" : mProject.IsDirty.ToString()));
if (mProject != null && mProject.IsDirty) {
DiscardChanges dlg = new DiscardChanges();
DiscardChanges dlg = new DiscardChanges(mMainWin);
bool? ok = dlg.ShowDialog();
if (ok != true) {
return false;
@ -1118,8 +1118,7 @@ namespace SourceGenWPF {
int offset = CodeLineList[selIndex].FileOffset;
Anattrib attr = mProject.GetAnattrib(offset);
EditAddress dlg = new EditAddress(attr.Address, mProject.CpuDef.MaxAddressValue);
dlg.Owner = mMainWin;
EditAddress dlg = new EditAddress(mMainWin, attr.Address, mProject.CpuDef.MaxAddressValue);
bool? ok = dlg.ShowDialog();
if (ok != true) {
return;

View File

@ -32,8 +32,9 @@ namespace SourceGenWPF.ProjWin {
private string mMessage;
public DataFileLoadIssue(string pathName, string message) {
public DataFileLoadIssue(Window owner, string pathName, string message) {
InitializeComponent();
Owner = owner;
mPathName = pathName;
mMessage = message;

View File

@ -31,8 +31,9 @@ namespace SourceGenWPF.ProjWin {
}
public Choice UserChoice { get; private set; }
public DiscardChanges() {
public DiscardChanges(Window owner) {
InitializeComponent();
Owner = owner;
}
// TODO:

View File

@ -14,10 +14,7 @@
* limitations under the License.
*/
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Controls;
@ -43,7 +40,7 @@ namespace SourceGenWPF.ProjWin {
public string AddressText { get; set; }
public EditAddress(int initialAddr, int maxAddressValue) {
public EditAddress(Window owner, int initialAddr, int maxAddressValue) {
// Set the property before initializing the window -- we don't have a property
// change notifier.
Address = -2;
@ -52,6 +49,7 @@ namespace SourceGenWPF.ProjWin {
this.DataContext = this;
InitializeComponent();
Owner = owner;
}
private void OkButton_Click(object sender, RoutedEventArgs e) {

View File

@ -36,8 +36,9 @@ namespace SourceGenWPF.ProjWin {
}
public ProjectLoadIssues(string msgs, Buttons allowedButtons) {
public ProjectLoadIssues(Window owner, string msgs, Buttons allowedButtons) {
InitializeComponent();
Owner = owner;
mMessages = msgs;
mAllowedButtons = allowedButtons;