Skip to content

Commit 0a8405f

Browse files
committed
Resolve issue and add partial replacement trick
1 parent 2fa0b52 commit 0a8405f

File tree

4 files changed

+51
-41
lines changed

4 files changed

+51
-41
lines changed

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ public CustomBrowserViewModel CustomBrowser
120120
PrivateArg = "-private",
121121
EnablePrivate = false,
122122
Editable = false
123-
}
124-
,
123+
},
125124
new()
126125
{
127126
Name = "MS Edge",
@@ -205,7 +204,10 @@ public bool HideNotifyIcon
205204

206205
// This needs to be loaded last by staying at the bottom
207206
public PluginsSettings PluginSettings { get; set; } = new PluginsSettings();
208-
internal List<ShortCutModel> ShortCuts { get; set; } = new List<ShortCutModel>();
207+
internal ObservableCollection<KeyValuePair<string, string>> ShortCuts { get; set; } = new()
208+
{
209+
new("spp", "sp play")
210+
};
209211
}
210212

211213
public enum LastQueryMode

Flow.Launcher.Infrastructure/UserSettings/ShortCutModel.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using Flow.Launcher.Storage;
1717
using Flow.Launcher.Infrastructure.Logger;
1818
using Microsoft.VisualStudio.Threading;
19+
using System.Text;
1920
using System.Threading.Channels;
2021
using ISavable = Flow.Launcher.Plugin.ISavable;
2122

@@ -303,9 +304,9 @@ private void InitializeKeyCommands()
303304
#region ViewModel Properties
304305

305306
public ResultsViewModel Results { get; private set; }
306-
307+
307308
public ResultsViewModel ContextMenu { get; private set; }
308-
309+
309310
public ResultsViewModel History { get; private set; }
310311

311312
public bool GameModeStatus { get; set; }
@@ -529,14 +530,16 @@ private async void QueryResults()
529530
return;
530531
}
531532

532-
string query = QueryText;
533+
StringBuilder queryBuilder = new(QueryText);
533534

534535
foreach (var shortcut in _settings.ShortCuts)
535536
{
536-
if (QueryText == shortcut.Key)
537+
if (queryBuilder.Equals(shortcut.Key))
537538
{
538-
query = shortcut.Value;
539+
queryBuilder.Replace(shortcut.Key, shortcut.Value);
539540
}
541+
542+
queryBuilder.Replace('@' + shortcut.Key, shortcut.Value);
540543
}
541544

542545
_updateSource?.Dispose();
@@ -554,8 +557,8 @@ private async void QueryResults()
554557

555558
if (currentCancellationToken.IsCancellationRequested)
556559
return;
557-
558-
var query = QueryBuilder.Build(query.Trim(), PluginManager.NonGlobalPlugins);
560+
561+
var query = QueryBuilder.Build(queryBuilder.ToString().Trim(), PluginManager.NonGlobalPlugins);
559562

560563
// handle the exclusiveness of plugin using action keyword
561564
RemoveOldQueryResults(query);

Flow.Launcher/ViewModel/SettingWindowViewModel.cs

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using Flow.Launcher.Infrastructure.UserSettings;
2020
using Flow.Launcher.Plugin;
2121
using Flow.Launcher.Plugin.SharedModels;
22+
using System.Collections.ObjectModel;
2223

2324
namespace Flow.Launcher.ViewModel
2425
{
@@ -117,7 +118,10 @@ public List<LastQueryMode> LastQueryModes
117118
{
118119
var key = $"LastQuery{e}";
119120
var display = _translater.GetTranslation(key);
120-
var m = new LastQueryMode { Display = display, Value = e, };
121+
var m = new LastQueryMode
122+
{
123+
Display = display, Value = e,
124+
};
121125
modes.Add(m);
122126
}
123127
return modes;
@@ -165,12 +169,17 @@ public List<string> QuerySearchPrecisionStrings
165169
}
166170
}
167171

168-
public List<string> OpenResultModifiersList => new List<string> { KeyConstant.Alt, KeyConstant.Ctrl, $"{KeyConstant.Ctrl}+{KeyConstant.Alt}" };
172+
public List<string> OpenResultModifiersList => new List<string>
173+
{
174+
KeyConstant.Alt,
175+
KeyConstant.Ctrl,
176+
$"{KeyConstant.Ctrl}+{KeyConstant.Alt}"
177+
};
169178
private Internationalization _translater => InternationalizationManager.Instance;
170179
public List<Language> Languages => _translater.LoadAvailableLanguages();
171180
public IEnumerable<int> MaxResultsRange => Enumerable.Range(2, 16);
172181

173-
public List<ShortCutModel> ShortCuts => Settings.ShortCuts;
182+
public ObservableCollection<KeyValuePair<string, string>> ShortCuts => Settings.ShortCuts;
174183

175184
public string TestProxy()
176185
{
@@ -230,7 +239,10 @@ public IList<PluginViewModel> PluginViewModels
230239
var metadatas = PluginManager.AllPlugins
231240
.OrderBy(x => x.Metadata.Disabled)
232241
.ThenBy(y => y.Metadata.Name)
233-
.Select(p => new PluginViewModel { PluginPair = p })
242+
.Select(p => new PluginViewModel
243+
{
244+
PluginPair = p
245+
})
234246
.ToList();
235247
return metadatas;
236248
}
@@ -269,8 +281,6 @@ public async Task RefreshExternalPluginsAsync()
269281
OnPropertyChanged(nameof(ExternalPlugins));
270282
}
271283

