11using MahApps . Metro . Controls . Dialogs ;
2+ using MahApps . Metro . SimpleChildWindow ;
23using NETworkManager . Localization . Resources ;
34using NETworkManager . Settings ;
45using NETworkManager . Utilities ;
@@ -23,11 +24,6 @@ public class IPScannerSettingsViewModel : ViewModelBase
2324 /// </summary>
2425 private readonly bool _isLoading ;
2526
26- /// <summary>
27- /// The dialog coordinator instance.
28- /// </summary>
29- private readonly IDialogCoordinator _dialogCoordinator ;
30-
3127 /// <summary>
3228 /// Backing field for <see cref="ShowAllResults"/>.
3329 /// </summary>
@@ -373,13 +369,10 @@ public int MaxPortThreads
373369 /// <summary>
374370 /// Initializes a new instance of the <see cref="IPScannerSettingsViewModel"/> class.
375371 /// </summary>
376- /// <param name="instance">The dialog coordinator instance.</param>
377- public IPScannerSettingsViewModel ( IDialogCoordinator instance )
372+ public IPScannerSettingsViewModel ( )
378373 {
379374 _isLoading = true ;
380375
381- _dialogCoordinator = instance ;
382-
383376 CustomCommands = CollectionViewSource . GetDefaultView ( SettingsManager . Current . IPScanner_CustomCommands ) ;
384377 CustomCommands . SortDescriptions . Add ( new SortDescription ( nameof ( CustomCommandInfo . Name ) ,
385378 ListSortDirection . Ascending ) ) ;
@@ -457,56 +450,67 @@ private void DeleteCustomCommandAction()
457450 #region Methods
458451
459452 /// <summary>
460- /// Adds a new custom command.
453+ /// Add a new custom command.
461454 /// </summary>
462- private async void AddCustomCommand ( )
455+ private Task AddCustomCommand ( )
463456 {
464- var customDialog = new CustomDialog
465- {
466- Title = Strings . AddCustomCommand
467- } ;
457+ var childWindow = new CustomCommandChildWindow ( ) ;
468458
469- var customCommandViewModel = new CustomCommandViewModel ( instance =>
459+ var childWindowViewModel = new CustomCommandViewModel ( instance =>
460+ {
461+ childWindow . IsOpen = false ;
462+ ConfigurationManager . Current . IsChildWindowOpen = false ;
463+
464+ SettingsManager . Current . IPScanner_CustomCommands . Add ( new CustomCommandInfo (
465+ instance . ID ,
466+ instance . Name ,
467+ instance . FilePath ,
468+ instance . Arguments )
469+ ) ;
470+ } , _ =>
470471 {
471- _dialogCoordinator . HideMetroDialogAsync ( this , customDialog ) ;
472+ childWindow . IsOpen = false ;
473+ ConfigurationManager . Current . IsChildWindowOpen = false ;
474+ } ) ;
472475
473- SettingsManager . Current . IPScanner_CustomCommands . Add ( new CustomCommandInfo ( instance . ID , instance . Name ,
474- instance . FilePath , instance . Arguments ) ) ;
475- } , _ => { _dialogCoordinator . HideMetroDialogAsync ( this , customDialog ) ; } ) ;
476+ childWindow . Title = Strings . AddCustomCommand ;
476477
477- customDialog . Content = new CustomCommandDialog
478- {
479- DataContext = customCommandViewModel
480- } ;
478+ childWindow . DataContext = childWindowViewModel ;
479+
480+ ConfigurationManager . Current . IsChildWindowOpen = true ;
481481
482- await _dialogCoordinator . ShowMetroDialogAsync ( this , customDialog ) ;
482+ return Application . Current . MainWindow . ShowChildWindowAsync ( childWindow ) ;
483483 }
484484
485485 /// <summary>
486- /// Edits the selected custom command.
486+ /// Edit the selected custom command.
487487 /// </summary>
488- public async void EditCustomCommand ( )
488+ public Task EditCustomCommand ( )
489489 {
490- var customDialog = new CustomDialog
491- {
492- Title = Strings . EditCustomCommand
493- } ;
494490
495- var customCommandViewModel = new CustomCommandViewModel ( instance =>
491+ var childWindow = new CustomCommandChildWindow ( ) ;
492+
493+ var childWindowViewModel = new CustomCommandViewModel ( instance =>
496494 {
497- _dialogCoordinator . HideMetroDialogAsync ( this , customDialog ) ;
495+ childWindow . IsOpen = false ;
496+ ConfigurationManager . Current . IsChildWindowOpen = false ;
498497
499498 SettingsManager . Current . IPScanner_CustomCommands . Remove ( SelectedCustomCommand ) ;
500499 SettingsManager . Current . IPScanner_CustomCommands . Add ( new CustomCommandInfo ( instance . ID , instance . Name ,
501500 instance . FilePath , instance . Arguments ) ) ;
502- } , _ => { _dialogCoordinator . HideMetroDialogAsync ( this , customDialog ) ; } , true , SelectedCustomCommand ) ;
503-
504- customDialog . Content = new CustomCommandDialog
501+ } , _ =>
505502 {
506- DataContext = customCommandViewModel
507- } ;
503+ childWindow . IsOpen = false ;
504+ ConfigurationManager . Current . IsChildWindowOpen = false ;
505+ } , true , SelectedCustomCommand ) ;
506+
507+ childWindow . Title = Strings . EditCustomCommand ;
508+
509+ childWindow . DataContext = childWindowViewModel ;
510+
511+ ConfigurationManager . Current . IsChildWindowOpen = true ;
508512
509- await _dialogCoordinator . ShowMetroDialogAsync ( this , customDialog ) ;
513+ return Application . Current . MainWindow . ShowChildWindowAsync ( childWindow ) ;
510514 }
511515
512516 /// <summary>
0 commit comments