2025-04-09 13:12:09 +00:00
|
|
|
|
using Flow.Launcher.Helper;
|
2020-06-19 08:52:11 +00:00
|
|
|
|
using Flow.Launcher.Infrastructure.UserSettings;
|
2016-05-22 19:50:06 +00:00
|
|
|
|
using System.Collections.ObjectModel;
|
2014-02-22 07:52:20 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Windows;
|
2020-06-19 08:52:11 +00:00
|
|
|
|
using System.Windows.Input;
|
2021-10-29 23:33:52 +00:00
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
|
|
2020-04-21 09:12:17 +00:00
|
|
|
|
namespace Flow.Launcher
|
2014-02-22 07:52:20 +00:00
|
|
|
|
{
|
2015-01-02 15:07:49 +00:00
|
|
|
|
public partial class CustomQueryHotkeySetting : Window
|
2014-02-22 07:52:20 +00:00
|
|
|
|
{
|
2025-02-23 05:19:55 +00:00
|
|
|
|
private readonly Settings _settings;
|
2014-02-22 07:52:20 +00:00
|
|
|
|
private bool update;
|
|
|
|
|
|
private CustomPluginHotkey updateCustomHotkey;
|
|
|
|
|
|
|
2025-01-13 04:00:45 +00:00
|
|
|
|
public CustomQueryHotkeySetting(Settings settings)
|
2014-02-22 07:52:20 +00:00
|
|
|
|
{
|
2025-02-23 05:19:55 +00:00
|
|
|
|
_settings = settings;
|
2014-02-22 07:52:20 +00:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void btnAdd_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!update)
|
|
|
|
|
|
{
|
2025-02-16 16:00:18 +00:00
|
|
|
|
_settings.CustomPluginHotkeys ??= new ObservableCollection<CustomPluginHotkey>();
|
2014-02-22 07:52:20 +00:00
|
|
|
|
|
2016-01-06 21:34:42 +00:00
|
|
|
|
var pluginHotkey = new CustomPluginHotkey
|
2014-02-22 07:52:20 +00:00
|
|
|
|
{
|
2024-04-17 16:57:54 +00:00
|
|
|
|
Hotkey = HotkeyControl.CurrentHotkey.ToString(), ActionKeyword = tbAction.Text
|
2014-02-22 07:52:20 +00:00
|
|
|
|
};
|
2025-02-16 16:00:18 +00:00
|
|
|
|
_settings.CustomPluginHotkeys.Add(pluginHotkey);
|
2016-02-18 12:56:53 +00:00
|
|
|
|
|
2021-07-13 11:53:02 +00:00
|
|
|
|
HotKeyMapper.SetCustomQueryHotkey(pluginHotkey);
|
2014-02-22 07:52:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
var oldHotkey = updateCustomHotkey.Hotkey;
|
|
|
|
|
|
updateCustomHotkey.ActionKeyword = tbAction.Text;
|
2024-04-17 16:57:54 +00:00
|
|
|
|
updateCustomHotkey.Hotkey = HotkeyControl.CurrentHotkey.ToString();
|
2014-02-22 07:52:20 +00:00
|
|
|
|
//remove origin hotkey
|
2021-07-13 11:53:02 +00:00
|
|
|
|
HotKeyMapper.RemoveHotkey(oldHotkey);
|
|
|
|
|
|
HotKeyMapper.SetCustomQueryHotkey(updateCustomHotkey);
|
2014-02-22 07:52:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void UpdateItem(CustomPluginHotkey item)
|
|
|
|
|
|
{
|
2025-02-16 16:00:18 +00:00
|
|
|
|
updateCustomHotkey = _settings.CustomPluginHotkeys.FirstOrDefault(o =>
|
2024-04-12 16:10:25 +00:00
|
|
|
|
o.ActionKeyword == item.ActionKeyword && o.Hotkey == item.Hotkey);
|
2014-02-22 07:52:20 +00:00
|
|
|
|
if (updateCustomHotkey == null)
|
|
|
|
|
|
{
|
2025-04-09 13:12:09 +00:00
|
|
|
|
App.API.ShowMsgBox(App.API.GetTranslation("invalidPluginHotkey"));
|
2014-02-22 07:52:20 +00:00
|
|
|
|
Close();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
tbAction.Text = updateCustomHotkey.ActionKeyword;
|
2024-04-17 16:57:54 +00:00
|
|
|
|
HotkeyControl.SetHotkey(updateCustomHotkey.Hotkey, false);
|
2014-02-22 07:52:20 +00:00
|
|
|
|
update = true;
|
2025-04-09 13:12:09 +00:00
|
|
|
|
lblAdd.Text = App.API.GetTranslation("update");
|
2014-02-22 07:52:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void BtnTestActionKeyword_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
2016-02-18 12:56:53 +00:00
|
|
|
|
App.API.ChangeQuery(tbAction.Text);
|
2025-02-18 03:32:47 +00:00
|
|
|
|
App.API.ShowMainWindow();
|
2021-07-14 11:04:48 +00:00
|
|
|
|
Application.Current.MainWindow.Focus();
|
2016-02-18 12:56:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-19 08:52:11 +00:00
|
|
|
|
private void cmdEsc_OnPress(object sender, ExecutedRoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Close();
|
|
|
|
|
|
}
|
2021-10-29 23:33:52 +00:00
|
|
|
|
|
|
|
|
|
|
private void window_MouseDown(object sender, MouseButtonEventArgs e) /* for close hotkey popup */
|
|
|
|
|
|
{
|
2024-04-18 05:58:41 +00:00
|
|
|
|
if (Keyboard.FocusedElement is not TextBox textBox) return;
|
|
|
|
|
|
|
|
|
|
|
|
TraversalRequest tRequest = new TraversalRequest(FocusNavigationDirection.Next);
|
|
|
|
|
|
textBox.MoveFocus(tRequest);
|
2021-10-29 23:33:52 +00:00
|
|
|
|
}
|
2014-02-22 07:52:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|