Skip to content

Commit d0e57db

Browse files
committed
Feature: Reset settings dialog redesigned
1 parent b70f324 commit d0e57db

File tree

8 files changed

+89
-33
lines changed

8 files changed

+89
-33
lines changed

Source/NETworkManager.Converters/ChildWindowIconToRectangleStyleConverter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
1717
{
1818
case ChildWindowIcon.Info:
1919
return Application.Current.FindResource("InfoImageRectangle");
20+
case ChildWindowIcon.Question:
21+
return Application.Current.FindResource("QuestionImageRectangle");
2022
case ChildWindowIcon.Warn:
2123
return Application.Current.FindResource("WarnImageRectangle");
2224
case ChildWindowIcon.Error:

Source/NETworkManager.Utilities/ChildWindowIcon.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ public enum ChildWindowIcon
1010
/// </summary>
1111
Info,
1212

13+
/// <summary>
14+
/// Question icon.
15+
/// </summary>
16+
Question,
17+
1318
/// <summary>
1419
/// Warning icon.
1520
/// </summary>

Source/NETworkManager/Resources/Styles/RectangleStyles.xaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@
3636
<Setter Property="ToolTipService.ShowDuration" Value="600000" />
3737
</Style>
3838

39+
<Style x:Key="QuestionImageRectangle" TargetType="{x:Type Rectangle}">
40+
<Style.Resources>
41+
<Style TargetType="{x:Type ToolTip}" BasedOn="{StaticResource DefaultToolTip}" />
42+
</Style.Resources>
43+
<Setter Property="Fill" Value="{DynamicResource MahApps.Brushes.Gray3}" />
44+
<Setter Property="OpacityMask">
45+
<Setter.Value>
46+
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Material Kind=HelpCircleOutline}" />
47+
</Setter.Value>
48+
</Setter>
49+
<Setter Property="ToolTipService.InitialShowDelay" Value="0" />
50+
<Setter Property="ToolTipService.ShowDuration" Value="600000" />
51+
</Style>
52+
3953
<Style x:Key="WarnImageRectangle" TargetType="{x:Type Rectangle}">
4054
<Style.Resources>
4155
<Style TargetType="{x:Type ToolTip}" BasedOn="{StaticResource DefaultToolTip}" />

Source/NETworkManager/ViewModels/OKCancelInfoMessageViewModel.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace NETworkManager.ViewModels;
77
public class OKCancelInfoMessageViewModel : ViewModelBase
88
{
99
public OKCancelInfoMessageViewModel(Action<OKCancelInfoMessageViewModel> okCommand,
10-
Action<OKCancelInfoMessageViewModel> cancelHandler, string message, string okButtonText = null, string cancelButtonText = null)
10+
Action<OKCancelInfoMessageViewModel> cancelHandler, string message, string okButtonText = null, string cancelButtonText = null, ChildWindowIcon icon = ChildWindowIcon.Info)
1111
{
1212
OKCommand = new RelayCommand(_ => okCommand(this));
1313
CancelCommand = new RelayCommand(_ => cancelHandler(this));
@@ -23,7 +23,6 @@ public OKCancelInfoMessageViewModel(Action<OKCancelInfoMessageViewModel> okComma
2323
public ICommand CancelCommand { get; }
2424

2525
private readonly string _message;
26-
2726
public string Message
2827
{
2928
get => _message;
@@ -38,7 +37,6 @@ private init
3837
}
3938

4039
private readonly string _okButtonText;
41-
4240
public string OKButtonText
4341
{
4442
get => _okButtonText;
@@ -53,7 +51,6 @@ private init
5351
}
5452

5553
private readonly string _cancelButtonText;
56-
5754
public string CancelButtonText
5855
{
5956
get => _cancelButtonText;
@@ -66,4 +63,18 @@ private init
6663
OnPropertyChanged();
6764
}
6865
}
66+
67+
private ChildWindowIcon _icon;
68+
public ChildWindowIcon Icon
69+
{
70+
get => _icon;
71+
private init
72+
{
73+
if (value == _icon)
74+
return;
75+
76+
_icon = value;
77+
OnPropertyChanged();
78+
}
79+
}
6980
}

