From 5879c843b0fdd994ea5cda54fb30f941a986d635 Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Thu, 13 Oct 2022 19:49:44 +0800 Subject: [PATCH] Show builtin vars in shortcut list --- .../UserSettings/CustomShortcutModel.cs | 43 +++++++++++-------- .../UserSettings/Settings.cs | 8 +++- Flow.Launcher/CustomShortcutSetting.xaml | 2 +- Flow.Launcher/CustomShortcutSetting.xaml.cs | 4 +- Flow.Launcher/SettingWindow.xaml | 2 +- Flow.Launcher/SettingWindow.xaml.cs | 18 ++++++-- Flow.Launcher/ViewModel/MainViewModel.cs | 19 ++++---- .../ViewModel/SettingWindowViewModel.cs | 21 ++++++++- 8 files changed, 81 insertions(+), 36 deletions(-) diff --git a/Flow.Launcher.Infrastructure/UserSettings/CustomShortcutModel.cs b/Flow.Launcher.Infrastructure/UserSettings/CustomShortcutModel.cs index 9df2633bc..eb10a3fbf 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/CustomShortcutModel.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/CustomShortcutModel.cs @@ -1,18 +1,40 @@ -using System; +using NLog.Time; +using System; +using System.Security.Cryptography.X509Certificates; +using System.Security.RightsManagement; using System.Text.Json.Serialization; namespace Flow.Launcher.Infrastructure.UserSettings { - public class CustomShortcutBaseModel + + public class CustomShortcutModel { public string Key { get; set; } + public string Value { get; set; } + public bool CanBeEdited { get; private set; } // Can be edited by user via dialog [JsonIgnore] public Func Expand { get; set; } = () => { return ""; }; + public CustomShortcutModel(string key, string value) + { + Key = key; + Value = value; + CanBeEdited = true; + Expand = () => { return Value; }; + } + + public CustomShortcutModel(string key, string description, Func expand) + { + Key = key; + Value = description; + CanBeEdited = false; + Expand = expand; + } + public override bool Equals(object obj) { - return obj is CustomShortcutBaseModel other && + return obj is CustomShortcutModel other && Key == other.Key; } @@ -20,21 +42,6 @@ namespace Flow.Launcher.Infrastructure.UserSettings { return HashCode.Combine(Key); } - }; - - public class CustomShortcutModel : CustomShortcutBaseModel - { - public string Value - { - get { return Expand(); } - set { Expand = () => { return value; }; } - } - - public CustomShortcutModel(string key, string value) - { - Key = key; - Value = value; - } public void Deconstruct(out string key, out string value) { diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index c9b76c2f5..cdbcf23ff 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -3,11 +3,11 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Drawing; using System.Text.Json.Serialization; +using System.Windows; using Flow.Launcher.Plugin; using Flow.Launcher.Plugin.SharedModels; using Flow.Launcher; using Flow.Launcher.ViewModel; - namespace Flow.Launcher.Infrastructure.UserSettings { public class Settings : BaseModel @@ -175,8 +175,14 @@ namespace Flow.Launcher.Infrastructure.UserSettings public ObservableCollection CustomPluginHotkeys { get; set; } = new ObservableCollection(); + public ObservableCollection CustomShortcuts { get; set; } = new ObservableCollection(); + [JsonIgnore] + public ObservableCollection BuiltinShortcuts { get; set; } = new ObservableCollection() { + new CustomShortcutModel("{clipboard}", "Get text from clipboard.", Clipboard.GetText) + }; + public bool DontPromptUpdateMsg { get; set; } public bool EnableUpdateLog { get; set; } diff --git a/Flow.Launcher/CustomShortcutSetting.xaml b/Flow.Launcher/CustomShortcutSetting.xaml index 1c87cfbe8..ab50bd859 100644 --- a/Flow.Launcher/CustomShortcutSetting.xaml +++ b/Flow.Launcher/CustomShortcutSetting.xaml @@ -149,7 +149,7 @@ x:Name="btnAdd" MinWidth="140" Margin="5,0,10,0" - Click="btnAdd_OnClick" + Click="BtnAdd_OnClick" Style="{StaticResource AccentButtonStyle}"> diff --git a/Flow.Launcher/CustomShortcutSetting.xaml.cs b/Flow.Launcher/CustomShortcutSetting.xaml.cs index 25ce82424..292288473 100644 --- a/Flow.Launcher/CustomShortcutSetting.xaml.cs +++ b/Flow.Launcher/CustomShortcutSetting.xaml.cs @@ -34,9 +34,9 @@ namespace Flow.Launcher Close(); } - private void btnAdd_OnClick(object sender, RoutedEventArgs e) + private void BtnAdd_OnClick(object sender, RoutedEventArgs e) { - if (!update && _settings.CustomShortcuts.Contains(new CustomShortcutModel(Key, Value))) + if (!update && (_settings.CustomShortcuts.Contains(new CustomShortcutModel(Key, Value)) || _settings.BuiltinShortcuts.Contains(new CustomShortcutModel(Key, Value)))) { MessageBox.Show(InternationalizationManager.Instance.GetTranslation("dulplicateShortcut")); return; diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index dc290ccd6..f15de6afe 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -2223,7 +2223,7 @@