mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-05-03 20:13:49 +12:00
Code cleanup, version 1.3.0.4
This commit is contained in:
parent
5007203094
commit
271a55d0ff
|
@ -166,7 +166,6 @@ namespace SystemTrayMenu.Helper
|
|||
{
|
||||
Log.Info("Failed to convert icon.");
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
@ -39,5 +39,5 @@ using System.Runtime.InteropServices;
|
|||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.3.0.3")]
|
||||
[assembly: AssemblyFileVersion("1.3.0.3")]
|
||||
[assembly: AssemblyVersion("1.3.0.4")]
|
||||
[assembly: AssemblyFileVersion("1.3.0.4")]
|
||||
|
|
|
@ -15,18 +15,16 @@ namespace SystemTrayMenu.UserInterface.HotkeyTextboxControl
|
|||
/// A simple control that allows the user to select pretty much any valid hotkey combination
|
||||
/// See: http://www.codeproject.com/KB/buttons/hotkeycontrol.aspx
|
||||
/// But is modified to fit in Greenshot, and have localized support.
|
||||
/// modfied to fit SystemTrayMenu.
|
||||
/// </summary>
|
||||
public sealed class HotkeyControl : TextBox
|
||||
{
|
||||
private const uint WmHotkey = 0x312;
|
||||
|
||||
private static readonly EventDelay EventDelay = new(TimeSpan.FromMilliseconds(600).Ticks);
|
||||
private static readonly bool IsWindows7OrOlder = Environment.OSVersion.Version.Major >= 6 && Environment.OSVersion.Version.Minor >= 1;
|
||||
private static readonly IntPtr HotkeyHwnd = (IntPtr)0x0000000000000000;
|
||||
|
||||
// Holds the list of hotkeys
|
||||
private static readonly IDictionary<int, HotKeyHandler> KeyHandlers = new Dictionary<int, HotKeyHandler>();
|
||||
private static int hotKeyCounter = 1;
|
||||
private static IntPtr hotkeyHwnd;
|
||||
|
||||
// ArrayLists used to enforce the use of proper modifiers.
|
||||
// Shift+A isn't a valid hotkey, for instance, as it would screw up when the user is typing.
|
||||
|
@ -121,13 +119,6 @@ namespace SystemTrayMenu.UserInterface.HotkeyTextboxControl
|
|||
}
|
||||
}
|
||||
|
||||
public static string GetLocalizedHotkeyStringFromString(string hotkeyString)
|
||||
{
|
||||
Keys virtualKeyCode = HotkeyFromString(hotkeyString);
|
||||
Keys modifiers = HotkeyModifiersFromString(hotkeyString);
|
||||
return HotkeyToLocalizedString(modifiers, virtualKeyCode);
|
||||
}
|
||||
|
||||
public static string HotkeyToString(Keys modifierKeyCode, Keys virtualKeyCode)
|
||||
{
|
||||
return HotkeyModifiersToString(modifierKeyCode) + virtualKeyCode;
|
||||
|
@ -246,16 +237,6 @@ namespace SystemTrayMenu.UserInterface.HotkeyTextboxControl
|
|||
return key;
|
||||
}
|
||||
|
||||
public static void RegisterHotkeyHwnd(IntPtr hWnd)
|
||||
{
|
||||
hotkeyHwnd = hWnd;
|
||||
}
|
||||
|
||||
public static int RegisterHotKey(string hotkey, HotKeyHandler handler)
|
||||
{
|
||||
return RegisterHotKey(HotkeyModifiersFromString(hotkey), HotkeyFromString(hotkey), handler);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register a hotkey.
|
||||
/// </summary>
|
||||
|
@ -297,7 +278,7 @@ namespace SystemTrayMenu.UserInterface.HotkeyTextboxControl
|
|||
modifiers |= (uint)Modifiers.NOREPEAT;
|
||||
}
|
||||
|
||||
if (NativeMethods.User32RegisterHotKey(hotkeyHwnd, hotKeyCounter, modifiers, (uint)virtualKeyCode))
|
||||
if (NativeMethods.User32RegisterHotKey(HotkeyHwnd, hotKeyCounter, modifiers, (uint)virtualKeyCode))
|
||||
{
|
||||
KeyHandlers.Add(hotKeyCounter, handler);
|
||||
return hotKeyCounter++;
|
||||
|
@ -313,56 +294,12 @@ namespace SystemTrayMenu.UserInterface.HotkeyTextboxControl
|
|||
{
|
||||
foreach (int hotkey in KeyHandlers.Keys)
|
||||
{
|
||||
NativeMethods.User32UnregisterHotKey(hotkeyHwnd, hotkey);
|
||||
NativeMethods.User32UnregisterHotKey(HotkeyHwnd, hotkey);
|
||||
}
|
||||
|
||||
KeyHandlers.Clear();
|
||||
}
|
||||
|
||||
public static void UnregisterHotkey(int hotkey)
|
||||
{
|
||||
bool removeHotkey = false;
|
||||
foreach (int availableHotkey in KeyHandlers.Keys)
|
||||
{
|
||||
if (availableHotkey == hotkey)
|
||||
{
|
||||
NativeMethods.User32UnregisterHotKey(hotkeyHwnd, hotkey);
|
||||
removeHotkey = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (removeHotkey)
|
||||
{
|
||||
// Remove key handler
|
||||
KeyHandlers.Remove(hotkey);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle WndProc messages for the hotkey.
|
||||
/// </summary>
|
||||
/// <param name="m">m.</param>
|
||||
/// <returns>true if the message was handled.</returns>
|
||||
public static bool HandleMessages(ref Message m)
|
||||
{
|
||||
if (m.Msg != WmHotkey)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsWindows7OrOlder && !EventDelay.Check())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (KeyHandlers.TryGetValue((int)m.WParam, out HotKeyHandler handler))
|
||||
{
|
||||
handler();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static string GetKeyName(Keys givenKey)
|
||||
{
|
||||
StringBuilder keyName = new();
|
||||
|
@ -454,15 +391,6 @@ namespace SystemTrayMenu.UserInterface.HotkeyTextboxControl
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets this hotkey control to None.
|
||||
/// </summary>
|
||||
public new void Clear()
|
||||
{
|
||||
Hotkey = Keys.None;
|
||||
HotkeyModifiers = Keys.None;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears the current hotkey and resets the TextBox.
|
||||
/// </summary>
|
||||
|
|
|
@ -13,6 +13,9 @@ namespace SystemTrayMenu.Utilities
|
|||
using SystemTrayMenu.Helper;
|
||||
|
||||
/// <summary>
|
||||
/// source: https://www.codeproject.com/Articles/22012/Explorer-Shell-Context-Menu
|
||||
/// modified to fit SystemTrayMenu.
|
||||
///
|
||||
/// "Stand-alone" shell context menu
|
||||
///
|
||||
/// It isn't really debugged but is mostly working.
|
||||
|
@ -841,13 +844,6 @@ namespace SystemTrayMenu.Utilities
|
|||
/// <param name="m">the Message of the Browser's WndProc.</param>
|
||||
protected override void WndProc(ref Message m)
|
||||
{
|
||||
if (oContextMenu != null &&
|
||||
m.Msg == (int)WM.MENUSELECT &&
|
||||
((int)ShellHelper.HiWord(m.WParam) & (int)MFT.SEPARATOR) == 0 &&
|
||||
((int)ShellHelper.HiWord(m.WParam) & (int)MFT.POPUP) == 0)
|
||||
{
|
||||
}
|
||||
|
||||
if (oContextMenu2 != null &&
|
||||
(m.Msg == (int)WM.INITMENUPOPUP ||
|
||||
m.Msg == (int)WM.MEASUREITEM ||
|
||||
|
|
Loading…
Reference in a new issue