Skip to content

Commit 3a49a6d

Browse files
committed
* Simplified some settings code
1 parent ee5bd2d commit 3a49a6d

12 files changed

+14
-49
lines changed

MemPlus/Views/Windows/AboutWindow.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
77
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
8+
xmlns:utils="clr-namespace:MemPlus.Business.UTILS"
89
mc:Ignorable="d"
910
TitleTextAlignment="Center"
1011
WindowStartupLocation="CenterScreen"
1112
UseLayoutRounding="True"
1213
AllowsTransparency="True" UseNativeChrome="True"
14+
Topmost="{utils:SettingsBinder Topmost}"
1315
Title="{DynamicResource AboutWindowTitle}" Height="200" Width="350" Icon="/MemPlus;component/Resources/Images/ram.png">
1416
<Grid VerticalAlignment="Center" HorizontalAlignment="Center">
1517
<Grid.RowDefinitions>

MemPlus/Views/Windows/AboutWindow.xaml.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ private void LoadProperties()
4747
_logController.AddLog(new ApplicationLog("Loading AboutWindow properties"));
4848
try
4949
{
50-
Topmost = Properties.Settings.Default.Topmost;
5150
if (Properties.Settings.Default.WindowDragging)
5251
{
5352
MouseDown += OnMouseDown;

MemPlus/Views/Windows/LogWindow.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
WindowStartupLocation="CenterScreen"
1313
AllowsTransparency="True"
1414
TitleTextAlignment="Center" UseNativeChrome="True"
15+
Topmost="{utils:SettingsBinder Topmost}"
1516
Title="{DynamicResource LogWindowTitle}" Height="300" Width="450" Icon="/Resources/Images/ram.png">
1617
<Grid>
1718
<Grid.RowDefinitions>

MemPlus/Views/Windows/LogWindow.xaml.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ private void LoadProperties()
6969
_logController.AddLog(new ApplicationLog("Loading LogWindow properties"));
7070
try
7171
{
72-
Topmost = Properties.Settings.Default.Topmost;
7372
if (Properties.Settings.Default.WindowDragging)
7473
{
7574
MouseDown += OnMouseDown;

MemPlus/Views/Windows/MainWindow.xaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
77
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
88
xmlns:tb="http://www.hardcodet.net/taskbar"
9+
xmlns:utils="clr-namespace:MemPlus.Business.UTILS"
910
mc:Ignorable="d"
1011
UseLayoutRounding="True"
1112
TitleTextAlignment="Center"
1213
Closing="MainWindow_OnClosing"
1314
AllowsTransparency="True" UseNativeChrome="True"
15+
Topmost="{utils:SettingsBinder Topmost}"
1416
Title="MemPlus" Height="300" Width="500" WindowStartupLocation="CenterScreen" Icon="/Resources/Images/ram.png">
1517
<Grid>
1618
<Grid.RowDefinitions>
@@ -138,8 +140,8 @@
138140
<MenuItem.Icon>
139141
<Image Width="16" Height="16" Source="/Resources/Images/monitor.png" />
140142
</MenuItem.Icon>
141-
<MenuItem x:Name="MniOnTop" Header="{DynamicResource Topmost}" IsCheckable="True" Checked="TopMenuItem_OnCheckedChanged" Unchecked="TopMenuItem_OnCheckedChanged" />
142-
<MenuItem x:Name="MniDisableInactive" Header="{DynamicResource DisableWhenInactive}" IsCheckable="True" Checked="DisableInactiveMenuItem_OnCheckedChanged" Unchecked="DisableInactiveMenuItem_OnCheckedChanged" />
143+
<MenuItem Header="{DynamicResource Topmost}" IsCheckable="true" IsChecked="{utils:SettingsBinder Topmost}" />
144+
<MenuItem Header="{DynamicResource DisableWhenInactive}" IsCheckable="True" IsChecked="{utils:SettingsBinder DisableOnInactive}" />
143145
<MenuItem x:Name="MniWindowDraggable" Header="{DynamicResource WindowDraggable}" IsCheckable="True" Checked="WindowDraggableMenuItem_OnCheckedChanged" Unchecked="WindowDraggableMenuItem_OnCheckedChanged" />
144146
<MenuItem x:Name="MniRamStatistics" Header="{DynamicResource DisplayRamStatistics}" IsCheckable="True" Checked="RamStatisticsMenuItem_OnCheckedChanged" Unchecked="RamStatisticsMenuItem_OnCheckedChanged" />
145147
<MenuItem x:Name="MniRamGauge" Header="{DynamicResource DisplayRamGauge}" IsCheckable="True" Checked="RamGaugeMenuItem_OnCheckedChanged" Unchecked="RamGaugeMenuItem_OnCheckedChanged" />

MemPlus/Views/Windows/MainWindow.xaml.cs

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,6 @@ internal void LoadProperties()
252252

253253
try
254254
{
255-
MniDisableInactive.IsChecked = Properties.Settings.Default.DisableOnInactive;
256-
MniOnTop.IsChecked = Properties.Settings.Default.Topmost;
257255
MniWindowDraggable.IsChecked = Properties.Settings.Default.WindowDragging;
258256
MniRamStatistics.IsChecked = Properties.Settings.Default.WindowRamStatistics;
259257
MniRamGauge.IsChecked = Properties.Settings.Default.DisplayGauge;
@@ -616,26 +614,6 @@ private void ErrorLogsMenuItem_OnClick(object sender, RoutedEventArgs e)
616614
new LogWindow(_logController, LogType.Error).Show();
617615
}
618616

619-
/// <summary>
620-
/// Method that is called when the Topmost property should be changed
621-
/// </summary>
622-
/// <param name="sender">The object that called this method</param>
623-
/// <param name="e">The RoutedEventArgs</param>
624-
private void TopMenuItem_OnCheckedChanged(object sender, RoutedEventArgs e)
625-
{
626-
try
627-
{
628-
Topmost = MniOnTop.IsChecked;
629-
Properties.Settings.Default.Topmost = Topmost;
630-
Properties.Settings.Default.Save();
631-
}
632-
catch (Exception ex)
633-
{
634-
_logController.AddLog(new ErrorLog(ex.Message));
635-
MessageBox.Show(ex.Message, "MemPlus", MessageBoxButton.OK, MessageBoxImage.Error);
636-
}
637-
}
638-
639617
/// <summary>
640618
/// Method that is called when the CodeDead homepage should be displayed
641619
/// </summary>
@@ -781,25 +759,6 @@ private void OpenTbItem_Click(object sender, RoutedEventArgs e)
781759
}
782760
}
783761

784-
/// <summary>
785-
/// Method that is called when the RAM Monitor should be disabled or not when the Application is inactive
786-
/// </summary>
787-
/// <param name="sender">The object that called this method</param>
788-
/// <param name="e">The RoutedEventArgs</param>
789-
private void DisableInactiveMenuItem_OnCheckedChanged(object sender, RoutedEventArgs e)
790-
{
791-
try
792-
{
793-
Properties.Settings.Default.DisableOnInactive = MniDisableInactive.IsChecked;
794-
Properties.Settings.Default.Save();
795-
}
796-
catch (Exception ex)
797-
{
798-
_logController.AddLog(new ErrorLog(ex.Message));
799-
MessageBox.Show(ex.Message, "MemPlus", MessageBoxButton.OK, MessageBoxImage.Error);
800-
}
801-
}
802-
803762
/// <summary>
804763
/// Method that is called when the Window draggable setting should be changed
805764
/// </summary>
@@ -1092,6 +1051,8 @@ private void MainWindow_OnClosing(object sender, CancelEventArgs e)
10921051
}
10931052
else
10941053
{
1054+
// Save properties
1055+
Properties.Settings.Default.Save();
10951056
// De-register any hotkeys, if applicable
10961057
_hotKeyController?.Dispose();
10971058
// Disable the RAM Monitor to prevent exceptions from being thrown

MemPlus/Views/Windows/ProcessAnalyzerWindow.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
88
xmlns:utils="clr-namespace:MemPlus.Business.UTILS"
99
xmlns:process="clr-namespace:MemPlus.Business.PROCESS"
10+
xmlns:bind="clr-namespace:MemPlus.Business.UTILS"
1011
mc:Ignorable="d" UseLayoutRounding="True"
1112
WindowStartupLocation="CenterScreen" AllowsTransparency="True"
1213
TitleTextAlignment="Center" UseNativeChrome="True"
14+
Topmost="{bind:SettingsBinder Topmost}"
1315
Title="{DynamicResource ProcessAnalyzerWindowTitle}" Height="350" Width="550" Icon="/Resources/Images/ram.png">
1416
<Grid>
1517
<Grid.RowDefinitions>

MemPlus/Views/Windows/ProcessAnalyzerWindow.xaml.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ private void LoadProperties()
5959
_logController.AddLog(new ApplicationLog("Loading ProcessAnalyzerWindow properties"));
6060
try
6161
{
62-
Topmost = Properties.Settings.Default.Topmost;
6362
if (Properties.Settings.Default.WindowDragging)
6463
{
6564
MouseDown += OnMouseDown;

MemPlus/Views/Windows/RamAnalyzerWindow.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
7+
xmlns:bind="clr-namespace:MemPlus.Business.UTILS"
78
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
89
mc:Ignorable="d"
910
UseLayoutRounding="True"
@@ -12,6 +13,7 @@
1213
Title="{DynamicResource RamAnalyzerWindowTitle}" Height="300" Width="350"
1314
Loaded="AnalyzerWindow_OnLoaded" UseNativeChrome="True"
1415
Icon="/MemPlus;component/Resources/Images/ram.png"
16+
Topmost="{bind:SettingsBinder Topmost}"
1517
WindowStartupLocation="CenterScreen">
1618
<Grid>
1719
<Grid.RowDefinitions>

MemPlus/Views/Windows/RamAnalyzerWindow.xaml.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ private void LoadProperties()
9797
_logController.AddLog(new ApplicationLog("Loading AnalyzerWindow properties"));
9898
try
9999
{
100-
Topmost = Properties.Settings.Default.Topmost;
101100
if (Properties.Settings.Default.WindowDragging)
102101
{
103102
MouseDown += OnMouseDown;

0 commit comments

Comments
 (0)