Skip to content

Commit abfeee1

Browse files
committed
Support multiple action keywords
1 parent e1f1b97 commit abfeee1

File tree

4 files changed

+39
-16
lines changed

4 files changed

+39
-16
lines changed

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,12 @@ public static List<Result> GetContextMenusForPlugin(Result result)
340340
return results;
341341
}
342342

343-
public static bool ActionKeywordRegistered(string actionKeyword)
343+
public static bool ActionKeywordRegistered(IReadOnlyList<string> actionKeywords)
344+
{
345+
return actionKeywords.Any(ActionKeywordRegistered);
346+
}
347+
348+
private static bool ActionKeywordRegistered(string actionKeyword)
344349
{
345350
// this method is only checking for action keywords (defined as not '*') registration
346351
// hence the actionKeyword != Query.GlobalPluginWildcardSign logic
@@ -385,19 +390,31 @@ public static void RemoveActionKeyword(string id, string oldActionkeyword)
385390
if (oldActionkeyword != Query.GlobalPluginWildcardSign)
386391
NonGlobalPlugins.Remove(oldActionkeyword);
387392

388-
389393
plugin.Metadata.ActionKeywords.Remove(oldActionkeyword);
390394
}
391395

392-
public static void ReplaceActionKeyword(string id, string oldActionKeyword, string newActionKeyword)
396+
public static void ReplaceActionKeyword(string id, IReadOnlyList<string> oldActionKeyword, IReadOnlyList<string> newActionKeyword)
393397
{
394-
if (oldActionKeyword != newActionKeyword)
398+
if (CheckActionKeywordChanged(oldActionKeyword, newActionKeyword))
395399
{
396-
AddActionKeyword(id, newActionKeyword);
397-
RemoveActionKeyword(id, oldActionKeyword);
400+
foreach (var actionKeyword in newActionKeyword)
401+
{
402+
AddActionKeyword(id, actionKeyword);
403+
}
404+
foreach (var actionKeyword in oldActionKeyword)
405+
{
406+
RemoveActionKeyword(id, actionKeyword);
407+
}
398408
}
399409
}
400410

411+
private static bool CheckActionKeywordChanged(IReadOnlyList<string> oldActionKeyword, IReadOnlyList<string> newActionKeyword)
412+
{
413+
if (oldActionKeyword.Count != newActionKeyword.Count)
414+
return true;
415+
return oldActionKeyword.Where((t, i) => t != newActionKeyword[i]).Any();
416+
}
417+
401418
private static string GetContainingFolderPathAfterUnzip(string unzippedParentFolderPath)
402419
{
403420
var unzippedFolderCount = Directory.GetDirectories(unzippedParentFolderPath).Length;

Flow.Launcher.Plugin/Query.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public Query() { }
3939
public const string TermSeparator = " ";
4040

4141
/// <summary>
42-
/// User can set multiple action keywords seperated by ';'
42+
/// User can set multiple action keywords seperated by whitespace
4343
/// </summary>
44-
public const string ActionKeywordSeparator = ";";
44+
public const string ActionKeywordSeparator = TermSeparator;
4545

4646
/// <summary>
4747
/// Wildcard action keyword. Plugins using this value will be queried on every search.

Flow.Launcher/ActionKeywords.xaml.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Flow.Launcher.Plugin;
44
using Flow.Launcher.ViewModel;
55
using Flow.Launcher.Core;
6+
using System.Linq;
67

78
namespace Flow.Launcher
89
{
@@ -32,13 +33,17 @@ private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
3233

3334
private void btnDone_OnClick(object sender, RoutedEventArgs _)
3435
{
35-
var oldActionKeyword = plugin.Metadata.ActionKeywords[0];
36-
var newActionKeyword = tbAction.Text.Trim();
37-
newActionKeyword = newActionKeyword.Length > 0 ? newActionKeyword : "*";
36+
var oldActionKeywords = plugin.Metadata.ActionKeywords;
37+
38+
var newActionKeywords = tbAction.Text.Split(Query.ActionKeywordSeparator).ToList();
39+
newActionKeywords.RemoveAll(string.IsNullOrEmpty);
40+
newActionKeywords = newActionKeywords.Distinct().ToList();
41+
42+
newActionKeywords = newActionKeywords.Count > 0 ? newActionKeywords : new() { Query.GlobalPluginWildcardSign };
3843

39-
if (!PluginViewModel.IsActionKeywordRegistered(newActionKeyword))
44+
if (!PluginViewModel.IsActionKeywordRegistered(newActionKeywords))
4045
{
41-
pluginViewModel.ChangeActionKeyword(newActionKeyword, oldActionKeyword);
46+
pluginViewModel.ChangeActionKeyword(newActionKeywords, oldActionKeywords);
4247
Close();
4348
}
4449
else

Flow.Launcher/ViewModel/PluginViewModel.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using CommunityToolkit.Mvvm.Input;
99
using Flow.Launcher.Core.Resource;
1010
using Flow.Launcher.Resources.Controls;
11+
using System.Collections.Generic;
1112

1213
namespace Flow.Launcher.ViewModel
1314
{
@@ -109,9 +110,9 @@ public Control SettingControl
109110
public int Priority => PluginPair.Metadata.Priority;
110111
public Infrastructure.UserSettings.Plugin PluginSettingsObject { get; set; }
111112

112-
public void ChangeActionKeyword(string newActionKeyword, string oldActionKeyword)
113+
public void ChangeActionKeyword(IReadOnlyList<string> newActionKeywords, IReadOnlyList<string> oldActionKeywords)
113114
{
114-
PluginManager.ReplaceActionKeyword(PluginPair.Metadata.ID, oldActionKeyword, newActionKeyword);
115+
PluginManager.ReplaceActionKeyword(PluginPair.Metadata.ID, oldActionKeywords, newActionKeywords);
115116
OnPropertyChanged(nameof(ActionKeywordsText));
116117
}
117118

@@ -150,7 +151,7 @@ private void OpenDeletePluginWindow()
150151
PluginManager.API.ShowMainWindow();
151152
}
152153

153-
public static bool IsActionKeywordRegistered(string newActionKeyword) => PluginManager.ActionKeywordRegistered(newActionKeyword);
154+
public static bool IsActionKeywordRegistered(IReadOnlyList<string> newActionKeywords) => PluginManager.ActionKeywordRegistered(newActionKeywords);
154155

155156
[RelayCommand]
156157
private void SetActionKeywords()

0 commit comments

Comments
 (0)