2025-04-23 04:43:34 +00:00
|
|
|
|
using System.Windows;
|
2022-06-04 05:30:33 +00:00
|
|
|
|
using System.Windows.Input;
|
2024-06-20 03:54:01 +00:00
|
|
|
|
using Flow.Launcher.SettingPages.ViewModels;
|
2022-06-04 05:30:33 +00:00
|
|
|
|
|
|
|
|
|
|
namespace Flow.Launcher
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class CustomShortcutSetting : Window
|
|
|
|
|
|
{
|
2024-06-20 03:54:01 +00:00
|
|
|
|
private readonly SettingsPaneHotkeyViewModel _hotkeyVm;
|
2025-04-23 04:43:34 +00:00
|
|
|
|
public string Key { get; set; } = string.Empty;
|
|
|
|
|
|
public string Value { get; set; } = string.Empty;
|
2024-06-20 03:54:01 +00:00
|
|
|
|
private string originalKey { get; } = null;
|
|
|
|
|
|
private string originalValue { get; } = null;
|
|
|
|
|
|
private bool update { get; } = false;
|
2025-04-23 04:43:34 +00:00
|
|
|
|
|
2024-06-20 03:54:01 +00:00
|
|
|
|
public CustomShortcutSetting(SettingsPaneHotkeyViewModel vm)
|
2022-06-04 05:30:33 +00:00
|
|
|
|
{
|
2024-06-20 03:54:01 +00:00
|
|
|
|
_hotkeyVm = vm;
|
2022-06-04 05:30:33 +00:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-20 03:54:01 +00:00
|
|
|
|
public CustomShortcutSetting(string key, string value, SettingsPaneHotkeyViewModel vm)
|
2022-06-04 05:30:33 +00:00
|
|
|
|
{
|
2022-11-06 06:52:21 +00:00
|
|
|
|
Key = key;
|
|
|
|
|
|
Value = value;
|
|
|
|
|
|
originalKey = key;
|
|
|
|
|
|
originalValue = value;
|
2022-10-08 09:52:27 +00:00
|
|
|
|
update = true;
|
2024-06-20 03:54:01 +00:00
|
|
|
|
_hotkeyVm = vm;
|
2022-06-04 05:30:33 +00:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
DialogResult = false;
|
|
|
|
|
|
Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-13 11:49:44 +00:00
|
|
|
|
private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
|
2022-06-04 05:30:33 +00:00
|
|
|
|
{
|
2025-04-09 13:12:09 +00:00
|
|
|
|
if (string.IsNullOrEmpty(Key) || string.IsNullOrEmpty(Value))
|
2022-10-08 09:01:18 +00:00
|
|
|
|
{
|
2025-09-23 08:21:09 +00:00
|
|
|
|
App.API.ShowMsgBox(Localize.emptyShortcut());
|
2022-10-08 09:52:27 +00:00
|
|
|
|
return;
|
2022-10-08 09:01:18 +00:00
|
|
|
|
}
|
2025-07-06 13:07:25 +00:00
|
|
|
|
|
2022-11-06 06:52:21 +00:00
|
|
|
|
// Check if key is modified or adding a new one
|
2024-06-20 03:54:01 +00:00
|
|
|
|
if (((update && originalKey != Key) || !update) && _hotkeyVm.DoesShortcutExist(Key))
|
2022-10-08 09:01:18 +00:00
|
|
|
|
{
|
2025-09-23 08:21:09 +00:00
|
|
|
|
App.API.ShowMsgBox(Localize.duplicateShortcut());
|
2022-11-06 06:52:21 +00:00
|
|
|
|
return;
|
2022-10-08 09:01:18 +00:00
|
|
|
|
}
|
2025-07-06 13:07:25 +00:00
|
|
|
|
|
2022-11-06 06:52:21 +00:00
|
|
|
|
DialogResult = !update || originalKey != Key || originalValue != Value;
|
2022-06-04 05:30:33 +00:00
|
|
|
|
Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void cmdEsc_OnPress(object sender, ExecutedRoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
DialogResult = false;
|
|
|
|
|
|
Close();
|
|
|
|
|
|
}
|
2022-10-08 09:52:27 +00:00
|
|
|
|
|
|
|
|
|
|
private void BtnTestShortcut_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
App.API.ChangeQuery(tbExpand.Text);
|
2025-02-18 03:32:47 +00:00
|
|
|
|
App.API.ShowMainWindow();
|
2022-10-08 09:52:27 +00:00
|
|
|
|
Application.Current.MainWindow.Focus();
|
|
|
|
|
|
}
|
2022-06-04 05:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|