Skip to content

Add user style selection page with CLI/GUI modes and Delete Word Backwards #3462

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

Closed

Conversation

onesounds
Copy link
Contributor

@onesounds onesounds commented Apr 14, 2025

Add user style selection page with CLI/GUI modes

What’s Changed

  • Introduced a new Style Selection page allowing users to choose between CLI and GUI modes.
  • Default mode is set to CLI.

Details

Depending on the selected mode, initial settings are adjusted:

CLI Mode

  • Autocomplete: TAB
  • Open Folder: Same behavior as before
  • Item Switching : CTRL+TAB

GUI Mode

  • Autocomplete: ALT + RIGHT
  • Open Folder: Single ENTER
  • Item Switching: TAB

Why

This gives users an immediate way to tailor the interface to their workflow—whether they prefer keyboard‑driven CLI or a more explorer‑style GUI.

Testing

  1. Launch the Style Selection page.
  2. Verify CLI is pre‑selected and settings are:
    • Autocomplete with TAB
    • Folders open in default file manager
  3. Select GUI and confirm settings change to:
    • Autocomplete with ALT + RIGHT
    • Folders open inside the app on ENTER
    • TAB switches between items
  4. Restart the app and ensure the selection persists.

Delete Word Backwards (New Feature)

  • A new feature has been implemented to delete the previous word or path segment, similar to system Ctrl + Backspace.

  • Issue:
    Ctrl + Backspace is reserved by the system

  • Solution:
    Implement a custom version of this behavior in Flow and map it to a new shortcut: Alt + Left.

  • Behavior:

    • Alt + Left: Deletes the previous word or path segment (e.g., moves up one folder level in a path).
    • Alt + Right: Accepts autocomplete suggestion or navigates deeper into a path.
    • Alt+Right (Child path) and Alt+Left(Parent path). This approach is considered intuitive

Todos

  • Add Info about folder open

Test Cases

  • Alt + Left should closely replicate Ctrl + Backspace, deleting one word or path segment at a time.

@prlabeler prlabeler bot added the enhancement New feature or request label Apr 14, 2025

This comment has been minimized.

@onesounds onesounds marked this pull request as ready for review April 17, 2025 03:33
@onesounds onesounds added kind/ui related to UI, icons, themes, etc kind/ux related to user experience labels Apr 17, 2025

This comment has been minimized.

Copy link

gitstream-cm bot commented Apr 17, 2025

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

This comment has been minimized.

Copy link
Contributor

coderabbitai bot commented Apr 17, 2025

📝 Walkthrough

Walkthrough

This update introduces a new "Delete Word" hotkey feature to the application, allowing users to delete the last word or path segment in the query box using configurable hotkeys. Two new hotkey settings are added, with corresponding UI controls and default values. The hotkey management logic, settings, and key bindings are extended to support these new actions. Additionally, the welcome flow is refactored to use a strongly typed enum for page navigation, and a new welcome page for user type selection is introduced, along with related UI resources and converters.

Changes

