Skip to content

Commit fd70326

Browse files
committed
Merge branch 'dev' of github.com:Flow-Launcher/Flow.Launcher into PluginStore
2 parents 2c96467 + e69b454 commit fd70326

File tree

17 files changed

+169
-129
lines changed

17 files changed

+169
-129
lines changed

Flow.Launcher.Core/Plugin/QueryBuilder.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,31 @@ public static class QueryBuilder
1010
public static Query Build(string text, Dictionary<string, PluginPair> nonGlobalPlugins)
1111
{
1212
// replace multiple white spaces with one white space
13-
var terms = text.Split(new[] { Query.TermSeperater }, StringSplitOptions.RemoveEmptyEntries);
13+
var terms = text.Split(Query.TermSeparator, StringSplitOptions.RemoveEmptyEntries);
1414
if (terms.Length == 0)
1515
{ // nothing was typed
1616
return null;
1717
}
1818

19-
var rawQuery = string.Join(Query.TermSeperater, terms);
19+
var rawQuery = string.Join(Query.TermSeparator, terms);
2020
string actionKeyword, search;
2121
string possibleActionKeyword = terms[0];
22-
List<string> actionParameters;
22+
string[] searchTerms;
23+
2324
if (nonGlobalPlugins.TryGetValue(possibleActionKeyword, out var pluginPair) && !pluginPair.Metadata.Disabled)
2425
{ // use non global plugin for query
2526
actionKeyword = possibleActionKeyword;
26-
actionParameters = terms.Skip(1).ToList();
27-
search = actionParameters.Count > 0 ? rawQuery.Substring(actionKeyword.Length + 1) : string.Empty;
27+
search = terms.Length > 1 ? rawQuery[(actionKeyword.Length + 1)..] : string.Empty;
28+
searchTerms = terms[1..];
2829
}
2930
else
3031
{ // non action keyword
3132
actionKeyword = string.Empty;
3233
search = rawQuery;
34+
searchTerms = terms;
3335
}
3436

35-
var query = new Query
36-
{
37-
Terms = terms,
38-
RawQuery = rawQuery,
39-
ActionKeyword = actionKeyword,
40-
Search = search
41-
};
37+
var query = new Query(rawQuery, search,terms, searchTerms, actionKeyword);
4238

4339
return query;
4440
}

Flow.Launcher.Plugin/Query.cs

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using JetBrains.Annotations;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45

@@ -11,65 +12,74 @@ public Query() { }
1112
/// <summary>
1213
/// to allow unit tests for plug ins
1314
/// </summary>
14-
public Query(string rawQuery, string search, string[] terms, string actionKeyword = "")
15+
public Query(string rawQuery, string search, string[] terms, string[] searchTerms, string actionKeyword = "")
1516
{
1617
Search = search;
1718
RawQuery = rawQuery;
1819
Terms = terms;
20+
SearchTerms = searchTerms;
1921
ActionKeyword = actionKeyword;
2022
}
2123

2224
/// <summary>
2325
/// Raw query, this includes action keyword if it has
2426
/// We didn't recommend use this property directly. You should always use Search property.
2527
/// </summary>
26-
public string RawQuery { get; internal set; }
28+
public string RawQuery { get; internal init; }
2729

2830
/// <summary>
2931
/// Search part of a query.
3032
/// This will not include action keyword if exclusive plugin gets it, otherwise it should be same as RawQuery.
3133
/// Since we allow user to switch a exclusive plugin to generic plugin,
3234
/// so this property will always give you the "real" query part of the query
3335
/// </summary>
34-
public string Search { get; internal set; }
36+
public string Search { get; internal init; }
3537

3638
/// <summary>
37-
/// The raw query splited into a string array.
39+
/// The search string split into a string array.
3840
/// </summary>
39-
public string[] Terms { get; set; }
41+
public string[] SearchTerms { get; init; }
42+
43+
/// <summary>
44+
/// The raw query split into a string array
45+
/// </summary>
46+
[Obsolete("It may or may not include action keyword, which can be confusing. Use SearchTerms instead")]
47+
public string[] Terms { get; init; }
4048

4149
/// <summary>
4250
/// Query can be splited into multiple terms by whitespace
4351
/// </summary>
44-
public const string TermSeperater = " ";
52+
public const string TermSeparator = " ";
53+
54+
[Obsolete("Typo")]
55+
public const string TermSeperater = TermSeparator;
4556
/// <summary>
4657
/// User can set multiple action keywords seperated by ';'
4758
/// </summary>
48-
public const string ActionKeywordSeperater = ";";
59+
public const string ActionKeywordSeparator = ";";
60+
61+
[Obsolete("Typo")]
62+
public const string ActionKeywordSeperater = ActionKeywordSeparator;
63+
4964

5065
/// <summary>
5166
/// '*' is used for System Plugin
5267
/// </summary>
5368
public const string GlobalPluginWildcardSign = "*";
5469

55-
public string ActionKeyword { get; set; }
70+
public string ActionKeyword { get; init; }
5671

5772
/// <summary>
5873
/// Return first search split by space if it has
5974
/// </summary>
6075
public string FirstSearch => SplitSearch(0);
6176

77+
private string _secondToEndSearch;
78+
6279
/// <summary>
6380
/// strings from second search (including) to last search
6481
/// </summary>
65-
public string SecondToEndSearch
66-
{
67-
get
68-
{
69-
var index = string.IsNullOrEmpty(ActionKeyword) ? 1 : 2;
70-
return string.Join(TermSeperater, Terms.Skip(index).ToArray());
71-
}
72-
}
82+
public string SecondToEndSearch => SearchTerms.Length > 1 ? (_secondToEndSearch ??= string.Join(' ', SearchTerms[1..])) : "";
7383

