Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6e4d9a5
Remove useless blank lines
Jack251970 Feb 21, 2025
26b2b59
Merge branch 'Flow-Launcher:dev' into multiple_keywords
Jack251970 Feb 21, 2025
8f6bed4
Remove useless * keywords
Jack251970 Feb 21, 2025
e1f1b97
Support allow modify action keywords & WebSearch does not let user ch…
Jack251970 Feb 21, 2025
abfeee1
Support multiple action keywords
Jack251970 Feb 21, 2025
d9ba38b
Fix issue that plugin cannot update ActionKeyword after changing its …
Jack251970 Feb 21, 2025
f999b97
Fix build issue
Jack251970 Feb 21, 2025
37ad5aa
Fix issue that ActionKeywordRegistered will not exclude old action key
Jack251970 Feb 21, 2025
300d64d
Remove action keyword first
Jack251970 Feb 21, 2025
cab3eb7
Update string resource
Jack251970 Feb 21, 2025
414684c
Replace action keyword function with api
Jack251970 Feb 21, 2025
4632932
Revert "Remove useless * keywords" and do not let users change action…
Jack251970 Feb 23, 2025
87febda
Add ReplaceActionKeyword api function
Jack251970 Feb 23, 2025
34cb078
Check old action keyword out of PluginManager
Jack251970 Feb 23, 2025
4ebc19a
Check action keywords without order
Jack251970 Feb 23, 2025
5d67eef
Improve code quality
Jack251970 Feb 23, 2025
3840284
Improve code quality for project references
Jack251970 Feb 23, 2025
6e763f0
Remove ReplaceActionKeyword api function & Add action keyword same no…
Jack251970 Feb 24, 2025
2741366
Improve code quality
Jack251970 Feb 24, 2025
afce702
Improve documents
Jack251970 Feb 25, 2025
f7b1190
Add global search panel
Jack251970 Feb 26, 2025
0c6b89f
Revert "Add global search panel"
Jack251970 Feb 26, 2025
c9f2a14
Remove useless usings
Jack251970 Feb 27, 2025
ca79994
Change to HideActionKeywordPanel
Jack251970 Feb 28, 2025
9ec8681
Remove useless project reference
Jack251970 Feb 28, 2025
ba0d412
Merge branch 'dev' into multiple_keywords
Jack251970 Mar 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 68 additions & 3 deletions Flow.Launcher.Core/Plugin/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ public static ICollection<PluginPair> ValidPluginsForQuery(Query query)
if (!NonGlobalPlugins.ContainsKey(query.ActionKeyword))
return GlobalPlugins;


var plugin = NonGlobalPlugins[query.ActionKeyword];
return new List<PluginPair>
{
Expand Down Expand Up @@ -341,6 +340,24 @@ public static List<Result> GetContextMenusForPlugin(Result result)
return results;
}

public static bool ActionKeywordRegistered(IReadOnlyList<string> newActionKeywords, IReadOnlyList<string> oldActionKeywords)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method does not make sense to me. If user want to exclude the current action keywords, they could check it themselves, rather than passing it as a parameter in this method.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check 34cb078 please.

{
foreach (var actionKeyword in newActionKeywords)
{
if (ActionKeywordRegistered(actionKeyword, oldActionKeywords))
{
return true;
}
}
return false;
}

private static bool ActionKeywordRegistered(string actionKeyword, IReadOnlyList<string> oldActionKeywords)
{
if (oldActionKeywords.Contains(actionKeyword)) return false;
return ActionKeywordRegistered(actionKeyword);
}

public static bool ActionKeywordRegistered(string actionKeyword)
{
// this method is only checking for action keywords (defined as not '*') registration
Expand All @@ -365,6 +382,7 @@ public static void AddActionKeyword(string id, string newActionKeyword)
NonGlobalPlugins[newActionKeyword] = plugin;
}

// Update action keywords in plugin metadata
plugin.Metadata.ActionKeywords.Add(newActionKeyword);
}

Expand All @@ -386,16 +404,63 @@ public static void RemoveActionKeyword(string id, string oldActionkeyword)
if (oldActionkeyword != Query.GlobalPluginWildcardSign)
NonGlobalPlugins.Remove(oldActionkeyword);


// Update action keywords in plugin metadata
plugin.Metadata.ActionKeywords.Remove(oldActionkeyword);
}

public static void ReplaceActionKeyword(string id, IReadOnlyList<string> oldActionKeywords, IReadOnlyList<string> newActionKeywords)
{
if (CheckActionKeywordChanged(oldActionKeywords, newActionKeywords))
{
// Fix collection modified while iterating exception
var oldActionKeywordsClone = oldActionKeywords.ToList();
foreach (var actionKeyword in oldActionKeywordsClone)
{
RemoveActionKeyword(id, actionKeyword);
}
foreach (var actionKeyword in newActionKeywords)
{
AddActionKeyword(id, actionKeyword);
}

// Update action keyword in plugin metadata
var plugin = GetPluginForId(id);
if (newActionKeywords.Count > 0)
{
plugin.Metadata.ActionKeyword = newActionKeywords[0];
}
else
{
plugin.Metadata.ActionKeyword = string.Empty;
}
}
}

