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

[v2/Windows]Set default extension for save file dialog #3205

Merged
merged 3 commits into from Jan 17, 2024

Conversation

almas1992
Copy link
Contributor

@almas1992 almas1992 commented Jan 16, 2024

Description

According to the comment, the default extension should be set when filters are set, so that the filename is automatically appended with the extension.

Fixes #3202

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration using wails doctor.

  • Windows
  • macOS
  • Linux

Test Configuration

Please paste the output of wails doctor. If you are unable to run this command, please describe your environment in as much detail as possible.

Checklist:

  • I have updated website/src/pages/changelog.mdx with details of this PR
  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Summary by CodeRabbit

  • Bug Fixes
    • Resolved issue with save file dialog not automatically appending file extensions on Windows.

Copy link
Contributor

coderabbitai bot commented Jan 16, 2024

Walkthrough

The update addresses a functional issue related to file handling in a desktop application framework on Windows. Specifically, it introduces a fix for the SaveFileDialog not automatically appending file extensions, improving the usability of file-saving operations.

Changes

File Path Change Summary
v2/internal/frontend/desktop/windows/dialog.go Introduced a fix for the SaveFileDialog not automatically appending file extensions on Windows.

Assessment against linked issues

Objective Addressed Explanation
runtime.SaveFileDialog should automatically add the suffix of the filter (#3202) The change explicitly addresses the issue by introducing the fix for automatically appending file extensions in the SaveFileDialog on Windows.

Poem

In code's embrace, a rabbit's dance, 🐇💻
Fixing dialogs with a joyful prance.
"Save with flair," the code now sings,
Windows rejoice, as the fix brings! 🎉

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 12d6336 and fa982a6.
Files selected for processing (1)
  • v2/internal/frontend/desktop/windows/dialog.go (1 hunks)

Comment on lines +124 to +126
if len(options.Filters) > 0 {
config.DefaultExtension = strings.TrimPrefix(strings.Split(options.Filters[0].Pattern, ";")[0], "*")
}
Copy link
Contributor

@coderabbitai coderabbitai bot Jan 16, 2024

Choose a reason for hiding this comment

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

The logic to set the default file extension assumes that the first filter's pattern contains the desired default extension and that it is separated by a semicolon. This may not always be the case, and the code does not handle potential edge cases where the pattern might not include a semicolon or might include multiple extensions. Consider adding more robust parsing to handle different filter formats.

- config.DefaultExtension = strings.TrimPrefix(strings.Split(options.Filters[0].Pattern, ";")[0], "*")
+ // Proposed change: Add a function to parse and return the default extension
+ config.DefaultExtension = parseDefaultExtension(options.Filters)

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.

Suggested change
if len(options.Filters) > 0 {
config.DefaultExtension = strings.TrimPrefix(strings.Split(options.Filters[0].Pattern, ";")[0], "*")
}
if len(options.Filters) > 0 {
// Proposed change: Add a function to parse and return the default extension
config.DefaultExtension = parseDefaultExtension(options.Filters)
}

Copy link
Member

Choose a reason for hiding this comment

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

Splitting on a non existent separator is fine if you're only interested in the first element

Copy link
Contributor

Choose a reason for hiding this comment

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

@leaanthony Thank you for the clarification. Understood, if the current implementation meets the intended use case and handles the scenarios as expected, there's no need for additional changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Splitting on a non existent separator is fine if you're only interested in the first element

The reason I split by semicolon first is to handle patterns with multiple extensions, such as

{
    DisplayName: "Image Files (*.jpg, *.png)",
    Pattern:     "*.jpg;*.png",
}

Just take the first extension, i.e. .jpg

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between fa982a6 and faebab1.
Files selected for processing (1)
  • website/src/pages/changelog.mdx (1 hunks)
Additional comments: 1
website/src/pages/changelog.mdx (1)
  • 29-29: The changelog entry correctly reflects the fix for the save file dialog issue on Windows.

@snopywithchary
Copy link

if I change my filter,Will the default suffix change based on the filter I select?
eg: this is my filters Images (*.png *.xpm .jpg);;Text (.txt)

@almas1992
Copy link
Contributor Author

if I change my filter,Will the default suffix change based on the filter I select? eg: this is my filters Images (*.png *.xpm .jpg);;Text (.txt)

If the user selects a different file filter, the default extension will be automatically updated to match the new file filter.

@leaanthony leaanthony merged commit 3e5df3c into wailsapp:master Jan 17, 2024
8 checks passed
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between fa982a6 and f6b701a.
Files selected for processing (1)
  • website/src/pages/changelog.mdx (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • website/src/pages/changelog.mdx

@leaanthony
Copy link
Member

Thanks @almas1992 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

runtime.SaveFileDialog automatically add the suffix of the filter
3 participants