From d60ba015e0b59344c8b7648115938ec54e62e2e3 Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Sat, 4 Jun 2022 00:30:33 -0500 Subject: [PATCH] Implement {clipboard} feature and the setting panel --- .../UserSettings/Settings.cs | 44 +++++- Flow.Launcher/CustomShortcutSetting.xaml | 148 ++++++++++++++++++ Flow.Launcher/CustomShortcutSetting.xaml.cs | 52 ++++++ Flow.Launcher/Flow.Launcher.csproj | 1 + Flow.Launcher/Languages/en.xaml | 2 + Flow.Launcher/SettingWindow.xaml | 11 +- Flow.Launcher/SettingWindow.xaml.cs | 50 +++++- Flow.Launcher/ViewModel/MainViewModel.cs | 32 ++-- .../ViewModel/SettingWindowViewModel.cs | 11 +- 9 files changed, 327 insertions(+), 24 deletions(-) create mode 100644 Flow.Launcher/CustomShortcutSetting.xaml create mode 100644 Flow.Launcher/CustomShortcutSetting.xaml.cs diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 568e6c53c..1c84c5fb4 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -204,9 +204,9 @@ namespace Flow.Launcher.Infrastructure.UserSettings // This needs to be loaded last by staying at the bottom public PluginsSettings PluginSettings { get; set; } = new PluginsSettings(); - internal ObservableCollection> ShortCuts { get; set; } = new() + internal ObservableCollection ShortCuts { get; set; } = new() { - new("spp", "sp play") + ("spp", "sp play") }; } @@ -223,4 +223,44 @@ namespace Flow.Launcher.Infrastructure.UserSettings Light, Dark } + + public struct ShortCutModel + { + public string Key { get; set; } + public string Value { get; set; } + + public ShortCutModel(string key, string value) + { + Key = key; + Value = value; + } + + public override bool Equals(object obj) + { + return obj is ShortCutModel other && + Key == other.Key && + Value == other.Value; + } + + public override int GetHashCode() + { + return HashCode.Combine(Key, Value); + } + + public void Deconstruct(out string key, out string value) + { + key = Key; + value = Value; + } + + public static implicit operator (string Key, string Value)(ShortCutModel value) + { + return (value.Key, value.Value); + } + + public static implicit operator ShortCutModel((string Key, string Value) value) + { + return new ShortCutModel(value.Key, value.Value); + } + } } \ No newline at end of file diff --git a/Flow.Launcher/CustomShortcutSetting.xaml b/Flow.Launcher/CustomShortcutSetting.xaml new file mode 100644 index 000000000..839836b6a --- /dev/null +++ b/Flow.Launcher/CustomShortcutSetting.xaml @@ -0,0 +1,148 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Flow.Launcher/CustomShortcutSetting.xaml.cs b/Flow.Launcher/CustomShortcutSetting.xaml.cs new file mode 100644 index 000000000..feea064a4 --- /dev/null +++ b/Flow.Launcher/CustomShortcutSetting.xaml.cs @@ -0,0 +1,52 @@ +using Flow.Launcher.Core.Resource; +using Flow.Launcher.Helper; +using Flow.Launcher.Infrastructure.UserSettings; +using System.Collections.ObjectModel; +using System.Linq; +using System.Windows; +using System.Windows.Input; +using System.Windows.Controls; +using System.Collections.Generic; + +namespace Flow.Launcher +{ + public partial class CustomShortcutSetting : Window + { + private SettingWindow _settingWidow; + private bool update; + private CustomPluginHotkey updateCustomHotkey; + private Settings _settings; + + public string Key { get; set; } + public string Value { get; set; } + public ShortCutModel ShortCut => (Key, Value); + public CustomShortcutSetting() + { + InitializeComponent(); + } + + public CustomShortcutSetting((string, string) shortcut) + { + (Key, Value) = shortcut; + InitializeComponent(); + } + + private void BtnCancel_OnClick(object sender, RoutedEventArgs e) + { + DialogResult = false; + Close(); + } + + private void btnAdd_OnClick(object sender, RoutedEventArgs e) + { + DialogResult = true; + Close(); + } + + private void cmdEsc_OnPress(object sender, ExecutedRoutedEventArgs e) + { + DialogResult = false; + Close(); + } + } +} diff --git a/Flow.Launcher/Flow.Launcher.csproj b/Flow.Launcher/Flow.Launcher.csproj index 35a6389ca..ef0bc4f14 100644 --- a/Flow.Launcher/Flow.Launcher.csproj +++ b/Flow.Launcher/Flow.Launcher.csproj @@ -12,6 +12,7 @@ false false en + false diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index 25de530bc..401f532a2 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -115,6 +115,8 @@ Show result selection hotkey with results. Custom Query Hotkey Query + Shortcut + Expanded Delete Edit Add diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index 2fe5d2353..47933f326 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -2159,7 +2159,7 @@