File(s) Change Summary
Flow.Launcher.Infrastructure/UserSettings/Settings.cs Added DeleteWordHotkey and DeleteWordHotkey2 properties with defaults; changed AutoCompleteHotkey default; extended registered hotkeys logic.
Flow.Launcher/HotkeyControl.xaml.cs Added DeleteWordHotkey and DeleteWordHotkey2 to HotkeyType enum and property logic.
Flow.Launcher/ViewModel/MainViewModel.cs Implemented DeleteWord command with file path and word deletion logic; exposed new hotkey properties.
Flow.Launcher/MainWindow.xaml Added two key bindings for DeleteWordHotkey and DeleteWordHotkey2 to trigger DeleteWordCommand.
Flow.Launcher/SettingPages/Views/SettingsPaneHotkey.xaml Added UI controls for configuring new delete word hotkeys; adjusted margins and default for autocomplete hotkey.
Flow.Launcher/Languages/en.xaml Added new hotkey and welcome page strings; updated some terminology from "position" to "location".
Flow.Launcher/Converters/NullToVisibilityConverter.cs Introduced NullToVisibilityConverter for conditional UI visibility based on value presence.
Flow.Launcher/Resources/Controls/HotkeyDisplay.xaml Updated XAML formatting for Padding/Margin and tweaked padding values.
Flow.Launcher/Resources/Dark.xaml
Flow.Launcher/Resources/Light.xaml
Added new color resources for "RadioCard" UI and popup backgrounds; updated one color value in light theme.
Flow.Launcher/Resources/Pages/WelcomePageUserType.xaml
Flow.Launcher/Resources/Pages/WelcomePageUserType.xaml.cs
Introduced new welcome page for user type selection with radio card UI and supporting data class.
Flow.Launcher/Resources/Pages/WelcomePage3.xaml.cs
Flow.Launcher/Resources/Pages/WelcomePage4.xaml.cs
Flow.Launcher/Resources/Pages/WelcomePage5.xaml.cs
Updated welcome page number assignments to match new enum-based navigation.
Flow.Launcher/ViewModel/WelcomeViewModel.cs Refactored welcome flow to use a WelcomePage enum, page sequence array, and improved navigation logic.
Flow.Launcher/WelcomeWindow.xaml.cs Refactored welcome page navigation to use enum-based page sequence and updated navigation logic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MainWindow
    participant MainViewModel
    participant Settings

    User->>MainWindow: Presses DeleteWordHotkey/DeleteWordHotkey2
    MainWindow->>MainViewModel: Execute DeleteWord command
    MainViewModel->>MainViewModel: Check if query is a file path
    alt Path-like
        MainViewModel->>MainViewModel: Remove last path segment or clear
    else
        MainViewModel->>MainViewModel: Delete last word (Ctrl+Backspace logic)
    end
    MainViewModel->>MainWindow: Update query text
Loading
sequenceDiagram
    participant User
    participant WelcomeWindow
    participant WelcomeViewModel

    User->>WelcomeWindow: Navigates welcome pages (Next/Back)
    WelcomeWindow->>WelcomeViewModel: Update CurrentPage (enum)
    WelcomeViewModel->>WelcomeWindow: Update UI and navigation state
    WelcomeWindow->>WelcomeWindow: Show corresponding page (via PageTypeSelector)
Loading

Possibly related PRs

  • Flow-Launcher/Flow.Launcher#3354: Modifies the same HotkeyControl enum and property logic to add a new None type and fixes custom query hotkey handling, making it related to the hotkey management changes in this PR.
  • Flow-Launcher/Flow.Launcher#3310: Refactors HotkeyControl by removing the HotkeySettings property and replacing it with a Type property of HotkeyType enum, which is extended in this PR, indicating a direct code-level connection.

Suggested reviewers

  • taooceros

Poem

In the warren of code, a new hop appears,
Delete words or paths with hotkeys—three cheers!
Enum pages now guide the welcome parade,
And radio cards sparkle in choices displayed.
With colors and converters, the UI feels bright—
Another fine leap in the launcher’s delight!
🐇✨⌨️

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.
✨ 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 added this to the Future milestone Apr 17, 2025

This comment has been minimized.

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 (5)
Flow.Launcher/Resources/Pages/WelcomePageUserType.xaml (4)

40-56: Consider translating non-English comments.

There are several non-English comments in the XAML code (appears to be Korean). For consistency with the rest of the codebase, consider translating these to English.

-                                    <!--  아이콘  -->
+                                    <!--  Icon  -->
...
-                                    <!--  제목  -->
+                                    <!--  Title  -->

58-114: Consider translating non-English comments.

For consistency with the rest of the codebase, consider translating the Korean comment to English.

-                                <!--  설명 및 bullet 목록  -->
+                                <!--  Description and bullet list  -->

166-179: Consider translating non-English comment.

