Index: Application/Application.Ringtoets/App.xaml.cs =================================================================== diff -u -r12056e0413d731a732ad1098c071f325ba5d632f -r8490de857fc360680dc71c559bc99e67db4cdcc0 --- Application/Application.Ringtoets/App.xaml.cs (.../App.xaml.cs) (revision 12056e0413d731a732ad1098c071f325ba5d632f) +++ Application/Application.Ringtoets/App.xaml.cs (.../App.xaml.cs) (revision 8490de857fc360680dc71c559bc99e67db4cdcc0) @@ -280,37 +280,25 @@ private static void HandleException(Exception exception, bool isTerminating) { - var dialog = new ExceptionDialog(exception); + var exceptionDialog = new ExceptionDialog(exception); - dialog.RestartClicked += delegate + exceptionDialog.OpenLogClicked = () => { - gui.SkipDialogsOnExit = true; - Restart(); - }; - - dialog.ExitClicked += delegate - { - gui.SkipDialogsOnExit = true; - Environment.Exit(1); - }; - - dialog.OpenLogClicked += delegate - { if (gui != null && gui.CommandHandler != null) { gui.CommandHandler.OpenLogFileExternal(); } }; - var mainWindow = gui.MainWindow as Form; - if (mainWindow != null && mainWindow.IsHandleCreated) + gui.SkipDialogsOnExit = true; + + if (exceptionDialog.ShowDialog() == DialogResult.OK) { - dialog.StartPosition = FormStartPosition.CenterParent; - dialog.ShowDialog(mainWindow); // show dialog at the center of main window + Restart(); } else { - dialog.ShowDialog(); + Environment.Exit(1); } } Index: Core/Common/src/Core.Common.Controls/Dialogs/ExceptionDialog.cs =================================================================== diff -u -r934175819c7bf0bcee299dace068f8cb7604cc14 -r8490de857fc360680dc71c559bc99e67db4cdcc0 --- Core/Common/src/Core.Common.Controls/Dialogs/ExceptionDialog.cs (.../ExceptionDialog.cs) (revision 934175819c7bf0bcee299dace068f8cb7604cc14) +++ Core/Common/src/Core.Common.Controls/Dialogs/ExceptionDialog.cs (.../ExceptionDialog.cs) (revision 8490de857fc360680dc71c559bc99e67db4cdcc0) @@ -1,54 +1,73 @@ using System; -using System.ComponentModel; using System.Linq; using System.Reflection; using System.Windows.Forms; using Core.Common.Controls.Properties; namespace Core.Common.Controls.Dialogs { + /// + /// Class for showing an exception dialog. + /// The exception dialog can return the following results: + /// + /// + /// : this result represents a request for restarting the application. + /// + /// + /// : this result represents a request for closing the application. + /// + /// + /// public partial class ExceptionDialog : DialogBase { - public event EventHandler RestartClicked; + private Action openLogClicked; - public event EventHandler ExitClicked; - - public event EventHandler OpenLogClicked; - /// - /// Initializes a new instance of the class. + /// Constructs a new . /// - /// The exception. + /// The exception to show in the dialog. public ExceptionDialog(Exception exception) : base(Resources.bug__exclamation) { InitializeComponent(); + buttonOpenLog.Visible = false; exceptionTextBox.Text = GetExceptionText(exception); } - private void ButtonRestartClick(object sender, EventArgs e) + /// + /// Gets or sets the action that should be performed after clicking the log button. + /// + /// The log button is only visible when this action is set. + public Action OpenLogClicked { - buttonRestart.Enabled = false; - buttonExit.Enabled = false; - - if (RestartClicked != null) + private get { - RestartClicked(this, null); + return openLogClicked; } + set + { + openLogClicked = value; + buttonOpenLog.Visible = openLogClicked != null; + } + } + + protected override Button GetCancelButton() + { + return buttonExit; + } + + private void ButtonRestartClick(object sender, EventArgs e) + { + DialogResult = DialogResult.OK; + Close(); } private void ButtonExitClick(object sender, EventArgs e) { - buttonRestart.Enabled = false; - buttonExit.Enabled = false; + DialogResult = DialogResult.Cancel; - if (ExitClicked != null) - { - ExitClicked(this, null); - } - Close(); } @@ -59,10 +78,7 @@ private void ButtonOpenLogClick(object sender, EventArgs e) { - if (OpenLogClicked != null) - { - OpenLogClicked(this, null); - } + OpenLogClicked(); } private string GetExceptionText(Exception exception) @@ -89,22 +105,5 @@ return str; } - - protected override void OnClosing(CancelEventArgs e) - { - if (ExitClicked != null) - { - ExitClicked(this, null); - } - - Close(); - - base.OnClosing(e); - } - - protected override Button GetCancelButton() - { - return buttonExit; - } } } \ No newline at end of file