From efd34c980f7326ddc6b938a1f68d8bfea10fda79 Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Thu, 23 Dec 2021 16:13:49 -0600 Subject: [PATCH 01/39] Draft Query Shortcut --- .../UserSettings/Settings.cs | 1 + .../UserSettings/ShortCutModel.cs | 12 +++++++++ Flow.Launcher/SettingWindow.xaml | 25 +++++++++++++++++++ Flow.Launcher/ViewModel/MainViewModel.cs | 12 ++++++++- .../ViewModel/SettingWindowViewModel.cs | 2 ++ 5 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 Flow.Launcher.Infrastructure/UserSettings/ShortCutModel.cs diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 8ecd6dc4b76..9d9a2e7a9ca 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -205,6 +205,7 @@ public bool HideNotifyIcon // This needs to be loaded last by staying at the bottom public PluginsSettings PluginSettings { get; set; } = new PluginsSettings(); + internal List ShortCuts { get; set; } = new List(); } public enum LastQueryMode diff --git a/Flow.Launcher.Infrastructure/UserSettings/ShortCutModel.cs b/Flow.Launcher.Infrastructure/UserSettings/ShortCutModel.cs new file mode 100644 index 00000000000..5853dbbb456 --- /dev/null +++ b/Flow.Launcher.Infrastructure/UserSettings/ShortCutModel.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Flow.Launcher.Infrastructure.UserSettings +{ + public record ShortCutModel(string Key, string Value) + { + } +} diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index e15d5285cd0..a90a3a006ad 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -873,6 +873,31 @@ SelectedValuePath="LanguageCode" /> + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 95ef5d4839e..1ab7301a8b7 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -529,6 +529,16 @@ private async void QueryResults() return; } + string query = QueryText; + + foreach (var shortcut in _settings.ShortCuts) + { + if (QueryText == shortcut.Key) + { + query = shortcut.Value; + } + } + _updateSource?.Dispose(); var currentUpdateSource = new CancellationTokenSource(); @@ -545,7 +555,7 @@ private async void QueryResults() if (currentCancellationToken.IsCancellationRequested) return; - var query = QueryBuilder.Build(QueryText.Trim(), PluginManager.NonGlobalPlugins); + var query = QueryBuilder.Build(query.Trim(), PluginManager.NonGlobalPlugins); // handle the exclusiveness of plugin using action keyword RemoveOldQueryResults(query); diff --git a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs index 342c85da202..720b0a00dac 100644 --- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs +++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs @@ -170,6 +170,8 @@ public List QuerySearchPrecisionStrings public List Languages => _translater.LoadAvailableLanguages(); public IEnumerable MaxResultsRange => Enumerable.Range(2, 16); + public List ShortCuts => Settings.ShortCuts; + public string TestProxy() { var proxyServer = Settings.Proxy.Server; From 4340c0896c4272512e9f18d61d021962e09f3550 Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Thu, 23 Dec 2021 16:13:49 -0600 Subject: [PATCH 02/39] Draft Query Shortcut --- .../UserSettings/Settings.cs | 1 + .../UserSettings/ShortCutModel.cs | 12 +++++++++ Flow.Launcher/SettingWindow.xaml | 25 +++++++++++++++++++ Flow.Launcher/ViewModel/MainViewModel.cs | 12 ++++++++- .../ViewModel/SettingWindowViewModel.cs | 2 ++ 5 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 Flow.Launcher.Infrastructure/UserSettings/ShortCutModel.cs diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 8ecd6dc4b76..9d9a2e7a9ca 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -205,6 +205,7 @@ public bool HideNotifyIcon // This needs to be loaded last by staying at the bottom public PluginsSettings PluginSettings { get; set; } = new PluginsSettings(); + internal List ShortCuts { get; set; } = new List(); } public enum LastQueryMode diff --git a/Flow.Launcher.Infrastructure/UserSettings/ShortCutModel.cs b/Flow.Launcher.Infrastructure/UserSettings/ShortCutModel.cs new file mode 100644 index 00000000000..5853dbbb456 --- /dev/null +++ b/Flow.Launcher.Infrastructure/UserSettings/ShortCutModel.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Flow.Launcher.Infrastructure.UserSettings +{ + public record ShortCutModel(string Key, string Value) + { + } +} diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index e15d5285cd0..a90a3a006ad 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -873,6 +873,31 @@ SelectedValuePath="LanguageCode" /> + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 95ef5d4839e..1ab7301a8b7 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -529,6 +529,16 @@ private async void QueryResults() return; } + string query = QueryText; + + foreach (var shortcut in _settings.ShortCuts) + { + if (QueryText == shortcut.Key) + { + query = shortcut.Value; + } + } + _updateSource?.Dispose(); var currentUpdateSource = new CancellationTokenSource(); @@ -545,7 +555,7 @@ private async void QueryResults() if (currentCancellationToken.IsCancellationRequested) return; - var query = QueryBuilder.Build(QueryText.Trim(), PluginManager.NonGlobalPlugins); + var query = QueryBuilder.Build(query.Trim(), PluginManager.NonGlobalPlugins); // handle the exclusiveness of plugin using action keyword RemoveOldQueryResults(query); diff --git a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs index 342c85da202..720b0a00dac 100644 --- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs +++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs @@ -170,6 +170,8 @@ public List QuerySearchPrecisionStrings public List Languages => _translater.LoadAvailableLanguages(); public IEnumerable MaxResultsRange => Enumerable.Range(2, 16); + public List ShortCuts => Settings.ShortCuts; + public string TestProxy() { var proxyServer = Settings.Proxy.Server; From 0a8405f72ab2d37517251f7ae9b6ae8fcf8c138d Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Tue, 1 Mar 2022 13:29:21 -0600 Subject: [PATCH 03/39] Resolve issue and add partial replacement trick --- .../UserSettings/Settings.cs | 8 ++- .../UserSettings/ShortCutModel.cs | 12 ---- Flow.Launcher/ViewModel/MainViewModel.cs | 17 +++--- .../ViewModel/SettingWindowViewModel.cs | 55 ++++++++++++------- 4 files changed, 51 insertions(+), 41 deletions(-) delete mode 100644 Flow.Launcher.Infrastructure/UserSettings/ShortCutModel.cs diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 9d9a2e7a9ca..568e6c53c2d 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -120,8 +120,7 @@ public CustomBrowserViewModel CustomBrowser PrivateArg = "-private", EnablePrivate = false, Editable = false - } - , + }, new() { Name = "MS Edge", @@ -205,7 +204,10 @@ public bool HideNotifyIcon // This needs to be loaded last by staying at the bottom public PluginsSettings PluginSettings { get; set; } = new PluginsSettings(); - internal List ShortCuts { get; set; } = new List(); + internal ObservableCollection> ShortCuts { get; set; } = new() + { + new("spp", "sp play") + }; } public enum LastQueryMode diff --git a/Flow.Launcher.Infrastructure/UserSettings/ShortCutModel.cs b/Flow.Launcher.Infrastructure/UserSettings/ShortCutModel.cs deleted file mode 100644 index 5853dbbb456..00000000000 --- a/Flow.Launcher.Infrastructure/UserSettings/ShortCutModel.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Flow.Launcher.Infrastructure.UserSettings -{ - public record ShortCutModel(string Key, string Value) - { - } -} diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 1ab7301a8b7..34c6b66b160 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -16,6 +16,7 @@ using Flow.Launcher.Storage; using Flow.Launcher.Infrastructure.Logger; using Microsoft.VisualStudio.Threading; +using System.Text; using System.Threading.Channels; using ISavable = Flow.Launcher.Plugin.ISavable; @@ -303,9 +304,9 @@ private void InitializeKeyCommands() #region ViewModel Properties public ResultsViewModel Results { get; private set; } - + public ResultsViewModel ContextMenu { get; private set; } - + public ResultsViewModel History { get; private set; } public bool GameModeStatus { get; set; } @@ -529,14 +530,16 @@ private async void QueryResults() return; } - string query = QueryText; + StringBuilder queryBuilder = new(QueryText); foreach (var shortcut in _settings.ShortCuts) { - if (QueryText == shortcut.Key) + if (queryBuilder.Equals(shortcut.Key)) { - query = shortcut.Value; + queryBuilder.Replace(shortcut.Key, shortcut.Value); } + + queryBuilder.Replace('@' + shortcut.Key, shortcut.Value); } _updateSource?.Dispose(); @@ -554,8 +557,8 @@ private async void QueryResults() if (currentCancellationToken.IsCancellationRequested) return; - - var query = QueryBuilder.Build(query.Trim(), PluginManager.NonGlobalPlugins); + + var query = QueryBuilder.Build(queryBuilder.ToString().Trim(), PluginManager.NonGlobalPlugins); // handle the exclusiveness of plugin using action keyword RemoveOldQueryResults(query); diff --git a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs index 720b0a00dac..965d33b6ee5 100644 --- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs +++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs @@ -19,6 +19,7 @@ using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; using Flow.Launcher.Plugin.SharedModels; +using System.Collections.ObjectModel; namespace Flow.Launcher.ViewModel { @@ -117,7 +118,10 @@ public List LastQueryModes { var key = $"LastQuery{e}"; var display = _translater.GetTranslation(key); - var m = new LastQueryMode { Display = display, Value = e, }; + var m = new LastQueryMode + { + Display = display, Value = e, + }; modes.Add(m); } return modes; @@ -165,12 +169,17 @@ public List QuerySearchPrecisionStrings } } - public List OpenResultModifiersList => new List { KeyConstant.Alt, KeyConstant.Ctrl, $"{KeyConstant.Ctrl}+{KeyConstant.Alt}" }; + public List OpenResultModifiersList => new List + { + KeyConstant.Alt, + KeyConstant.Ctrl, + $"{KeyConstant.Ctrl}+{KeyConstant.Alt}" + }; private Internationalization _translater => InternationalizationManager.Instance; public List Languages => _translater.LoadAvailableLanguages(); public IEnumerable MaxResultsRange => Enumerable.Range(2, 16); - public List ShortCuts => Settings.ShortCuts; + public ObservableCollection> ShortCuts => Settings.ShortCuts; public string TestProxy() { @@ -230,7 +239,10 @@ public IList PluginViewModels var metadatas = PluginManager.AllPlugins .OrderBy(x => x.Metadata.Disabled) .ThenBy(y => y.Metadata.Name) - .Select(p => new PluginViewModel { PluginPair = p }) + .Select(p => new PluginViewModel + { + PluginPair = p + }) .ToList(); return metadatas; } @@ -269,8 +281,6 @@ public async Task RefreshExternalPluginsAsync() OnPropertyChanged(nameof(ExternalPlugins)); } - - #endregion #region theme @@ -284,7 +294,7 @@ public string SelectedTheme { Settings.Theme = value; ThemeManager.Instance.ChangeTheme(value); - + if (ThemeManager.Instance.BlurEnabled && Settings.UseDropShadowEffect) DropShadowEffect = false; } @@ -333,7 +343,10 @@ public List ColorSchemes { var key = $"ColorScheme{e}"; var display = _translater.GetTranslation(key); - var m = new ColorScheme { Display = display, Value = e, }; + var m = new ColorScheme + { + Display = display, Value = e, + }; modes.Add(m); } return modes; @@ -376,7 +389,10 @@ public Brush PreviewBackground bitmap.BeginInit(); bitmap.StreamSource = memStream; bitmap.EndInit(); - var brush = new ImageBrush(bitmap) { Stretch = Stretch.UniformToFill }; + var brush = new ImageBrush(bitmap) + { + Stretch = Stretch.UniformToFill + }; return brush; } else @@ -404,19 +420,19 @@ public ResultsViewModel PreviewResults { Title = "WebSearch", SubTitle = "Search the web with different search engine support", - IcoPath =Path.Combine(Constant.ProgramDirectory, @"Plugins\Flow.Launcher.Plugin.WebSearch\Images\web_search.png") + IcoPath = Path.Combine(Constant.ProgramDirectory, @"Plugins\Flow.Launcher.Plugin.WebSearch\Images\web_search.png") }, new Result { Title = "Program", SubTitle = "Launch programs as admin or a different user", - IcoPath =Path.Combine(Constant.ProgramDirectory, @"Plugins\Flow.Launcher.Plugin.Program\Images\program.png") + IcoPath = Path.Combine(Constant.ProgramDirectory, @"Plugins\Flow.Launcher.Plugin.Program\Images\program.png") }, new Result { Title = "ProcessKiller", SubTitle = "Terminate unwanted processes", - IcoPath =Path.Combine(Constant.ProgramDirectory, @"Plugins\Flow.Launcher.Plugin.ProcessKiller\Images\app.png") + IcoPath = Path.Combine(Constant.ProgramDirectory, @"Plugins\Flow.Launcher.Plugin.ProcessKiller\Images\app.png") } }; var vm = new ResultsViewModel(Settings); @@ -430,8 +446,8 @@ public FontFamily SelectedQueryBoxFont get { if (Fonts.SystemFontFamilies.Count(o => - o.FamilyNames.Values != null && - o.FamilyNames.Values.Contains(Settings.QueryBoxFont)) > 0) + o.FamilyNames.Values != null && + o.FamilyNames.Values.Contains(Settings.QueryBoxFont)) > 0) { var font = new FontFamily(Settings.QueryBoxFont); return font; @@ -458,7 +474,7 @@ public FamilyTypeface SelectedQueryBoxFontFaces Settings.QueryBoxFontStyle, Settings.QueryBoxFontWeight, Settings.QueryBoxFontStretch - )); + )); return typeface; } set @@ -475,8 +491,8 @@ public FontFamily SelectedResultFont get { if (Fonts.SystemFontFamilies.Count(o => - o.FamilyNames.Values != null && - o.FamilyNames.Values.Contains(Settings.ResultFont)) > 0) + o.FamilyNames.Values != null && + o.FamilyNames.Values.Contains(Settings.ResultFont)) > 0) { var font = new FontFamily(Settings.ResultFont); return font; @@ -503,7 +519,7 @@ public FamilyTypeface SelectedResultFontFaces Settings.ResultFontStyle, Settings.ResultFontWeight, Settings.ResultFontStretch - )); + )); return typeface; } set @@ -534,6 +550,7 @@ public FamilyTypeface SelectedResultFontFaces public string Github => Constant.GitHub; public static string Version => Constant.Version; public string ActivatedTimes => string.Format(_translater.GetTranslation("about_activate_times"), Settings.ActivateTimes); + #endregion } -} +} \ No newline at end of file From 0d355bdef80dab753c142ef4eeb682914d87050e Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Thu, 23 Dec 2021 16:13:49 -0600 Subject: [PATCH 04/39] Draft Query Shortcut --- .../UserSettings/Settings.cs | 1 + .../UserSettings/ShortCutModel.cs | 12 +++++++++ Flow.Launcher/SettingWindow.xaml | 25 +++++++++++++++++++ Flow.Launcher/ViewModel/MainViewModel.cs | 12 ++++++++- .../ViewModel/SettingWindowViewModel.cs | 2 ++ 5 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 Flow.Launcher.Infrastructure/UserSettings/ShortCutModel.cs diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 8ecd6dc4b76..9d9a2e7a9ca 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -205,6 +205,7 @@ public bool HideNotifyIcon // This needs to be loaded last by staying at the bottom public PluginsSettings PluginSettings { get; set; } = new PluginsSettings(); + internal List ShortCuts { get; set; } = new List(); } public enum LastQueryMode diff --git a/Flow.Launcher.Infrastructure/UserSettings/ShortCutModel.cs b/Flow.Launcher.Infrastructure/UserSettings/ShortCutModel.cs new file mode 100644 index 00000000000..5853dbbb456 --- /dev/null +++ b/Flow.Launcher.Infrastructure/UserSettings/ShortCutModel.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Flow.Launcher.Infrastructure.UserSettings +{ + public record ShortCutModel(string Key, string Value) + { + } +} diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index 967e4d52b1a..0cb2343bc43 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -875,6 +875,31 @@ SelectedValuePath="LanguageCode" /> + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 0fe3bdf8052..7706db614d4 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -553,6 +553,16 @@ private async void QueryResults() return; } + string query = QueryText; + + foreach (var shortcut in _settings.ShortCuts) + { + if (QueryText == shortcut.Key) + { + query = shortcut.Value; + } + } + _updateSource?.Dispose(); var currentUpdateSource = new CancellationTokenSource(); @@ -569,7 +579,7 @@ private async void QueryResults() if (currentCancellationToken.IsCancellationRequested) return; - var query = QueryBuilder.Build(QueryText.Trim(), PluginManager.NonGlobalPlugins); + var query = QueryBuilder.Build(query.Trim(), PluginManager.NonGlobalPlugins); // handle the exclusiveness of plugin using action keyword RemoveOldQueryResults(query); diff --git a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs index 2fc6934d58a..2096b43c627 100644 --- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs +++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs @@ -170,6 +170,8 @@ public List QuerySearchPrecisionStrings public List Languages => _translater.LoadAvailableLanguages(); public IEnumerable MaxResultsRange => Enumerable.Range(2, 16); + public List ShortCuts => Settings.ShortCuts; + public string TestProxy() { var proxyServer = Settings.Proxy.Server; From 2bb88124e62429e70d34d35fd2727809f1adbd89 Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Tue, 1 Mar 2022 13:29:21 -0600 Subject: [PATCH 05/39] Resolve issue and add partial replacement trick --- .../UserSettings/Settings.cs | 8 ++- .../UserSettings/ShortCutModel.cs | 12 ---- Flow.Launcher/ViewModel/MainViewModel.cs | 17 +++--- .../ViewModel/SettingWindowViewModel.cs | 55 ++++++++++++------- 4 files changed, 51 insertions(+), 41 deletions(-) delete mode 100644 Flow.Launcher.Infrastructure/UserSettings/ShortCutModel.cs diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 9d9a2e7a9ca..568e6c53c2d 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -120,8 +120,7 @@ public CustomBrowserViewModel CustomBrowser PrivateArg = "-private", EnablePrivate = false, Editable = false - } - , + }, new() { Name = "MS Edge", @@ -205,7 +204,10 @@ public bool HideNotifyIcon // This needs to be loaded last by staying at the bottom public PluginsSettings PluginSettings { get; set; } = new PluginsSettings(); - internal List ShortCuts { get; set; } = new List(); + internal ObservableCollection> ShortCuts { get; set; } = new() + { + new("spp", "sp play") + }; } public enum LastQueryMode diff --git a/Flow.Launcher.Infrastructure/UserSettings/ShortCutModel.cs b/Flow.Launcher.Infrastructure/UserSettings/ShortCutModel.cs deleted file mode 100644 index 5853dbbb456..00000000000 --- a/Flow.Launcher.Infrastructure/UserSettings/ShortCutModel.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Flow.Launcher.Infrastructure.UserSettings -{ - public record ShortCutModel(string Key, string Value) - { - } -} diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 7706db614d4..f6e76bb2231 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -17,6 +17,7 @@ using Flow.Launcher.Storage; using Flow.Launcher.Infrastructure.Logger; using Microsoft.VisualStudio.Threading; +using System.Text; using System.Threading.Channels; using ISavable = Flow.Launcher.Plugin.ISavable; using System.IO; @@ -317,9 +318,9 @@ private void InitializeKeyCommands() #region ViewModel Properties public ResultsViewModel Results { get; private set; } - + public ResultsViewModel ContextMenu { get; private set; } - + public ResultsViewModel History { get; private set; } public bool GameModeStatus { get; set; } @@ -553,14 +554,16 @@ private async void QueryResults() return; } - string query = QueryText; + StringBuilder queryBuilder = new(QueryText); foreach (var shortcut in _settings.ShortCuts) { - if (QueryText == shortcut.Key) + if (queryBuilder.Equals(shortcut.Key)) { - query = shortcut.Value; + queryBuilder.Replace(shortcut.Key, shortcut.Value); } + + queryBuilder.Replace('@' + shortcut.Key, shortcut.Value); } _updateSource?.Dispose(); @@ -578,8 +581,8 @@ private async void QueryResults() if (currentCancellationToken.IsCancellationRequested) return; - - var query = QueryBuilder.Build(query.Trim(), PluginManager.NonGlobalPlugins); + + var query = QueryBuilder.Build(queryBuilder.ToString().Trim(), PluginManager.NonGlobalPlugins); // handle the exclusiveness of plugin using action keyword RemoveOldQueryResults(query); diff --git a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs index 2096b43c627..70a11b2a6a3 100644 --- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs +++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs @@ -19,6 +19,7 @@ using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; using Flow.Launcher.Plugin.SharedModels; +using System.Collections.ObjectModel; namespace Flow.Launcher.ViewModel { @@ -117,7 +118,10 @@ public List LastQueryModes { var key = $"LastQuery{e}"; var display = _translater.GetTranslation(key); - var m = new LastQueryMode { Display = display, Value = e, }; + var m = new LastQueryMode + { + Display = display, Value = e, + }; modes.Add(m); } return modes; @@ -165,12 +169,17 @@ public List QuerySearchPrecisionStrings } } - public List OpenResultModifiersList => new List { KeyConstant.Alt, KeyConstant.Ctrl, $"{KeyConstant.Ctrl}+{KeyConstant.Alt}" }; + public List OpenResultModifiersList => new List + { + KeyConstant.Alt, + KeyConstant.Ctrl, + $"{KeyConstant.Ctrl}+{KeyConstant.Alt}" + }; private Internationalization _translater => InternationalizationManager.Instance; public List Languages => _translater.LoadAvailableLanguages(); public IEnumerable MaxResultsRange => Enumerable.Range(2, 16); - public List ShortCuts => Settings.ShortCuts; + public ObservableCollection> ShortCuts => Settings.ShortCuts; public string TestProxy() { @@ -230,7 +239,10 @@ public IList PluginViewModels var metadatas = PluginManager.AllPlugins .OrderBy(x => x.Metadata.Disabled) .ThenBy(y => y.Metadata.Name) - .Select(p => new PluginViewModel { PluginPair = p }) + .Select(p => new PluginViewModel + { + PluginPair = p + }) .ToList(); return metadatas; } @@ -269,8 +281,6 @@ public async Task RefreshExternalPluginsAsync() OnPropertyChanged(nameof(ExternalPlugins)); } - - #endregion #region theme @@ -284,7 +294,7 @@ public string SelectedTheme { Settings.Theme = value; ThemeManager.Instance.ChangeTheme(value); - + if (ThemeManager.Instance.BlurEnabled && Settings.UseDropShadowEffect) DropShadowEffect = false; } @@ -333,7 +343,10 @@ public List ColorSchemes { var key = $"ColorScheme{e}"; var display = _translater.GetTranslation(key); - var m = new ColorScheme { Display = display, Value = e, }; + var m = new ColorScheme + { + Display = display, Value = e, + }; modes.Add(m); } return modes; @@ -376,7 +389,10 @@ public Brush PreviewBackground bitmap.BeginInit(); bitmap.StreamSource = memStream; bitmap.EndInit(); - var brush = new ImageBrush(bitmap) { Stretch = Stretch.UniformToFill }; + var brush = new ImageBrush(bitmap) + { + Stretch = Stretch.UniformToFill + }; return brush; } else @@ -404,19 +420,19 @@ public ResultsViewModel PreviewResults { Title = "WebSearch", SubTitle = "Search the web with different search engine support", - IcoPath =Path.Combine(Constant.ProgramDirectory, @"Plugins\Flow.Launcher.Plugin.WebSearch\Images\web_search.png") + IcoPath = Path.Combine(Constant.ProgramDirectory, @"Plugins\Flow.Launcher.Plugin.WebSearch\Images\web_search.png") }, new Result { Title = "Program", SubTitle = "Launch programs as admin or a different user", - IcoPath =Path.Combine(Constant.ProgramDirectory, @"Plugins\Flow.Launcher.Plugin.Program\Images\program.png") + IcoPath = Path.Combine(Constant.ProgramDirectory, @"Plugins\Flow.Launcher.Plugin.Program\Images\program.png") }, new Result { Title = "ProcessKiller", SubTitle = "Terminate unwanted processes", - IcoPath =Path.Combine(Constant.ProgramDirectory, @"Plugins\Flow.Launcher.Plugin.ProcessKiller\Images\app.png") + IcoPath = Path.Combine(Constant.ProgramDirectory, @"Plugins\Flow.Launcher.Plugin.ProcessKiller\Images\app.png") } }; var vm = new ResultsViewModel(Settings); @@ -430,8 +446,8 @@ public FontFamily SelectedQueryBoxFont get { if (Fonts.SystemFontFamilies.Count(o => - o.FamilyNames.Values != null && - o.FamilyNames.Values.Contains(Settings.QueryBoxFont)) > 0) + o.FamilyNames.Values != null && + o.FamilyNames.Values.Contains(Settings.QueryBoxFont)) > 0) { var font = new FontFamily(Settings.QueryBoxFont); return font; @@ -458,7 +474,7 @@ public FamilyTypeface SelectedQueryBoxFontFaces Settings.QueryBoxFontStyle, Settings.QueryBoxFontWeight, Settings.QueryBoxFontStretch - )); + )); return typeface; } set @@ -475,8 +491,8 @@ public FontFamily SelectedResultFont get { if (Fonts.SystemFontFamilies.Count(o => - o.FamilyNames.Values != null && - o.FamilyNames.Values.Contains(Settings.ResultFont)) > 0) + o.FamilyNames.Values != null && + o.FamilyNames.Values.Contains(Settings.ResultFont)) > 0) { var font = new FontFamily(Settings.ResultFont); return font; @@ -503,7 +519,7 @@ public FamilyTypeface SelectedResultFontFaces Settings.ResultFontStyle, Settings.ResultFontWeight, Settings.ResultFontStretch - )); + )); return typeface; } set @@ -534,6 +550,7 @@ public FamilyTypeface SelectedResultFontFaces public string Github => Constant.GitHub; public static string Version => Constant.Version; public string ActivatedTimes => string.Format(_translater.GetTranslation("about_activate_times"), Settings.ActivateTimes); + #endregion } -} +} \ No newline at end of file From 4d42e52dc1249a45d7e7b569e6a9036c1ed5fa74 Mon Sep 17 00:00:00 2001 From: DB p Date: Wed, 2 Mar 2022 06:49:54 +0900 Subject: [PATCH 06/39] - Move the 'Shorcut' to Hotkey tab from General - Adjust Layout --- Flow.Launcher/SettingWindow.xaml | 371 +++++++++++++++++-------------- 1 file changed, 207 insertions(+), 164 deletions(-) diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index 0cb2343bc43..2fe5d2353c0 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -875,31 +875,6 @@ SelectedValuePath="LanguageCode" /> - - - - - - - - - - - - - - - - - - - - - - - - - @@ -2026,11 +2001,8 @@ - - - - + - - - - - - - + + + + + + + + + + + +  + + + + + + + - -  - - - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ 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 00000000000..feea064a4ac --- /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 35a6389ca11..ef0bc4f14c1 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 25de530bc45..401f532a25a 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 2fe5d2353c0..47933f3266e 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -2159,7 +2159,7 @@ diff --git a/Flow.Launcher/CustomShortcutSetting.xaml.cs b/Flow.Launcher/CustomShortcutSetting.xaml.cs index 25ce82424f2..2922884736c 100644 --- a/Flow.Launcher/CustomShortcutSetting.xaml.cs +++ b/Flow.Launcher/CustomShortcutSetting.xaml.cs @@ -34,9 +34,9 @@ private void BtnCancel_OnClick(object sender, RoutedEventArgs e) 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 dc290ccd619..f15de6afeed 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -2223,7 +2223,7 @@