gtk-ng: use action helper in tab

pull/8228/head
Jeffrey C. Ollie 2025-08-13 18:48:37 -05:00
parent d66212dcce
commit 31c71c6c5a
No known key found for this signature in database
GPG Key ID: 6F86035A6D97044E
1 changed files with 6 additions and 38 deletions

View File

@ -177,7 +177,7 @@ pub const Tab = extern struct {
gtk.Widget.initTemplate(self.as(gtk.Widget)); gtk.Widget.initTemplate(self.as(gtk.Widget));
// Init our actions // Init our actions
self.initActions(); self.initActionMap();
// If our configuration is null then we get the configuration // If our configuration is null then we get the configuration
// from the application. // from the application.
@ -198,45 +198,13 @@ pub const Tab = extern struct {
}; };
} }
/// Setup our action map. fn initActionMap(self: *Self) void {
fn initActions(self: *Self) void { const actions = [_]ext.Action(Self){
// The set of actions. Each action has (in order): .init("close", actionClose, null),
// [0] The action name .init("ring-bell", actionRingBell, null),
// [1] The callback function
// [2] The glib.VariantType of the parameter
//
// For action names:
// https://docs.gtk.org/gio/type_func.Action.name_is_valid.html
const actions = .{
.{ "close", actionClose, null },
.{ "ring-bell", actionRingBell, null },
}; };
// We need to collect our actions into a group since we're just ext.addActionsAsGroup(Self, self, "tab", &actions);
// a plain widget that doesn't implement ActionGroup directly.
const group = gio.SimpleActionGroup.new();
errdefer group.unref();
const map = group.as(gio.ActionMap);
inline for (actions) |entry| {
const action = gio.SimpleAction.new(
entry[0],
entry[2],
);
defer action.unref();
_ = gio.SimpleAction.signals.activate.connect(
action,
*Self,
entry[1],
self,
.{},
);
map.addAction(action.as(gio.Action));
}
self.as(gtk.Widget).insertActionGroup(
"tab",
group.as(gio.ActionGroup),
);
} }
//--------------------------------------------------------------- //---------------------------------------------------------------