For consistency with the rest of the codebase, consider translating the Korean comment to English.

-                <!--  CLI 카드  -->
+                <!--  CLI card  -->

181-195: Consider translating non-English comment.

For consistency with the rest of the codebase, consider translating the Korean comment to English.

-                <!--  Windows 카드 (Bullet 3개)  -->
+                <!--  Windows card (3 Bullets)  -->
Flow.Launcher/Resources/Pages/WelcomePageUserType.xaml.cs (1)

29-36: Consider using enum-based page navigation for consistency

Consider updating the navigation to use CurrentPage = WelcomePage.UserType instead of PageNum = 3 to align with the enum-based navigation approach used in other files.

Also, calling InitializeComponent() a second time may be unnecessary and could potentially cause UI initialization issues, as it's already called in the constructor.

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    Settings = Ioc.Default.GetRequiredService<Settings>();
    // Sometimes the navigation is not triggered by button click,
    // so we need to reset the page number
-    Ioc.Default.GetRequiredService<WelcomeViewModel>().PageNum = 3;
+    Ioc.Default.GetRequiredService<WelcomeViewModel>().CurrentPage = WelcomePage.UserType;
-    InitializeComponent();
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4c55fbf and 2e6728f.

📒 Files selected for processing (13)
  • Flow.Launcher.Infrastructure/UserSettings/Settings.cs (2 hunks)
  • Flow.Launcher/Converters/NullToVisibilityConverter.cs (1 hunks)
  • Flow.Launcher/Languages/en.xaml (2 hunks)
  • Flow.Launcher/Resources/Controls/HotkeyDisplay.xaml (2 hunks)
  • Flow.Launcher/Resources/Dark.xaml (2 hunks)
  • Flow.Launcher/Resources/Light.xaml (2 hunks)
  • Flow.Launcher/Resources/Pages/WelcomePage3.xaml.cs (1 hunks)
  • Flow.Launcher/Resources/Pages/WelcomePage4.xaml.cs (1 hunks)
  • Flow.Launcher/Resources/Pages/WelcomePage5.xaml.cs (1 hunks)
  • Flow.Launcher/Resources/Pages/WelcomePageUserType.xaml (1 hunks)
  • Flow.Launcher/Resources/Pages/WelcomePageUserType.xaml.cs (1 hunks)
  • Flow.Launcher/ViewModel/WelcomeViewModel.cs (3 hunks)
  • Flow.Launcher/WelcomeWindow.xaml.cs (3 hunks)
✅ Files skipped from review due to trivial changes (5)
  • Flow.Launcher/Resources/Light.xaml
  • Flow.Launcher/Converters/NullToVisibilityConverter.cs
  • Flow.Launcher/Resources/Controls/HotkeyDisplay.xaml
  • Flow.Launcher/Resources/Dark.xaml
  • Flow.Launcher/Languages/en.xaml
🚧 Files skipped from review as they are similar to previous changes (1)
  • Flow.Launcher.Infrastructure/UserSettings/Settings.cs
🧰 Additional context used
🧬 Code Graph Analysis (3)
Flow.Launcher/Resources/Pages/WelcomePage4.xaml.cs (1)
Flow.Launcher/ViewModel/WelcomeViewModel.cs (1)
  • WelcomeViewModel (16-99)
Flow.Launcher/Resources/Pages/WelcomePage3.xaml.cs (1)
Flow.Launcher/ViewModel/WelcomeViewModel.cs (1)
  • WelcomeViewModel (16-99)
Flow.Launcher/Resources/Pages/WelcomePage5.xaml.cs (1)
Flow.Launcher/ViewModel/WelcomeViewModel.cs (1)
  • WelcomeViewModel (16-99)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: gitStream.cm
🔇 Additional comments (13)
Flow.Launcher/Resources/Pages/WelcomePage4.xaml.cs (1)

15-15: Correctly updated page numbering for welcome page navigation.

