Skip to content

Commit 83d9758

Browse files
committed
Chore: Migrate dialogs...
1 parent c981aa0 commit 83d9758

20 files changed

+86
-128
lines changed

Source/NETworkManager/Controls/PowerShellControl.xaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
xmlns:localization="clr-namespace:NETworkManager.Localization.Resources;assembly=NETworkManager.Localization"
99
xmlns:local="clr-namespace:NETworkManager.Controls"
1010
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
11-
xmlns:settings="clr-namespace:NETworkManager.Settings;assembly=NETworkManager.Settings"
12-
mah:DialogParticipation.Register="{Binding}"
11+
xmlns:settings="clr-namespace:NETworkManager.Settings;assembly=NETworkManager.Settings"
1312
mc:Ignorable="d" Loaded="UserControl_Loaded"
1413
d:DataContext="{d:DesignInstance local:PowerShellControl}">
1514
<local:UserControlBase.Resources>

Source/NETworkManager/Controls/PowerShellControl.xaml.cs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Threading.Tasks;
66
using System.Windows;
77
using System.Windows.Input;
8-
using MahApps.Metro.Controls.Dialogs;
98
using NETworkManager.Localization.Resources;
109
using NETworkManager.Models.PowerShell;
1110
using NETworkManager.Settings;
@@ -29,8 +28,6 @@ private void WindowGrid_SizeChanged(object sender, SizeChangedEventArgs e)
2928
private bool _initialized;
3029
private bool _closed;
3130

32-
private readonly IDialogCoordinator _dialogCoordinator;
33-
3431
private readonly Guid _tabId;
3532
private readonly PowerShellSessionInfo _sessionInfo;
3633

@@ -76,8 +73,6 @@ public PowerShellControl(Guid tabId, PowerShellSessionInfo sessionInfo)
7673
InitializeComponent();
7774
DataContext = this;
7875

79-
_dialogCoordinator = DialogCoordinator.Instance;
80-
8176
ConfigurationManager.Current.PowerShellTabCount++;
8277

8378
_tabId = tabId;
@@ -196,17 +191,7 @@ private async Task Connect()
196191
catch (Exception ex)
197192
{
198193
if (!_closed)
199-
{
200-
var settings = AppearanceManager.MetroDialog;
201-
settings.AffirmativeButtonText = Strings.OK;
202-
203-
ConfigurationManager.OnDialogOpen();
204-
205-
await _dialogCoordinator.ShowMessageAsync(this, Strings.Error,
206-
ex.Message, MessageDialogStyle.Affirmative, settings);
207-
208-
ConfigurationManager.OnDialogClose();
209-
}
194+
await DialogHelper.ShowMessageAsync(Application.Current.MainWindow, Strings.Error, ex.Message, ChildWindowIcon.Error);
210195
}
211196

212197
IsConnecting = false;

