Flow.Launcher/Flow.Launcher/CustomQueryHotkeySetting.xaml.cs

93 lines
3 KiB
C#
Raw Normal View History

using Flow.Launcher.Helper;
using Flow.Launcher.Infrastructure.UserSettings;
using System.Collections.ObjectModel;
2014-02-22 07:52:20 +00:00
using System.Linq;
using System.Windows;
using System.Windows.Input;
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;
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
{
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);
HotKeyMapper.SetCustomQueryHotkey(pluginHotkey);
2014-02-22 07:52:20 +00:00
}
else
{
var oldHotkey = updateCustomHotkey.Hotkey;
updateCustomHotkey.ActionKeyword = tbAction.Text;
updateCustomHotkey.Hotkey = HotkeyControl.CurrentHotkey.ToString();
2014-02-22 07:52:20 +00:00
//remove origin hotkey
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 =>
o.ActionKeyword == item.ActionKeyword && o.Hotkey == item.Hotkey);
2014-02-22 07:52:20 +00:00
if (updateCustomHotkey == null)
{
App.API.ShowMsgBox(App.API.GetTranslation("invalidPluginHotkey"));
2014-02-22 07:52:20 +00:00
Close();
return;
}
tbAction.Text = updateCustomHotkey.ActionKeyword;
HotkeyControl.SetHotkey(updateCustomHotkey.Hotkey, false);
2014-02-22 07:52:20 +00:00
update = true;
lblAdd.Text = App.API.GetTranslation("update");
2014-02-22 07:52:20 +00:00
}
private void BtnTestActionKeyword_OnClick(object sender, RoutedEventArgs e)
{
App.API.ChangeQuery(tbAction.Text);
App.API.ShowMainWindow();
Application.Current.MainWindow.Focus();
}
private void cmdEsc_OnPress(object sender, ExecutedRoutedEventArgs e)
{
Close();
}
private void window_MouseDown(object sender, MouseButtonEventArgs e) /* for close hotkey popup */
{
if (Keyboard.FocusedElement is not TextBox textBox) return;
TraversalRequest tRequest = new TraversalRequest(FocusNavigationDirection.Next);
textBox.MoveFocus(tRequest);
}
2014-02-22 07:52:20 +00:00
}
}