|
10 | 10 | using System; |
11 | 11 | using System.Collections.Generic; |
12 | 12 | using System.Configuration; |
| 13 | +using System.Diagnostics; |
13 | 14 | using System.Security; |
14 | 15 | using System.Threading.Tasks; |
15 | 16 | using System.Windows; |
@@ -308,7 +309,7 @@ private static GroupInfo ParseGroupInfo(GroupViewModel instance) |
308 | 309 | { |
309 | 310 | Name = name, |
310 | 311 | Description = instance.Description?.Trim(), |
311 | | - |
| 312 | + |
312 | 313 | Profiles = profiles, |
313 | 314 |
|
314 | 315 | // Remote Desktop |
@@ -468,133 +469,139 @@ private static GroupInfo ParseGroupInfo(GroupViewModel instance) |
468 | 469 |
|
469 | 470 | #region Dialog to add, edit, copy as and delete profile |
470 | 471 |
|
471 | | - public static Task ShowAddProfileDialog(Window parentWindow,IProfileManagerMinimal viewModel, |
| 472 | + public static Task ShowAddProfileDialog(Window parentWindow, IProfileManagerMinimal viewModel, |
472 | 473 | ProfileInfo profile = null, string group = null, |
473 | 474 | ApplicationName applicationName = ApplicationName.None) |
474 | 475 | { |
475 | | - |
476 | 476 | var childWindow = new ProfileChildWindow(parentWindow); |
477 | 477 |
|
478 | 478 | ProfileViewModel profileViewModel = new(instance => |
479 | 479 | { |
480 | 480 | childWindow.IsOpen = false; |
481 | | - Settings.ConfigurationManager.Current.IsChildWindowOpen = false; |
482 | | - |
| 481 | + Settings.ConfigurationManager.Current.IsChildWindowOpen = false; |
| 482 | + |
483 | 483 | viewModel.OnProfileManagerDialogClose(); |
484 | | - |
| 484 | + |
485 | 485 | ProfileManager.AddProfile(ParseProfileInfo(instance)); |
486 | 486 | }, _ => |
487 | 487 | { |
| 488 | + Debug.WriteLine("Profile dialog closed without saving"); |
| 489 | + |
488 | 490 | childWindow.IsOpen = false; |
489 | 491 | Settings.ConfigurationManager.Current.IsChildWindowOpen = false; |
490 | | - |
| 492 | + |
491 | 493 | viewModel.OnProfileManagerDialogClose(); |
492 | 494 | }, ProfileManager.GetGroupNames(), group, ProfileEditMode.Add, profile, applicationName); |
493 | 495 |
|
494 | 496 | childWindow.Title = Strings.AddProfile; |
495 | | - |
496 | | - childWindow.DataContext = profileViewModel; |
| 497 | + |
| 498 | + childWindow.DataContext = profileViewModel; |
| 499 | + |
| 500 | + viewModel.OnProfileManagerDialogOpen(); |
497 | 501 |
|
498 | 502 | Settings.ConfigurationManager.Current.IsChildWindowOpen = true; |
499 | 503 |
|
500 | 504 | return parentWindow.ShowChildWindowAsync(childWindow); |
501 | 505 | } |
502 | 506 |
|
503 | | - public static Task ShowEditProfileDialog(IProfileManagerMinimal viewModel, |
504 | | - IDialogCoordinator dialogCoordinator, ProfileInfo profile) |
| 507 | + public static Task ShowEditProfileDialog(Window parentWindow, IProfileManagerMinimal viewModel, |
| 508 | + ProfileInfo profile) |
505 | 509 | { |
506 | | - CustomDialog customDialog = new() |
507 | | - { |
508 | | - Title = Strings.EditProfile, |
509 | | - Style = (Style)Application.Current.FindResource(DialogResourceKey) |
510 | | - }; |
| 510 | + var childWindow = new ProfileChildWindow(parentWindow); |
511 | 511 |
|
512 | | - ProfileViewModel profileViewModel = new(async instance => |
| 512 | + ProfileViewModel profileViewModel = new(instance => |
513 | 513 | { |
514 | | - await dialogCoordinator.HideMetroDialogAsync(viewModel, customDialog); |
| 514 | + childWindow.IsOpen = false; |
| 515 | + Settings.ConfigurationManager.Current.IsChildWindowOpen = false; |
| 516 | + |
515 | 517 | viewModel.OnProfileManagerDialogClose(); |
516 | 518 |
|
517 | 519 | ProfileManager.ReplaceProfile(profile, ParseProfileInfo(instance)); |
518 | | - }, async _ => |
| 520 | + }, _ => |
519 | 521 | { |
520 | | - await dialogCoordinator.HideMetroDialogAsync(viewModel, customDialog); |
| 522 | + childWindow.IsOpen = false; |
| 523 | + Settings.ConfigurationManager.Current.IsChildWindowOpen = false; |
| 524 | + |
521 | 525 | viewModel.OnProfileManagerDialogClose(); |
522 | 526 | }, ProfileManager.GetGroupNames(), profile.Group, ProfileEditMode.Edit, profile); |
523 | 527 |
|
524 | | - customDialog.Content = new ProfileDialog |
525 | | - { |
526 | | - DataContext = profileViewModel |
527 | | - }; |
| 528 | + childWindow.Title = Strings.EditProfile; |
528 | 529 |
|
529 | | - viewModel.OnProfileManagerDialogOpen(); |
| 530 | + childWindow.DataContext = profileViewModel; |
530 | 531 |
|
531 | | - return dialogCoordinator.ShowMetroDialogAsync(viewModel, customDialog); |
| 532 | + viewModel.OnProfileManagerDialogOpen(); |
| 533 | + |
| 534 | + Settings.ConfigurationManager.Current.IsChildWindowOpen = true; |
| 535 | + |
| 536 | + return parentWindow.ShowChildWindowAsync(childWindow); |
532 | 537 | } |
533 | 538 |
|
534 | | - public static Task ShowCopyAsProfileDialog(IProfileManagerMinimal viewModel, |
535 | | - IDialogCoordinator dialogCoordinator, ProfileInfo profile) |
| 539 | + public static Task ShowCopyAsProfileDialog(Window parentWindow, IProfileManagerMinimal viewModel, |
| 540 | + ProfileInfo profile) |
536 | 541 | { |
537 | | - CustomDialog customDialog = new() |
538 | | - { |
539 | | - Title = Strings.CopyProfile, |
540 | | - Style = (Style)Application.Current.FindResource(DialogResourceKey) |
541 | | - }; |
| 542 | + var childWindow = new ProfileChildWindow(parentWindow); |
542 | 543 |
|
543 | | - ProfileViewModel profileViewModel = new(async instance => |
| 544 | + ProfileViewModel profileViewModel = new(instance => |
544 | 545 | { |
545 | | - await dialogCoordinator.HideMetroDialogAsync(viewModel, customDialog); |
| 546 | + childWindow.IsOpen = false; |
| 547 | + Settings.ConfigurationManager.Current.IsChildWindowOpen = false; |
| 548 | + |
546 | 549 | viewModel.OnProfileManagerDialogClose(); |
547 | 550 |
|
548 | 551 | ProfileManager.AddProfile(ParseProfileInfo(instance)); |
549 | | - }, async _ => |
| 552 | + }, _ => |
550 | 553 | { |
551 | | - await dialogCoordinator.HideMetroDialogAsync(viewModel, customDialog); |
| 554 | + childWindow.IsOpen = false; |
| 555 | + Settings.ConfigurationManager.Current.IsChildWindowOpen = false; |
| 556 | + |
552 | 557 | viewModel.OnProfileManagerDialogClose(); |
553 | 558 | }, ProfileManager.GetGroupNames(), profile.Group, ProfileEditMode.Copy, profile); |
554 | 559 |
|
555 | | - customDialog.Content = new ProfileDialog |
556 | | - { |
557 | | - DataContext = profileViewModel |
558 | | - }; |
559 | | - |
| 560 | + childWindow.Title = Strings.CopyProfile; |
| 561 | + |
| 562 | + childWindow.DataContext = profileViewModel; |
| 563 | + |
560 | 564 | viewModel.OnProfileManagerDialogOpen(); |
| 565 | + |
| 566 | + Settings.ConfigurationManager.Current.IsChildWindowOpen = true; |
561 | 567 |
|
562 | | - return dialogCoordinator.ShowMetroDialogAsync(viewModel, customDialog); |
| 568 | + return parentWindow.ShowChildWindowAsync(childWindow); |
563 | 569 | } |
564 | 570 |
|
565 | | - public static Task ShowDeleteProfileDialog(IProfileManagerMinimal viewModel, |
566 | | - IDialogCoordinator dialogCoordinator, IList<ProfileInfo> profiles) |
| 571 | + public static Task ShowDeleteProfileDialog(Window parentWindow, IProfileManagerMinimal viewModel, |
| 572 | + IList<ProfileInfo> profiles) |
567 | 573 | { |
568 | | - CustomDialog customDialog = new() |
569 | | - { |
570 | | - Title = profiles.Count == 1 |
571 | | - ? Strings.DeleteProfile |
572 | | - : Strings.DeleteProfiles |
573 | | - }; |
574 | | - |
575 | | - ConfirmDeleteViewModel confirmDeleteViewModel = new(async _ => |
| 574 | + var childWindow = new ConfirmDeleteChildWindow(); |
| 575 | + |
| 576 | + ConfirmDeleteViewModel confirmDeleteViewModel = new(_ => |
576 | 577 | { |
577 | | - await dialogCoordinator.HideMetroDialogAsync(viewModel, customDialog); |
| 578 | + childWindow.IsOpen = false; |
| 579 | + Settings.ConfigurationManager.Current.IsChildWindowOpen = false; |
| 580 | + |
578 | 581 | viewModel.OnProfileManagerDialogClose(); |
579 | 582 |
|
580 | 583 | ProfileManager.RemoveProfiles(profiles); |
581 | | - }, async _ => |
| 584 | + }, _ => |
582 | 585 | { |
583 | | - await dialogCoordinator.HideMetroDialogAsync(viewModel, customDialog); |
| 586 | + childWindow.IsOpen = false; |
| 587 | + Settings.ConfigurationManager.Current.IsChildWindowOpen = false; |
| 588 | + |
| 589 | + |
584 | 590 | viewModel.OnProfileManagerDialogClose(); |
585 | 591 | }, |
586 | 592 | profiles.Count == 1 |
587 | 593 | ? Strings.DeleteProfileMessage |
588 | 594 | : Strings.DeleteProfilesMessage); |
589 | 595 |
|
590 | | - customDialog.Content = new ConfirmDeleteDialog |
591 | | - { |
592 | | - DataContext = confirmDeleteViewModel |
593 | | - }; |
| 596 | + childWindow.Title = Strings.DeleteProfile; |
| 597 | + |
| 598 | + childWindow.DataContext = confirmDeleteViewModel; |
594 | 599 |
|
595 | 600 | viewModel.OnProfileManagerDialogOpen(); |
| 601 | + |
| 602 | + Settings.ConfigurationManager.Current.IsChildWindowOpen = true; |
596 | 603 |
|
597 | | - return dialogCoordinator.ShowMetroDialogAsync(viewModel, customDialog); |
| 604 | + return parentWindow.ShowChildWindowAsync(childWindow); |
598 | 605 | } |
599 | 606 |
|
600 | 607 | #endregion |
|
0 commit comments