private static bool CheckActionKeywordChanged(IReadOnlyList<string> oldActionKeyword, IReadOnlyList<string> newActionKeyword)
{
if (oldActionKeyword.Count != newActionKeyword.Count)
return true;
return oldActionKeyword.Where((t, i) => t != newActionKeyword[i]).Any();
}

public static void ReplaceActionKeyword(string id, string oldActionKeyword, string newActionKeyword)
{
if (oldActionKeyword != newActionKeyword)
{
AddActionKeyword(id, newActionKeyword);
RemoveActionKeyword(id, oldActionKeyword);
AddActionKeyword(id, newActionKeyword);

// Update action keyword in plugin metadata
var plugin = GetPluginForId(id);
var newActionKeywords = plugin.Metadata.ActionKeywords;
if (newActionKeywords.Count > 0)
{
plugin.Metadata.ActionKeyword = newActionKeywords[0];
}
else
{
plugin.Metadata.ActionKeyword = string.Empty;
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions Flow.Launcher.Plugin/PluginMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ internal set

public List<string> ActionKeywords { get; set; }

public bool AllowModifyActionKeywords { get; set; } = true;

public string IcoPath { get; set;}

public override string ToString()
Expand Down
5 changes: 2 additions & 3 deletions Flow.Launcher.Plugin/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ public Query() { }
public const string TermSeparator = " ";

/// <summary>
/// User can set multiple action keywords seperated by ';'
/// User can set multiple action keywords seperated by whitespace
/// </summary>
public const string ActionKeywordSeparator = ";";

public const string ActionKeywordSeparator = TermSeparator;

/// <summary>
/// Wildcard action keyword. Plugins using this value will be queried on every search.
Expand Down
16 changes: 11 additions & 5 deletions Flow.Launcher/ActionKeywords.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using Flow.Launcher.Plugin;
using Flow.Launcher.ViewModel;
using Flow.Launcher.Core;
using System.Linq;
using Flow.Launcher.Core.Plugin;

namespace Flow.Launcher
{
Expand Down Expand Up @@ -32,13 +34,17 @@ private void BtnCancel_OnClick(object sender, RoutedEventArgs e)

private void btnDone_OnClick(object sender, RoutedEventArgs _)
{
var oldActionKeyword = plugin.Metadata.ActionKeywords[0];
var newActionKeyword = tbAction.Text.Trim();
newActionKeyword = newActionKeyword.Length > 0 ? newActionKeyword : "*";
var oldActionKeywords = plugin.Metadata.ActionKeywords;

var newActionKeywords = tbAction.Text.Split(Query.ActionKeywordSeparator).ToList();
newActionKeywords.RemoveAll(string.IsNullOrEmpty);
newActionKeywords = newActionKeywords.Distinct().ToList();

newActionKeywords = newActionKeywords.Count > 0 ? newActionKeywords : new() { Query.GlobalPluginWildcardSign };

if (!PluginViewModel.IsActionKeywordRegistered(newActionKeyword))
if (!PluginManager.ActionKeywordRegistered(newActionKeywords, oldActionKeywords))
{
pluginViewModel.ChangeActionKeyword(newActionKeyword, oldActionKeyword);
pluginViewModel.ChangeActionKeyword(newActionKeywords, oldActionKeywords);
Close();
}
else
Expand Down
2 changes: 1 addition & 1 deletion Flow.Launcher/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@
<system:String x:Key="newActionKeywordsHasBeenAssigned">This new Action Keyword is already assigned to another plugin, please choose a different one</system:String>
<system:String x:Key="success">Success</system:String>
<system:String x:Key="completedSuccessfully">Completed successfully</system:String>
<system:String x:Key="actionkeyword_tips">Enter the action keyword you like to use to start the plugin. Use * if you don't want to specify any, and the plugin will be triggered without any action keywords.</system:String>
<system:String x:Key="actionkeyword_tips">Enter the action keywords you like to use to start the plugin and use whitespace to divide them. Use * if you don't want to specify any, and the plugin will be triggered without any action keywords.</system:String>

<!-- Custom Query Hotkey Dialog -->
<system:String x:Key="customeQueryHotkeyTitle">Custom Query Hotkey</system:String>
Expand Down
2 changes: 0 additions & 2 deletions Flow.Launcher/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,6 @@ private async void QueryResults(bool isReQuery = false, bool reSelect = true)
SearchIconVisibility = Visibility.Visible;
}


if (query.ActionKeyword == Plugin.Query.GlobalPluginWildcardSign)
{
// Wait 45 millisecond for query change in global query
Expand All @@ -1145,7 +1144,6 @@ private async void QueryResults(bool isReQuery = false, bool reSelect = true)
true => Task.CompletedTask
}).ToArray();


try
{
// Check the code, WhenAll will translate all type of IEnumerable or Collection to Array, so make an array at first
Expand Down
9 changes: 4 additions & 5 deletions Flow.Launcher/ViewModel/PluginViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using CommunityToolkit.Mvvm.Input;
using Flow.Launcher.Core.Resource;
using Flow.Launcher.Resources.Controls;
using System.Collections.Generic;

namespace Flow.Launcher.ViewModel
{
Expand Down Expand Up @@ -100,7 +101,7 @@ public Control SettingControl
: null;
private ImageSource _image = ImageLoader.MissingImage;

public Visibility ActionKeywordsVisibility => PluginPair.Metadata.ActionKeywords.Count == 1 ? Visibility.Visible : Visibility.Collapsed;
public Visibility ActionKeywordsVisibility => PluginPair.Metadata.AllowModifyActionKeywords ? Visibility.Visible : Visibility.Collapsed;
public string InitilizaTime => PluginPair.Metadata.InitTime + "ms";
public string QueryTime => PluginPair.Metadata.AvgQueryTime + "ms";
public string Version => InternationalizationManager.Instance.GetTranslation("plugin_query_version") + " " + PluginPair.Metadata.Version;
Expand All @@ -109,9 +110,9 @@ public Control SettingControl
public int Priority => PluginPair.Metadata.Priority;
public Infrastructure.UserSettings.Plugin PluginSettingsObject { get; set; }

public void ChangeActionKeyword(string newActionKeyword, string oldActionKeyword)
public void ChangeActionKeyword(IReadOnlyList<string> newActionKeywords, IReadOnlyList<string> oldActionKeywords)
{
PluginManager.ReplaceActionKeyword(PluginPair.Metadata.ID, oldActionKeyword, newActionKeyword);
PluginManager.ReplaceActionKeyword(PluginPair.Metadata.ID, oldActionKeywords, newActionKeywords);
OnPropertyChanged(nameof(ActionKeywordsText));
}

Expand Down Expand Up @@ -150,8 +151,6 @@ private void OpenDeletePluginWindow()
PluginManager.API.ShowMainWindow();
}

public static bool IsActionKeywordRegistered(string newActionKeyword) => PluginManager.ActionKeywordRegistered(newActionKeyword);

[RelayCommand]
private void SetActionKeywords()
{
Expand Down
5 changes: 1 addition & 4 deletions Plugins/Flow.Launcher.Plugin.Explorer/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
"ID": "572be03c74c642baae319fc283e561a8",
"ActionKeywords": [
"*",
"doc:",
"*",
"*",
"*"
"doc:"
],
"Name": "Explorer",
"Description": "Find and manage files and folders via Windows Search or Everything",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ private void OnConfirmButtonClick(object sender, RoutedEventArgs e)
private void AddSearchSource()
{
var keyword = _searchSource.ActionKeyword;
if (!PluginManager.ActionKeywordRegistered(keyword))
if (!_context.API.ActionKeywordAssigned(keyword))
{
var id = _context.CurrentPluginMetadata.ID;
PluginManager.AddActionKeyword(id, keyword);
_context.API.AddActionKeyword(id, keyword);

_searchSources.Add(_searchSource);

Expand All @@ -100,7 +100,7 @@ private void EditSearchSource()
{
var newKeyword = _searchSource.ActionKeyword;
var oldKeyword = _oldSearchSource.ActionKeyword;
if (!PluginManager.ActionKeywordRegistered(newKeyword) || oldKeyword == newKeyword)
if (!_context.API.ActionKeywordAssigned(newKeyword) || oldKeyword == newKeyword)
{
var id = _context.CurrentPluginMetadata.ID;
PluginManager.ReplaceActionKeyword(id, oldKeyword, newKeyword);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private void OnDeleteSearchSearchClick(object sender, RoutedEventArgs e)
if (result == MessageBoxResult.Yes)
{
var id = _context.CurrentPluginMetadata.ID;
PluginManager.RemoveActionKeyword(id, selected.ActionKeyword);
_context.API.RemoveActionKeyword(id, selected.ActionKeyword);
_settings.SearchSources.Remove(selected);
}
}
Expand Down
1 change: 1 addition & 0 deletions Plugins/Flow.Launcher.Plugin.WebSearch/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"yahoo",
"bd"
],
"AllowModifyActionKeywords": false,
"Name": "Web Searches",
"Description": "Provide the web search ability",
"Author": "qianlifeng",
Expand Down
Loading