gtk-rs-core
gtk-rs-core copied to clipboard
Provide a builder pattern to create actions
Similar to the builder pattern we have for creating signals, it would be nice to have something similar for gio::SimpleAction
. We should probably do that as part of a new trait, the same way we can register signals as part of ObjectImpl trait.
This might be useful later for gtk-rs/gtk3-rs#240
I don't understand what you mean with this issue :) Can you explain in more detail?
I don't understand what you mean with this issue :) Can you explain in more detail?
Actually, I am still not sure how to make something useful out of this, often you connect the signals on other objects than the one you're currently creating. There's also connect_
part where we have to be careful with whether we want to enforce Send trait or not depending on the use cases. Did you had something specific in mind?
Me? You suggested this here :)
What I suggested in the PR was about making install_action()
from something that the user calls into a function on the Impl
trait like we do for signals/etc. And that should probably come with a builder for the actions, similar to the one for signals. Is that what you mean here?
Oh, I completely mis-understood your other comment then. I'm not sure if we want to provide a Builder pattern for creating actions, it could be useful but I think something like gtk-rs/gtk3-rs#240 should cover more than enough use cases.
The install_action
itself is useful as you don't need to have your widget implementing ActionMap
interface to add the actions to it which makes it much more interesting.
I will update the issue to reflect that :)
The
install_action
itself is useful as you don't need to have your widget implementingActionMap
interface to add the actions to it which makes it much more interesting.
It would be part of WidgetImpl
then or not? :)
Not really, as you can use can define actions on any object. I guess as part of a new trait exposed by gio
itself, so maybe a new ActionsImpl
? Then maybe gtk-rs/gtk3-rs#240 could just generate such trait for you.
On any object? How does that work? :)
The actions themselves can be anywhere yes, it depends on the use cases of course. For the actions to be useful, they have to be added to an action map with ActionMapExt::add_action
. It could be a widget, or just a gio::Application
in case you're writing a CLI app, a DBus server or whatever.
In GTK only two objects implement such interface, gtk::Application
with the action group name app
and gtk::ApplicationWindow
with win
as an action group name. If you want to use your actions on your new widget, you either have to implement the interface manually or use a gio::SimpleActionGroup
. The custom action group can be added to a widget using WidgetExt::insert_action_group
so that GTK's internals know where to look for actions.
In the case for say a CLI app, you can look for an action by it's name form your action group and call activate on it.
I believe we can close this one now that we have gio::ActionEntry
support which has a builder pattern.