1- using System ;
2- using System . Diagnostics ;
3- using System . Windows ;
4- using System . Windows . Input ;
5- using MahApps . Metro . Controls . Dialogs ;
1+ using MahApps . Metro . SimpleChildWindow ;
62using NETworkManager . Localization . Resources ;
73using NETworkManager . Settings ;
84using NETworkManager . Utilities ;
5+ using NETworkManager . Views ;
6+ using System ;
7+ using System . Diagnostics ;
8+ using System . Threading . Tasks ;
9+ using System . Windows ;
10+ using System . Windows . Input ;
911
1012namespace NETworkManager . ViewModels ;
1113
1214public class SettingsSettingsViewModel : ViewModelBase
1315{
1416 #region Variables
15-
16- private readonly IDialogCoordinator _dialogCoordinator ;
17-
1817 public Action CloseAction { get ; set ; }
1918
2019 private string _location ;
@@ -31,15 +30,12 @@ public string Location
3130 OnPropertyChanged ( ) ;
3231 }
3332 }
34-
3533 #endregion
3634
3735 #region Constructor, LoadSettings
3836
39- public SettingsSettingsViewModel ( IDialogCoordinator instance )
37+ public SettingsSettingsViewModel ( )
4038 {
41- _dialogCoordinator = instance ;
42-
4339 LoadSettings ( ) ;
4440 }
4541
@@ -61,26 +57,47 @@ private static void OpenLocationAction()
6157
6258 public ICommand ResetSettingsCommand => new RelayCommand ( _ => ResetSettingsAction ( ) ) ;
6359
64- private async void ResetSettingsAction ( )
60+ private void ResetSettingsAction ( )
6561 {
66- var settings = AppearanceManager . MetroDialog ;
62+ ResetSettings ( ) . ConfigureAwait ( false ) ;
63+ }
6764
68- settings . AffirmativeButtonText = Strings . Reset ;
69- settings . NegativeButtonText = Strings . Cancel ;
65+ #endregion
7066
71- settings . DefaultButtonFocus = MessageDialogResult . Affirmative ;
67+ #region Methods
7268
73- if ( await _dialogCoordinator . ShowMessageAsync ( this , Strings . ResetSettingsQuestion ,
74- Strings . SettingsAreResetAndApplicationWillBeRestartedMessage ,
75- MessageDialogStyle . AffirmativeAndNegative , settings ) != MessageDialogResult . Affirmative )
76- return ;
69+ private Task ResetSettings ( )
70+ {
71+ var childWindow = new OKCancelInfoMessageChildWindow ( ) ;
7772
78- // Init default settings
79- SettingsManager . Initialize ( ) ;
73+ var childWindowViewModel = new OKCancelInfoMessageViewModel ( _ =>
74+ {
75+ childWindow . IsOpen = false ;
76+ ConfigurationManager . Current . IsChildWindowOpen = false ;
8077
81- // Restart the application
82- ( Application . Current . MainWindow as MainWindow ) ? . RestartApplication ( ) ;
83- }
78+ // Init default settings
79+ SettingsManager . Initialize ( ) ;
80+
81+ // Restart the application
82+ ( Application . Current . MainWindow as MainWindow ) ? . RestartApplication ( ) ;
83+ } , _ =>
84+ {
85+ childWindow . IsOpen = false ;
86+ ConfigurationManager . Current . IsChildWindowOpen = false ;
87+ } ,
88+ Strings . SettingsAreResetAndApplicationWillBeRestartedMessage ,
89+ Strings . Reset ,
90+ Strings . Cancel ,
91+ ChildWindowIcon . Question
92+ ) ;
93+
94+ childWindow . Title = Strings . ResetSettingsQuestion ;
95+
96+ childWindow . DataContext = childWindowViewModel ;
8497
98+ ConfigurationManager . Current . IsChildWindowOpen = true ;
99+
100+ return ( Application . Current . MainWindow as MainWindow ) . ShowChildWindowAsync ( childWindow ) ;
101+ }
85102 #endregion
86- }
103+ }
0 commit comments