Skip to content

Commit c85f20a

Browse files
committed
#32 done, cleanup, small improvements
1 parent ea4b3b1 commit c85f20a

13 files changed

Lines changed: 166 additions & 38 deletions

Source/NETworkManager/App.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Lime.xaml" />
1414
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml" />
1515
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/FlatButton.xaml" />
16+
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/FlatSlider.xaml" />
1617
<!-- Use Icons -->
1718
<ResourceDictionary Source="/Resources/Icons.xaml" />
1819
<!-- Localization -->

Source/NETworkManager/MainWindow.xaml.cs

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,19 @@ private void OnPropertyChanged(string propertyName)
3535
#endregion
3636

3737
#region Variables
38+
MetroDialogSettings dialogSettings = new MetroDialogSettings();
39+
3840
NotifyIcon notifyIcon;
3941

4042
private bool _isLoading = true;
4143

4244
private bool _isInTray;
4345
private bool _closeApplication;
4446

47+
// Indicates a restart message, when settings changed
48+
private string _cultureCode;
49+
private bool? _developerMode;
50+
4551
private bool _applicationView_Expand;
4652
public bool ApplicationView_Expand
4753
{
@@ -191,7 +197,7 @@ public bool SearchNothingFound
191197
OnPropertyChanged("SearchNothingFound");
192198
}
193199
}
194-
200+
195201
private string _version;
196202
public string Version
197203
{
@@ -227,6 +233,18 @@ public MainWindow()
227233
// Load appearance
228234
AppearanceManager.Load();
229235

236+
if (SettingsManager.Current.Appearance_EnableTransparency)
237+
{
238+
AllowsTransparency = true;
239+
Opacity = SettingsManager.Current.Appearance_Opacity;
240+
}
241+
242+
// Dialog
243+
dialogSettings.CustomResourceDictionary = new ResourceDictionary
244+
{
245+
Source = new Uri("NETworkManager;component/Resources/Styles/MetroDialogStyles.xaml", UriKind.RelativeOrAbsolute)
246+
};
247+
230248
// Autostart & Window start
231249
if (CommandLineManager.Current.Autostart && SettingsManager.Current.Autostart_StartMinimizedInTray || SettingsManager.Current.TrayIcon_AlwaysShowIcon)
232250
InitNotifyIcon();
@@ -284,20 +302,13 @@ private async void MetroWindowMain_Closing(object sender, CancelEventArgs e)
284302
{
285303
e.Cancel = true;
286304

287-
MetroDialogSettings dialogSettings = new MetroDialogSettings()
288-
{
289-
CustomResourceDictionary = new ResourceDictionary
290-
{
291-
Source = new Uri("NETworkManager;component/Resources/Styles/MetroDialogStyles.xaml", UriKind.RelativeOrAbsolute)
292-
},
293-
294-
AffirmativeButtonText = System.Windows.Application.Current.Resources["String_Button_Close"] as string,
295-
NegativeButtonText = System.Windows.Application.Current.Resources["String_Button_Cancel"] as string,
305+
MetroDialogSettings settings = dialogSettings;
296306

297-
DefaultButtonFocus = MessageDialogResult.Affirmative
298-
};
307+
settings.AffirmativeButtonText = System.Windows.Application.Current.Resources["String_Button_Close"] as string;
308+
settings.NegativeButtonText = System.Windows.Application.Current.Resources["String_Button_Cancel"] as string;
309+
settings.DefaultButtonFocus = MessageDialogResult.Affirmative;
299310

300-
if (await this.ShowMessageAsync(System.Windows.Application.Current.Resources["String_Header_Confirm"] as string, System.Windows.Application.Current.Resources["String_ConfirmCloseQuesiton"] as string, MessageDialogStyle.AffirmativeAndNegative, dialogSettings) == MessageDialogResult.Affirmative)
311+
if (await this.ShowMessageAsync(System.Windows.Application.Current.Resources["String_Header_Confirm"] as string, System.Windows.Application.Current.Resources["String_ConfirmCloseQuesiton"] as string, MessageDialogStyle.AffirmativeAndNegative, settings) == MessageDialogResult.Affirmative)
301312
{
302313
_closeApplication = true;
303314
Close();
@@ -616,6 +627,12 @@ public ICommand OpenSettingsCommand
616627

617628
private async void OpenSettingsAction()
618629
{
630+
if (string.IsNullOrEmpty(_cultureCode))
631+
_cultureCode = SettingsManager.Current.Localization_CultureCode;
632+
633+
if (_developerMode == null)
634+
_developerMode = SettingsManager.Current.DeveloperMode;
635+
619636
SettingsWindow settingsWindow = _isInTray ? new SettingsWindow() : new SettingsWindow(SelectedApplicationViewInfo.Name);
620637

621638
if (_isInTray)
@@ -649,30 +666,32 @@ private async void OpenSettingsAction()
649666
}
650667

651668
// Ask the user to restart (if he has changed the language or enables the developer mode)
652-
if (SettingsManager.RestartRequired)
669+
if ((_cultureCode != SettingsManager.Current.Localization_CultureCode) || (_developerMode != SettingsManager.Current.DeveloperMode) || (AllowsTransparency != SettingsManager.Current.Appearance_EnableTransparency))
653670
{
654671
ShowWindowAction();
655672

656-
MetroDialogSettings dialogSettings = new MetroDialogSettings()
657-
{
658-
CustomResourceDictionary = new ResourceDictionary
659-
{
660-
Source = new Uri("NETworkManager;component/Resources/Styles/MetroDialogStyles.xaml", UriKind.RelativeOrAbsolute)
661-
},
662-
663-
AffirmativeButtonText = System.Windows.Application.Current.Resources["String_Button_RestartNow"] as string,
664-
NegativeButtonText = System.Windows.Application.Current.Resources["String_Button_OK"] as string,
673+
MetroDialogSettings settings = dialogSettings;
665674

666-
DefaultButtonFocus = MessageDialogResult.Affirmative
667-
};
675+
settings.AffirmativeButtonText = System.Windows.Application.Current.Resources["String_Button_RestartNow"] as string;
676+
settings.NegativeButtonText = System.Windows.Application.Current.Resources["String_Button_OK"] as string;
677+
settings.DefaultButtonFocus = MessageDialogResult.Affirmative;
668678

669-
if (await this.ShowMessageAsync(System.Windows.Application.Current.Resources["String_RestartRequired"] as string, System.Windows.Application.Current.Resources["String_RestartRequiredAfterSettingsChanged"] as string, MessageDialogStyle.AffirmativeAndNegative, dialogSettings) == MessageDialogResult.Affirmative)
679+
if (await this.ShowMessageAsync(System.Windows.Application.Current.Resources["String_RestartRequired"] as string, System.Windows.Application.Current.Resources["String_RestartRequiredAfterSettingsChanged"] as string, MessageDialogStyle.AffirmativeAndNegative, settings) == MessageDialogResult.Affirmative)
670680
{
671681
RestartApplication();
672682
return;
673683
}
674684
}
675685

686+
// Change the transparency
687+
if ((AllowsTransparency != SettingsManager.Current.Appearance_EnableTransparency) || (Opacity != SettingsManager.Current.Appearance_Opacity))
688+
{
689+
if (!AllowsTransparency || !SettingsManager.Current.Appearance_EnableTransparency)
690+
Opacity = 1;
691+
else
692+
Opacity = SettingsManager.Current.Appearance_Opacity;
693+
}
694+
676695
if (SettingsManager.HotKeysChanged)
677696
{
678697
UnregisterHotKeys();

Source/NETworkManager/Models/Settings/SettingsInfo.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,38 @@ public string Appearance_Accent
144144
}
145145
}
146146

147+
private bool _appearance_EnableTransparency;
148+
public bool Appearance_EnableTransparency
149+
{
150+
get { return _appearance_EnableTransparency; }
151+
set
152+
{
153+
if (value == _appearance_EnableTransparency)
154+
return;
155+
156+
SettingsChanged = true;
157+
158+
_appearance_EnableTransparency = value;
159+
}
160+
}
161+
162+
private double _appearance_Opacity = 0.85;
163+
public double Appearance_Opacity
164+
{
165+
get { return _appearance_Opacity; }
166+
set
167+
{
168+
if (value == _appearance_Opacity)
169+
return;
170+
171+
SettingsChanged = true;
172+
173+
_appearance_Opacity = value;
174+
}
175+
}
176+
147177
// Localization
148-
private string _localization_CultureCode;
178+
private string _localization_CultureCode = "en-US";
149179
public string Localization_CultureCode
150180
{
151181
get { return _localization_CultureCode; }

Source/NETworkManager/Models/Settings/SettingsManager.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public static class SettingsManager
1414

1515
public static SettingsInfo Current { get; set; }
1616

17-
public static bool RestartRequired { get; set; }
1817
public static bool ForceRestart { get; set; }
1918
public static bool HotKeysChanged { get; set; }
2019

Source/NETworkManager/NETworkManager.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
<SubType>Designer</SubType>
9595
</ApplicationDefinition>
9696
<Compile Include="Converters\NullableDateTimeToStringConverter.cs" />
97+
<Compile Include="Validators\OpacityTextboxValidator.cs" />
9798
<Compile Include="WpfHelper\ProtocolSettingsLayout.cs" />
9899
<Page Include="Resources\ContextMenu\ContextMenu.xaml">
99100
<Generator>MSBuild:Compile</Generator>

Source/NETworkManager/Resources/Localization/Resources.de-DE.xaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
<system:String x:Key="String_Header_History">History</system:String>
6565
<system:String x:Key="String_Header_Applications">Anwendungen</system:String>
6666
<system:String x:Key="String_Header_Update">Update</system:String>
67+
<system:String x:Key="String_Header_Transparency">Transparenz</system:String>
6768

6869
<!-- Normal strings -->
6970
<system:String x:Key="String_ProductName">NETworkManager</system:String>
@@ -205,7 +206,8 @@
205206
<system:String x:Key="String_EndTime">Endzeit</system:String>
206207
<system:String x:Key="String_NoPortsFoundCheckYourInput">Keine Ports gefunden. Überprüfen Sie Ihre Eingabe!</system:String>
207208
<system:String x:Key="String_NoVendorFoundCheckYourInput">Kein Hersteller gefunden. Überprüfen Sie Ihre Eingabe!</system:String>
208-
209+
<system:String x:Key="String_EnableTransparency">Transparenz aktivieren</system:String>
210+
209211
<!-- Buttons -->
210212
<system:String x:Key="String_Button_Change">Wechseln</system:String>
211213
<system:String x:Key="String_Button_Default">Standard</system:String>

Source/NETworkManager/Resources/Localization/Resources.en-US.xaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
<system:String x:Key="String_Header_History">History</system:String>
6666
<system:String x:Key="String_Header_Applications">Applications</system:String>
6767
<system:String x:Key="String_Header_Update">Update</system:String>
68+
<system:String x:Key="String_Header_Transparency">Transparency</system:String>
6869

6970
<!-- Normal strings -->
7071
<system:String x:Key="String_ProductName">NETworkManager</system:String>
@@ -207,7 +208,8 @@
207208
<system:String x:Key="String_EndTime">End time</system:String>
208209
<system:String x:Key="String_NoPortsFoundCheckYourInput">No ports found. Check your input!</system:String>
209210
<system:String x:Key="String_NoVendorFoundCheckYourInput">No vendor found. Check your input!</system:String>
210-
211+
<system:String x:Key="String_EnableTransparency">Enable transparency</system:String>
212+
211213
<!-- Buttons -->
212214
<system:String x:Key="String_Button_Change">Change</system:String>
213215
<system:String x:Key="String_Button_Default">Default</system:String>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Globalization;
2+
using System.Windows;
3+
using System.Windows.Controls;
4+
5+
namespace NETworkManager.Validators
6+
{
7+
public class OpacityTextboxValidator : ValidationRule
8+
{
9+
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
10+
{
11+
if (int.TryParse(value as string, out int result))
12+
{
13+
if (result < 10 || result > 100)
14+
return new ValidationResult(false, Application.Current.Resources["String_ValidateError_EnterValidValueBetween10and100"] as string);
15+
else
16+
return ValidationResult.ValidResult;
17+
}
18+
else
19+
{
20+
return new ValidationResult(false, Application.Current.Resources["String_ValidateError_OnlyNumbersCanBeEntered"] as string);
21+
}
22+
}
23+
}
24+
}

Source/NETworkManager/ViewModels/Settings/SettingsGeneralAppearanceViewModel.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,40 @@ public Accent AccentSelectedItem
4848
OnPropertyChanged();
4949
}
5050
}
51+
52+
private bool _enableTransparency;
53+
public bool EnableTransparency
54+
{
55+
get { return _enableTransparency; }
56+
set
57+
{
58+
if (value == _enableTransparency)
59+
return;
60+
61+
if (!_isLoading)
62+
SettingsManager.Current.Appearance_EnableTransparency = value;
63+
64+
_enableTransparency = value;
65+
OnPropertyChanged();
66+
}
67+
}
68+
69+
private int _opacity;
70+
public int Opacity
71+
{
72+
get { return _opacity; }
73+
set
74+
{
75+
if (value == _opacity)
76+
return;
77+
78+
if (!_isLoading)
79+
SettingsManager.Current.Appearance_Opacity = (double)value / 100;
80+
81+
_opacity = value;
82+
OnPropertyChanged();
83+
}
84+
}
5185
#endregion
5286

5387
#region Constructor, LoadSettings
@@ -62,6 +96,8 @@ private void LoadSettings()
6296
{
6397
AppThemeSelectedItem = ThemeManager.DetectAppStyle().Item1;
6498
AccentSelectedItem = ThemeManager.DetectAppStyle().Item2;
99+
EnableTransparency = SettingsManager.Current.Appearance_EnableTransparency;
100+
Opacity = (int)(SettingsManager.Current.Appearance_Opacity * 100);
65101
}
66102
#endregion
67103
}

Source/NETworkManager/ViewModels/Settings/SettingsGeneralDeveloperViewModel.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@ public bool DeveloperMode
1717
return;
1818

1919
if (!_isLoading)
20-
{
2120
SettingsManager.Current.DeveloperMode = value;
2221

23-
SettingsManager.RestartRequired = true;
24-
}
25-
2622
_developerMode = value;
2723
OnPropertyChanged();
2824
}

0 commit comments

Comments
 (0)