The page number has been updated from 4 to 5 to accommodate the new WelcomePageUserType in the welcome page sequence. This change aligns with the refactored WelcomeViewModel that now uses a strongly typed WelcomePage enum with a sequence of 6 pages.

Flow.Launcher/Resources/Pages/WelcomePageUserType.xaml (1)

1-199: Well-structured new welcome page for user style selection.

This new page provides an intuitive UI for users to choose between CLI-friendly and Windows-friendly interaction styles, which directly relates to the PR objectives of changing default shortcuts and behaviors.

Flow.Launcher/Resources/Pages/WelcomePage5.xaml.cs (1)

22-22: Correctly updated page numbering for welcome page navigation.

The page number has been updated from 5 to 6 to accommodate the new WelcomePageUserType in the welcome page sequence. This change aligns with the refactored WelcomeViewModel that now uses a strongly typed WelcomePage enum with a sequence of 6 pages.

Flow.Launcher/Resources/Pages/WelcomePage3.xaml.cs (1)

15-15: Correctly updated page numbering for welcome page navigation.

The page number has been updated from 3 to 4 to accommodate the new WelcomePageUserType in the welcome page sequence. This change aligns with the refactored WelcomeViewModel that now uses a strongly typed WelcomePage enum with a sequence of 6 pages.

Flow.Launcher/WelcomeWindow.xaml.cs (4)

35-44: Well-implemented navigation refactoring!

The refactoring from numeric indices to a strongly typed enum approach makes the navigation logic more maintainable and robust. Using Array.IndexOf to find the current position in the sequence is a good practice.


63-76: Good use of switch expression with comprehensive case handling

The refactored PageTypeSelector method using a switch expression with the WelcomePage enum improves type safety and maintainability. The explicit handling of all enum cases with a default case for unexpected values follows best practices.


78-82: Well-designed adapter method for backward compatibility

This overload provides a clean bridge between the old integer-based page navigation and the new enum-based approach, facilitating a smooth transition while maintaining compatibility with any existing code.


101-101: Improved initialization logic

Using the view model's current page rather than a hardcoded page number improves consistency and makes the code more maintainable. This change aligns with the overall refactoring approach.

Flow.Launcher/Resources/Pages/WelcomePageUserType.xaml.cs (1)

12-19: Clean data model implementation

The RadioCardData class provides a clear and concise data structure for the radio card UI elements with appropriate properties for all the visual elements.

Flow.Launcher/ViewModel/WelcomeViewModel.cs (4)

6-14: Well-structured enum with clear documentation

The WelcomePage enum is well-defined with intuitive names and helpful comments indicating the corresponding page classes. This improves code readability and maintainability.


20-28: Logical page sequence with good encapsulation

The static PageSequence array encapsulates the welcome flow order, making it easy to modify the sequence in the future without changing navigation logic. The inclusion of the new UserType page in the appropriate position is well thought out.


32-46: Well-implemented bidirectional property synchronization

The CurrentPage property implementation ensures bidirectional synchronization with the PageNum property, maintaining backward compatibility while enabling the transition to the enum-based approach. The property change notifications are handled correctly.


91-98: Simplified and more maintainable view update logic

The refactored UpdateView method uses the page sequence index to determine button states, making it more maintainable than explicit numeric checks. This approach automatically adapts to any changes in the page sequence.

This comment has been minimized.

Copy link

gitstream-cm bot commented Apr 18, 2025

🥷 Code experts: Jack251970

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

See details

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Activity based on git-commit:

Jack251970 onesounds
APR 16 additions & 79 deletions 90 additions & 29 deletions
MAR 142 additions & 94 deletions 10 additions & 0 deletions
FEB 10 additions & 4 deletions
JAN 17 additions & 4 deletions
DEC 1 additions & 1 deletions
NOV

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

Flow.Launcher/HotkeyControl.xaml.cs

Activity based on git-commit:

Jack251970 onesounds
APR 11 additions & 15 deletions 3 additions & 0 deletions
MAR 150 additions & 37 deletions
FEB
JAN
DEC
NOV

Knowledge based on git-blame:
Jack251970: 45%

Flow.Launcher/Languages/en.xaml

Activity based on git-commit:

Jack251970 onesounds
APR 21 additions & 21 deletions 38 additions & 16 deletions
MAR 67 additions & 42 deletions 8 additions & 3 deletions
FEB 15 additions & 9 deletions
JAN 1 additions & 0 deletions
DEC
NOV

Knowledge based on git-blame:
onesounds: 42%
Jack251970: 10%

Flow.Launcher/MainWindow.xaml

Activity based on git-commit:

Jack251970 onesounds
APR
MAR 42 additions & 26 deletions
FEB 1 additions & 1 deletions
JAN
DEC
NOV 1 additions & 1 deletions

Knowledge based on git-blame:
onesounds: 85%
Jack251970: 6%

Flow.Launcher/Resources/Controls/HotkeyDisplay.xaml

Activity based on git-commit:

Jack251970 onesounds
APR
MAR
FEB
JAN
DEC
NOV

Knowledge based on git-blame:
onesounds: 100%

Flow.Launcher/Resources/Dark.xaml

Activity based on git-commit:

Jack251970 onesounds
APR 25 additions & 7 deletions
MAR 14 additions & 9 deletions
FEB
JAN
DEC
NOV

Knowledge based on git-blame:
onesounds: 100%

Flow.Launcher/Resources/Light.xaml

Activity based on git-commit:

Jack251970 onesounds
APR 30 additions & 6 deletions
MAR 11 additions & 7 deletions
FEB
JAN
DEC
NOV

Knowledge based on git-blame:
onesounds: 100%

Flow.Launcher/Resources/Pages/WelcomePage3.xaml.cs

Activity based on git-commit:

Jack251970 onesounds
APR
MAR 7 additions & 6 deletions
FEB
JAN
DEC
NOV

Knowledge based on git-blame:
onesounds: 48%
Jack251970: 33%

Flow.Launcher/Resources/Pages/WelcomePage4.xaml.cs

Activity based on git-commit:

Jack251970 onesounds
APR
MAR 7 additions & 6 deletions
FEB
JAN
DEC
NOV

Knowledge based on git-blame:
onesounds: 48%
Jack251970: 33%

Flow.Launcher/Resources/Pages/WelcomePage5.xaml.cs

Activity based on git-commit:

Jack251970 onesounds
APR
MAR 7 additions & 6 deletions
FEB
JAN
DEC
NOV

Knowledge based on git-blame:
onesounds: 75%
Jack251970: 11%

Flow.Launcher/SettingPages/Views/SettingsPaneHotkey.xaml

Activity based on git-commit:

Jack251970 onesounds
APR
MAR 14 additions & 28 deletions
FEB
JAN
DEC
NOV

Knowledge based on git-blame:
onesounds: 10%
Jack251970: 3%

Flow.Launcher/ViewModel/MainViewModel.cs

Activity based on git-commit:

Jack251970 onesounds
APR 35 additions & 28 deletions
MAR 695 additions & 628 deletions 293 additions & 201 deletions
FEB 63 additions & 21 deletions 23 additions & 25 deletions
JAN 17 additions & 21 deletions
DEC 59 additions & 63 deletions
NOV 39 additions & 15 deletions

Knowledge based on git-blame:
Jack251970: 30%
onesounds: 10%

Flow.Launcher/ViewModel/WelcomeViewModel.cs

Activity based on git-commit:

Jack251970 onesounds
APR
MAR 68 additions & 0 deletions
FEB
JAN
DEC
NOV

Knowledge based on git-blame:
Jack251970: 100%

Flow.Launcher/WelcomeWindow.xaml.cs

Activity based on git-commit:

