I need a way to listen to the GAction::notify::state (also works with GActionGroup::state-changed::<name>) signal from a widget lower in the hierarchy to a Widget with a property action installed, that is higher in the hierarchy.
I read in the documentation that the actions are searched in parent layers of the widget, so I though that there could be a function to do that.
Widget.query_action doesn’t work because it only searches in installed actions for the current class, but it doesn’t search in other widgets.
You should only be connecting to actions you installed yourself, from within the widget that installed them; you should not be randomly accessing actions on random widgets.
Then why and how GtkCheckButton in radio mode, access the action specified in its action-name prop, and tracks its state value, if its not installed by itself?
What I’m trying to achieve is some kind of “context” functionality, that depending on a upper action state value, the widget will style himself, change layout, etc.
For example just like the GtkCheckButton is currently doing, it activates himself when the state value is X, and changes his styling to a radio button (sorry, it changes to radio styling when it has a group assigned, nothing to do with actions).
class FooParentWidget extends gtk.Widget {
display_mode: "desktop" | "mobile";
class_init(klass) {
klass.install_property_action("foo-parent.display-mode", "display_mode");
}
}
class FooWidget extends gtk.Widget {
constructed() {
// hypothetic function, returning a GAction would be dangerous,
// because then you can mutate it, that's why it would be safe
// to just expose connecting to state, although GActions are inmutable,
// so idk
this.find_action_and_connect_state("foo.bar", (state) => {
auto_break switch state {
case "desktop":
this.child_0.orientation = gtk.Orientation.HORIZONTAL;
this.child_0.add_css_classes(["foo"]);
this.child_0.remove_css_classes(["bar"]);
case "mobile":
this.child_0.orientation = gtk.Orientation.VERTICAL;
this.child_0.description = "Oops, we currently not support mobile views";
}
});
}
}