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

Easier and more intuitive way of adding actions and keyboard shortcuts #548

Open
AaronErhardt opened this issue Oct 4, 2023 Discussed in #544 · 0 comments
Open

Easier and more intuitive way of adding actions and keyboard shortcuts #548

AaronErhardt opened this issue Oct 4, 2023 Discussed in #544 · 0 comments

Comments

@AaronErhardt
Copy link
Member

Discussed in https://github.com/orgs/Relm4/discussions/544

Originally posted by kdwk September 28, 2023
The current way of adding actions and keyboard shortcuts for them is complicated and verbose. First, outside of the component one needs to declare an action group and action with macros, then in the fn init() of the component I need to get the main app, declare an action group (again), actually define the action, add the action to the action group, and attach the action group to a window.

Not only is this very troublesome, but it goes against the Relm model of handling inputs with the Input enum in fn update(), since actions bypass this mechanism. This also duplicates lots of code because many actions with keyboard shortcuts are also triggered with e.g. buttons in the UI, so the code needs to exist twice when one defines the action and in fn update().

Instead of the status quo, I would love to see actions being integrated with the Input enum or fn init(). Ideally, one should not need to declare any action or action group separately. Instead, either in the Input enum or fn update() one can attach the keyboard shortcut to the inputs.

e.g.

#[derive(Debug)]
enum WebWindowInput {
    CreateSmallWebWindow(WebView),
    TitleChanged(String),
    InsecureContentDetected,
    #[shortcut("<primary>b")]
    GoBack,
    #[shortcut("<primary>f")]
    GoForward,
}

and Relm4 would automatically do the setting up of actions and actiongroups and attach the keyboard shortcut to the root of the component.

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

No branches or pull requests

1 participant