Skip to content

Commit 76f56d5

Browse files
committed
* Added ability to clear the clipboard
* Fixed an issue with the clear memory button being unavailable if an error occured during memory clearing
1 parent a0a2c05 commit 76f56d5

File tree

7 files changed

+44
-13
lines changed

7 files changed

+44
-13
lines changed

MemPlus/App.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@
108108
<setting name="HotKeyModifiers" serializeAs="String">
109109
<value />
110110
</setting>
111+
<setting name="ClearClipboard" serializeAs="String">
112+
<value>True</value>
113+
</setting>
111114
</MemPlus.Properties.Settings>
112115
</userSettings>
113116
</configuration>

MemPlus/Business/RAM/RamController.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Threading.Tasks;
44
using System.Timers;
5+
using System.Windows;
56
using MemPlus.Business.LOG;
67
using Microsoft.VisualBasic.Devices;
78
// ReSharper disable PossibleNullReferenceException
@@ -42,6 +43,10 @@ internal sealed class RamController : IDisposable
4243
/// An integer value representative of the percentage of RAM usage that should be reached before RAM optimisation should be called
4344
/// </summary>
4445
private double _autoOptimizeRamThreshold;
46+
/// <summary>
47+
/// The last time automatic RAM optimisation was called in terms of RAM percentage threshold settings
48+
/// </summary>
49+
private DateTime _lastAutoOptimizeTime;
4550
#endregion
4651

4752
#region Properties
@@ -82,9 +87,9 @@ internal sealed class RamController : IDisposable
8287
/// </summary>
8388
internal bool AutoOptimizePercentage { get; set; }
8489
/// <summary>
85-
/// The last time automatic RAM optimisation was called in terms of RAM percentage threshold settings
90+
/// Property displaying whether the clipboard should be cleared during memory cleaning
8691
/// </summary>
87-
private DateTime _lastAutoOptimizeTime;
92+
internal bool ClearClipboard { get; set; }
8893
#endregion
8994

9095
#region Delegates
@@ -273,6 +278,11 @@ await Task.Run(async () =>
273278
RamSavings = oldUsage - newUsage;
274279
});
275280

281+
if (ClearClipboard)
282+
{
283+
Clipboard.Clear();
284+
}
285+
276286
RamClearingCompletedEvcent.Invoke();
277287

278288
_logController.AddLog(new ApplicationLog("Done clearing RAM memory"));

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
@@ -102,5 +102,8 @@
102102
<Setting Name="HotKeyModifiers" Type="System.String" Scope="User">
103103
<Value Profile="(Default)" />
104104
</Setting>
105+
<Setting Name="ClearClipboard" Type="System.Boolean" Scope="User">
106+
<Value Profile="(Default)">True</Value>
107+
</Setting>
105108
</Settings>
106109
</SettingsFile>

MemPlus/Views/Windows/MainWindow.xaml.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ internal void LoadProperties()
197197

198198
_ramController.AutoOptimizePercentage = Properties.Settings.Default.AutoOptimizePercentage;
199199
_ramController.SetAutoOptimizeThreshold(Properties.Settings.Default.AutoOptimizePercentageThreshold);
200+
_ramController.ClearClipboard = Properties.Settings.Default.ClearClipboard;
200201

201202
if (Properties.Settings.Default.RamMonitor)
202203
{
@@ -868,7 +869,7 @@ private void ClearFileSystemCacheDropDownMenuItem_OnClick(object sender, RoutedE
868869
private async void ClearMemory(int index)
869870
{
870871
if (_clearingMemory) return;
871-
if (!_ramController.EmptyWorkingSets && !_ramController.ClearFileSystemCache) return;
872+
if (!_ramController.EmptyWorkingSets && !_ramController.ClearFileSystemCache && !_ramController.ClearClipboard) return;
872873

873874
_logController.AddLog(new ApplicationLog("Clearing RAM Memory"));
874875
_clearingMemory = true;
@@ -890,16 +891,16 @@ private async void ClearMemory(int index)
890891
await _ramController.ClearFileSystemCaches();
891892
break;
892893
}
893-
894-
BtnClearMemory.IsEnabled = true;
895894
}
896895
catch (Exception ex)
897896
{
898897
_logController.AddLog(new ApplicationLog(ex.Message));
899898
MessageBox.Show(ex.Message, "MemPlus", MessageBoxButton.OK, MessageBoxImage.Error);
900899
}
901900

901+
BtnClearMemory.IsEnabled = true;
902902
_clearingMemory = false;
903+
903904
_logController.AddLog(new ApplicationLog("Done clearing RAM memory"));
904905
}
905906

