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

[feat] Menu event handler directly on MenuItemBuilder #9060

Open
martpie opened this issue Mar 3, 2024 · 1 comment · May be fixed by #9380
Open

[feat] Menu event handler directly on MenuItemBuilder #9060

martpie opened this issue Mar 3, 2024 · 1 comment · May be fixed by #9380

Comments

@martpie
Copy link

martpie commented Mar 3, 2024

Describe the problem

Building complex menu means complex on_menu_event, keeping track of event names, etc.

Describe the solution you'd like

Build the event handler directly when creating a menu item. Something like:

let view_menu = SubmenuBuilder::new(app_handle, "View")
    .item(
        &MenuItemBuilder::new("Jump to playing track")
            .id(MenuId::new("jump_to_playing_track"))
            .accelerator("CmdOrCtrl+T")
            .handler(|app_handler| { // HERE (triggered on click + accelearator)
                app_handler.get_webview_window("main").unwrap().emit("hey_yah")
            })
            .build(app_handle)
            .unwrap(),
    )
    .build()
    .unwrap();

Alternatives considered

none.

Additional context

No response

@martpie
Copy link
Author

martpie commented Mar 14, 2024

I realize there is an action property on the Menu builder on JS side, just having the same Rust side would be super cool.

amrbashir added a commit that referenced this issue Apr 4, 2024
@amrbashir amrbashir linked a pull request Apr 4, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant