Flow.Launcher/Flow.Launcher/CustomShortcutSetting.xaml.cs

74 lines
2.4 KiB
C#
Raw Normal View History

using Flow.Launcher.Core.Resource;
using System;
using System.Windows;
using System.Windows.Input;
using Flow.Launcher.SettingPages.ViewModels;
using Flow.Launcher.Core;
namespace Flow.Launcher
{
public partial class CustomShortcutSetting : Window
{
private readonly SettingsPaneHotkeyViewModel _hotkeyVm;
2022-11-06 06:59:31 +00:00
public string Key { get; set; } = String.Empty;
public string Value { get; set; } = String.Empty;
private string originalKey { get; } = null;
private string originalValue { get; } = null;
private bool update { get; } = false;
public CustomShortcutSetting(SettingsPaneHotkeyViewModel vm)
{
_hotkeyVm = vm;
InitializeComponent();
}
public CustomShortcutSetting(string key, string value, SettingsPaneHotkeyViewModel vm)
{
2022-11-06 06:52:21 +00:00
Key = key;
Value = value;
originalKey = key;
originalValue = value;
update = true;
_hotkeyVm = vm;
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-10-13 18:08:29 +00:00
if (String.IsNullOrEmpty(Key) || String.IsNullOrEmpty(Value))
2022-10-08 09:01:18 +00:00
{
MessageBoxEx.Show(InternationalizationManager.Instance.GetTranslation("emptyShortcut"));
return;
2022-10-08 09:01:18 +00:00
}
2022-11-06 06:52:21 +00:00
// Check if key is modified or adding a new one
if (((update && originalKey != Key) || !update) && _hotkeyVm.DoesShortcutExist(Key))
2022-10-08 09:01:18 +00:00
{
MessageBoxEx.Show(InternationalizationManager.Instance.GetTranslation("duplicateShortcut"));
2022-11-06 06:52:21 +00:00
return;
2022-10-08 09:01:18 +00:00
}
2022-11-06 06:52:21 +00:00
DialogResult = !update || originalKey != Key || originalValue != Value;
Close();
}
private void cmdEsc_OnPress(object sender, ExecutedRoutedEventArgs e)
{
DialogResult = false;
Close();
}
private void BtnTestShortcut_OnClick(object sender, RoutedEventArgs e)
{
App.API.ChangeQuery(tbExpand.Text);
Application.Current.MainWindow.Show();
Application.Current.MainWindow.Opacity = 1;
Application.Current.MainWindow.Focus();
}
}
}