272-
273-
274284
#endregion
275285

276286
#region theme
@@ -284,7 +294,7 @@ public string SelectedTheme
284294
{
285295
Settings.Theme = value;
286296
ThemeManager.Instance.ChangeTheme(value);
287-
297+
288298
if (ThemeManager.Instance.BlurEnabled && Settings.UseDropShadowEffect)
289299
DropShadowEffect = false;
290300
}
@@ -333,7 +343,10 @@ public List<ColorScheme> ColorSchemes
333343
{
334344
var key = $"ColorScheme{e}";
335345
var display = _translater.GetTranslation(key);
336-
var m = new ColorScheme { Display = display, Value = e, };
346+
var m = new ColorScheme
347+
{
348+
Display = display, Value = e,
349+
};
337350
modes.Add(m);
338351
}
339352
return modes;
@@ -376,7 +389,10 @@ public Brush PreviewBackground
376389
bitmap.BeginInit();
377390
bitmap.StreamSource = memStream;
378391
bitmap.EndInit();
379-
var brush = new ImageBrush(bitmap) { Stretch = Stretch.UniformToFill };
392+
var brush = new ImageBrush(bitmap)
393+
{
394+
Stretch = Stretch.UniformToFill
395+
};
380396
return brush;
381397
}
382398
else
@@ -404,19 +420,19 @@ public ResultsViewModel PreviewResults
404420
{
405421
Title = "WebSearch",
406422
SubTitle = "Search the web with different search engine support",
407-
IcoPath =Path.Combine(Constant.ProgramDirectory, @"Plugins\Flow.Launcher.Plugin.WebSearch\Images\web_search.png")
423+
IcoPath = Path.Combine(Constant.ProgramDirectory, @"Plugins\Flow.Launcher.Plugin.WebSearch\Images\web_search.png")
408424
},
409425
new Result
410426
{
411427
Title = "Program",
412428
SubTitle = "Launch programs as admin or a different user",
413-
IcoPath =Path.Combine(Constant.ProgramDirectory, @"Plugins\Flow.Launcher.Plugin.Program\Images\program.png")
429+
IcoPath = Path.Combine(Constant.ProgramDirectory, @"Plugins\Flow.Launcher.Plugin.Program\Images\program.png")
414430
},
415431
new Result
416432
{
417433
Title = "ProcessKiller",
418434
SubTitle = "Terminate unwanted processes",
419-
IcoPath =Path.Combine(Constant.ProgramDirectory, @"Plugins\Flow.Launcher.Plugin.ProcessKiller\Images\app.png")
435+
IcoPath = Path.Combine(Constant.ProgramDirectory, @"Plugins\Flow.Launcher.Plugin.ProcessKiller\Images\app.png")
420436
}
421437
};
422438
var vm = new ResultsViewModel(Settings);
@@ -430,8 +446,8 @@ public FontFamily SelectedQueryBoxFont
430446
get
431447
{
432448
if (Fonts.SystemFontFamilies.Count(o =>
433-
o.FamilyNames.Values != null &&
434-
o.FamilyNames.Values.Contains(Settings.QueryBoxFont)) > 0)
449+
o.FamilyNames.Values != null &&
450+
o.FamilyNames.Values.Contains(Settings.QueryBoxFont)) > 0)
435451
{
436452
var font = new FontFamily(Settings.QueryBoxFont);
437453
return font;
@@ -458,7 +474,7 @@ public FamilyTypeface SelectedQueryBoxFontFaces
458474
Settings.QueryBoxFontStyle,
459475
Settings.QueryBoxFontWeight,
460476
Settings.QueryBoxFontStretch
461-
));
477+
));
462478
return typeface;
463479
}
464480
set
@@ -475,8 +491,8 @@ public FontFamily SelectedResultFont
475491
get
476492
{
477493
if (Fonts.SystemFontFamilies.Count(o =>
478-
o.FamilyNames.Values != null &&
479-
o.FamilyNames.Values.Contains(Settings.ResultFont)) > 0)
494+
o.FamilyNames.Values != null &&
495+
o.FamilyNames.Values.Contains(Settings.ResultFont)) > 0)
480496
{
481497
var font = new FontFamily(Settings.ResultFont);
482498
return font;
@@ -503,7 +519,7 @@ public FamilyTypeface SelectedResultFontFaces
503519
Settings.ResultFontStyle,
504520
Settings.ResultFontWeight,
505521
Settings.ResultFontStretch
506-
));
522+
));
507523
return typeface;
508524
}
509525
set
@@ -534,6 +550,7 @@ public FamilyTypeface SelectedResultFontFaces
534550
public string Github => Constant.GitHub;
535551
public static string Version => Constant.Version;
536552
public string ActivatedTimes => string.Format(_translater.GetTranslation("about_activate_times"), Settings.ActivateTimes);
553+
537554
#endregion
538555
}
539-
}
556+
}

0 commit comments

Comments
 (0)