@@ -133,15 +133,16 @@ private async Task AddProfileFileAction()
133133
134134 await ( Application . Current . MainWindow as MainWindow ) . ShowChildWindowAsync ( childWindow ) ;
135135
136+ // Re-select the profile file
136137 if ( string . IsNullOrEmpty ( profileName ) )
137138 return ;
138139
139140 SelectedProfileFile = ProfileFiles . Cast < ProfileFileInfo > ( )
140141 . FirstOrDefault ( p => p . Name . Equals ( profileName , StringComparison . OrdinalIgnoreCase ) ) ;
141142
142- // Ask to enable encryption for the new profile file
143- var result = await DialogHelper . ShowOKCancelMessageAsync ( Application . Current . MainWindow ,
144- Strings . EnableEncryptionQuestion ,
143+ // Ask the user if they want to enable encryption for the new profile file
144+ var result = await DialogHelper . ShowOKCancelMessageAsync ( Application . Current . MainWindow ,
145+ Strings . EnableEncryptionQuestion ,
145146 Strings . EnableEncryptionForProfileFileMessage ) ;
146147
147148 if ( result )
@@ -178,6 +179,7 @@ private async Task EditProfileFileAction()
178179
179180 await ( Application . Current . MainWindow as MainWindow ) . ShowChildWindowAsync ( childWindow ) ;
180181
182+ // Re-select the profile file
181183 if ( string . IsNullOrEmpty ( profileName ) )
182184 return ;
183185
@@ -193,7 +195,7 @@ private bool DeleteProfileFile_CanExecute(object obj)
193195 return ProfileFiles . Cast < ProfileFileInfo > ( ) . Count ( ) > 1 ;
194196 }
195197
196- private Task DeleteProfileFileAction ( )
198+ private async Task DeleteProfileFileAction ( )
197199 {
198200 var childWindow = new OKCancelMessageChildWindow ( ) ;
199201
@@ -216,14 +218,20 @@ private Task DeleteProfileFileAction()
216218
217219 ConfigurationManager . Current . IsChildWindowOpen = true ;
218220
219- return ( Application . Current . MainWindow as MainWindow ) . ShowChildWindowAsync ( childWindow ) ;
221+ await ( Application . Current . MainWindow as MainWindow ) . ShowChildWindowAsync ( childWindow ) ;
222+
223+ // Select the first profile file
224+ SelectedProfileFile = ProfileFiles . Cast < ProfileFileInfo > ( ) . FirstOrDefault ( ) ;
220225 }
221226
222227 public ICommand EnableEncryptionCommand => new RelayCommand ( _ => EnableEncryptionAction ( ) ) ;
223228
224229 private async void EnableEncryptionAction ( )
225230 {
226- if ( ! await ShowEncryptionDisclaimerAsync ( ) )
231+ // Show encryption disclaimer
232+ if ( ! await DialogHelper . ShowOKCancelMessageAsync ( Application . Current . MainWindow ,
233+ Strings . Disclaimer ,
234+ Strings . ProfileEncryptionDisclaimer ) )
227235 return ;
228236
229237 var customDialog = new CustomDialog
@@ -257,87 +265,66 @@ await _dialogCoordinator.ShowMessageAsync(this, Strings.EncryptionError,
257265
258266 await _dialogCoordinator . ShowMetroDialogAsync ( this , customDialog ) ;
259267 }
268+
269+ public ICommand ChangeMasterPasswordCommand => new RelayCommand ( async _ => await ChangeMasterPasswordAction ( ) . ConfigureAwait ( false ) ) ;
260270
261- private async Task < bool > ShowEncryptionDisclaimerAsync ( )
271+ private async Task ChangeMasterPasswordAction ( )
262272 {
263- var result = false ;
264-
265- var childWindow = new OKCancelMessageChildWindow ( ) ;
273+ var profileName = SelectedProfileFile . Name ;
266274
267- var childWindowViewModel = new OKCancelMessageViewModel ( _ =>
268- {
269- childWindow . IsOpen = false ;
270- ConfigurationManager . Current . IsChildWindowOpen = false ;
275+ var childWindow = new CredentialsChangePasswordChildWindow ( ) ;
271276
272- result = true ;
273- } , _ =>
277+ var childWindowViewModel = new CredentialsChangePasswordViewModel ( async instance =>
274278 {
275279 childWindow . IsOpen = false ;
276280 ConfigurationManager . Current . IsChildWindowOpen = false ;
277- } ,
278- Strings . ProfileEncryptionDisclaimer
279- ) ;
280-
281- childWindow . Title = Strings . Disclaimer ;
282-
283- childWindow . DataContext = childWindowViewModel ;
284-
285- ConfigurationManager . Current . IsChildWindowOpen = true ;
286-
287- await ( Application . Current . MainWindow as MainWindow ) . ShowChildWindowAsync ( childWindow ) ;
288-
289- return result ;
290- }
291-
292- public ICommand ChangeMasterPasswordCommand => new RelayCommand ( _ => ChangeMasterPasswordAction ( ) ) ;
293-
294- private async void ChangeMasterPasswordAction ( )
295- {
296- var customDialog = new CustomDialog
297- {
298- Title = Strings . ChangeMasterPassword
299- } ;
300-
301- var credentialsPasswordViewModel = new CredentialsChangePasswordViewModel ( async instance =>
302- {
303- await _dialogCoordinator . HideMetroDialogAsync ( this , customDialog ) ;
304281
305282 try
306283 {
307284 ProfileManager . ChangeMasterPassword ( SelectedProfileFile , instance . Password , instance . NewPassword ) ;
308285 }
309286 catch ( CryptographicException )
310287 {
311- var settings = AppearanceManager . MetroDialog ;
312- settings . AffirmativeButtonText = Strings . OK ;
313-
314- await _dialogCoordinator . ShowMessageAsync ( this , Strings . WrongPassword ,
315- Strings . WrongPasswordDecryptionFailedMessage , MessageDialogStyle . Affirmative ,
316- settings ) ;
288+ await DialogHelper . ShowOKMessageAsync ( Application . Current . MainWindow ,
289+ Strings . WrongPassword ,
290+ Strings . WrongPasswordDecryptionFailedMessage ,
291+ ChildWindowIcon . Error ) . ConfigureAwait ( false ) ;
317292 }
318293 catch ( Exception ex )
319294 {
320- var settings = AppearanceManager . MetroDialog ;
321- settings . AffirmativeButtonText = Strings . OK ;
322-
323- await _dialogCoordinator . ShowMessageAsync ( this , Strings . DecryptionError ,
295+ await DialogHelper . ShowOKMessageAsync ( Application . Current . MainWindow ,
296+ Strings . DecryptionError ,
324297 $ "{ Strings . DecryptionErrorMessage } \n \n { ex . Message } ",
325- MessageDialogStyle . Affirmative , settings ) ;
298+ ChildWindowIcon . Error ) . ConfigureAwait ( false ) ;
326299 }
327- } , async _ => { await _dialogCoordinator . HideMetroDialogAsync ( this , customDialog ) ; } ) ;
328-
329- customDialog . Content = new CredentialsChangePasswordDialog
300+ } , _ =>
330301 {
331- DataContext = credentialsPasswordViewModel
332- } ;
302+ childWindow . IsOpen = false ;
303+ ConfigurationManager . Current . IsChildWindowOpen = false ;
304+ } ) ;
333305
334- await _dialogCoordinator . ShowMetroDialogAsync ( this , customDialog ) ;
306+ childWindow . Title = Strings . ChangeMasterPassword ;
307+
308+ childWindow . DataContext = childWindowViewModel ;
309+
310+ ConfigurationManager . Current . IsChildWindowOpen = true ;
311+
312+ await ( Application . Current . MainWindow as MainWindow ) . ShowChildWindowAsync ( childWindow ) ;
313+
314+ // Re-select the profile file
315+ if ( string . IsNullOrEmpty ( profileName ) )
316+ return ;
317+
318+ SelectedProfileFile = ProfileFiles . Cast < ProfileFileInfo > ( )
319+ . FirstOrDefault ( p => p . Name . Equals ( profileName , StringComparison . OrdinalIgnoreCase ) ) ;
335320 }
336321
337322 public ICommand DisableEncryptionCommand => new RelayCommand ( async _ => await DisableEncryptionAction ( ) . ConfigureAwait ( false ) ) ;
338323
339- private Task DisableEncryptionAction ( )
324+ private async Task DisableEncryptionAction ( )
340325 {
326+ var profileName = SelectedProfileFile . Name ;
327+
341328 var childWindow = new CredentialsPasswordChildWindow ( ) ;
342329
343330 var childWindowViewModel = new CredentialsPasswordViewModel ( async instance =>
@@ -376,8 +363,15 @@ await DialogHelper.ShowOKMessageAsync(Application.Current.MainWindow,
376363
377364 ConfigurationManager . Current . IsChildWindowOpen = true ;
378365
379- return ( Application . Current . MainWindow as MainWindow ) . ShowChildWindowAsync ( childWindow ) ;
366+ await ( Application . Current . MainWindow as MainWindow ) . ShowChildWindowAsync ( childWindow ) ;
367+
368+ // Re-select the profile file
369+ if ( string . IsNullOrEmpty ( profileName ) )
370+ return ;
371+
372+ SelectedProfileFile = ProfileFiles . Cast < ProfileFileInfo > ( )
373+ . FirstOrDefault ( p => p . Name . Equals ( profileName , StringComparison . OrdinalIgnoreCase ) ) ;
380374 }
381375
382376 #endregion
383- }
377+ }
0 commit comments