@@ -82,6 +82,8 @@ public SettingsProfilesViewModel(IDialogCoordinator instance)
8282 ProfileFiles . SortDescriptions . Add (
8383 new SortDescription ( nameof ( ProfileFileInfo . Name ) , ListSortDirection . Ascending ) ) ;
8484
85+ SelectedProfileFile = ProfileFiles . Cast < ProfileFileInfo > ( ) . FirstOrDefault ( ) ;
86+
8587 LoadSettings ( ) ;
8688 }
8789
@@ -101,52 +103,113 @@ private static void OpenLocationAction()
101103 Process . Start ( "explorer.exe" , ProfileManager . GetProfilesFolderLocation ( ) ) ;
102104 }
103105
104- public ICommand AddProfileFileCommand => new RelayCommand ( _ => AddProfileFileAction ( ) ) ;
106+ public ICommand AddProfileFileCommand => new RelayCommand ( async _ => await AddProfileFileAction ( ) . ConfigureAwait ( false ) ) ;
105107
106- private async void AddProfileFileAction ( )
108+ private async Task AddProfileFileAction ( )
107109 {
108- var customDialog = new CustomDialog
109- {
110- Title = Strings . AddProfileFile
111- } ;
110+ var profileName = string . Empty ;
111+
112+ var childWindow = new ProfileFileChildWindow ( ) ;
112113
113- var profileFileViewModel = new ProfileFileViewModel ( async instance =>
114+ var childWindowViewModel = new ProfileFileViewModel ( instance =>
114115 {
115- await _dialogCoordinator . HideMetroDialogAsync ( this , customDialog ) ;
116+ childWindow . IsOpen = false ;
117+ ConfigurationManager . Current . IsChildWindowOpen = false ;
118+
119+ profileName = instance . Name ;
116120
117121 ProfileManager . CreateEmptyProfileFile ( instance . Name ) ;
118- } , async _ => { await _dialogCoordinator . HideMetroDialogAsync ( this , customDialog ) ; } ) ;
122+ } , _ =>
123+ {
124+ childWindow . IsOpen = false ;
125+ ConfigurationManager . Current . IsChildWindowOpen = false ;
126+ } ) ;
127+
128+ childWindow . Title = Strings . AddProfileFile ;
129+
130+ childWindow . DataContext = childWindowViewModel ;
131+
132+ ConfigurationManager . Current . IsChildWindowOpen = true ;
133+
134+ await ( Application . Current . MainWindow as MainWindow ) . ShowChildWindowAsync ( childWindow ) ;
135+
136+ if ( string . IsNullOrEmpty ( profileName ) )
137+ return ;
138+
139+ SelectedProfileFile = ProfileFiles . Cast < ProfileFileInfo > ( )
140+ . FirstOrDefault ( p => p . Name . Equals ( profileName , StringComparison . OrdinalIgnoreCase ) ) ;
119141
120- customDialog . Content = new ProfileFileDialog
142+ // Ask to enable encryption for the new profile file
143+ if ( await ShowEnableEncryptionMessage ( ) )
144+ EnableEncryptionAction ( ) ;
145+ }
146+
147+ private async Task < bool > ShowEnableEncryptionMessage ( )
148+ {
149+ var result = false ;
150+
151+ var childWindow = new OKCancelInfoMessageChildWindow ( ) ;
152+
153+ var childWindowViewModel = new OKCancelInfoMessageViewModel ( _ =>
121154 {
122- DataContext = profileFileViewModel
123- } ;
155+ childWindow . IsOpen = false ;
156+ ConfigurationManager . Current . IsChildWindowOpen = false ;
124157
125- await _dialogCoordinator . ShowMetroDialogAsync ( this , customDialog ) ;
158+ result = true ;
159+ } , _ =>
160+ {
161+ childWindow . IsOpen = false ;
162+ ConfigurationManager . Current . IsChildWindowOpen = false ;
163+ } ,
164+ Strings . EnableEncryptionForProfileFileMessage
165+ ) ;
166+
167+ childWindow . Title = Strings . EnableEncryptionQuestion ;
168+
169+ childWindow . DataContext = childWindowViewModel ;
170+
171+ ConfigurationManager . Current . IsChildWindowOpen = true ;
172+
173+ await ( Application . Current . MainWindow as MainWindow ) . ShowChildWindowAsync ( childWindow ) ;
174+
175+ return result ;
126176 }
127177
128- public ICommand EditProfileFileCommand => new RelayCommand ( _ => EditProfileFileAction ( ) ) ;
178+ public ICommand EditProfileFileCommand => new RelayCommand ( async _ => await EditProfileFileAction ( ) . ConfigureAwait ( false ) ) ;
129179
130- private async void EditProfileFileAction ( )
180+ private async Task EditProfileFileAction ( )
131181 {
132- var customDialog = new CustomDialog
133- {
134- Title = Strings . EditProfileFile
135- } ;
182+ var profileName = string . Empty ;
183+
184+ var childWindow = new ProfileFileChildWindow ( ) ;
136185
137- var profileFileViewModel = new ProfileFileViewModel ( async instance =>
186+ var childWindowViewModel = new ProfileFileViewModel ( instance =>
138187 {
139- await _dialogCoordinator . HideMetroDialogAsync ( this , customDialog ) ;
188+ childWindow . IsOpen = false ;
189+ ConfigurationManager . Current . IsChildWindowOpen = false ;
140190
141- ProfileManager . RenameProfileFile ( SelectedProfileFile , instance . Name ) ;
142- } , async _ => { await _dialogCoordinator . HideMetroDialogAsync ( this , customDialog ) ; } , SelectedProfileFile ) ;
191+ profileName = instance . Name ;
143192
144- customDialog . Content = new ProfileFileDialog
193+ ProfileManager . RenameProfileFile ( SelectedProfileFile , instance . Name ) ;
194+ } , _ =>
145195 {
146- DataContext = profileFileViewModel
147- } ;
196+ childWindow . IsOpen = false ;
197+ ConfigurationManager . Current . IsChildWindowOpen = false ;
198+ } , SelectedProfileFile ) ;
148199
149- await _dialogCoordinator . ShowMetroDialogAsync ( this , customDialog ) ;
200+ childWindow . Title = Strings . EditProfileFile ;
201+
202+ childWindow . DataContext = childWindowViewModel ;
203+
204+ ConfigurationManager . Current . IsChildWindowOpen = true ;
205+
206+ await ( Application . Current . MainWindow as MainWindow ) . ShowChildWindowAsync ( childWindow ) ;
207+
208+ if ( string . IsNullOrEmpty ( profileName ) )
209+ return ;
210+
211+ SelectedProfileFile = ProfileFiles . Cast < ProfileFileInfo > ( )
212+ . FirstOrDefault ( p => p . Name . Equals ( profileName , StringComparison . OrdinalIgnoreCase ) ) ;
150213 }
151214
152215 public ICommand DeleteProfileFileCommand =>
@@ -172,7 +235,7 @@ private Task DeleteProfileFileAction()
172235 childWindow . IsOpen = false ;
173236 ConfigurationManager . Current . IsChildWindowOpen = false ;
174237 } ,
175- Strings . DeleteProfileFileMessage , Strings . Delete ) ;
238+ string . Format ( Strings . DeleteProfileFileXMessage , SelectedProfileFile . Name ) , Strings . Delete ) ;
176239
177240 childWindow . Title = Strings . DeleteProfileFile ;
178241
@@ -187,13 +250,7 @@ private Task DeleteProfileFileAction()
187250
188251 private async void EnableEncryptionAction ( )
189252 {
190- var settings = AppearanceManager . MetroDialog ;
191-
192- settings . AffirmativeButtonText = Strings . OK ;
193- settings . NegativeButtonText = Strings . Cancel ;
194- settings . DefaultButtonFocus = MessageDialogResult . Affirmative ;
195-
196- if ( await _dialogCoordinator . ShowMessageAsync ( this , Strings . Disclaimer , Strings . ProfileEncryptionDisclaimer , MessageDialogStyle . AffirmativeAndNegative , settings ) != MessageDialogResult . Affirmative )
253+ if ( ! await ShowEncryptionDisclaimerAsync ( ) )
197254 return ;
198255
199256 var customDialog = new CustomDialog
@@ -228,6 +285,37 @@ await _dialogCoordinator.ShowMessageAsync(this, Strings.EncryptionError,
228285 await _dialogCoordinator . ShowMetroDialogAsync ( this , customDialog ) ;
229286 }
230287
288+ private async Task < bool > ShowEncryptionDisclaimerAsync ( )
289+ {
290+ var result = false ;
291+
292+ var childWindow = new OKCancelInfoMessageChildWindow ( ) ;
293+
294+ var childWindowViewModel = new OKCancelInfoMessageViewModel ( _ =>
295+ {
296+ childWindow . IsOpen = false ;
297+ ConfigurationManager . Current . IsChildWindowOpen = false ;
298+
299+ result = true ;
300+ } , _ =>
301+ {
302+ childWindow . IsOpen = false ;
303+ ConfigurationManager . Current . IsChildWindowOpen = false ;
304+ } ,
305+ Strings . ProfileEncryptionDisclaimer
306+ ) ;
307+
308+ childWindow . Title = Strings . Disclaimer ;
309+
310+ childWindow . DataContext = childWindowViewModel ;
311+
312+ ConfigurationManager . Current . IsChildWindowOpen = true ;
313+
314+ await ( Application . Current . MainWindow as MainWindow ) . ShowChildWindowAsync ( childWindow ) ;
315+
316+ return result ;
317+ }
318+
231319 public ICommand ChangeMasterPasswordCommand => new RelayCommand ( _ => ChangeMasterPasswordAction ( ) ) ;
232320
233321 private async void ChangeMasterPasswordAction ( )
0 commit comments