Source/NETworkManager/DialogHelper.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ public static class DialogHelper
2424
/// <param name="title">The title text displayed in the message dialog window. Cannot be null.</param>
2525
/// <param name="message">The main message content shown in the dialog. Cannot be null.</param>
2626
/// <param name="icon">The icon to display in the dialog, indicating the message type. Defaults to Info if not specified.</param>
27-
/// <param name="buttonOKText">The text to display on the OK button. If null, a default value is used.</param>
27+
/// <param name="confirmButtonText">The text to display on the confirm button. If null, a default value is used.</param>
2828
/// <returns>A task that completes when the user closes the message dialog.</returns>
29-
public static Task ShowOKMessageAsync(Window parentWindow, string title, string message, ChildWindowIcon icon = ChildWindowIcon.Info, string buttonOKText = null)
30-
{
31-
buttonOKText ??= Strings.OK;
29+
public static Task ShowMessageAsync(Window parentWindow, string title, string message, ChildWindowIcon icon = ChildWindowIcon.Info, string confirmButtonText = null)
30+
{
31+
confirmButtonText ??= Strings.OK;
3232

33-
var childWindow = new OKMessageChildWindow();
33+
var childWindow = new MessageChildWindow();
3434

35-
var childWindowViewModel = new OKMessageViewModel(_ =>
35+
var childWindowViewModel = new MessageViewModel(_ =>
3636
{
3737
childWindow.IsOpen = false;
3838
ConfigurationManager.Current.IsChildWindowOpen = false;
39-
}, message, icon, buttonOKText);
39+
}, message, icon, confirmButtonText);
4040

4141
childWindow.Title = title;
4242

@@ -58,20 +58,20 @@ public static Task ShowOKMessageAsync(Window parentWindow, string title, string
5858
/// <param name="title">The title text displayed in the dialog window.</param>
5959
/// <param name="message">The message content shown to the user in the dialog.</param>
6060
/// <param name="icon">The icon displayed in the dialog to indicate the message type. Defaults to Info.</param>
61-
/// <param name="buttonOKText">The text label for the OK button. If null, a default value is used.</param>
62-
/// <param name="buttonCancelText">The text label for the Cancel button. If null, a default value is used.</param>
61+
/// <param name="confirmButtonText">The text label for the confirm button. If null, a default value is used.</param>
62+
/// <param name="cancelButtonText">The text label for the cancel button. If null, a default value is used.</param>
6363
/// <returns>A task that represents the asynchronous operation. The task result is <see langword="true"/> if the user
6464
/// clicks OK; otherwise, <see langword="false"/>.</returns>
65-
public static async Task<bool> ShowOKCancelMessageAsync(Window parentWindow, string title, string message, ChildWindowIcon icon = ChildWindowIcon.Info, string buttonOKText = null, string buttonCancelText = null)
65+
public static async Task<bool> ShowConfirmationMessageAsync(Window parentWindow, string title, string message, ChildWindowIcon icon = ChildWindowIcon.Info, string confirmButtonText = null, string cancelButtonText = null)
6666
{
67-
buttonOKText ??= Strings.OK;
68-
buttonCancelText ??= Strings.Cancel;
67+
confirmButtonText ??= Strings.OK;
68+
cancelButtonText ??= Strings.Cancel;
6969

7070
var result = false;
7171

72-
var childWindow = new OKCancelMessageChildWindow();
72+
var childWindow = new MessageConfirmationChildWindow();
7373

74-
var childWindowViewModel = new OKCancelMessageViewModel(_ =>
74+
var childWindowViewModel = new MessageConfirmationViewModel(_ =>
7575
{
7676
childWindow.IsOpen = false;
7777
ConfigurationManager.Current.IsChildWindowOpen = false;
@@ -83,7 +83,7 @@ public static async Task<bool> ShowOKCancelMessageAsync(Window parentWindow, str
8383
childWindow.IsOpen = false;
8484
ConfigurationManager.Current.IsChildWindowOpen = false;
8585
},
86-
message, icon, buttonOKText, buttonCancelText);
86+
message, icon, confirmButtonText, cancelButtonText);
8787

8888
childWindow.Title = title;
8989
childWindow.DataContext = childWindowViewModel;

Source/NETworkManager/NETworkManager.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
<XamlRuntime>Wpf</XamlRuntime>
142142
<SubType>Designer</SubType>
143143
</Page>
144-
<Page Update="Views\OKCancelMessageChildWindow.xaml">
144+
<Page Update="Views\MessageConfirmationChildWindow.xaml">
145145
<Generator>MSBuild:Compile</Generator>
146146
<XamlRuntime>Wpf</XamlRuntime>
147147
<SubType>Designer</SubType>

Source/NETworkManager/ProfileDialogManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ public static async Task ShowDeleteProfileDialog(Window parentWindow, IProfileMa
553553

554554
viewModel.OnProfileManagerDialogOpen();
555555

556-
var result = await DialogHelper.ShowOKCancelMessageAsync(parentWindow,
556+
var result = await DialogHelper.ShowConfirmationMessageAsync(parentWindow,
557557
profiles.Count == 1 ? Strings.DeleteProfile : Strings.DeleteProfiles,
558558
profiles.Count == 1 ? Strings.DeleteProfileMessage : Strings.DeleteProfilesMessage,
559559
ChildWindowIcon.Info,
@@ -639,7 +639,7 @@ public static async Task ShowDeleteGroupDialog(Window parentWindow, IProfileMana
639639
{
640640
viewModel.OnProfileManagerDialogOpen();
641641

642-
var result = await DialogHelper.ShowOKCancelMessageAsync(parentWindow,
642+
var result = await DialogHelper.ShowConfirmationMessageAsync(parentWindow,
643643
Strings.DeleteGroup,
644644
Strings.DeleteGroupMessage,
645645
ChildWindowIcon.Info,

Source/NETworkManager/ViewModels/DNSLookupSettingsViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ public async Task EditDNSServer()
481481
/// </summary>
482482
private async Task DeleteDNSServer()
483483
{
484-
var result = await DialogHelper.ShowOKCancelMessageAsync(Application.Current.MainWindow,
484+
var result = await DialogHelper.ShowConfirmationMessageAsync(Application.Current.MainWindow,
485485
Strings.DeleteDNSServer,
486486
Strings.DeleteDNSServerMessage,
487487
ChildWindowIcon.Info,

Source/NETworkManager/ViewModels/HostsFileEditorViewModel.cs

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ private async Task DeleteEntryAction()
505505
{
506506
IsModifying = true;
507507

508-
var result = await DialogHelper.ShowOKCancelMessageAsync(Application.Current.MainWindow,
508+
var result = await DialogHelper.ShowConfirmationMessageAsync(Application.Current.MainWindow,
509509
Strings.DeleteEntry,
510510
string.Format(Strings.DeleteHostsFileEntryMessage, SelectedResult.IPAddress, SelectedResult.Hostname,
511511
string.IsNullOrEmpty(SelectedResult.Comment) ? "" : $"# {SelectedResult.Comment}"),
@@ -557,21 +557,8 @@ private async Task ShowErrorMessageAsync(HostsFileEntryModifyResult result)
557557
_ => Strings.UnkownError
558558
};
559559

560-
var childWindow = new OKMessageChildWindow();
561-
562-
var childWindowViewModel = new OKMessageViewModel(_ =>
563-
{
564-
childWindow.IsOpen = false;
565-
ConfigurationManager.Current.IsChildWindowOpen = false;
566-
}, message, ChildWindowIcon.Error, Strings.OK);
567-
568-
childWindow.Title = Strings.Error;
569-
570-
childWindow.DataContext = childWindowViewModel;
571-
572-
ConfigurationManager.Current.IsChildWindowOpen = true;
573-
574-
await (Application.Current.MainWindow as MainWindow).ShowChildWindowAsync(childWindow);
560+
await DialogHelper.ShowMessageAsync(Application.Current.MainWindow, Strings.Error, message,
561+
ChildWindowIcon.Error);
575562
}
576563

577564
/// <summary>
@@ -590,21 +577,8 @@ private async Task RestartAsAdminAction()
590577
}
591578
catch (Exception ex)
592579
{
593-
var childWindow = new OKMessageChildWindow();
594-
595-
var childWindowViewModel = new OKMessageViewModel(_ =>
596-
{
597-
childWindow.IsOpen = false;
598-
ConfigurationManager.Current.IsChildWindowOpen = false;
599-
}, ex.Message, ChildWindowIcon.Error, Strings.OK);
600-
601-
childWindow.Title = Strings.Error;
602-
603-
childWindow.DataContext = childWindowViewModel;
604-
605-
ConfigurationManager.Current.IsChildWindowOpen = true;
606-
607-
await (Application.Current.MainWindow as MainWindow).ShowChildWindowAsync(childWindow);
580+
await DialogHelper.ShowMessageAsync(Application.Current.MainWindow, Strings.Error, ex.Message,
581+
ChildWindowIcon.Error);
608582
}
609583
}
610584

Source/NETworkManager/ViewModels/IPScannerSettingsViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ public async void EditCustomCommand()
515515
/// </summary>
516516
private async Task DeleteCustomCommand()
517517
{
518-
var result = await DialogHelper.ShowOKCancelMessageAsync(Application.Current.MainWindow,
518+
var result = await DialogHelper.ShowConfirmationMessageAsync(Application.Current.MainWindow,
519519
Strings.DeleteCustomCommand,
520520
Strings.DeleteCustomCommandMessage,
521521
ChildWindowIcon.Info,

Source/NETworkManager/ViewModels/OKCancelMessageViewModel.cs renamed to Source/NETworkManager/ViewModels/MessageConfirmationViewModel.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,33 @@ namespace NETworkManager.ViewModels;
77
/// <summary>
88
/// Represents the ViewModel for a message dialog with OK and Cancel options.
99
/// </summary>
10-
public class OKCancelMessageViewModel : ViewModelBase
10+
public class MessageConfirmationViewModel : ViewModelBase
1111
{
1212
/// <summary>
13-
/// Initializes a new instance of the <see cref="OKCancelMessageViewModel"/> class.
13+
/// Initializes a new instance of the <see cref="MessageConfirmationViewModel"/> class.
1414
/// </summary>
15-
/// <param name="okCommand">The action to execute when the OK button is clicked.</param>
15+
/// <param name="confirmCommand">The action to execute when the confirm button is clicked.</param>
1616
/// <param name="cancelHandler">The action to execute when the Cancel button is clicked.</param>
1717
/// <param name="message">The message to display.</param>
1818
/// <param name="icon">The icon to display in the message window.</param>
19-
/// <param name="okButtonText">The text for the OK button.</param>
20-
/// <param name="cancelButtonText">The text for the Cancel button.</param>
21-
public OKCancelMessageViewModel(Action<OKCancelMessageViewModel> okCommand,
22-
Action<OKCancelMessageViewModel> cancelHandler, string message, ChildWindowIcon icon = ChildWindowIcon.Info, string okButtonText = null, string cancelButtonText = null)
19+
/// <param name="confirmButtonText">The text for the confirm button.</param>
20+
/// <param name="cancelButtonText">The text for the cancel button.</param>
21+
public MessageConfirmationViewModel(Action<MessageConfirmationViewModel> confirmCommand,
22+
Action<MessageConfirmationViewModel> cancelHandler, string message, ChildWindowIcon icon = ChildWindowIcon.Info, string confirmButtonText = null, string cancelButtonText = null)
2323
{
24-
OKCommand = new RelayCommand(_ => okCommand(this));
24+
ConfirmCommand = new RelayCommand(_ => confirmCommand(this));
2525
CancelCommand = new RelayCommand(_ => cancelHandler(this));
2626

2727
Message = message;
2828

29-
OKButtonText = okButtonText ?? Localization.Resources.Strings.OK;
29+
ConfirmButtonText = confirmButtonText ?? Localization.Resources.Strings.OK;
3030
CancelButtonText = cancelButtonText ?? Localization.Resources.Strings.Cancel;
3131
}
3232

3333
/// <summary>
3434
/// Gets the command for the OK button.
3535
/// </summary>
36-
public ICommand OKCommand { get; }
36+
public ICommand ConfirmCommand { get; }
3737

3838
/// <summary>
3939
/// Gets the command for the Cancel button.
@@ -58,28 +58,28 @@ private init
5858
}
5959
}
6060

61-
private readonly string _okButtonText;
61+
private readonly string _confirmButtonText;
6262

6363
/// <summary>
64-
/// Gets the text for the OK button.
64+
/// Gets the text for the confirm button.
6565
/// </summary>
66-
public string OKButtonText
66+
public string ConfirmButtonText
6767
{
68-
get => _okButtonText;
68+
get => _confirmButtonText;
6969
private init
7070
{
71-
if (value == _okButtonText)
71+
if (value == _confirmButtonText)
7272
return;
7373

74-
_okButtonText = value;
74+
_confirmButtonText = value;
7575
OnPropertyChanged();
7676
}
7777
}
7878

7979
private readonly string _cancelButtonText;
8080

8181
/// <summary>
82-
/// Gets the text for the Cancel button.
82+
/// Gets the text for the cancel button.
8383
/// </summary>
8484
public string CancelButtonText
8585
{

Source/NETworkManager/ViewModels/OKMessageViewModel.cs renamed to Source/NETworkManager/ViewModels/MessageViewModel.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,29 @@ namespace NETworkManager.ViewModels;
77
/// <summary>
88
/// Represents the ViewModel for a message dialog with an OK option.
99
/// </summary>
10-
public class OKMessageViewModel : ViewModelBase
10+
public class MessageViewModel : ViewModelBase
1111
{
1212
/// <summary>
13-
/// Initializes a new instance of the <see cref="OKMessageViewModel"/> class.
13+
/// Initializes a new instance of the <see cref="MessageViewModel"/> class.
1414
/// </summary>
15-
/// <param name="okCommand">The action to execute when the OK button is clicked.</param>
15+
/// <param name="confirmCommand">The action to execute when the confirm button is clicked.</param>
1616
/// <param name="message">The message to display.</param>
1717
/// <param name="icon">The icon to display in the message window.</param>
18-
/// <param name="okButtonText">The text for the OK button.</param>
19-
public OKMessageViewModel(Action<OKMessageViewModel> okCommand, string message, ChildWindowIcon icon = ChildWindowIcon.Info, string okButtonText = null)
18+
/// <param name="confirmButtonText">The text for the OK button.</param>
19+
public MessageViewModel(Action<MessageViewModel> confirmCommand, string message, ChildWindowIcon icon = ChildWindowIcon.Info, string confirmButtonText = null)
2020
{
21-
OKCommand = new RelayCommand(_ => okCommand(this));
21+
ConfirmCommand = new RelayCommand(_ => confirmCommand(this));
2222

2323
Message = message;
2424

25-
OKButtonText = okButtonText ?? Localization.Resources.Strings.OK;
25+
ConfirmButtonText = confirmButtonText ?? Localization.Resources.Strings.OK;
2626
Icon = icon;
2727
}
2828

2929
/// <summary>
3030
/// Gets the command for the OK button.
3131
/// </summary>
32-
public ICommand OKCommand { get; }
32+
public ICommand ConfirmCommand { get; }
3333

3434
private readonly string _message;
3535

@@ -49,20 +49,20 @@ private init
4949
}
5050
}
5151

52-
private readonly string _okButtonText;
52+
private readonly string _confirmButtonText;
5353

5454
/// <summary>
55-
/// Gets the text for the OK button.
55+
/// Gets the text for the confirm button.
5656
/// </summary>
57-
public string OKButtonText
57+
public string ConfirmButtonText
5858
{
59-
get => _okButtonText;
59+
get => _confirmButtonText;
6060
private init
6161
{
62-
if (value == _okButtonText)
62+
if (value == _confirmButtonText)
6363
return;
6464

65-
_okButtonText = value;
65+
_confirmButtonText = value;
6666
OnPropertyChanged();
6767
}
6868
}

0 commit comments

Comments
 (0)