Jack251970 onesounds
APR
MAR 31 additions & 43 deletions
FEB
JAN
DEC
NOV 7 additions & 2 deletions

Knowledge based on git-blame:
onesounds: 45%
Jack251970: 33%

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

This comment has been minimized.

@onesounds onesounds changed the title Default Settings and Shortcut Changes Add user style selection page with CLI/GUI modes and Delete Word Backwards Apr 19, 2025
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
⚠️ 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 Author

Choose a reason for hiding this comment

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

For bullet hiding.

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: 3

🧹 Nitpick comments (6)
Flow.Launcher/Resources/Pages/WelcomePageUserType.xaml.cs (6)

54-56: Extract file path logic to a helper method or consider using a settings manager.

Directly constructing file paths in the event handler makes the code less maintainable. Consider extracting this logic to a helper method or using a dedicated settings manager if one exists.

- var pluginDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins", "Flow.Launcher.Plugin.Explorer");
- var explorerSettingsPath = Path.Combine(pluginDirectory, "Settings.json");
+ var explorerSettingsPath = GetExplorerSettingsPath();

// Add this method to the class:
+ private string GetExplorerSettingsPath()
+ {
+     var pluginDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins", "Flow.Launcher.Plugin.Explorer");
+     return Path.Combine(pluginDirectory, "Settings.json");
+ }

60-60: Consider using a strongly-typed settings model instead of Dictionary.

Using Dictionary<string, object> for settings deserialization is not type-safe and could lead to runtime errors if the settings format changes. Consider creating a strongly-typed model for Explorer plugin settings.

- var explorerSettings = JsonSerializer.Deserialize<Dictionary<string, object>>(explorerSettingsJson);
+ var explorerSettings = JsonSerializer.Deserialize<ExplorerPluginSettings>(explorerSettingsJson);

// Add this class:
+ private class ExplorerPluginSettings
+ {
+     public bool UseLocationAsWorkingDir { get; set; }
+     // Add other properties as needed
+ }

Then update the usage:

- if (explorerSettings != null)
-     explorerSettings["UseLocationAsWorkingDir"] = false;
+ if (explorerSettings != null)
+     explorerSettings.UseLocationAsWorkingDir = false;

62-75: Isolate settings logic to separate methods for better readability.

The switch statement handling different user types would be more maintainable if the settings logic for each type was isolated in separate methods.

- switch (data.Key)
- {
-     case "CLI":
-         if (explorerSettings != null)
-             explorerSettings["UseLocationAsWorkingDir"] = false;
-         settings.AutoCompleteHotkey = "Tab";
-         break;
- 
-     case "GUI":
-         if (explorerSettings != null)
-             explorerSettings["UseLocationAsWorkingDir"] = true;
-         settings.AutoCompleteHotkey = $"{KeyConstant.Alt} + Right";
-         break;
- }
+ switch (data.Key)
+ {
+     case "CLI":
+         ApplyCliSettings(explorerSettings, settings);
+         break;
+ 
+     case "GUI":
+         ApplyGuiSettings(explorerSettings, settings);
+         break;
+ }

// Add these methods:
+ private void ApplyCliSettings(Dictionary<string, object> explorerSettings, Settings settings)
+ {
+     if (explorerSettings != null)
+         explorerSettings["UseLocationAsWorkingDir"] = false;
+     settings.AutoCompleteHotkey = "Tab";
+ }
+ 
+ private void ApplyGuiSettings(Dictionary<string, object> explorerSettings, Settings settings)
+ {
+     if (explorerSettings != null)
+         explorerSettings["UseLocationAsWorkingDir"] = true;
+     settings.AutoCompleteHotkey = $"{KeyConstant.Alt} + Right";
+ }

73-73: Use a constant for the AutoCompleteHotkey value to ensure consistency.

The string "{KeyConstant.Alt} + Right" could potentially be inconsistent with other hotkey string representations in the application. Consider using a constant or helper method to ensure consistent hotkey formatting.

