diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 9d9a2e7a9..568e6c53c 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -120,8 +120,7 @@ namespace Flow.Launcher.Infrastructure.UserSettings PrivateArg = "-private", EnablePrivate = false, Editable = false - } - , + }, new() { Name = "MS Edge", @@ -205,7 +204,10 @@ namespace Flow.Launcher.Infrastructure.UserSettings // 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 5853dbbb4..000000000 --- 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 7706db614..f6e76bb22 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -17,6 +17,7 @@ using Flow.Launcher.Plugin.SharedCommands; 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 @@ namespace Flow.Launcher.ViewModel #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 @@ namespace Flow.Launcher.ViewModel 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 @@ namespace Flow.Launcher.ViewModel 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 2096b43c6..70a11b2a6 100644 --- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs +++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs @@ -19,6 +19,7 @@ using Flow.Launcher.Infrastructure.Storage; 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 @@ namespace Flow.Launcher.ViewModel { 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 @@ namespace Flow.Launcher.ViewModel } } - 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 @@ namespace Flow.Launcher.ViewModel 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 @@ namespace Flow.Launcher.ViewModel OnPropertyChanged(nameof(ExternalPlugins)); } - - #endregion #region theme @@ -284,7 +294,7 @@ namespace Flow.Launcher.ViewModel { Settings.Theme = value; ThemeManager.Instance.ChangeTheme(value); - + if (ThemeManager.Instance.BlurEnabled && Settings.UseDropShadowEffect) DropShadowEffect = false; } @@ -333,7 +343,10 @@ namespace Flow.Launcher.ViewModel { 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 @@ namespace Flow.Launcher.ViewModel 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 @@ namespace Flow.Launcher.ViewModel { 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 @@ namespace Flow.Launcher.ViewModel 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 @@ namespace Flow.Launcher.ViewModel Settings.QueryBoxFontStyle, Settings.QueryBoxFontWeight, Settings.QueryBoxFontStretch - )); + )); return typeface; } set @@ -475,8 +491,8 @@ namespace Flow.Launcher.ViewModel 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 @@ namespace Flow.Launcher.ViewModel Settings.ResultFontStyle, Settings.ResultFontWeight, Settings.ResultFontStretch - )); + )); return typeface; } set @@ -534,6 +550,7 @@ namespace Flow.Launcher.ViewModel 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