Skip to content

Commit 3cabd2a

Browse files
committed
* Added general settings
* Added ability to change ram monitor timer interval * Design changes * Code fixes
1 parent 3af5c5b commit 3cabd2a

File tree

9 files changed

+135
-8
lines changed

9 files changed

+135
-8
lines changed

MemPlus/App.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
<setting name="AutoUpdate" serializeAs="String">
3535
<value>True</value>
3636
</setting>
37+
<setting name="RamMonitorInterval" serializeAs="String">
38+
<value>1000</value>
39+
</setting>
3740
</MemPlus.Properties.Settings>
3841
</userSettings>
3942
</configuration>

MemPlus/Classes/RAM/RamController.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ internal RamController(Dispatcher dispatcher, SfCircularGauge gauge, Label lblTo
108108
_logController.AddLog(new ApplicationLog("Done initializing RamController"));
109109
}
110110

111+
/// <summary>
112+
/// Set the interval for the RAM Monitor updates
113+
/// </summary>
114+
/// <param name="interval">The amount of miliseconds before an update should occur</param>
115+
internal void SetTimerInterval(int interval)
116+
{
117+
_ramTimer.Interval = interval;
118+
}
119+
111120
/// <summary>
112121
/// Enable RAM usage monitoring
113122
/// </summary>

MemPlus/Properties/Settings.Designer.cs

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MemPlus/Properties/Settings.settings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,8 @@
2929
<Setting Name="AutoUpdate" Type="System.Boolean" Scope="User">
3030
<Value Profile="(Default)">True</Value>
3131
</Setting>
32+
<Setting Name="RamMonitorInterval" Type="System.Int32" Scope="User">
33+
<Value Profile="(Default)">1000</Value>
34+
</Setting>
3235
</Settings>
3336
</SettingsFile>

MemPlus/Windows/AboutWindow.xaml.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,19 @@ public AboutWindow(LogController logController)
2525

2626
InitializeComponent();
2727
ChangeVisualStyle();
28+
LoadProperties();
2829

2930
_logController.AddLog(new ApplicationLog("Done initializing AboutWindow"));
3031
}
3132

33+
/// <summary>
34+
/// Load the properties of the application
35+
/// </summary>
36+
private void LoadProperties()
37+
{
38+
Topmost = Properties.Settings.Default.Topmost;
39+
}
40+
3241
/// <summary>
3342
/// Change the visual style of the controls, depending on the settings.
3443
/// </summary>

MemPlus/Windows/LogWindow.xaml.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public LogWindow(LogController logController, LogType logType)
2929

3030
InitializeComponent();
3131
ChangeVisualStyle();
32+
LoadProperties();
3233

3334
FillLogView();
3435

@@ -42,6 +43,11 @@ public LogWindow(LogController logController, LogType logType)
4243
_logController.AddLog(new ApplicationLog("Done initializing LogWindow"));
4344
}
4445