- settings.AutoCompleteHotkey = $"{KeyConstant.Alt} + Right";
+ settings.AutoCompleteHotkey = HotkeyFormattingHelper.FormatHotkey(KeyConstant.Alt, "Right");

Where HotkeyFormattingHelper would be a utility class ensuring consistent hotkey string formatting across the application.


77-77: Consider adding a backup mechanism when writing settings.

When overwriting settings files, it's a good practice to create a backup first in case the write operation fails.

+ // Create a backup of the original settings file
+ if (File.Exists(explorerSettingsPath))
+ {
+     File.Copy(explorerSettingsPath, $"{explorerSettingsPath}.bak", true);
+ }
File.WriteAllText(explorerSettingsPath, JsonSerializer.Serialize(explorerSettings, new JsonSerializerOptions { WriteIndented = true }));

20-28: Consider adding XML documentation to the RadioCardData class.

Adding XML documentation comments to the class and its properties would improve code maintainability and help other developers understand its purpose and usage.

+ /// <summary>
+ /// Data class for radio button cards in the user type selection UI
+ /// </summary>
public class RadioCardData
{
+   /// <summary>
+   /// Unique identifier for the radio card option (e.g., "CLI" or "GUI")
+   /// </summary>
    public string Key { get; set; }
+   /// <summary>
+   /// Icon to display for this option
+   /// </summary>
    public string Icon { get; set; }
+   /// <summary>
+   /// Primary description text
+   /// </summary>
    public string Description1 { get; set; }
+   /// <summary>
+   /// First bullet point text
+   /// </summary>
    public string Bullet1 { get; set; }
+   /// <summary>
+   /// Second bullet point text
+   /// </summary>
    public string Bullet2 { get; set; }
+   /// <summary>
+   /// Third bullet point text
+   /// </summary>
    public string Bullet3 { get; set; }
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a6ef43f and a67c919.

📒 Files selected for processing (2)
  • Flow.Launcher/Resources/Pages/WelcomePageUserType.xaml (1 hunks)
  • Flow.Launcher/Resources/Pages/WelcomePageUserType.xaml.cs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Flow.Launcher/Resources/Pages/WelcomePageUserType.xaml
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: build

Comment on lines +38 to +45
protected override void OnNavigatedTo(NavigationEventArgs e)
{
Settings = Ioc.Default.GetRequiredService<Settings>();
// Sometimes the navigation is not triggered by button click,
// so we need to reset the page number
Ioc.Default.GetRequiredService<WelcomeViewModel>().PageNum = 3;
InitializeComponent();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Redundant InitializeComponent call may cause UI issues.

There's a second call to InitializeComponent() in the OnNavigatedTo method, but this has already been called in the constructor. This redundant initialization could potentially cause UI elements to be recreated unexpectedly.

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    Settings = Ioc.Default.GetRequiredService<Settings>();
    // Sometimes the navigation is not triggered by button click,
    // so we need to reset the page number
    Ioc.Default.GetRequiredService<WelcomeViewModel>().PageNum = 3;
-   InitializeComponent();
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
protected override void OnNavigatedTo(NavigationEventArgs e)
{
Settings = Ioc.Default.GetRequiredService<Settings>();
// Sometimes the navigation is not triggered by button click,
// so we need to reset the page number
Ioc.Default.GetRequiredService<WelcomeViewModel>().PageNum = 3;
InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
Settings = Ioc.Default.GetRequiredService<Settings>();
// Sometimes the navigation is not triggered by button click,
// so we need to reset the page number
Ioc.Default.GetRequiredService<WelcomeViewModel>().PageNum = 3;
}

Settings = Ioc.Default.GetRequiredService<Settings>();
// Sometimes the navigation is not triggered by button click,
// so we need to reset the page number
Ioc.Default.GetRequiredService<WelcomeViewModel>().PageNum = 3;
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use enum instead of magic number for page navigation.

The hardcoded value 3 for PageNum is a magic number that makes the code less maintainable. Since the PR mentions a strongly typed enum for page navigation, you should use the enum value instead.

- Ioc.Default.GetRequiredService<WelcomeViewModel>().PageNum = 3;
+ Ioc.Default.GetRequiredService<WelcomeViewModel>().PageNum = (int)WelcomePage.UserType;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Ioc.Default.GetRequiredService<WelcomeViewModel>().PageNum = 3;
Ioc.Default.GetRequiredService<WelcomeViewModel>().PageNum = (int)WelcomePage.UserType;

Comment on lines +57 to +78
if (File.Exists(explorerSettingsPath))
{
var explorerSettingsJson = File.ReadAllText(explorerSettingsPath);
var explorerSettings = JsonSerializer.Deserialize<Dictionary<string, object>>(explorerSettingsJson);

switch (data.Key)
{
case "CLI":
if (explorerSettings != null)
explorerSettings["UseLocationAsWorkingDir"] = false;
settings.AutoCompleteHotkey = "Tab";
break;

case "GUI":
if (explorerSettings != null)
explorerSettings["UseLocationAsWorkingDir"] = true;
settings.AutoCompleteHotkey = $"{KeyConstant.Alt} + Right";
break;
}

File.WriteAllText(explorerSettingsPath, JsonSerializer.Serialize(explorerSettings, new JsonSerializerOptions { WriteIndented = true }));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add error handling for file operations and JSON deserialization.

The current implementation lacks proper error handling for file operations and JSON deserialization. If any of these operations fail, the application might crash or behave unexpectedly.

- if (File.Exists(explorerSettingsPath))
- {
-     var explorerSettingsJson = File.ReadAllText(explorerSettingsPath);
-     var explorerSettings = JsonSerializer.Deserialize<Dictionary<string, object>>(explorerSettingsJson);
+try
+{
+    if (File.Exists(explorerSettingsPath))
+    {
+        var explorerSettingsJson = File.ReadAllText(explorerSettingsPath);
+        var explorerSettings = JsonSerializer.Deserialize<Dictionary<string, object>>(explorerSettingsJson);

      // ... existing switch and settings update code ...

-     File.WriteAllText(explorerSettingsPath, JsonSerializer.Serialize(explorerSettings, new JsonSerializerOptions { WriteIndented = true }));
-}
+        File.WriteAllText(explorerSettingsPath, JsonSerializer.Serialize(explorerSettings, new JsonSerializerOptions { WriteIndented = true }));
+    }
+}
+catch (Exception ex)
+{
+    // Log the error and possibly show a user-friendly message
+    Log.Exception($"Failed to update Explorer plugin settings: {ex.Message}", ex);
+    // Consider notifying the user that settings might not be fully applied
+}

@@ -44,7 +44,7 @@
<system:String x:Key="GameMode">Game Mode</system:String>
<system:String x:Key="GameModeToolTip">Suspend the use of Hotkeys.</system:String>
<system:String x:Key="PositionReset">Position Reset</system:String>
<system:String x:Key="PositionResetToolTip">Reset search window position</system:String>
<system:String x:Key="PositionResetToolTip">Reset search window location</system:String>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Small Fix. requested by CitizenDee

@@ -51,14 +51,14 @@
<Border.Style>
<Style TargetType="{x:Type Border}">
<Setter Property="Background" Value="{DynamicResource SystemControlBackgroundBaseLowBrush}" />
<Setter Property="Padding" Value="10,5,10,5" />
<Setter Property="Margin" Value="2,5,2,5" />
<Setter Property="Padding" Value="10 5 10 5" />
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Minor fix: Corrected vertical alignment

@onesounds onesounds closed this Apr 19, 2025
@jjw24 jjw24 removed this from the Future milestone Apr 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
30 min review enhancement New feature or request kind/ui related to UI, icons, themes, etc kind/ux related to user experience
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants