Skip to content

Conversation

onesounds
Copy link
Contributor

What's the PR

  • Related Improve File Manager Configuration Error Handling #3561
  • Fixes an issue in the Explorer plugin where using "Open Containing Folder" on a file (instead of a folder path) with the default file explorer setting would launch the file's associated program instead of opening its containing folder.

Cause

  • When using the default explorer setting, the plugin attempted to open the full path directly—even when the path pointed to a file (including the filename itself).

  • This has been fixed to work correctly. The -select option now functions as expected.

@prlabeler prlabeler bot added the bug Something isn't working label May 27, 2025
@onesounds onesounds self-assigned this May 27, 2025

This comment has been minimized.

Copy link

gitstream-cm bot commented May 27, 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 May 27, 2025

📝 Walkthrough

Walkthrough

The OpenDirectory method was refactored to improve process handling and file selection behavior when opening directories or files in Windows Explorer or a custom file manager. It now uses native Windows Shell API calls (SHParseDisplayName, SHOpenFolderAndSelectItems) to open folders and select files, with enhanced error handling and removal of redundant process starts.

Changes

File(s) Change Summary
Flow.Launcher/PublicAPIInstance.cs Refactored OpenDirectory to use native shell API calls for opening folders and selecting files; improved process handling and error reporting; removed unused using.
Flow.Launcher.Infrastructure/NativeMethods.txt Added native method declarations: SHParseDisplayName, SHOpenFolderAndSelectItems, and CoTaskMemFree.
Flow.Launcher.Infrastructure/Win32Helper.cs Added OpenFolderAndSelectFile method using Windows Shell API to open folder and select a file, with COM error handling and memory cleanup.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant PublicAPIInstance
    participant WindowsShell
    participant CustomFileManager

    Caller->>PublicAPIInstance: OpenDirectory(directoryPath, fileNameOrFilePath)
    alt Using default Windows Explorer and file specified
        PublicAPIInstance->>WindowsShell: SHParseDisplayName(folderPath)
        WindowsShell-->>PublicAPIInstance: folderPIDL
        PublicAPIInstance->>WindowsShell: SHParseDisplayName(filePath)
        WindowsShell-->>PublicAPIInstance: filePIDL
        PublicAPIInstance->>WindowsShell: SHOpenFolderAndSelectItems(folderPIDL, filePIDL)
    else Using default Windows Explorer and no file specified
        PublicAPIInstance->>WindowsShell: Start explorer.exe with folderPath
    else Using custom file manager
        PublicAPIInstance->>CustomFileManager: Start process with replaced arguments
    end
    PublicAPIInstance-->>Caller: Completion or error handling
Loading

Possibly related PRs

Suggested labels

bug

Suggested reviewers

  • taooceros

Poem

🐇 In folders deep, I softly tread,
Selecting files where paths are led.
No more stray processes to chase,
Explorer’s dance now finds its place.
A rabbit’s hop, a code refined,
With native calls, the way aligned! 🌿✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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 Dev branch only An issue or fix for the Dev branch build and removed bug Something isn't working labels May 27, 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: 2

🔭 Outside diff range comments (1)
Flow.Launcher/PublicAPIInstance.cs (1)

371-437: 💡 Verification agent

🧩 Analysis chain

Replace Korean comments with English and improve code organization.

The method logic is correct and handles both default and custom explorers appropriately. However, there are Korean comments that should be replaced with English for better maintainability.

Apply this diff to replace Korean comments with English:

                 if (fileNameOrFilePath is null)
                 {
-                    // 폴더만 열기
+                    // Open folder only
                     Process.Start(new ProcessStartInfo
                     {
                         FileName = directoryPath,
                         UseShellExecute = true
                     })?.Dispose();
                 }
                 else
                 {
-                    // SHOpenFolderAndSelectItems 방식
+                    // Use SHOpenFolderAndSelectItems approach
                     OpenFolderAndSelectItem(targetPath);
                 }
             }
             else
             {
-                // 커스텀 파일 관리자
+                // Custom file manager
                 var shellProcess = new ProcessStartInfo

Verify the fix resolves the original issue.

The implementation correctly addresses the original problem by using Shell APIs when the default explorer is used with a file path, which should open the containing folder and select the file instead of launching the file directly.

Let me verify the fix works as intended:


🏁 Script executed:

#!/bin/bash
# Description: Verify the fix addresses the original issue by checking the logic flow

# Check if the method correctly handles the file vs folder logic
ast-grep --pattern $'if (fileNameOrFilePath is null) {
  $$$
} else {
  OpenFolderAndSelectItem($$$);
}'

# Verify the custom explorer handling remains intact
ast-grep --pattern $'var shellProcess = new ProcessStartInfo
{
  FileName = $$$,
  UseShellExecute = true,
  Arguments = $$$
};'

Length of output: 1191


I’d like to confirm that all Korean comments have been removed. Running a quick check on the current snippet:


🏁 Script executed:

#!/bin/bash
# Show lines 350–440 to inspect comments
sed -n '350,440p' Flow.Launcher/PublicAPIInstance.cs

# Search for any remaining Korean (Hangul) in comments
grep -nP '//.*[\x{AC00}-\x{D7A3}]' Flow.Launcher/PublicAPIInstance.cs || echo 'No Korean comments found'

Length of output: 3833


Replace remaining Korean comments with English

The OpenDirectory method in Flow.Launcher/PublicAPIInstance.cs still contains Korean comments that need replacing. Please apply the following changes:

--- a/Flow.Launcher/PublicAPIInstance.cs
+++ b/Flow.Launcher/PublicAPIInstance.cs
@@ -378,9 +378,9 @@ public void OpenDirectory(string directoryPath, string fileNameOrFilePath = nul
                 if (fileNameOrFilePath is null)
                 {
-                    // 폴더만 열기
+                    // Open folder only
                     Process.Start(new ProcessStartInfo
                     {
                         FileName = directoryPath,
                         UseShellExecute = true
                     })?.Dispose();
                 }
                 else
                 {
-                    // SHOpenFolderAndSelectItems 방식
+                    // Use SHOpenFolderAndSelectItems approach
                     OpenFolderAndSelectItem(targetPath);
                 }
@@ -386,7 +386,7 @@ public void OpenDirectory(string directoryPath, string fileNameOrFilePath = nul
             }
             else
             {
-                // 커스텀 파일 관리자
+                // Custom file manager
                 var shellProcess = new ProcessStartInfo
                 {
                     FileName = explorerInfo.Path.Replace("%d", directoryPath),

These updates ensure all inline comments are in English for maintainability.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 47878f3 and 41c5b36.

📒 Files selected for processing (1)
  • Flow.Launcher/PublicAPIInstance.cs (3 hunks)
🧰 Additional context used
🪛 GitHub Actions: Check Spelling
Flow.Launcher/PublicAPIInstance.cs

[warning] 54-54: Spell check warning: Ioc is not a recognized word. (unrecognized-spelling)


[warning] 152-152: Spell check warning: VSTHRD is not a recognized word. (unrecognized-spelling)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: gitStream.cm
  • GitHub Check: build
🔇 Additional comments (1)
Flow.Launcher/PublicAPIInstance.cs (1)

11-11: LGTM: Required using statement for P/Invoke declarations.

The addition of System.Runtime.InteropServices namespace is necessary for the P/Invoke declarations that follow.

Copy link
Member

@Jack251970 Jack251970 left a comment

Choose a reason for hiding this comment

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

Excellent fix!

This comment has been minimized.

@Jack251970 Jack251970 requested a review from Copilot May 27, 2025 06:37
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the file explorer behavior so that when “Open Containing Folder” is used on a file, the file’s containing directory is opened and the file gets selected (when supported). Key changes include renaming parameters for consistency, splitting the logic between Windows and custom file managers, and adding a native helper method for folder/file selection.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
Flow.Launcher/PublicAPIInstance.cs Updated OpenDirectory to correctly handle file vs folder paths and improved parameter naming conventions.
Flow.Launcher.Infrastructure/Win32Helper.cs Introduced OpenFolderAndSelectFile with appropriate COM invocations and added required using directives.
Flow.Launcher.Infrastructure/NativeMethods.txt Registered new native method entries required for file selection in the Windows File Manager.

Copy link

@check-spelling-bot Report

🔴 Please review

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

❌ Errors and Warnings Count
❌ forbidden-pattern 22
⚠️ non-alpha-in-dictionary 13

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

gitstream-cm bot commented May 27, 2025

🥷 Code experts: Jack251970

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

See details

Flow.Launcher.Infrastructure/NativeMethods.txt

Activity based on git-commit:

Jack251970 onesounds
MAY 4 additions & 1 deletions
APR 0 additions & 5 deletions
MAR 40 additions & 5 deletions
FEB 4 additions & 1 deletions
JAN 1 additions & 4 deletions
DEC 24 additions & 2 deletions

Knowledge based on git-blame:
Jack251970: 93%

Flow.Launcher.Infrastructure/Win32Helper.cs

Activity based on git-commit:

Jack251970 onesounds
MAY 74 additions & 0 deletions
APR 202 additions & 33 deletions 4 additions & 0 deletions
MAR 581 additions & 226 deletions
FEB 13 additions & 16 deletions 22 additions & 0 deletions
JAN 0 additions & 138 deletions
DEC 243 additions & 4 deletions

Knowledge based on git-blame:
Jack251970: 95%

Flow.Launcher/PublicAPIInstance.cs

Activity based on git-commit:

Jack251970 onesounds
MAY 109 additions & 70 deletions 110 additions & 50 deletions
APR 165 additions & 61 deletions
MAR 21 additions & 19 deletions
FEB 28 additions & 11 deletions
JAN 45 additions & 47 deletions
DEC 25 additions & 32 deletions

Knowledge based on git-blame:
Jack251970: 47%

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

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

♻️ Duplicate comments (1)
Flow.Launcher.Infrastructure/Win32Helper.cs (1)

768-768: ⚠️ Potential issue

Address the validation concern from previous review.

As noted in the previous review, Path.GetDirectoryName(filePath) can return null if the file path doesn't include a directory component, which would cause issues when passed to SHParseDisplayName.

 var folderPath = Path.GetDirectoryName(filePath);
+if (string.IsNullOrEmpty(folderPath))
+    throw new ArgumentException("Unable to determine directory from file path.", nameof(filePath));
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 41c5b36 and eb69ce9.

📒 Files selected for processing (3)
  • Flow.Launcher.Infrastructure/NativeMethods.txt (1 hunks)
  • Flow.Launcher.Infrastructure/Win32Helper.cs (3 hunks)
  • Flow.Launcher/PublicAPIInstance.cs (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • Flow.Launcher.Infrastructure/NativeMethods.txt
🚧 Files skipped from review as they are similar to previous changes (1)
  • Flow.Launcher/PublicAPIInstance.cs
🧰 Additional context used
🪛 GitHub Actions: Check Spelling
Flow.Launcher.Infrastructure/Win32Helper.cs

[warning] 19-33: Dwm is not a recognized word. (unrecognized-spelling)


[warning] 43-31: Dwm is not a recognized word. (unrecognized-spelling)


[warning] 43-27: PInvoke is not a recognized word. (unrecognized-spelling)


[warning] 54-60: SYSTEMBACKDROP is not a recognized word. (unrecognized-spelling)


[warning] 55-69: DWMSBT is not a recognized word. (unrecognized-spelling)


[warning] 55-57: SYSTEMBACKDROP is not a recognized word. (unrecognized-spelling)


[warning] 56-72: DWMSBT is not a recognized word. (unrecognized-spelling)


[warning] 56-60: SYSTEMBACKDROP is not a recognized word. (unrecognized-spelling)


[warning] 57-52: DWMSBT is not a recognized word. (unrecognized-spelling)


[warning] 57-40: SYSTEMBACKDROP is not a recognized word. (unrecognized-spelling)


[warning] 60-31: Dwm is not a recognized word. (unrecognized-spelling)


[warning] 60-27: PInvoke is not a recognized word. (unrecognized-spelling)


[warning] 62-41: DWMWA is not a recognized word. (unrecognized-spelling)


[warning] 62-35: DWMWINDOWATTRIBUTE is not a recognized word. (unrecognized-spelling)


[warning] 71-31: Dwm is not a recognized word. (unrecognized-spelling)


[warning] 71-27: PInvoke is not a recognized word. (unrecognized-spelling)


[warning] 73-41: DWMWA is not a recognized word. (unrecognized-spelling)


[warning] 73-35: DWMWINDOWATTRIBUTE is not a recognized word. (unrecognized-spelling)


[warning] 89-63: DWMWCP is not a recognized word. (unrecognized-spelling)


[warning] 90-68: DWMWCP is not a recognized word. (unrecognized-spelling)


[warning] 91-65: DWMWCP is not a recognized word. (unrecognized-spelling)


[warning] 95-27: PInvoke is not a recognized word. (unrecognized-spelling)


[warning] 97-41: DWMWA is not a recognized word. (unrecognized-spelling)


[warning] 97-35: DWMWINDOWATTRIBUTE is not a recognized word. (unrecognized-spelling)


[warning] 163-59: GWL is not a recognized word. (unrecognized-spelling)


[warning] 174-73: GWL is not a recognized word. (unrecognized-spelling)


[warning] 179-78: GWL is not a recognized word. (unrecognized-spelling)


[warning] 190-71: GWL is not a recognized word. (unrecognized-spelling)


[warning] 199-51: Wnd is not a recognized word. (unrecognized-spelling)


[warning] 207-53: Wnd is not a recognized word. (unrecognized-spelling)


[warning] 211-55: Wnd is not a recognized word. (unrecognized-spelling)


[warning] 240-21: Wnd is not a recognized word. (unrecognized-spelling)


[warning] 264-51: WINTAB is not a recognized word. (unrecognized-spelling)


[warning] 277-36: Progman is not a recognized word. (unrecognized-spelling)


[warning] 278-76: WORKERW is not a recognized word. (unrecognized-spelling)


[warning] 518-39: hkl is not a recognized word. (unrecognized-spelling)


[warning] 524-31: hkl is not a recognized word. (unrecognized-spelling)


[warning] 550-35: nqo is not a recognized word. (unrecognized-spelling)


[warning] 623-73: tsf is not a recognized word. (unrecognized-spelling)


[warning] 646-69: tsf is not a recognized word. (unrecognized-spelling)


[warning] 646-73: tsf is not a recognized word. (unrecognized-spelling)


[warning] 647-44: Tsf is not a recognized word. (unrecognized-spelling)


[warning] 683-26: Noto is not a recognized word. (unrecognized-spelling)


[warning] 684-26: Noto is not a recognized word. (unrecognized-spelling)


[warning] 685-29: Noto is not a recognized word. (unrecognized-spelling)


[warning] 686-29: Noto is not a recognized word. (unrecognized-spelling)


[warning] 727-106: noto is not a recognized word. (unrecognized-spelling)


[warning] 730-83: noto is not a recognized word. (unrecognized-spelling)


[warning] 732-40: noto is not a recognized word. (unrecognized-spelling)


[warning] 752-75: noto is not a recognized word. (unrecognized-spelling)

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: build
🔇 Additional comments (2)
Flow.Launcher.Infrastructure/Win32Helper.cs (2)

6-6: LGTM: Required using statements added correctly.

The new using statements are appropriately added to support the new Explorer functionality.

Also applies to: 21-21


770-786: LGTM: Excellent implementation with proper error handling and resource management.

The implementation correctly:

  • Uses appropriate Windows Shell APIs (SHParseDisplayName, SHOpenFolderAndSelectItems)
  • Provides proper error handling with meaningful COM exceptions
  • Ensures memory cleanup with CoTaskMemFree in the finally block
  • Uses unsafe code appropriately for native pointer operations

This addresses the core issue described in the PR objectives by properly opening the containing folder and selecting the file.

@onesounds onesounds merged commit 6144d4a into Flow-Launcher:dev May 27, 2025
8 checks passed
@Jack251970 Jack251970 added this to the 1.20.0 milestone May 27, 2025
@jjw24 jjw24 added bug Something isn't working and removed Dev branch only An issue or fix for the Dev branch build labels Jun 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: "Open containing folder" fails to open long paths but open This PC page - File Name Too Long

3 participants