Skip to content

Support Multiple keywords for Plugins #3261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Mar 20, 2025

Conversation

Jack251970
Copy link
Contributor

@Jack251970 Jack251970 commented Feb 21, 2025

Support multiple keywords for plugins

Support user to set multiple keywords for plugins

I change the action keyword separator from ; to because is the character we used to split terms so we should not let user include that character in one action keyword so we can use it as separator which can help us to fix one possible issue that action keyword with cannot work (I find FL does not notify users about this).

Support plugin to not allow user change its action keyword

I find WebSearch and Explorer plugin need this because these plugins let user change its keywords from settings panel.

Fix issue that plugin cannot update ActionKeyword after changing its keywords

Check d9ba38b

Test

2025-02-21.14-03-47.online-video-cutter.com.mp4

@prlabeler prlabeler bot added the bug Something isn't working label Feb 21, 2025
@Jack251970 Jack251970 linked an issue Feb 21, 2025 that may be closed by this pull request

This comment has been minimized.

Copy link

gitstream-cm bot commented Feb 21, 2025

Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX.

@Jack251970 Jack251970 added enhancement New feature or request and removed bug Something isn't working labels Feb 21, 2025
Copy link
Contributor

coderabbitai bot commented Feb 21, 2025

📝 Walkthrough

Walkthrough

The pull request refines the management of action keywords across multiple modules. In the core PluginManager, the AddActionKeyword and RemoveActionKeyword methods now automatically update the primary action keyword, while the ReplaceActionKeyword method has been removed. The PluginMetadata class gains a new configurable property, and the ActionKeywordSeparator constant is updated to use whitespace. UI components have been enhanced to process multiple keywords with improved validation. Additionally, keyword registration has shifted from PluginManager to the API context, with minor cleanup adjustments applied in various view models and project files.

Changes

File(s) Change Summary
Flow.Launcher.Core/Plugin/PluginManager.cs Enhanced AddActionKeyword and RemoveActionKeyword to update primary action keyword; removed ReplaceActionKeyword.
Flow.Launcher.Plugin/PluginMetadata.cs Added new property HideActionKeywordPanel (bool).
Flow.Launcher.Plugin/Query.cs Updated constant ActionKeywordSeparator from ";" to TermSeparator (whitespace) with revised comments.
Flow.Launcher/ActionKeywords.xaml.cs Modified btnDone_OnClick to process multiple, duplicate-filtered keywords and added internal ReplaceActionKeyword logic.
Flow.Launcher/Languages/en.xaml Added newActionKeywordsSameAsOld resource and updated actionkeyword_tips for multiple keywords (whitespace-separated).
Flow.Launcher/ViewModel/MainViewModel.cs
Flow.Launcher/ViewModel/PluginViewModel.cs
Removed extra blank lines; updated PluginViewModel’s action keyword visibility logic, renamed method from ChangeActionKeyword to OnActionKeywordsChanged, and removed IsActionKeywordRegistered.
Plugins/Flow.Launcher.Plugin.Explorer/plugin.json
Plugins/Flow.Launcher.Plugin.WebSearch/plugin.json
Added "HideActionKeywordPanel": true to hide the action keyword panel.
Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml.cs
Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs
Replaced calls from PluginManager to _context.API for registering and removing action keywords.
Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs
Flow.Launcher/PublicAPIInstance.cs
Updated documentation comments and minor formatting changes.
Plugins/Flow.Launcher.Plugin.WebSearch/Flow.Launcher.Plugin.WebSearch.csproj Removed project reference to Flow.Launcher.Core.
Plugins/Flow.Launcher.Plugin.Calculator/Flow.Launcher.Plugin.Calculator.csproj Added project references to Flow.Launcher.Infrastructure and Flow.Launcher.Plugin.
Plugins/Flow.Launcher.Plugin.PluginsManager/Flow.Launcher.Plugin.PluginsManager.csproj Adjusted indentation formatting for project references.

Possibly related PRs

Suggested reviewers

  • jjw24
  • taooceros

Poem

I'm a rabbit with a hop in my code,
New keywords dance in every mode.
With action flows now crisp and clear,
I skip along with a joyful cheer.
In ASCII hops, my heart exclaims—progress leads the way!
🥕🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9ec8681 and ba0d412.

📒 Files selected for processing (7)
  • Flow.Launcher.Core/Plugin/PluginManager.cs (2 hunks)
  • Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs (1 hunks)
  • Flow.Launcher/ActionKeywords.xaml.cs (2 hunks)
  • Flow.Launcher/Languages/en.xaml (1 hunks)
  • Flow.Launcher/PublicAPIInstance.cs (0 hunks)
  • Flow.Launcher/ViewModel/MainViewModel.cs (0 hunks)
  • Flow.Launcher/ViewModel/PluginViewModel.cs (2 hunks)
💤 Files with no reviewable changes (2)
  • Flow.Launcher/PublicAPIInstance.cs
  • Flow.Launcher/ViewModel/MainViewModel.cs
🚧 Files skipped from review as they are similar to previous changes (4)
  • Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs
  • Flow.Launcher/ViewModel/PluginViewModel.cs
  • Flow.Launcher.Core/Plugin/PluginManager.cs
  • Flow.Launcher/Languages/en.xaml
🔇 Additional comments (4)
Flow.Launcher/ActionKeywords.xaml.cs (4)

6-7: Appropriate addition of necessary namespaces.

The addition of System.Linq and System.Collections.Generic namespaces supports the new implementation for handling multiple action keywords with collection operations.


37-47: Good implementation of multi-keyword processing with validation.

The code now correctly handles multiple action keywords by:

  1. Retrieving existing keywords from plugin metadata
  2. Splitting input by the separator
  3. Removing empty entries and duplicates
  4. Defaulting to wildcard when empty
  5. Calculating added and removed keywords

The use of LINQ's Except method is efficient for determining which keywords to add or remove.


48-68: Well-structured decision logic for action keyword updates.

The implementation correctly handles different scenarios:

  1. Checks if new keywords are already assigned to other plugins
  2. Handles count differences between old and new keywords
  3. Detects when only the sequence has changed (nice UX touch)
  4. Shows appropriate messages to the user

This approach is robust and provides good user feedback.


76-90: Clean implementation of the ReplaceActionKeyword method.

The method effectively:

  1. Removes old keywords one by one
  2. Adds new keywords one by one
  3. Updates the UI and closes the window

This extraction of functionality improves code readability and maintainability.

Note: According to the PR objectives, there was a discussion about removing the ReplaceActionKeyword method from the PluginManager class. This implementation in the ActionKeywords class seems appropriate as it encapsulates the logic for updating keywords at the UI level.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
Flow.Launcher/ActionKeywords.xaml.cs (1)

39-41: Consider adding validation for individual keywords and a maximum limit.

To prevent potential issues:

  1. Add validation for individual keyword format (e.g., no special characters).
  2. Add a maximum limit on the number of keywords to prevent performance issues.
 var newActionKeywords = tbAction.Text.Split(Query.ActionKeywordSeparator).ToList();
 newActionKeywords.RemoveAll(string.IsNullOrEmpty);
 newActionKeywords = newActionKeywords.Distinct().ToList();
+const int MaxKeywords = 5;
+newActionKeywords = newActionKeywords.Where(k => IsValidKeyword(k)).Take(MaxKeywords).ToList();
+
+bool IsValidKeyword(string keyword)
+{
+    return !string.IsNullOrWhiteSpace(keyword) && 
+           keyword.All(c => char.IsLetterOrDigit(c) || c == '_');
+}
Plugins/Flow.Launcher.Plugin.Explorer/plugin.json (1)

3-6: Clarify the ActionKeywords change.
The ActionKeywords array now contains only two entries: "*" and "doc:". This indicates that redundant * keywords have been removed, which aligns with the PR objective to eliminate superfluous keywords. Please verify that retaining the single "*" entry is intentional (e.g., for backward compatibility or a default behavior) and that its usage is well documented in the plugin documentation if needed.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c137091 and 414684c.

📒 Files selected for processing (11)
  • Flow.Launcher.Core/Plugin/PluginManager.cs (3 hunks)
  • Flow.Launcher.Plugin/PluginMetadata.cs (1 hunks)
  • Flow.Launcher.Plugin/Query.cs (1 hunks)
  • Flow.Launcher/ActionKeywords.xaml.cs (2 hunks)
  • Flow.Launcher/Languages/en.xaml (1 hunks)
  • Flow.Launcher/ViewModel/MainViewModel.cs (0 hunks)
  • Flow.Launcher/ViewModel/PluginViewModel.cs (3 hunks)
  • Plugins/Flow.Launcher.Plugin.Explorer/plugin.json (1 hunks)
  • Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml.cs (2 hunks)
  • Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs (1 hunks)
  • Plugins/Flow.Launcher.Plugin.WebSearch/plugin.json (1 hunks)