7484
/// <summary>
7585
/// Return second search split by space if it has
@@ -83,16 +93,9 @@ public string SecondToEndSearch
8393

8494
private string SplitSearch(int index)
8595
{
86-
try
87-
{
88-
return string.IsNullOrEmpty(ActionKeyword) ? Terms[index] : Terms[index + 1];
89-
}
90-
catch (IndexOutOfRangeException)
91-
{
92-
return string.Empty;
93-
}
96+
return index < SearchTerms.Length ? SearchTerms[index] : string.Empty;
9497
}
9598

9699
public override string ToString() => RawQuery;
97100
}
98-
}
101+
}

Flow.Launcher/ActionKeywords.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public ActionKeywords(string pluginId, Settings settings, PluginViewModel plugin
3030

3131
private void ActionKeyword_OnLoaded(object sender, RoutedEventArgs e)
3232
{
33-
tbOldActionKeyword.Text = string.Join(Query.ActionKeywordSeperater, plugin.Metadata.ActionKeywords.ToArray());
33+
tbOldActionKeyword.Text = string.Join(Query.ActionKeywordSeparator, plugin.Metadata.ActionKeywords.ToArray());
3434
tbAction.Focus();
3535
}
3636

Flow.Launcher/Helper/HotKeyMapper.cs

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using Flow.Launcher.Core.Resource;
77
using System.Windows;
88
using Flow.Launcher.ViewModel;
9+
using System.Threading.Tasks;
10+
using System.Threading;
911

1012
namespace Flow.Launcher.Helper
1113
{
@@ -19,10 +21,15 @@ internal static void Initialize(MainViewModel mainVM)
1921
mainViewModel = mainVM;
2022
settings = mainViewModel._settings;
2123

22-
SetHotkey(settings.Hotkey, OnHotkey);
24+
SetHotkey(settings.Hotkey, OnToggleHotkey);
2325
LoadCustomPluginHotkey();
2426
}
2527

28+
internal static void OnToggleHotkey(object sender, HotkeyEventArgs args)
29+
{
30+
mainViewModel.ToggleFlowLauncher();
31+
}
32+
2633
private static void SetHotkey(string hotkeyStr, EventHandler<HotkeyEventArgs> action)
2734
{
2835
var hotkey = new HotkeyModel(hotkeyStr);
@@ -53,44 +60,6 @@ internal static void RemoveHotkey(string hotkeyStr)
5360
}
5461
}
5562

56-
internal static void OnHotkey(object sender, HotkeyEventArgs e)
57-
{
58-
if (!ShouldIgnoreHotkeys())
59-
{
60-
UpdateLastQUeryMode();
61-
62-
mainViewModel.ToggleFlowLauncher();
63-
e.Handled = true;
64-
}
65-
}
66-
67-
/// <summary>
68-
/// Checks if Flow Launcher should ignore any hotkeys
69-
/// </summary>
70-
private static bool ShouldIgnoreHotkeys()
71-
{
72-
return settings.IgnoreHotkeysOnFullscreen && WindowsInteropHelper.IsWindowFullscreen();
73-
}
74-
75-
private static void UpdateLastQUeryMode()
76-
{
77-
switch(settings.LastQueryMode)
78-
{
79-
case LastQueryMode.Empty:
80-
mainViewModel.ChangeQueryText(string.Empty);
81-
break;
82-
case LastQueryMode.Preserved:
83-
mainViewModel.LastQuerySelected = true;
84-
break;
85-
case LastQueryMode.Selected:
86-
mainViewModel.LastQuerySelected = false;
87-
break;
88-
default:
89-
throw new ArgumentException($"wrong LastQueryMode: <{settings.LastQueryMode}>");
90-
91-
}
92-
}
93-
9463
internal static void LoadCustomPluginHotkey()
9564
{
9665
if (settings.CustomPluginHotkeys == null)
@@ -106,7 +75,7 @@ internal static void SetCustomQueryHotkey(CustomPluginHotkey hotkey)
10675
{
10776
SetHotkey(hotkey.Hotkey, (s, e) =>
10877
{
109-
if (ShouldIgnoreHotkeys())
78+
if (mainViewModel.ShouldIgnoreHotkeys())
11079
return;
11180

11281
mainViewModel.MainWindowVisibility = Visibility.Visible;

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ private void OnDeactivated(object sender, EventArgs e)
262262
{
263263
if (_settings.HideWhenDeactive)
264264
{
265-
Hide();
265+
_viewModel.Hide();
266266
}
267267
}
268268

Flow.Launcher/SettingWindow.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public partial class SettingWindow
2525
public readonly IPublicAPI API;
2626
private Settings settings;
2727
private SettingWindowViewModel viewModel;
28+
private static MainViewModel mainViewModel;
2829

2930
public SettingWindow(IPublicAPI api, SettingWindowViewModel viewModel)
3031
{
@@ -128,7 +129,7 @@ void OnHotkeyChanged(object sender, EventArgs e)
128129
if (HotkeyControl.CurrentHotkeyAvailable)
129130
{
130131

131-
HotKeyMapper.SetHotkey(HotkeyControl.CurrentHotkey, HotKeyMapper.OnHotkey);
132+
HotKeyMapper.SetHotkey(HotkeyControl.CurrentHotkey, HotKeyMapper.OnToggleHotkey);
132133
HotKeyMapper.RemoveHotkey(settings.Hotkey);
133134
settings.Hotkey = HotkeyControl.CurrentHotkey.ToString();
134135
}

0 commit comments

Comments
 (0)