Skip to content
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

Use Command Keyword to Search System Command #3344

Merged
merged 8 commits into from
Mar 16, 2025

Conversation

Jack251970
Copy link
Contributor

@Jack251970 Jack251970 commented Mar 13, 2025

Use Command Keyword to Search System Command

Previously, FL uses the English title & translated title & subtitle to search the commands. If English title is matched, the result title will be in English which I think can cause confusion for users.

This PR Introduces command keyword to replace the original function of searching with English title. (Users can still search with translated title & subtitle) And users can change this command keyword.

By default, the command keywords are the same as the English title. And users can set whatever they like for faster query.

Demo

2025-03-13.23-58-58.mp4

Test

  • Change command keyword & Search them.
  • Name & Description column are now translated.
  • Sys plugin can correctly save & load settings.

Close #3343

@Jack251970 Jack251970 added the enhancement New feature or request label Mar 13, 2025
@Jack251970 Jack251970 added this to the 1.20.0 milestone Mar 13, 2025
@Jack251970 Jack251970 requested a review from onesounds March 13, 2025 10:21
@Jack251970 Jack251970 enabled auto-merge March 13, 2025 10:22

This comment has been minimized.

Copy link

gitstream-cm bot commented Mar 13, 2025

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

Copy link
Contributor

coderabbitai bot commented Mar 13, 2025

📝 Walkthrough

Walkthrough

The changes involve significant updates to the Main class and the introduction of new classes and UI elements in the Flow.Launcher.Plugin.Sys namespace. Key modifications include the initialization of command title and description mappings, updates to the settings panel, and the addition of a new user interface for command keyword settings. Several methods have been added or modified to enhance command handling, and new string resources have been introduced to support the updated functionality.

Changes

File Change Summary
Plugins/Flow.Launcher.Plugin.Sys/Main.cs Updated command title and description handling with new mappings. Modified CreateSettingPanel and Query methods. Renamed GetDynamicTitle to GetTitle and added GetDescription. Introduced OnCultureInfoChanged method.
Plugins/Flow.Launcher.Plugin.Sys/Command.cs Introduced new Command class with properties Key, Name, Description, and Keyword, supporting data binding and change notifications.
Plugins/Flow.Launcher.Plugin.Sys/CommandKeywordSetting.xaml Added new XAML file for the command keyword settings interface, including layout and data bindings.
Plugins/Flow.Launcher.Plugin.Sys/CommandKeywordSetting.xaml.cs Added CommandKeywordSettingWindow class to manage the command keyword settings UI, including event handlers for user interactions.
Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml Modified string resources for command keywords, including renaming and adding new keys for improved functionality.
Plugins/Flow.Launcher.Plugin.Sys/Settings.cs Introduced new Settings class with an ObservableCollection<Command> and a SelectedCommand property.
Plugins/Flow.Launcher.Plugin.Sys/SettingsViewModel.cs Added SettingsViewModel class to encapsulate the Settings object, facilitating data binding.
Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml Updated layout and data binding in the settings interface, including new event handlers and column definitions.
Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml.cs Modified constructor and added methods for handling command keyword editing and double-click events in the settings UI.
Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs Renamed type alias for settings, updating the _settings field type without changing functionality.
Plugins/Flow.Launcher.Plugin.WebSearch/SettingsViewModel.cs Removed storage functionality, including the _storage field and Save method.

Suggested reviewers

  • onesounds

Suggested labels

kind/ui, kind/ux

Poem

In a burrow of code, I hop with glee,
New commands and titles, as bright as can be.
A window for keywords, a dance of delight,
With each little change, our plugin takes flight!
🐇✨

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.

@Jack251970 Jack251970 marked this pull request as draft March 13, 2025 11:09
auto-merge was automatically disabled March 13, 2025 11:09

Pull request was converted to draft

This comment has been minimized.

This comment has been minimized.

@Jack251970 Jack251970 changed the title Add translations for system plugin command column Use Command Keyword to Search System Command Mar 13, 2025

This comment has been minimized.

@Jack251970 Jack251970 marked this pull request as ready for review March 13, 2025 16:05
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: 1

🧹 Nitpick comments (5)
Plugins/Flow.Launcher.Plugin.Sys/SettingsViewModel.cs (1)

1-12: Simple View Model for System Command Settings

This is a clean implementation of a ViewModel for the System Commands settings. It follows the MVVM pattern by providing a way to bind the UI to the Settings object.

Consider implementing INotifyPropertyChanged if you need to support UI updates when properties change, though it's not strictly necessary for this simple case since Settings is a read-only property.