💤 Files with no reviewable changes (1)
  • Flow.Launcher/ViewModel/MainViewModel.cs
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
🔇 Additional comments (12)
Flow.Launcher.Plugin/PluginMetadata.cs (1)

37-37: LGTM! Good addition of the AllowModifyActionKeywords property.

The property aligns with the PR objectives by providing a way to restrict keyword modifications for certain plugins, with a sensible default value of true.

Flow.Launcher/ActionKeywords.xaml.cs (1)

37-44: LGTM! Good implementation of multiple action keywords support.

The changes correctly handle multiple action keywords by:

  1. Splitting input by whitespace
  2. Removing empty entries
  3. Removing duplicates
  4. Adding wildcard sign if no valid keywords remain
Flow.Launcher.Plugin/Query.cs (1)

42-44: LGTM! Good update to use whitespace as separator.

The changes:

  1. Align with PR objectives by changing separator from ; to space.
  2. Maintain consistency by reusing TermSeparator.
  3. Include clear documentation.
Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs (1)

43-43: LGTM! Good update to use API context.

The change correctly uses _context.API.RemoveActionKeyword instead of PluginManager.RemoveActionKeyword, maintaining consistency with the broader changes in action keyword management.

Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml.cs (1)

82-87: LGTM! The changes improve the API usage.

The switch from PluginManager.ActionKeywordRegistered to _context.API.ActionKeywordAssigned is a good architectural improvement that:

  1. Maintains proper separation of concerns
  2. Follows the principle of using the API context for plugin operations

Also applies to: 101-106

Flow.Launcher/ViewModel/PluginViewModel.cs (2)

104-104: LGTM! The visibility logic aligns with the PR objectives.

The change to use AllowModifyActionKeywords properly implements the requirement to restrict keyword modifications for certain plugins.


113-117: LGTM! The method signature change supports multiple keywords.

The update to accept IReadOnlyList<string> parameters properly implements the requirement to support multiple keywords while maintaining immutability through read-only collections.

Flow.Launcher.Core/Plugin/PluginManager.cs (3)

343-353: LGTM! The method properly validates multiple keywords.

The implementation correctly:

  1. Iterates through new keywords
  2. Checks each against old keywords
  3. Returns early on first conflict

411-437: LGTM! The method safely handles keyword replacements.

The implementation:

  1. Checks if keywords actually changed
  2. Safely handles collection modifications
  3. Updates metadata correctly
  4. Maintains proper error handling

439-444: LGTM! The helper method properly detects changes.

The implementation efficiently detects changes by:

  1. Comparing counts first
  2. Using LINQ to compare elements
Flow.Launcher/Languages/en.xaml (1)

338-338: LGTM! The instructions clearly explain the new keyword format.

The updated text properly informs users about:

  1. Using multiple keywords
  2. Using whitespace as the separator
  3. Using * for global triggers
Plugins/Flow.Launcher.Plugin.WebSearch/plugin.json (1)

26-26: Enforce Action Keyword Modification Restrictions.
The addition of the "AllowModifyActionKeywords": false property clearly prevents users from modifying the action keywords for the WebSearch plugin. This change aligns with the PR objective to preserve the integrity of the plugin's functionality. Ensure that the consuming code correctly reads and respects this flag when processing action keyword changes.

@Jack251970 Jack251970 added the kind/ux related to user experience label Feb 21, 2025
@Jack251970 Jack251970 requested a review from taooceros February 22, 2025 11:16

This comment has been minimized.

@prlabeler prlabeler bot added the bug Something isn't working label Feb 23, 2025
@taooceros
Copy link
Member

Does this mean the explorer plugin (and the web search plugin) will demonstrate the actionkeyword assign panel? They should not display the control for user to change the actionkeyword.

@Jack251970
Copy link
Contributor Author

Does this mean the explorer plugin (and the web search plugin) will demonstrate the actionkeyword assign panel? They should not display the control for user to change the actionkeyword.

Yes, if one plugin can change its action keyword in its settings panel, it can add "AllowModifyActionKeywords": false, in its plugin.json so that we will not show action keyword panel.

