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

74 lines
2.3 KiB
C#
Raw Normal View History

using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Flow.Launcher.Infrastructure.UserSettings;
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
{
public string Hotkey { get; set; } = string.Empty;
public string ActionKeyword { get; set; } = string.Empty;
private readonly bool update;
private readonly CustomPluginHotkey originalCustomHotkey;
public CustomQueryHotkeySetting()
2014-02-22 07:52:20 +00:00
{
InitializeComponent();
2025-07-10 05:24:07 +00:00
tbAdd.Visibility = Visibility.Visible;
2014-02-22 07:52:20 +00:00
}
public CustomQueryHotkeySetting(CustomPluginHotkey hotkey)
2014-02-22 07:52:20 +00:00
{
originalCustomHotkey = hotkey;
update = true;
ActionKeyword = originalCustomHotkey.ActionKeyword;
InitializeComponent();
2025-07-10 05:24:07 +00:00
tbUpdate.Visibility = Visibility.Visible;
HotkeyControl.SetHotkey(originalCustomHotkey.Hotkey, false);
2014-02-22 07:52:20 +00:00
}
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
2014-02-22 07:52:20 +00:00
{
DialogResult = false;
2014-02-22 07:52:20 +00:00
Close();
}
private void btnAdd_OnClick(object sender, RoutedEventArgs e)
2014-02-22 07:52:20 +00:00
{
Hotkey = HotkeyControl.CurrentHotkey.ToString();
if (string.IsNullOrEmpty(Hotkey) && string.IsNullOrEmpty(ActionKeyword))
2014-02-22 07:52:20 +00:00
{
App.API.ShowMsgBox(Localize.emptyPluginHotkey());
2014-02-22 07:52:20 +00:00
return;
}
DialogResult = !update || originalCustomHotkey.Hotkey != Hotkey || originalCustomHotkey.ActionKeyword != ActionKeyword;
Close();
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)
{
DialogResult = false;
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
}
}