Source/NETworkManager/ViewModels/OKMessageViewModel.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public OKMessageViewModel(Action<OKMessageViewModel> okCommand, string message,
1919
public ICommand OKCommand { get; }
2020

2121
private readonly string _message;
22-
2322
public string Message
2423
{
2524
get => _message;
@@ -34,7 +33,6 @@ private init
3433
}
3534

3635
private readonly string _okButtonText;
37-
3836
public string OKButtonText
3937
{
4038
get => _okButtonText;
@@ -49,7 +47,6 @@ private init
4947
}
5048

5149
private ChildWindowIcon _icon;
52-
5350
public ChildWindowIcon Icon
5451
{
5552
get => _icon;

Source/NETworkManager/ViewModels/SettingsSettingsViewModel.cs

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
using System;
2-
using System.Diagnostics;
3-
using System.Windows;
4-
using System.Windows.Input;
5-
using MahApps.Metro.Controls.Dialogs;
1+
using MahApps.Metro.Controls.Dialogs;
2+
using MahApps.Metro.SimpleChildWindow;
63
using NETworkManager.Localization.Resources;
74
using NETworkManager.Settings;
85
using NETworkManager.Utilities;
6+
using NETworkManager.Views;
7+
using System;
8+
using System.Diagnostics;
9+
using System.Threading.Tasks;
10+
using System.Windows;
11+
using System.Windows.Input;
912

1013
namespace NETworkManager.ViewModels;
1114

@@ -61,26 +64,47 @@ private static void OpenLocationAction()
6164

6265
public ICommand ResetSettingsCommand => new RelayCommand(_ => ResetSettingsAction());
6366

64-
private async void ResetSettingsAction()
67+
private void ResetSettingsAction()
6568
{
66-
var settings = AppearanceManager.MetroDialog;
69+
ResetSettings().ConfigureAwait(false);
70+
}
6771

68-
settings.AffirmativeButtonText = Strings.Reset;
69-
settings.NegativeButtonText = Strings.Cancel;
72+
#endregion
7073

71-
settings.DefaultButtonFocus = MessageDialogResult.Affirmative;
74+
#region Methods
7275

73-
if (await _dialogCoordinator.ShowMessageAsync(this, Strings.ResetSettingsQuestion,
74-
Strings.SettingsAreResetAndApplicationWillBeRestartedMessage,
75-
MessageDialogStyle.AffirmativeAndNegative, settings) != MessageDialogResult.Affirmative)
76-
return;
76+
private Task ResetSettings()
77+
{
78+
var childWindow = new OKCancelInfoMessageChildWindow();
7779

78-
// Init default settings
79-
SettingsManager.Initialize();
80+
var childWindowViewModel = new OKCancelInfoMessageViewModel(_ =>
81+
{
82+
childWindow.IsOpen = false;
83+
ConfigurationManager.Current.IsChildWindowOpen = false;
8084

81-
// Restart the application
82-
(Application.Current.MainWindow as MainWindow)?.RestartApplication();
83-
}
85+
// Init default settings
86+
SettingsManager.Initialize();
87+
88+
// Restart the application
89+
(Application.Current.MainWindow as MainWindow)?.RestartApplication();
90+
}, _ =>
91+
{
92+
childWindow.IsOpen = false;
93+
ConfigurationManager.Current.IsChildWindowOpen = false;
94+
},
95+
Strings.SettingsAreResetAndApplicationWillBeRestartedMessage,
96+
Strings.Reset,
97+
Strings.Cancel,
98+
ChildWindowIcon.Question
99+
);
84100

101+
childWindow.Title = Strings.ResetSettingsQuestion;
102+
103+
childWindow.DataContext = childWindowViewModel;
104+
105+
ConfigurationManager.Current.IsChildWindowOpen = true;
106+
107+
return (Application.Current.MainWindow as MainWindow).ShowChildWindowAsync(childWindow);
108+
}
85109
#endregion
86-
}
110+
}

Source/NETworkManager/ViewModels/WebConsoleSettingsViewModel.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
using System;
2-
using MahApps.Metro.SimpleChildWindow;
1+
using MahApps.Metro.SimpleChildWindow;
2+
using Microsoft.Web.WebView2.Core;
33
using NETworkManager.Localization.Resources;
44
using NETworkManager.Settings;
55
using NETworkManager.Utilities;
66
using NETworkManager.Views;
7+
using System;
78
using System.Threading.Tasks;
89
using System.Windows;
910
using System.Windows.Input;
10-
using Microsoft.Web.WebView2.Core;
11-
using Microsoft.Web.WebView2.Wpf;
1211

1312
namespace NETworkManager.ViewModels;
1413

Source/NETworkManager/Views/OKCancelInfoMessageChildWindow.xaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
xmlns:localization="clr-namespace:NETworkManager.Localization.Resources;assembly=NETworkManager.Localization"
88
xmlns:simpleChildWindow="clr-namespace:MahApps.Metro.SimpleChildWindow;assembly=MahApps.Metro.SimpleChildWindow"
99
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
10+
xmlns:converters="clr-namespace:NETworkManager.Converters;assembly=NETworkManager.Converters"
1011
ChildWindowWidth="450"
1112
ChildWindowMaxHeight="500"
1213
ShowTitleBar="True"
@@ -20,6 +21,9 @@
2021
OverlayBrush="{DynamicResource ResourceKey=MahApps.Brushes.Gray.SemiTransparent}"
2122
Loaded="ChildWindow_Loaded"
2223
mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:OKCancelInfoMessageViewModel}">
24+
<simpleChildWindow:ChildWindow.Resources>
25+
<converters:ChildWindowIconToRectangleStyleConverter x:Key="ChildWindowIconToRectangleStyleConverter" />
26+
</simpleChildWindow:ChildWindow.Resources>
2327
<Grid Margin="10">
2428
<Grid.RowDefinitions>
2529
<RowDefinition Height="*" />
@@ -36,8 +40,8 @@
3640
<ColumnDefinition Width="*" />
3741
</Grid.ColumnDefinitions>
3842
<Rectangle Grid.Column="0" Grid.Row="0"
39-
Width="32" Height="32"
40-
Style="{StaticResource InfoImageRectangle}" />
43+
Width="32" Height="32"
44+
Style="{Binding Icon, Converter={StaticResource ChildWindowIconToRectangleStyleConverter}}" />
4145
<TextBlock Grid.Column="2" Grid.Row="0"
4246
VerticalAlignment="Center"
4347
Text="{Binding Message}"

0 commit comments

Comments
 (0)