diff --git a/Flow.Launcher/CustomQueryHotkeySetting.xaml b/Flow.Launcher/CustomQueryHotkeySetting.xaml
index 1113cb24d..c470be903 100644
--- a/Flow.Launcher/CustomQueryHotkeySetting.xaml
+++ b/Flow.Launcher/CustomQueryHotkeySetting.xaml
@@ -2,6 +2,7 @@
x:Class="Flow.Launcher.CustomQueryHotkeySetting"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:flowlauncher="clr-namespace:Flow.Launcher"
Title="{DynamicResource customeQueryHotkeyTitle}"
Width="530"
@@ -11,7 +12,8 @@
MouseDown="window_MouseDown"
ResizeMode="NoResize"
SizeToContent="Height"
- WindowStartupLocation="CenterScreen">
+ WindowStartupLocation="CenterScreen"
+ DataContext="{Binding RelativeSource={RelativeSource Self}}">
@@ -104,7 +106,7 @@
Grid.Column="1"
Orientation="Horizontal">
o.ActionKeyword == item.ActionKeyword && o.Hotkey == item.Hotkey);
+ updateCustomHotkey = _settings.CustomPluginHotkeys.FirstOrDefault(o =>
+ o.ActionKeyword == item.ActionKeyword && o.Hotkey == item.Hotkey);
if (updateCustomHotkey == null)
{
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("invalidPluginHotkey"));
@@ -81,7 +86,7 @@ namespace Flow.Launcher
}
tbAction.Text = updateCustomHotkey.ActionKeyword;
- _ = ctlHotkey.SetHotkeyAsync(updateCustomHotkey.Hotkey, false);
+ _ = HotkeyControlViewModel.SetHotkeyAsync(updateCustomHotkey.Hotkey, false);
update = true;
lblAdd.Text = InternationalizationManager.Instance.GetTranslation("update");
}
diff --git a/Flow.Launcher/HotkeyControl.xaml b/Flow.Launcher/HotkeyControl.xaml
index 26d9d2cea..864e9d648 100644
--- a/Flow.Launcher/HotkeyControl.xaml
+++ b/Flow.Launcher/HotkeyControl.xaml
@@ -5,8 +5,10 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:input="clr-namespace:System.Windows.Input;assembly=PresentationCore"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:vm="clr-namespace:Flow.Launcher.ViewModel"
d:DesignWidth="300"
- mc:Ignorable="d">
+ mc:Ignorable="d"
+ d:DataContext="{d:DesignInstance vm:HotkeyControlViewModel}">
+ KeyboardNavigation.TabNavigation="Continue"
+ IsChecked="{Binding Recording}">
@@ -62,9 +65,9 @@
BorderThickness="1"
CornerRadius="5">
-
-
-
+
+
+
@@ -100,7 +103,8 @@
-
+
@@ -122,4 +126,4 @@
-
+
\ No newline at end of file
diff --git a/Flow.Launcher/HotkeyControl.xaml.cs b/Flow.Launcher/HotkeyControl.xaml.cs
index a2d82da13..071f844f4 100644
--- a/Flow.Launcher/HotkeyControl.xaml.cs
+++ b/Flow.Launcher/HotkeyControl.xaml.cs
@@ -10,141 +10,42 @@ using Flow.Launcher.Core.Resource;
using Flow.Launcher.Helper;
using Flow.Launcher.Infrastructure.Hotkey;
using Flow.Launcher.Plugin;
+using Flow.Launcher.ViewModel;
using NHotkey;
namespace Flow.Launcher
{
- public partial class HotkeyControl : UserControl, IDisposable, INotifyPropertyChanged
+ public partial class HotkeyControl : UserControl, INotifyPropertyChanged
{
- public static readonly DependencyProperty HotkeyProperty = DependencyProperty.Register(
- nameof(Hotkey),
- typeof(string),
- typeof(HotkeyControl),
- new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)
- );
- public HotkeyModel CurrentHotkey { get; private set; }
- public bool CurrentHotkeyAvailable { get; private set; }
-
- public string Hotkey
- {
- get => (string)GetValue(HotkeyProperty);
- set
- {
- SetValue(HotkeyProperty, value);
- OnPropertyChanged(nameof(KeysToDisplay));
- }
- }
-
- public string DefaultHotkey { get; set; }
-
- private const string EmptyKeyValue = "";
- private const string KeySeparator = " + ";
-
- private string[] _keysToDisplay = { EmptyKeyValue };
-
- public string[] KeysToDisplay
- {
- get => _keysToDisplay;
- set
- {
- _keysToDisplay = value;
- OnPropertyChanged();
- }
- }
-
- #nullable enable
- public EventHandler? Action { get; set; }
- #nullable restore
-
- public event EventHandler HotkeyChanged;
-
- ///
- /// Designed for Preview Hotkey and KeyGesture.
- ///
- public bool ValidateKeyGesture { get; set; } = false;
-
- protected virtual void OnHotkeyChanged() => HotkeyChanged?.Invoke(this, EventArgs.Empty);
+ // ///
+ // /// Designed for Preview Hotkey and KeyGesture.
+ // ///
+ // public static readonly DependencyProperty ValidateKeyGestureProperty = DependencyProperty.Register(
+ // nameof(ValidateKeyGesture), typeof(bool), typeof(HotkeyControlViewModel),
+ // new PropertyMetadata(default(bool)));
+ //
+ // public bool ValidateKeyGesture
+ // {
+ // get { return (bool)GetValue(ValidateKeyGestureProperty); }
+ // set { SetValue(ValidateKeyGestureProperty, value); }
+ // }
+ //
+ // public static readonly DependencyProperty DefaultHotkeyProperty = DependencyProperty.Register(
+ // nameof(DefaultHotkey), typeof(string), typeof(HotkeyControl), new PropertyMetadata(default(string)));
+ //
+ // public string DefaultHotkey
+ // {
+ // get { return (string)GetValue(DefaultHotkeyProperty); }
+ // set { SetValue(DefaultHotkeyProperty, value); }
+ // }
public HotkeyControl()
{
InitializeComponent();
- Loaded += HotkeyControl_Loaded;
- }
-
- /*------------------ New Logic Structure Part ------------------------*/
-
- private void OnStartRecordingClicked(object sender, RoutedEventArgs e)
- {
- if (HotkeyBtn.IsChecked == true)
- {
- if (!string.IsNullOrEmpty(Hotkey))
- {
- HotKeyMapper.RemoveHotkey(Hotkey);
- }
- /* 1. Key Recording Start */
- /* 2. Key Display area clear
- * 3. Key Display when typing*/
- }
- }
-
- private void OnStopRecordingClicked(object sender, RoutedEventArgs e)
- {
- HotkeyBtn.IsChecked = false;
-
- if (KeysToDisplay.Length == 0 || (KeysToDisplay.Length == 1 && KeysToDisplay[0] == EmptyKeyValue))
- {
- return;
- }
- _ = SetHotkeyAsync(string.Join(KeySeparator, KeysToDisplay));
- }
-
- private void OnResetToDefaultClicked(object sender, RoutedEventArgs e)
- {
- HotkeyBtn.IsChecked = false;
- if (!string.IsNullOrEmpty(Hotkey))
- HotKeyMapper.RemoveHotkey(Hotkey);
- Hotkey = DefaultHotkey;
- KeysToDisplay = Hotkey.Split(KeySeparator);
- _ = SetHotkeyAsync(Hotkey);
- }
-
- private void OnDeleteClicked(object sender, RoutedEventArgs e)
- {
- HotkeyBtn.IsChecked = false;
- if (!string.IsNullOrEmpty(Hotkey))
- HotKeyMapper.RemoveHotkey(Hotkey);
- Hotkey = "";
- KeysToDisplay = new []{ EmptyKeyValue };
}
/*------------------ New Logic Structure Part------------------------*/
- private void HotkeyControl_LostFocus(object o, RoutedEventArgs routedEventArgs)
- {
- HotKeyMapper.SetHotkey(CurrentHotkey, Action);
- }
-
- private void HotkeyControl_GotFocus(object o, RoutedEventArgs routedEventArgs)
- {
- HotKeyMapper.RemoveHotkey(Hotkey);
- }
-
- private void HotkeyControl_Loaded(object sender, RoutedEventArgs e)
- {
- _ = SetHotkeyAsync(Hotkey, false);
- KeysToDisplay = Hotkey switch
- {
- null or "" => new[] { EmptyKeyValue },
- _ => Hotkey.Split(KeySeparator)
- };
-
- if (Action is not null)
- {
- GotFocus += HotkeyControl_GotFocus;
- LostFocus += HotkeyControl_LostFocus;
- }
- }
-
private void OnPreviewKeyDown(object sender, KeyEventArgs e)
{
if (HotkeyBtn.IsChecked != true)
@@ -163,49 +64,9 @@ namespace Flow.Launcher
specialKeyState.CtrlPressed,
key);
- if (hotkeyModel.Equals(CurrentHotkey))
- {
- return;
- }
-
- KeysToDisplay = hotkeyModel.ToString().Split(KeySeparator);
+ ((HotkeyControlViewModel)this.DataContext).KeyDown(hotkeyModel);
}
- public async Task SetHotkeyAsync(HotkeyModel keyModel, bool triggerValidate = true)
- {
- // tbHotkey.Text = keyModel.ToString();
- // tbHotkey.Select(tbHotkey.Text.Length, 0);
-
- if (triggerValidate)
- {
- bool hotkeyAvailable = CheckHotkeyAvailability(keyModel, ValidateKeyGesture);
- CurrentHotkeyAvailable = hotkeyAvailable;
- SetMessage(hotkeyAvailable);
- OnHotkeyChanged();
-
- if (CurrentHotkeyAvailable)
- {
- CurrentHotkey = keyModel;
- Hotkey = keyModel.ToString();
- KeysToDisplay = Hotkey.Split(KeySeparator);
- // To trigger LostFocus
- FocusManager.SetFocusedElement(FocusManager.GetFocusScope(this), null);
- Keyboard.ClearFocus();
- }
- }
- else
- {
- CurrentHotkey = keyModel;
- Hotkey = keyModel.ToString();
- }
- }
-
- public Task SetHotkeyAsync(string keyStr, bool triggerValidate = true)
- {
- return SetHotkeyAsync(new HotkeyModel(keyStr), triggerValidate);
- }
-
- private static bool CheckHotkeyAvailability(HotkeyModel hotkey, bool validateKeyGesture) => hotkey.Validate(validateKeyGesture) && HotKeyMapper.CheckAvailability(hotkey);
// public new bool IsFocused => tbHotkey.IsFocused;
@@ -226,28 +87,6 @@ namespace Flow.Launcher
tbMsg.SetResourceReference(TextBox.ForegroundProperty, "Color05B");
}
- private void SetMessage(bool hotkeyAvailable)
- {
- if (!hotkeyAvailable)
- {
- tbMsg.Foreground = new SolidColorBrush(Colors.Red);
- tbMsg.Text = InternationalizationManager.Instance.GetTranslation("hotkeyUnavailable");
- }
- else
- {
- tbMsg.Foreground = new SolidColorBrush(Colors.Green);
- tbMsg.Text = InternationalizationManager.Instance.GetTranslation("success");
- }
- tbMsg.Visibility = Visibility.Visible;
- }
-
- public void Dispose()
- {
- Loaded -= HotkeyControl_Loaded;
- GotFocus -= HotkeyControl_GotFocus;
- LostFocus -= HotkeyControl_LostFocus;
- }
-
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
diff --git a/Flow.Launcher/Resources/Pages/WelcomePage2.xaml b/Flow.Launcher/Resources/Pages/WelcomePage2.xaml
index 033f9fe66..c15fe59a3 100644
--- a/Flow.Launcher/Resources/Pages/WelcomePage2.xaml
+++ b/Flow.Launcher/Resources/Pages/WelcomePage2.xaml
@@ -9,7 +9,8 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.modernwpf.com/2019"
Title="WelcomePage2"
- mc:Ignorable="d">
+ mc:Ignorable="d"
+ DataContext="{Binding RelativeSource={RelativeSource Self}}">