Skip to content

Fixed example for macOS menu#3847

Merged
leaanthony merged 3 commits into
wailsapp:masterfrom
takuyahara:patch-2
Nov 6, 2024
Merged

Fixed example for macOS menu#3847
leaanthony merged 3 commits into
wailsapp:masterfrom
takuyahara:patch-2

Conversation

@takuyahara

@takuyahara takuyahara commented Oct 22, 2024

Copy link
Copy Markdown
Contributor

Description

Example in menus is not correctly written. This PR corrects code for macOS to add menus properly.

    AppMenu := menu.NewMenu()
    if runtime.GOOS == "darwin" {
        AppMenu.Append(menu.AppMenu()) // On macOS platform, this must be done right after `NewMenu()`
    }
    FileMenu := AppMenu.AddSubmenu("File")
    FileMenu.AddText("&Open", keys.CmdOrCtrl("o"), func(_ *menu.CallbackData) {
        // do something
    })
    FileMenu.AddSeparator()
    FileMenu.AddText("Quit", keys.CmdOrCtrl("q"), func(_ *menu.CallbackData) {
        // `rt` is an alias of "github.com/wailsapp/wails/v2/pkg/runtime" to prevent collision with standard package
        rt.Quit(app.ctx)
    })

    if runtime.GOOS == "darwin" {
	AppMenu.Append(menu.EditMenu())  // On macOS platform, EditMenu should be appended to enable Cmd+C, Cmd+V, Cmd+Z... shortcuts
    }

Writing AppMenu.Append() twice and separately looks weird but this do matters to menus be added in File Edit order. For instance, the following code results menus to be added in Edit File order.

AppMenu := menu.NewMenu()
if runtime.GOOS == "darwin" {
	AppMenu.Append(menu.AppMenu()) // On macOS platform, this must be done right after `NewMenu()`
	AppMenu.Append(menu.EditMenu()) // On macOS platform, EditMenu should be appended to enable Cmd+C, Cmd+V, Cmd+Z... shortcutsCmd+Z... shortcuts
}

image

Summary by CodeRabbit

  • New Features

    • Enhanced macOS application menu configuration with conditional checks.
    • Updated menu actions for improved clarity and functionality.
  • Documentation

    • Improved comments for better understanding of menu setup and actions.

@coderabbitai

coderabbitai Bot commented Oct 22, 2024

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@takuyahara has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 26 minutes and 43 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 5352ce0 and 70698da.

Walkthrough

The changes in this pull request involve modifications to the example code for creating application menus in Wails projects. A conditional check for macOS is introduced to ensure the AppMenu is configured correctly. The FileMenu's AddText method is updated to use an inline function for the "Open" action, and the "Quit" menu item now uses an alias for the runtime package. Additionally, comments have been clarified without altering the functionality.

Changes

File Path Change Summary
website/docs/reference/menus.mdx - Added conditional check for macOS to configure AppMenu correctly.
- Updated FileMenu's AddText method to use an inline function for "Open".
- Changed "Quit" menu item to use alias rt for the runtime package.
- Clarified comments regarding EditMenu.

Possibly related PRs

Suggested reviewers

  • leaanthony

🐰 In the land of code where rabbits play,
Menus are crafted in a clearer way.
For macOS, a check is now in place,
With actions defined, we quicken the pace.
So hop along, let’s make it right,
With menus that shine, oh what a sight! 🌟


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

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

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

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

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
website/docs/reference/menus.mdx (3)

22-24: Good improvement to the "Open" menu item example.

The use of an inline function for the "Open" action is a good practice. It provides a clear structure for adding custom logic.

Consider enhancing the comment to be more specific:

- // do something
+ // Add your file opening logic here

This would provide clearer guidance for developers implementing this menu item.


27-28: Good clarification on the rt alias usage.

The added comment explains the purpose of the rt alias, which is helpful for code clarity. Using an alias is a good practice to avoid potential naming conflicts.

For consistency with the previous menu item:

- rt.Quit(app.ctx)
+ rt.Quit(app.ctx) // Quit the application

This would maintain a consistent style of adding brief comments for each action.


31-33: Crucial addition for macOS Edit menu functionality.

This change correctly implements the macOS-specific requirement of appending the EditMenu. The comment clearly explains the purpose, which is essential for enabling standard macOS shortcuts.

To further improve clarity:

- AppMenu.Append(menu.EditMenu())  // On macOS platform, EditMenu should be appended to enable Cmd+C, Cmd+V, Cmd+Z... shortcuts
+ AppMenu.Append(menu.EditMenu())  // On macOS, append EditMenu to enable standard shortcuts (Cmd+C, Cmd+V, Cmd+Z, etc.)

This slight rewording makes the comment more concise while maintaining its informative nature.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 5ebccf1 and 5352ce0.

📒 Files selected for processing (1)
  • website/docs/reference/menus.mdx (1 hunks)
🧰 Additional context used
🔇 Additional comments (2)
website/docs/reference/menus.mdx (2)

18-20: Excellent addition for macOS-specific menu setup!

This change correctly addresses the macOS-specific requirement of appending the AppMenu immediately after creation. The added comment provides clear guidance for developers, which is crucial for proper menu functionality on macOS.


18-33: Overall, excellent improvements to the macOS menu example!

These changes successfully address the PR objectives by correctly demonstrating the macOS-specific menu setup. The additions and modifications provide clear, accurate guidance for developers implementing menus in Wails projects, especially for macOS.

Key improvements:

  1. Correct ordering of AppMenu and EditMenu appending for macOS.
  2. Clear comments explaining macOS-specific requirements.
  3. Enhanced example of menu item action implementation.

These changes significantly enhance the quality and accuracy of the documentation.

@leaanthony

Copy link
Copy Markdown
Member

Thanks 🙏 Please could you add an entry to the changelog located at website/src/pages/changelog.mdx?

@sonarqubecloud

sonarqubecloud Bot commented Nov 6, 2024

Copy link
Copy Markdown

@takuyahara

Copy link
Copy Markdown
Contributor Author

@leaanthony Done 👍

@leaanthony leaanthony merged commit 1c16342 into wailsapp:master Nov 6, 2024
@leaanthony

Copy link
Copy Markdown
Member

Thanks 🙏

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.

2 participants