@Jack251970 Jack251970 changed the title Support Multiple keywords for Plugins Support Multiple keywords for Plugins & Add ReplaceActionKeyword API Function Feb 23, 2025
@jjw24
Copy link
Member

jjw24 commented Feb 26, 2025

Yeah ok in this case let's keep how you have done it @Jack251970.

@jjw24
Copy link
Member

jjw24 commented Feb 26, 2025

Also what's the reason for disallowing the WebSearch and Explorer action keywords been changed from settings panel?

@Jack251970
Copy link
Contributor Author

Yeah ok in this case let's keep how you have done it @Jack251970.

Well, we can do this UI improvement in the future.

@Jack251970
Copy link
Contributor Author

Also what's the reason for disallowing the WebSearch and Explorer action keywords been changed from settings panel?

The main reason is that those plugins can let users edit their action keywords from their settings controls, so action keyword panels seem to be redundant.

image

Also, I follow the original logic that plugins with multiple keywords do no show the action keyword panel and those plugins are all plugins with multiple action keywords by default.

Additionally, if we want to enable action keyword panels for those plugins, we need to add more like ActionKeywordsChanged callback to update their settings controls when we change their keywords from action keyword panels.

This comment has been minimized.

@jjw24
Copy link
Member

jjw24 commented Feb 27, 2025

I don't think there is a need to allow users to assign more than one action keyword for a single plugin action unless the plugin like Explorer and WebSearches have different actions and specifically support it. It's just confusing.
image

If this is to allow results to also be included in global search, can we not achieve this via a plugin settings property IncludeInGlobalSearch and if the plugin has this true/false then add/remove from GlobalPlugins?

@Jack251970
Copy link
Contributor Author

I don't think there is a need to allow users to assign more than one action keyword for a single plugin action unless the plugin like Explorer and WebSearches have different actions and specifically support it. It's just confusing. image

If this is to allow results to also be included in global search, can we not achieve this via a plugin settings property IncludeInGlobalSearch and if the plugin has this true/false then add/remove from GlobalPlugins?

I don't think this will cause confusion because it's all set by the user. (Users still can only set one action keyword)

@Jack251970
Copy link
Contributor Author

If this is to allow results to also be included in global search, can we not achieve this via a plugin settings property IncludeInGlobalSearch and if the plugin has this true/false then add/remove from GlobalPlugins?

Yeah, we can do that and I want to do that in another PR. (I need onesounds's help with UI desgin)

@jjw24
Copy link
Member

jjw24 commented Feb 27, 2025

If this is to allow results to also be included in global search, can we not achieve this via a plugin settings property IncludeInGlobalSearch and if the plugin has this true/false then add/remove from GlobalPlugins?

Yeah, we can do that and I want to do that in another PR. (I need onesounds's help with UI desgin)

Ok sounds good.

@jjw24
Copy link
Member

jjw24 commented Feb 27, 2025

I don't think AllowModifyActionKeywords is working? As you can see in my screenshot Explorer plugin still shows the change action keyword box.

Also maybe call it HideActionKeywordPanel or something because that name suggests no longer allowing modifying action keywords.

@Jack251970
Copy link
Contributor Author

I don't think AllowModifyActionKeywords is working? As you can see in my screenshot Explorer plugin still shows the change action keyword box.

Also maybe call it HideActionKeywordPanel or something because that name suggests no longer allowing modifying action keywords.

It works fine for me. I guess you have not changed plugin.json in plugin directories?

image

This comment has been minimized.

@taooceros taooceros requested a review from jjw24 February 28, 2025 06:55

This comment has been minimized.

Copy link

github-actions bot commented Mar 1, 2025

@check-spelling-bot Report

🔴 Please review

See the 📂 files view, the 📜action log, or 📝 job summary for details.

❌ Errors Count
❌ forbidden-pattern 22
⚠️ ignored-expect-variant 1
⚠️ non-alpha-in-dictionary 19

See ❌ Event descriptions for more information.

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

@Jack251970
Copy link
Contributor Author

@jjw24 Hi, is this working as expected?

@Jack251970 Jack251970 merged commit 87f765b into Flow-Launcher:dev Mar 20, 2025
4 checks passed
@Jack251970 Jack251970 added this to the 1.20.0 milestone Mar 20, 2025
@jjw24 jjw24 removed the bug Something isn't working label Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request kind/ux related to user experience
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add option to include result in global search result.
6 participants