Skip to content

Commit a0a2c05

Browse files
committed
* Fixed scrolling with mousewheel not disabling autoscroll in the LogWindow
1 parent 01372b1 commit a0a2c05

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

MemPlus/Business/UTILS/HotKeyController.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Runtime.InteropServices;
44
using System.Windows.Forms;
55
using System.Windows.Interop;
6+
using MemPlus.Business.LOG;
67

78
namespace MemPlus.Business.UTILS
89
{
@@ -25,6 +26,10 @@ internal sealed class HotKeyController : IDisposable
2526
/// The HwndSource that can be used to retrieve messages
2627
/// </summary>
2728
private HwndSource _source;
29+
/// <summary>
30+
/// The LogController object that can be used to add logs
31+
/// </summary>
32+
private readonly LogController _logController;
2833
#endregion
2934

3035
#region Events
@@ -41,10 +46,17 @@ internal sealed class HotKeyController : IDisposable
4146
/// <summary>
4247
/// Initialize a new HotKeyController
4348
/// </summary>
44-
internal HotKeyController(WindowInteropHelper helper)
49+
/// <param name="helper">The WindowInteropHelper object that can be used to retrieve the Window handle</param>
50+
/// <param name="logController">The LogController object that can be used to add logs</param>
51+
internal HotKeyController(WindowInteropHelper helper, LogController logController)
4552
{
53+
_logController = logController;
54+
_logController?.AddLog(new ApplicationLog("Initializing HotKeyController"));
55+
4656
_helper = helper;
4757
_source = HwndSource.FromHwnd(_helper.Handle);
58+
59+
_logController?.AddLog(new ApplicationLog("Done initializing HotKeyController"));
4860
}
4961

5062
/// <summary>
@@ -54,6 +66,7 @@ internal HotKeyController(WindowInteropHelper helper)
5466
/// <param name="key">The key that is associated with the hotkey</param>
5567
internal void RegisterHotKey(uint modifier, Keys key)
5668
{
69+
_logController?.AddLog(new ApplicationLog("Registering hotkey"));
5770
// Increment the counter.
5871
_currentId++;
5972

@@ -64,6 +77,7 @@ internal void RegisterHotKey(uint modifier, Keys key)
6477

6578
if (!NativeMethods.RegisterHotKey(_helper.Handle, _currentId, modifier, (uint)key))
6679
throw new Exception("RegisterHotKey: ", new Win32Exception(Marshal.GetLastWin32Error()));
80+
_logController?.AddLog(new ApplicationLog("Done registering hotkey"));
6781
}
6882

6983
private IntPtr HwndHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
@@ -84,14 +98,17 @@ private IntPtr HwndHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref
8498
/// </summary>
8599
public void Dispose()
86100
{
101+
_logController?.AddLog(new ApplicationLog("Disposing all available hotkey objects and hooks"));
87102
// Unregister all the registered hot keys.
88103
for (int i = _currentId; i > 0; i--)
89104
{
90105
NativeMethods.UnregisterHotKey(_helper.Handle, i);
91106
}
92107
// Remove the hook from the HwndSource
93-
_source.RemoveHook(HwndHook);
108+
_source?.RemoveHook(HwndHook);
94109
_source = null;
110+
111+
_logController?.AddLog(new ApplicationLog("Done disposing all available hotkey objects and hooks"));
95112
}
96113
#endregion
97114
}

MemPlus/Views/Windows/LogWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<RowDefinition />
1717
<RowDefinition Height="Auto" />
1818
</Grid.RowDefinitions>
19-
<ListView x:Name="LsvLogs" ScrollBar.Scroll="LsvLogs_OnScroll" SelectionMode="Single">
19+
<ListView x:Name="LsvLogs" ScrollBar.Scroll="LsvLogs_OnScroll" SelectionMode="Single" PreviewMouseWheel="LsvLogs_MouseWheel">
2020
<ListView.ContextMenu>
2121
<ContextMenu>
2222
<MenuItem Header="Copy" Click="CopyMenuItem_OnClick">

MemPlus/Views/Windows/LogWindow.xaml.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,5 +239,15 @@ private void CopyMenuItem_OnClick(object sender, RoutedEventArgs e)
239239
MessageBox.Show(ex.Message, "MemPlus", MessageBoxButton.OK, MessageBoxImage.Error);
240240
}
241241
}
242+
243+
/// <summary>
244+
/// Event that is called when the mouse wheel is used
245+
/// </summary>
246+
/// <param name="sender">The object that called this method</param>
247+
/// <param name="e">The MouseWheelEventArgs</param>
248+
private void LsvLogs_MouseWheel(object sender, MouseWheelEventArgs e)
249+
{
250+
_autoScroll = false;
251+
}
242252
}
243253
}

MemPlus/Views/Windows/MainWindow.xaml.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ protected override void OnSourceInitialized(EventArgs e)
233233
/// </summary>
234234
internal void HotKeyModifier(WindowInteropHelper helper)
235235
{
236+
_logController?.AddLog(new ApplicationLog("Initializing hotkey hook"));
236237
try
237238
{
238239
if (Properties.Settings.Default.UseHotKey)
@@ -241,8 +242,9 @@ internal void HotKeyModifier(WindowInteropHelper helper)
241242

242243
if (Properties.Settings.Default.HotKey == Key.None) return;
243244

244-
_hotKeyController = new HotKeyController(helper);
245+
_hotKeyController = new HotKeyController(helper, _logController);
245246
_hotKeyController.HotKeyPressedEvent += HotKeyPressed;
247+
246248
string[] mods = Properties.Settings.Default.HotKeyModifiers.Split('+');
247249

248250
uint values = 0;
@@ -273,6 +275,7 @@ internal void HotKeyModifier(WindowInteropHelper helper)
273275
_logController?.AddLog(new ApplicationLog(ex.Message));
274276
MessageBox.Show(ex.Message, "MemPlus", MessageBoxButton.OK, MessageBoxImage.Error);
275277
}
278+
_logController?.AddLog(new ApplicationLog("Done initializing hotkey hook"));
276279
}
277280

278281
/// <summary>

0 commit comments

Comments
 (0)