gtk-ng: use action helper in surface

pull/8228/head
Jeffrey C. Ollie 2025-08-13 18:49:05 -05:00
parent 6b690e6b4e
commit 0e3ec24d2c
No known key found for this signature in database
GPG Key ID: 6F86035A6D97044E
1 changed files with 5 additions and 36 deletions

View File

@ -1233,7 +1233,7 @@ pub const Surface = extern struct {
gtk.Widget.initTemplate(self.as(gtk.Widget));
// Initialize our actions
self.initActions();
self.initActionMap();
const priv = self.private();
@ -1281,43 +1281,12 @@ pub const Surface = extern struct {
self.propConfig(undefined, null);
}
fn initActions(self: *Self) void {
// The set of actions. Each action has (in order):
// [0] The action name
// [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 = .{
.{ "prompt-title", actionPromptTitle, null },
fn initActionMap(self: *Self) void {
const actions = [_]ext.Action(Self){
.init("prompt-title", actionPromptTitle, null),
};
// We need to collect our actions into a group since we're just
// 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(
"surface",
group.as(gio.ActionGroup),
);
ext.addActionsAsGroup(Self, self, "surface", &actions);
}
fn dispose(self: *Self) callconv(.c) void {