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

99 lines
3.3 KiB
C#
Raw Normal View History

using Flow.Launcher.Core.Resource;
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;
using Flow.Launcher.ViewModel;
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
{
private SettingWindow _settingWidow;
2014-02-22 07:52:20 +00:00
private bool update;
private CustomPluginHotkey updateCustomHotkey;
public Settings Settings { get; }
2014-02-22 07:52:20 +00:00
public CustomQueryHotkeySetting(SettingWindow settingWidow, Settings settings)
2014-02-22 07:52:20 +00:00
{
_settingWidow = settingWidow;
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)
{
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
};
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();
}
2014-02-22 07:52:20 +00:00
public void UpdateItem(CustomPluginHotkey item)
{
updateCustomHotkey = Settings.CustomPluginHotkeys.FirstOrDefault(o =>
o.ActionKeyword == item.ActionKeyword && o.Hotkey == item.Hotkey);
2014-02-22 07:52:20 +00:00
if (updateCustomHotkey == null)
{
2015-01-21 15:00:56 +00:00
MessageBox.Show(InternationalizationManager.Instance.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;
2015-01-21 15:00:56 +00:00
lblAdd.Text = InternationalizationManager.Instance.GetTranslation("update");
2014-02-22 07:52:20 +00:00
}
private void BtnTestActionKeyword_OnClick(object sender, RoutedEventArgs e)
{
App.API.ChangeQuery(tbAction.Text);
Application.Current.MainWindow.Show();
Application.Current.MainWindow.Opacity = 1;
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
}
}