OUT-590: Capture all dialog close events correctly refactor_dialogs
authorThomas
Fri, 04 Oct 2019 10:27:10 +0200
branchrefactor_dialogs
changeset 27928a137ccf6a95
parent 2791 96077c374bcb
child 2793 96b1caccde65
child 2795 6e3f8b15a125
OUT-590: Capture all dialog close events correctly
AdapterCallbacks.cs
UI/ViewModels/WizardViewModelBase.cs
UI/Views/DialogWindow.xaml.cs
     1.1 --- a/AdapterCallbacks.cs	Fri Oct 04 07:57:47 2019 +0200
     1.2 +++ b/AdapterCallbacks.cs	Fri Oct 04 10:27:10 2019 +0200
     1.3 @@ -12,8 +12,8 @@
     1.4      /// </summary>   
     1.5      internal class AdapterCallbacks : IpEpEngineCallbacks
     1.6      {
     1.7 -        // Action to close the sync dialog
     1.8 -        public static Action CloseDialogAction = null;
     1.9 +        // Action to send a sync handshake signal to the dialog
    1.10 +        public static Action<SyncHandshakeSignal> SyncHandshakeSignalAction = null;
    1.11  
    1.12          #region Callbacks
    1.13          /// <summary>
    1.14 @@ -31,15 +31,8 @@
    1.15  #if DEBUG
    1.16              Notification.Show(signal.ToString(), "NotifyHandshake called with signal " + signal.ToString());
    1.17  #endif
    1.18 -
    1.19 -            /* Close handshake dialog if it was still open and the signal type
    1.20 -             * is not "undefined" or "Forming Group", in which case the status quo should be preserved.
    1.21 -             */
    1.22 -            if ((signal != SyncHandshakeSignal.SyncNotifyUndefined) &&
    1.23 -                (signal != SyncHandshakeSignal.SyncNotifyFormingGroup))
    1.24 -            {
    1.25 -                AdapterCallbacks.CloseDialogAction?.Invoke();
    1.26 -            }
    1.27 +            // Send sync handshake signal to dialog (if existing)
    1.28 +            AdapterCallbacks.SyncHandshakeSignalAction?.Invoke(signal);
    1.29  
    1.30              // The action to take depends on the given signal
    1.31              switch (signal)
     2.1 --- a/UI/ViewModels/WizardViewModelBase.cs	Fri Oct 04 07:57:47 2019 +0200
     2.2 +++ b/UI/ViewModels/WizardViewModelBase.cs	Fri Oct 04 10:27:10 2019 +0200
     2.3 @@ -205,7 +205,7 @@
     2.4                          {
     2.5                              Log.Error("AcceptHandshake: Error delivering handshake result. " + ex.ToString());
     2.6                          }
     2.7 -                        this.DialogResult = true;
     2.8 +
     2.9                          this.MoveToNextPage();
    2.10                      }
    2.11                      break;
     3.1 --- a/UI/Views/DialogWindow.xaml.cs	Fri Oct 04 07:57:47 2019 +0200
     3.2 +++ b/UI/Views/DialogWindow.xaml.cs	Fri Oct 04 10:27:10 2019 +0200
     3.3 @@ -83,14 +83,40 @@
     3.4          /// <summary>
     3.5          /// Closes the dialog on the dialog window's thread.
     3.6          /// </summary>
     3.7 -        public void InvokeClosing()
     3.8 +        /// <param name="dialogResult">The dialog result fo this dialog.</param>
     3.9 +        private void InvokeClosing(bool? dialogResult)
    3.10          {
    3.11              this.Dispatcher.Invoke(() =>
    3.12              {
    3.13 +                /* Set dialog result to the view model.
    3.14 +                 * Note: Setting it directly in the DialogWindow caused issues,
    3.15 +                 * so this is the workaround for that.
    3.16 +                 */ 
    3.17 +                if (this.Content is SyncWizardViewModel viewModel)
    3.18 +                {
    3.19 +                    viewModel.DialogResult = dialogResult;
    3.20 +                }
    3.21 +
    3.22                  this.Close();
    3.23              });
    3.24          }
    3.25  
    3.26 +        /// <summary>
    3.27 +        /// Action to perform when a sync handshake signal is received.
    3.28 +        /// </summary>
    3.29 +        /// <param name="signal">The received sync handshake signal.</param>
    3.30 +        private void SyncHandshakeSignalReceivedAction(SyncHandshakeSignal signal)
    3.31 +        {
    3.32 +            /* Close handshake dialog if the signal type is not "Undefined" 
    3.33 +             * or "Forming Group", in which case the status quo should be preserved.
    3.34 +             */
    3.35 +            if ((signal != SyncHandshakeSignal.SyncNotifyUndefined) &&
    3.36 +                (signal != SyncHandshakeSignal.SyncNotifyFormingGroup))
    3.37 +            {
    3.38 +                this.InvokeClosing(true);
    3.39 +            }
    3.40 +        }
    3.41 +
    3.42          #endregion
    3.43  
    3.44          #region Static methods
    3.45 @@ -111,12 +137,8 @@
    3.46  
    3.47                  if (type != Dialog.Type.Handshake)
    3.48                  {
    3.49 -                    // Create the action to close the dialog
    3.50 -                    AdapterCallbacks.CloseDialogAction = new Action(() =>
    3.51 -                    {
    3.52 -                        dialogWindow?.InvokeClosing();
    3.53 -                        dialogWindow = null;
    3.54 -                    });
    3.55 +                    // Connect the action to handle sync handshake signals
    3.56 +                    AdapterCallbacks.SyncHandshakeSignalAction = dialogWindow.SyncHandshakeSignalReceivedAction;
    3.57  
    3.58                      // Show the dialog
    3.59                      dialogWindow.ShowDialog();