46+
private void LoadProperties()
47+
{
48+
Topmost = Properties.Settings.Default.Topmost;
49+
}
50+
4551
private void LogTypeClearedEvent(List<Log> clearedList)
4652
{
4753
Dispatcher.Invoke(() =>

MemPlus/Windows/MainWindow.xaml.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public MainWindow()
2727
InitializeComponent();
2828
ChangeVisualStyle();
2929

30-
_ramController = new RamController(Dispatcher, CgRamUsage, LblTotalPhysicalMemory, LblAvailablePhysicalMemory, 1000, _logController);
30+
_ramController = new RamController(Dispatcher, CgRamUsage, LblTotalPhysicalMemory, LblAvailablePhysicalMemory, Properties.Settings.Default.RamMonitorInterval, _logController);
3131

3232
Application app = Application.Current;
3333
app.Activated += Active;
@@ -43,7 +43,7 @@ internal void LoadProperties()
4343
MniDisableInactive.IsChecked = Properties.Settings.Default.DisableOnInactive;
4444
MniOnTop.IsChecked = Properties.Settings.Default.Topmost;
4545
MniRamMonitor.IsChecked = Properties.Settings.Default.RamMonitor;
46-
_logController.AddLog(new ApplicationLog("Done loading properties"));
46+
_ramController.SetTimerInterval(Properties.Settings.Default.RamMonitorInterval);
4747

4848
if (Properties.Settings.Default.RamMonitor)
4949
{
@@ -54,6 +54,8 @@ internal void LoadProperties()
5454
{
5555
_rmEnabledBeforeInvisible = false;
5656
}
57+
58+
_logController.AddLog(new ApplicationLog("Done loading properties"));
5759
}
5860

5961
private void Active(object sender, EventArgs args)
@@ -69,6 +71,8 @@ private void Active(object sender, EventArgs args)
6971
private void Passive(object sender, EventArgs args)
7072
{
7173
if (!Properties.Settings.Default.DisableOnInactive) return;
74+
if (!_ramController.RamMonitorEnabled) return;
75+
7276
_ramController.DisableMonitor();
7377
Overlay.Visibility = Visibility.Visible;
7478
}

MemPlus/Windows/SettingsWindow.xaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,52 @@
2121
Image="../Resources/Images/settings.png"
2222
ImageWidth="16" ImageHeight="16">
2323

24+
25+
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
26+
<Grid.RowDefinitions>
27+
<RowDefinition Height="Auto"></RowDefinition>
28+
<RowDefinition Height="Auto"></RowDefinition>
29+
</Grid.RowDefinitions>
30+
31+
<GroupBox Grid.Row="0" Header="General" MinWidth="250" Margin="3">
32+
<Grid>
33+
<Grid.RowDefinitions>
34+
<RowDefinition Height="Auto"></RowDefinition>
35+
<RowDefinition Height="Auto"></RowDefinition>
36+
</Grid.RowDefinitions>
37+
38+
<CheckBox Grid.Row="0" x:Name="ChbAutoUpdate" Content="Automatic updates" Margin="3" />
39+
<CheckBox Grid.Row="1" x:Name="ChbTopmost" Content="Topmost" Margin="3" />
40+
41+
</Grid>
42+
</GroupBox>
43+
44+
<GroupBox Grid.Row="1" Header="RAM Monitor" Margin="3">
45+
<Grid MinWidth="250">
46+
<Grid.RowDefinitions>
47+
<RowDefinition Height="Auto"></RowDefinition>
48+
<RowDefinition Height="Auto"></RowDefinition>
49+
<RowDefinition Height="Auto"></RowDefinition>
50+
</Grid.RowDefinitions>
51+
52+
<CheckBox x:Name="ChbRamMonitor" Content="RAM Monitor" Margin="3" />
53+
<CheckBox x:Name="ChbDisableInactive" Grid.Row="1" Content="Disable when inactive" Margin="3" />
54+
<Grid Grid.Row="2">
55+
<Grid.ColumnDefinitions>
56+
<ColumnDefinition Width="Auto"></ColumnDefinition>
57+
<ColumnDefinition Width="Auto"></ColumnDefinition>
58+
<ColumnDefinition Width="Auto"></ColumnDefinition>
59+
</Grid.ColumnDefinitions>
60+
61+
<Label Content="Update interval:" Margin="3" />
62+
<syncfusion:IntegerTextBox Grid.Column="1" x:Name="ItbRamMonitorTimeout" MinValue="100" MaxValue="60000" Margin="3" />
63+
<Label Grid.Column="2" Content="ms" Margin="3"></Label>
64+
65+
</Grid>
66+
</Grid>
67+
</GroupBox>
68+
</Grid>
69+
2470
</syncfusion:TabItemExt>
2571

2672
<syncfusion:TabItemExt Header="Memory Optimizer"

MemPlus/Windows/SettingsWindow.xaml.cs

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public SettingsWindow(MainWindow mainWindow, LogController logController)
2020

2121
InitializeComponent();
2222
ChangeVisualStyle();
23-
LoadSettings();
23+
LoadProperties();
2424

2525
_mainWindow = mainWindow;
2626

@@ -39,31 +39,66 @@ private void ChangeVisualStyle()
3939
_logController.AddLog(new ApplicationLog("Done changing SettingsWindow theme style"));
4040
}
4141

42-
private void LoadSettings()
42+
private void LoadProperties()
4343
{
44+
_logController.AddLog(new ApplicationLog("Loading properties"));
45+
4446
//TODO
47+
//General
48+
ChbAutoUpdate.IsChecked = Properties.Settings.Default.AutoUpdate;
49+
if (Properties.Settings.Default.Topmost)
50+
{
51+
ChbTopmost.IsChecked = Properties.Settings.Default.Topmost;
52+
Topmost = true;
53+
}
54+
else
55+
{
56+
Topmost = false;
57+
}
58+
59+
ChbRamMonitor.IsChecked = Properties.Settings.Default.RamMonitor;
60+
ChbDisableInactive.IsChecked = Properties.Settings.Default.DisableOnInactive;
61+
ItbRamMonitorTimeout.Value = Properties.Settings.Default.RamMonitorInterval;
62+
63+
_logController.AddLog(new ApplicationLog("Properties have been loaded"));
4564
}
4665

47-
private void SaveSettings()
66+
private void SaveProperties()
4867
{
68+
_logController.AddLog(new ApplicationLog("Saving properties"));
69+
4970
//TODO
71+
//General
72+
if (ChbAutoUpdate.IsChecked != null) Properties.Settings.Default.AutoUpdate = ChbAutoUpdate.IsChecked.Value;
73+
if (ChbTopmost.IsChecked != null) Properties.Settings.Default.Topmost = ChbTopmost.IsChecked.Value;
74+
if (ChbRamMonitor.IsChecked != null) Properties.Settings.Default.RamMonitor = ChbRamMonitor.IsChecked.Value;
75+
if (ChbDisableInactive.IsChecked != null) Properties.Settings.Default.DisableOnInactive = ChbDisableInactive.IsChecked.Value;
76+
if (ItbRamMonitorTimeout.Value != null) Properties.Settings.Default.RamMonitorInterval = (int) ItbRamMonitorTimeout.Value;
77+
5078
Properties.Settings.Default.Save();
5179

5280
_mainWindow.ChangeVisualStyle();
5381
_mainWindow.LoadProperties();
5482

55-
_logController.AddLog(new ApplicationLog("Settings have been saved"));
83+
_logController.AddLog(new ApplicationLog("Properties have been saved"));
5684

57-
MessageBox.Show("All settings have been saved!", "MemPlus", MessageBoxButton.OK, MessageBoxImage.Information);
85+
MessageBox.Show("All properties have been saved!", "MemPlus", MessageBoxButton.OK, MessageBoxImage.Information);
5886
}
5987

6088
private void ResetSettings()
6189
{
90+
_logController.AddLog(new ApplicationLog("Resetting properties"));
91+
6292
Properties.Settings.Default.Reset();
6393
Properties.Settings.Default.Save();
6494

6595
_mainWindow.ChangeVisualStyle();
6696
_mainWindow.LoadProperties();
97+
LoadProperties();
98+
99+
MessageBox.Show("All settings have been reset!", "MemPlus", MessageBoxButton.OK, MessageBoxImage.Information);
100+
101+
_logController.AddLog(new ApplicationLog("Properties have been reset"));
67102
}
68103

69104
private void BtnReset_OnClick(object sender, RoutedEventArgs e)
@@ -73,7 +108,7 @@ private void BtnReset_OnClick(object sender, RoutedEventArgs e)
73108

74109
private void BtnSave_OnClick(object sender, RoutedEventArgs e)
75110
{
76-
SaveSettings();
111+
SaveProperties();
77112
}
78113
}
79114
}

0 commit comments

Comments
 (0)