mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
refactor- point CustomQueryHotkey to HotkeyMapper
This commit is contained in:
parent
b96a02bd60
commit
8c31039328
3 changed files with 27 additions and 54 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using Flow.Launcher.Core.Resource;
|
||||
using Flow.Launcher.Helper;
|
||||
using Flow.Launcher.Infrastructure.Hotkey;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using NHotkey;
|
||||
|
|
@ -52,11 +53,7 @@ namespace Flow.Launcher
|
|||
};
|
||||
_settings.CustomPluginHotkeys.Add(pluginHotkey);
|
||||
|
||||
SetHotkey(ctlHotkey.CurrentHotkey, delegate
|
||||
{
|
||||
App.API.ChangeQuery(pluginHotkey.ActionKeyword);
|
||||
ShowMainWindow();
|
||||
});
|
||||
HotKeyMapper.SetCustomQueryHotkey(pluginHotkey);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -69,22 +66,11 @@ namespace Flow.Launcher
|
|||
updateCustomHotkey.ActionKeyword = tbAction.Text;
|
||||
updateCustomHotkey.Hotkey = ctlHotkey.CurrentHotkey.ToString();
|
||||
//remove origin hotkey
|
||||
RemoveHotkey(oldHotkey);
|
||||
SetHotkey(new HotkeyModel(updateCustomHotkey.Hotkey), delegate
|
||||
{
|
||||
App.API.ChangeQuery(updateCustomHotkey.ActionKeyword);
|
||||
ShowMainWindow();
|
||||
});
|
||||
HotKeyMapper.RemoveHotkey(oldHotkey);
|
||||
HotKeyMapper.SetCustomQueryHotkey(updateCustomHotkey);
|
||||
}
|
||||
|
||||
Close();
|
||||
|
||||
static void ShowMainWindow()
|
||||
{
|
||||
Window mainWindow = Application.Current.MainWindow;
|
||||
mainWindow.Visibility = Visibility.Visible;
|
||||
mainWindow.Focus();
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateItem(CustomPluginHotkey item)
|
||||
|
|
@ -109,28 +95,6 @@ namespace Flow.Launcher
|
|||
Application.Current.MainWindow.Visibility = Visibility.Visible;
|
||||
}
|
||||
|
||||
private void RemoveHotkey(string hotkeyStr)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(hotkeyStr))
|
||||
{
|
||||
HotkeyManager.Current.Remove(hotkeyStr);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetHotkey(HotkeyModel hotkey, EventHandler<HotkeyEventArgs> action)
|
||||
{
|
||||
string hotkeyStr = hotkey.ToString();
|
||||
try
|
||||
{
|
||||
HotkeyManager.Current.AddOrReplace(hotkeyStr, hotkey.CharKey, hotkey.ModifierKeys, action);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
string errorMsg = string.Format(InternationalizationManager.Instance.GetTranslation("registerHotkeyFailed"), hotkeyStr);
|
||||
MessageBox.Show(errorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
private void cmdEsc_OnPress(object sender, ExecutedRoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ namespace Flow.Launcher.Helper
|
|||
settings = mainViewModel._settings;
|
||||
|
||||
SetHotkey(settings.Hotkey, OnHotkey);
|
||||
SetCustomPluginHotkey();
|
||||
LoadCustomPluginHotkey();
|
||||
}
|
||||
|
||||
private static void SetHotkey(string hotkeyStr, EventHandler<HotkeyEventArgs> action)
|
||||
|
|
@ -91,22 +91,29 @@ namespace Flow.Launcher.Helper
|
|||
}
|
||||
}
|
||||
|
||||
private static void SetCustomPluginHotkey()
|
||||
internal static void LoadCustomPluginHotkey()
|
||||
{
|
||||
if (settings.CustomPluginHotkeys == null) return;
|
||||
if (settings.CustomPluginHotkeys == null)
|
||||
return;
|
||||
|
||||
foreach (CustomPluginHotkey hotkey in settings.CustomPluginHotkeys)
|
||||
{
|
||||
SetHotkey(hotkey.Hotkey, (s, e) =>
|
||||
{
|
||||
if (ShouldIgnoreHotkeys())
|
||||
return;
|
||||
|
||||
UpdateLastQUeryMode();
|
||||
|
||||
mainViewModel.MainWindowVisibility = Visibility.Visible;
|
||||
mainViewModel.ChangeQueryText(hotkey.ActionKeyword);
|
||||
});
|
||||
SetCustomQueryHotkey(hotkey);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void SetCustomQueryHotkey(CustomPluginHotkey hotkey)
|
||||
{
|
||||
SetHotkey(hotkey.Hotkey, (s, e) =>
|
||||
{
|
||||
if (ShouldIgnoreHotkeys())
|
||||
return;
|
||||
|
||||
UpdateLastQUeryMode();
|
||||
|
||||
mainViewModel.MainWindowVisibility = Visibility.Visible;
|
||||
mainViewModel.ChangeQueryText(hotkey.ActionKeyword);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,9 @@ namespace Flow.Launcher
|
|||
protected virtual void OnHotkeyChanged()
|
||||
{
|
||||
EventHandler handler = HotkeyChanged;
|
||||
if (handler != null) handler(this, EventArgs.Empty);
|
||||
|
||||
if (handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
public HotkeyControl()
|
||||
|
|
|
|||
Loading…
Reference in a new issue