Skip to content

Commit 6043467

Browse files
committed
* Added ability to change window dragging from MainWindow
1 parent 8827223 commit 6043467

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

MemPlus/Views/Windows/MainWindow.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
</MenuItem.Icon>
137137
<MenuItem x:Name="MniOnTop" Header="Always on top" IsCheckable="True" Checked="TopMenuItem_OnCheckedChanged" Unchecked="TopMenuItem_OnCheckedChanged" />
138138
<MenuItem x:Name="MniDisableInactive" Header="Disable when inactive" IsCheckable="True" Checked="DisableInactiveMenuItem_OnCheckedChanged" Unchecked="DisableInactiveMenuItem_OnCheckedChanged" />
139+
<MenuItem x:Name="MniWindowDraggable" Header="Window draggable" IsCheckable="True" Checked="WindowDraggableMenuItem_OnCheckedChanged" Unchecked="WindowDraggableMenuItem_OnCheckedChanged" />
139140
</MenuItem>
140141
<MenuItem Header="Settings" Click="SettingsMenuItem_OnClick">
141142
<MenuItem.Icon>

MemPlus/Views/Windows/MainWindow.xaml.cs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ internal void LoadProperties()
132132
{
133133
MniDisableInactive.IsChecked = Properties.Settings.Default.DisableOnInactive;
134134
MniOnTop.IsChecked = Properties.Settings.Default.Topmost;
135+
MniWindowDraggable.IsChecked = Properties.Settings.Default.WindowDragging;
135136
MniRamMonitor.IsChecked = Properties.Settings.Default.RamMonitor;
136137

137138
_ramController.SetProcessExceptionList(Properties.Settings.Default.ProcessExceptions);
@@ -161,9 +162,28 @@ internal void LoadProperties()
161162
}
162163

163164
TbiIcon.Visibility = !Properties.Settings.Default.NotifyIcon ? Visibility.Hidden : Visibility.Visible;
165+
WindowDraggable();
166+
}
167+
catch (Exception ex)
168+
{
169+
_logController.AddLog(new ApplicationLog(ex.Message));
170+
MessageBox.Show(ex.Message, "MemPlus", MessageBoxButton.OK, MessageBoxImage.Error);
171+
}
172+
173+
_logController.AddLog(new ApplicationLog("Done loading MainWindow properties"));
174+
}
164175

176+
/// <summary>
177+
/// Check whether the Window should be draggable or not
178+
/// </summary>
179+
private void WindowDraggable()
180+
{
181+
try
182+
{
165183
if (Properties.Settings.Default.WindowDragging)
166184
{
185+
// Delete event handler first to prevent duplicate handlers
186+
MouseDown -= OnMouseDown;
167187
MouseDown += OnMouseDown;
168188
}
169189
else
@@ -176,8 +196,6 @@ internal void LoadProperties()
176196
_logController.AddLog(new ApplicationLog(ex.Message));
177197
MessageBox.Show(ex.Message, "MemPlus", MessageBoxButton.OK, MessageBoxImage.Error);
178198
}
179-
180-
_logController.AddLog(new ApplicationLog("Done loading MainWindow properties"));
181199
}
182200

183201
/// <summary>
@@ -532,6 +550,27 @@ private void DisableInactiveMenuItem_OnCheckedChanged(object sender, RoutedEvent
532550
}
533551
}
534552

553+
/// <summary>
554+
/// Method that is called when the Window draggable setting should be changed
555+
/// </summary>
556+
/// <param name="sender">The object that called this method</param>
557+
/// <param name="e">The RoutedEventArgs</param>
558+
private void WindowDraggableMenuItem_OnCheckedChanged(object sender, RoutedEventArgs e)
559+
{
560+
try
561+
{
562+
Properties.Settings.Default.WindowDragging = MniWindowDraggable.IsChecked;
563+
Properties.Settings.Default.Save();
564+
565+
WindowDraggable();
566+
}
567+
catch (Exception ex)
568+
{
569+
_logController.AddLog(new ApplicationLog(ex.Message));
570+
MessageBox.Show(ex.Message, "MemPlus", MessageBoxButton.OK, MessageBoxImage.Error);
571+
}
572+
}
573+
535574
/// <summary>
536575
/// Method that is called when the SettingsWindow should be displayed
537576
/// </summary>

0 commit comments

Comments
 (0)