Plugins/Flow.Launcher.Plugin.Sys/CommandKeywordSetting.xaml (2)

91-98: Fix misleading control name

The button is named btnTestActionKeyword but its function is to reset the keyword (as indicated by the click handler OnResetButtonClick and the "Reset" text content). This naming inconsistency could cause confusion for future maintenance.

-                    <Button
-                        x:Name="btnTestActionKeyword"
+                    <Button
+                        x:Name="btnResetKeyword"
                         Grid.Row="1"
                         Grid.Column="2"
                         Margin="0 0 10 0"
                         Padding="10 5 10 5"
                         Click="OnResetButtonClick"
                         Content="{DynamicResource flowlauncher_plugin_sys_reset}" />

1-121: Well-structured UI for Command Keyword editing

The UI is well-designed with proper layout and styling. The window provides a good user experience for editing command keywords, with clear labels and intuitive controls.

Consider adding a tooltip or help text to explain the purpose of the keyword feature to users, especially since this is a new feature.

Plugins/Flow.Launcher.Plugin.Sys/Main.cs (2)

23-46: Consolidate or clarify overlapping command labels.

You have commands like "Restart" and "Restart Flow Launcher" in the same dictionary. While functionally distinct, it may be worth distinguishing them more clearly or ensuring their distinction is evident in UI and logs.


96-104: Check for null command keywords.

Using _context.API.FuzzySearch with command.Keyword might throw an error if command.Keyword is null. If user input or older settings lead to empty keywords, this could cause issues.

Consider defaulting command.Keyword to an empty string in the Settings model or defending against null here.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bc0cde2 and 0f279df.

📒 Files selected for processing (11)
  • Plugins/Flow.Launcher.Plugin.Sys/Command.cs (1 hunks)
  • Plugins/Flow.Launcher.Plugin.Sys/CommandKeywordSetting.xaml (1 hunks)
  • Plugins/Flow.Launcher.Plugin.Sys/CommandKeywordSetting.xaml.cs (1 hunks)
  • Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml (3 hunks)
  • Plugins/Flow.Launcher.Plugin.Sys/Main.cs (11 hunks)
  • Plugins/Flow.Launcher.Plugin.Sys/Settings.cs (1 hunks)
  • Plugins/Flow.Launcher.Plugin.Sys/SettingsViewModel.cs (1 hunks)
  • Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml (1 hunks)
  • Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml.cs (2 hunks)
  • Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs (2 hunks)
  • Plugins/Flow.Launcher.Plugin.WebSearch/SettingsViewModel.cs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
🔇 Additional comments (22)
Plugins/Flow.Launcher.Plugin.WebSearch/SettingsViewModel.cs (1)

1-12:

✅ Verification successful

Code simplification looks good

The simplified ViewModel for WebSearch plugin follows the same pattern as the new Sys plugin ViewModel, which provides consistency across the codebase.

The removal of the storage-related code suggests that saving functionality is now handled elsewhere, which should be verified to ensure settings persistence still works correctly.


🏁 Script executed:

#!/bin/bash
# Verify if saving functionality is implemented elsewhere
echo "Checking for save functionality in related files..."
rg -A 5 "Save.*Settings" --type cs

Length of output: 9992


Simplified ViewModel verified – Global saving mechanism confirmed

The refactored SettingsViewModel in the WebSearch plugin now omits storage logic, which is consistent with the refactoring seen in the Sys plugin. The repository-wide search confirms that saving functionality (e.g., via API.SaveAppAllSettings() and related methods) is implemented elsewhere. This global approach ensures settings persistence without requiring each plugin ViewModel to manage its own storage.

No further changes are needed here, but please ensure that integration tests confirm that settings continue to persist correctly.

Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs (2)

5-5: Good use of type aliasing to avoid naming conflicts

Using the alias FLSettings for Flow.Launcher.Infrastructure.UserSettings.Settings is a good approach to avoid naming conflicts with the new Settings class in the same namespace.


13-13: Consistent update of type references

The update of the field type from Settings to FLSettings and its corresponding initialization is properly implemented.

Also applies to: 46-46

Plugins/Flow.Launcher.Plugin.Sys/Command.cs (1)

1-44: Well-structured model class for command customization

This Command class is well-designed with:

  • Clear property structure with proper change notification
  • Appropriate use of JsonIgnore to prevent serialization of UI-specific properties
  • Consistent implementation of property change notifications

The class effectively supports the new command keyword customization feature.

Plugins/Flow.Launcher.Plugin.Sys/CommandKeywordSetting.xaml.cs (3)

10-17: Well-implemented dialog initialization

