2020-06-19 08:52:11 +00:00
|
|
|
|
using Flow.Launcher.Core.Resource;
|
2021-07-13 11:53:02 +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
|
|
|
|
{
|
2016-03-28 02:09:57 +00:00
|
|
|
|
private SettingWindow _settingWidow;
|
2014-02-22 07:52:20 +00:00
|
|
|
|
private bool update;
|
|
|
|
|
|
private CustomPluginHotkey updateCustomHotkey;
|
2016-04-21 00:53:21 +00:00
|
|
|
|
private Settings _settings;
|
2014-02-22 07:52:20 +00:00
|
|
|
|
|
2016-04-21 00:53:21 +00:00
|
|
|
|
public CustomQueryHotkeySetting(SettingWindow settingWidow, Settings settings)
|
2014-02-22 07:52:20 +00:00
|
|
|
|
{
|
2016-03-28 02:09:57 +00:00
|
|
|
|
_settingWidow = settingWidow;
|
2014-02-22 07:52:20 +00:00
|
|
|
|
InitializeComponent();
|
2016-03-28 02:09:57 +00:00
|
|
|
|
_settings = settings;
|
2014-02-22 07:52:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void btnAdd_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!update)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!ctlHotkey.CurrentHotkeyAvailable)
|
|
|
|
|
|
{
|
2015-01-21 15:00:56 +00:00
|
|
|
|
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("hotkeyIsNotUnavailable"));
|
2014-02-22 07:52:20 +00:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-03-28 02:09:57 +00:00
|
|
|
|
if (_settings.CustomPluginHotkeys == null)
|
2014-02-22 07:52:20 +00:00
|
|
|
|
{
|
2016-05-22 19:50:06 +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 = ctlHotkey.CurrentHotkey.ToString(),
|
|
|
|
|
|
ActionKeyword = tbAction.Text
|
|
|
|
|
|
};
|
2016-03-28 02:09:57 +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
|
|
|
|
|
|
{
|
|
|
|
|
|
if (updateCustomHotkey.Hotkey != ctlHotkey.CurrentHotkey.ToString() && !ctlHotkey.CurrentHotkeyAvailable)
|
|
|
|
|
|
{
|
2015-01-21 15:00:56 +00:00
|
|
|
|
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("hotkeyIsNotUnavailable"));
|
2014-02-22 07:52:20 +00:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
var oldHotkey = updateCustomHotkey.Hotkey;
|
|
|
|
|
|
updateCustomHotkey.ActionKeyword = tbAction.Text;
|
|
|
|
|
|
updateCustomHotkey.Hotkey = ctlHotkey.CurrentHotkey.ToString();
|
|
|
|
|
|
//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)
|
|
|
|
|
|
{
|
2016-03-28 02:09:57 +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)
|
|
|
|
|
|
{
|
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;
|
2022-08-10 03:18:37 +00:00
|
|
|
|
_ = ctlHotkey.SetHotkeyAsync(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)
|
|
|
|
|
|
{
|
2016-02-18 12:56:53 +00:00
|
|
|
|
App.API.ChangeQuery(tbAction.Text);
|
2021-11-27 02:51:45 +00:00
|
|
|
|
Application.Current.MainWindow.Show();
|
2021-11-14 09:13:03 +00:00
|
|
|
|
Application.Current.MainWindow.Opacity = 1;
|
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 */
|
|
|
|
|
|
{
|
|
|
|
|
|
TextBox textBox = Keyboard.FocusedElement as TextBox;
|
|
|
|
|
|
if (textBox != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
TraversalRequest tRequest = new TraversalRequest(FocusNavigationDirection.Next);
|
|
|
|
|
|
textBox.MoveFocus(tRequest);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-02-22 07:52:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|