MemPlus/Views/Windows/SettingsWindow.xaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
TitleTextAlignment="Center"
1212
UseNativeChrome="True"
1313
WindowStartupLocation="CenterScreen"
14-
Title="MemPlus - Settings" Height="380" Width="550"
14+
Title="MemPlus - Settings" Height="400" Width="550"
1515
Icon="/MemPlus;component/Resources/Images/ram.png">
1616
<Grid>
1717
<Grid.RowDefinitions>
@@ -142,18 +142,18 @@
142142
<Grid.RowDefinitions>
143143
<RowDefinition Height="Auto" />
144144
<RowDefinition Height="Auto" />
145-
<RowDefinition Height="Auto" />
146-
<RowDefinition Height="Auto" />
145+
<RowDefinition Height="Auto"/>
147146
</Grid.RowDefinitions>
148147
<Grid.ColumnDefinitions>
149148
<ColumnDefinition Width="Auto" />
150149
<ColumnDefinition />
151150
</Grid.ColumnDefinitions>
152-
<CheckBox Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" x:Name="ChbEmptyWorkingSet" Content="Empty working sets" Margin="3" />
153-
<CheckBox Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" x:Name="ChbFileSystemCache" Content="Clear FileSystem cache" Margin="3" />
154-
<CheckBox Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" x:Name="ChbStandByCache" Content="Clear standby cache" Margin="3" />
155-
<CheckBox Grid.Row="3" Grid.Column="0" x:Name="ChbHotKey" Content="Hotkey:" Margin="3" />
156-
<TextBox Grid.Row="3" Grid.Column="1" x:Name="TxtHotKey" Margin="3" PreviewKeyDown="TxtHotKey_PreviewKeyDown"/>
151+
<CheckBox Grid.Row="0" Grid.Column="0" x:Name="ChbEmptyWorkingSet" Content="Empty working sets" Margin="3" />
152+
<CheckBox Grid.Row="0" Grid.Column="1" x:Name="ChbFileSystemCache" Content="Clear FileSystem cache" Margin="3" />
153+
<CheckBox Grid.Row="1" Grid.Column="0" x:Name="ChbStandByCache" Content="Clear standby cache" Margin="3" />
154+
<CheckBox Grid.Row="1" Grid.Column="1" x:Name="ChbClearClipboard" Content="Clear clipboard data" Margin="3" />
155+
<CheckBox Grid.Row="2" Grid.Column="0" x:Name="ChbHotKey" Content="Hotkey:" Margin="3" />
156+
<TextBox Grid.Row="2" Grid.Column="1" x:Name="TxtHotKey" Margin="3" HorizontalAlignment="Stretch" PreviewKeyDown="TxtHotKey_PreviewKeyDown"/>
157157
</Grid>
158158
</GroupBox>
159159
<GroupBox Grid.Row="1" Header="Working Set Exclusions" MinWidth="250" Margin="3">

MemPlus/Views/Windows/SettingsWindow.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ private void LoadProperties()
150150
ChbEmptyWorkingSet.IsChecked = Properties.Settings.Default.EmptyWorkingSet;
151151
ChbFileSystemCache.IsChecked = Properties.Settings.Default.FileSystemCache;
152152
ChbStandByCache.IsChecked = Properties.Settings.Default.StandByCache;
153+
ChbClearClipboard.IsChecked = Properties.Settings.Default.ClearClipboard;
153154
if (Properties.Settings.Default.ProcessExceptions != null)
154155
{
155156
foreach (string s in Properties.Settings.Default.ProcessExceptions)
@@ -287,6 +288,7 @@ private void SaveProperties()
287288
if (ChbEmptyWorkingSet.IsChecked != null) Properties.Settings.Default.EmptyWorkingSet = ChbEmptyWorkingSet.IsChecked.Value;
288289
if (ChbFileSystemCache.IsChecked != null) Properties.Settings.Default.FileSystemCache = ChbFileSystemCache.IsChecked.Value;
289290
if (ChbStandByCache.IsChecked != null) Properties.Settings.Default.StandByCache = ChbStandByCache.IsChecked.Value;
291+
if (ChbClearClipboard.IsChecked != null) Properties.Settings.Default.ClearClipboard = ChbClearClipboard.IsChecked.Value;
290292
List<string> exclusionList = LsvExclusions.Items.Cast<string>().ToList();
291293
Properties.Settings.Default.ProcessExceptions = exclusionList;
292294
if (ChbHotKey.IsChecked != null) Properties.Settings.Default.UseHotKey = ChbHotKey.IsChecked.Value;

0 commit comments

Comments
 (0)