Good implementation of the dialog constructor with proper initialization of UI elements and translation support. The use of string formatting for the tip text enhances user understanding.


24-37: Proper validation and error handling for keyword input

The confirmation logic correctly validates against empty keywords and displays appropriate error messages using the translation system. This ensures users understand the requirement for non-empty keywords.


39-43: Useful reset functionality

The reset button implementation provides a convenient way for users to revert to the default keyword. The comment explaining that Key is the default value adds clarity to the code.

Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml (6)

7-8: Good design-time support

Adding the ViewModel namespace and DataContext for design-time support improves development experience by providing IntelliSense and preview capabilities in the XAML designer.


12-16: Well-structured layout

The updated Grid with proper row definitions creates a clean separation between the command list and action buttons, improving the UI organization.


24-26: Proper data binding implementation

The ListView now correctly binds to the Commands collection and tracks the selected command, providing the foundation for the keyword customization feature.


31-35: Updated column bindings for clarity

The changes to column headers and bindings from Title/SubTitle to Name/Description improve clarity and better align with the Command object properties.

Also applies to: 39-45


47-53: New column for command keywords

The addition of a dedicated column for displaying command keywords gives users clear visibility of the customized keywords.


58-67: Well-positioned action button

The Edit button is appropriately positioned in a separate row with proper alignment and spacing, providing a clear call-to-action for customizing command keywords.

Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml.cs (4)

8-16: Validate constructor dependencies.

The constructor now accepts and stores both _context and _settings for the control. Generally, storing the plugin context in a UI control is acceptable if it’s truly needed, but ensure that no null reference exceptions occur if _context or viewModel is not properly initialized.

Please verify upstream usage to confirm _context is never null at construction time; otherwise, consider defensive checks (e.g., ArgumentNullException).


25-27: Column resizing logic looks consistent.

The adjusted column widths (0.2, 0.6, 0.2) sum to 1.0 and should evenly fill the available ListView space. This design is straightforward and should not pose performance or layout issues.

Also applies to: 36-37


39-43: Consider null-check before opening the CommandKeywordSettingWindow.

When calling the window constructor (CommandKeywordSettingWindow(_context, _settings.SelectedCommand)), it’s assumed _settings.SelectedCommand is valid. If _settings.SelectedCommand could be null, guard against that case to prevent exceptions.

Please confirm that _settings.SelectedCommand is always set before a user can click "Edit".


45-51: Double-click handling logic looks clean.

The double-click event properly verifies the data context is a Command and checks _settings.SelectedCommand for null. This helps avoid accidental null dereferences or exceptions. No issues found.

Plugins/Flow.Launcher.Plugin.Sys/Main.cs (2)

77-78: Guard against empty or missing commands.

_settings.Commands.First(x => x.Key == c.Title) will throw an exception if no command is found, which could happen if _settings.Commands is missing the corresponding command. Consider using FirstOrDefault with a null check or validating that the key exists.

Also applies to: 79-79


144-154: Ensure collection safety in UpdateLocalizedNameDescription.

_settings.Commands[0] could lead to an index out-of-range exception if _settings.Commands is empty. Add a defensive check to avoid potential runtime errors.

Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml (3)

7-9: Confirm resource usage and naming consistency.

“Name” (flowlauncher_plugin_sys_name) vs. “Command” (flowlauncher_plugin_sys_command) might cause confusion if both appear in similar contexts. Verify that these are used in clearly distinct UI columns or labels.


33-33: New 'Edit' resource is consistent with UI.

Defining flowlauncher_plugin_sys_edit for future usage is a good extension. No further issues identified.


67-75: Useful additions for customizing command keywords.

The newly introduced resource strings clarify user actions for command keyword configuration and error handling. This should enhance user experience when customizing search keywords.

@Jack251970
Copy link
Contributor Author

@onesounds I have completed my work and please review when you have a chance. Regarding the tips for changing the command keyword, I would like your feedback on whether they are clear enough for users.

Copy link

gitstream-cm bot commented Mar 14, 2025

🥷 Code experts: onesounds

Jack251970 has most 👩‍💻 activity in the files.
Jack251970, onesounds have most 🧠 knowledge in the files.

See details

Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml

Activity based on git-commit:

Jack251970
MAR
FEB
JAN
DEC
NOV
OCT

Knowledge based on git-blame:
onesounds: 12%

Plugins/Flow.Launcher.Plugin.Sys/Main.cs

Activity based on git-commit:

Jack251970
MAR 3 additions & 9 deletions
FEB 92 additions & 48 deletions
JAN
DEC 12 additions & 38 deletions
NOV 12 additions & 14 deletions
OCT

Knowledge based on git-blame:
Jack251970: 18%
onesounds: 4%

Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml

Activity based on git-commit:

Jack251970
MAR
FEB
JAN
DEC
NOV
OCT

Knowledge based on git-blame:
onesounds: 97%

Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml.cs

Activity based on git-commit:

Jack251970
MAR
FEB
JAN
DEC
NOV
OCT

Knowledge based on git-blame:
onesounds: 33%

Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs

Activity based on git-commit:

Jack251970
MAR 114 additions & 89 deletions
FEB
JAN
DEC
NOV
OCT

Knowledge based on git-blame:
Jack251970: 57%

Plugins/Flow.Launcher.Plugin.WebSearch/SettingsViewModel.cs

Activity based on git-commit:

Jack251970
MAR
FEB
JAN
DEC
NOV
OCT

Knowledge based on git-blame:

To learn more about /:\ gitStream - Visit our Docs

Copy link

@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.

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 (1)
Plugins/Flow.Launcher.Plugin.Sys/Main.cs (1)

337-338: Consider localizing error message

While most messages use localization, this error message for recycling bin operation is still hardcoded in English.

Consider using the translation API for this error message as well:

-            _context.API.ShowMsgBox("Failed to empty the recycle bin. This might happen if:\n" +
+            _context.API.ShowMsgBox(_context.API.GetTranslation("flowlauncher_plugin_sys_failed_empty_recycle_bin") +
                             "- A file in the recycle bin is in use\n" +
                             "- You don't have permission to delete some items\n" +
                             "Please close any applications that might be using these files and try again.",
                    "Error",
                    MessageBoxButton.OK, MessageBoxImage.Error);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0f279df and ab3cd8a.

📒 Files selected for processing (1)
  • Plugins/Flow.Launcher.Plugin.Sys/Main.cs (11 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Report (PR)
🔇 Additional comments (13)
Plugins/Flow.Launcher.Plugin.Sys/Main.cs (13)

23-46: Good organizational structure for command mapping

The introduction of a structured dictionary for command mappings provides a clear and maintainable way to manage system commands and their translations. This approach eliminates potential string inconsistencies and centralizes command definitions.


47-47: KeywordDescriptionMappings empty initialization is appropriate

The empty initialization of KeywordDescriptionMappings is correct as it will be populated later in the Init method, providing a clean separation between declaration and population logic.


49-54: Improved code documentation

Adding clear comments for the shutdown reason constants improves code understanding and maintainability.


55-58: ViewModel pattern implementation

The addition of the SettingsViewModel field implements the MVVM pattern, which is a good practice for separating UI logic from data models.


62-63: Initialization before UI creation

Calling UpdateLocalizedNameDescription before creating the settings panel ensures the UI will display properly localized content from the start.


77-80: Core feature implementation for command keyword searching

This code effectively implements the command keyword feature by retrieving command names and descriptions from settings, allowing users to search by their preferred keywords instead of relying solely on English titles.


81-89: Comprehensive search matching logic

The search logic now checks across title, subtitle, and keyword fields, which provides users with more flexible ways to find commands. The implementation correctly calculates and compares match scores to determine the best result.


106-115: Simplified title retrieval method

The renamed and streamlined GetTitle method improves code readability while maintaining proper error handling with helpful log messages.


117-126: Parallel implementation for descriptions

The new GetDescription method follows the same pattern as GetTitle, maintaining consistency in the codebase while extending functionality to include command descriptions.


130-138: Clever description mapping logic

The implementation cleverly derives description translation keys by removing the "_cmd" suffix from title keys, avoiding the need to maintain two separate mapping dictionaries.


141-151: Efficient localization update mechanism

The UpdateLocalizedNameDescription method efficiently handles command localization by only updating when necessary (empty names or forced update), which is a good performance optimization.


206-209: Consistently localized dialog messages

The dialog messages are now properly localized using the translation API, which improves the user experience for non-English users.

Also applies to: 227-230, 248-251, 269-272


505-508: Culture change handling

The implementation of OnCultureInfoChanged ensures that command names and descriptions are properly updated when the user changes the language settings.

@onesounds
Copy link
Contributor

Good. there are no issues. (It works fine even when no command is entered or when there are duplicate inputs.) There was a request before to allow certain items to be disabled (since options like "Restart with Advanced" aren’t used often), but I’m not sure if that should be included. For now, this PR is good to go, so I'll approve it.

@Jack251970 Jack251970 merged commit 82af6ab into Flow-Launcher:dev Mar 16, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

System plugin translation
3 participants