gtk-ng: use action helper in split-tree
parent
31c71c6c5a
commit
6b690e6b4e
|
|
@ -160,62 +160,26 @@ pub const SplitTree = extern struct {
|
||||||
gtk.Widget.initTemplate(self.as(gtk.Widget));
|
gtk.Widget.initTemplate(self.as(gtk.Widget));
|
||||||
|
|
||||||
// Initialize our actions
|
// Initialize our actions
|
||||||
self.initActions();
|
self.initActionMap();
|
||||||
|
|
||||||
// Initialize some basic state
|
// Initialize some basic state
|
||||||
const priv = self.private();
|
const priv = self.private();
|
||||||
priv.pending_close = null;
|
priv.pending_close = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn initActions(self: *Self) void {
|
fn initActionMap(self: *Self) void {
|
||||||
// The set of actions. Each action has (in order):
|
const s_variant_type = glib.ext.VariantType.newFor([:0]const u8);
|
||||||
// [0] The action name
|
defer s_variant_type.free();
|
||||||
// [1] The callback function
|
|
||||||
// [2] The glib.VariantType of the parameter
|
const actions = [_]ext.Action(Self){
|
||||||
//
|
|
||||||
// For action names:
|
|
||||||
// https://docs.gtk.org/gio/type_func.Action.name_is_valid.html
|
|
||||||
const actions: []const struct {
|
|
||||||
[:0]const u8,
|
|
||||||
*const fn (*gio.SimpleAction, ?*glib.Variant, *Self) callconv(.c) void,
|
|
||||||
?*glib.VariantType,
|
|
||||||
} = &.{
|
|
||||||
// All of these will eventually take a target surface parameter.
|
// All of these will eventually take a target surface parameter.
|
||||||
// For now all our targets originate from the focused surface.
|
// For now all our targets originate from the focused surface.
|
||||||
.{ "new-split", &actionNewSplit, glib.ext.VariantType.newFor([:0]const u8) },
|
.init("new-split", actionNewSplit, s_variant_type),
|
||||||
.{ "equalize", &actionEqualize, null },
|
.init("equalize", actionEqualize, null),
|
||||||
.{ "zoom", &actionZoom, null },
|
.init("zoom", actionZoom, null),
|
||||||
};
|
};
|
||||||
|
|
||||||
// We need to collect our actions into a group since we're just
|
ext.addActionsAsGroup(Self, self, "split-tree", &actions);
|
||||||
// a plain widget that doesn't implement ActionGroup directly.
|
|
||||||
const group = gio.SimpleActionGroup.new();
|
|
||||||
errdefer group.unref();
|
|
||||||
const map = group.as(gio.ActionMap);
|
|
||||||
for (actions) |entry| {
|
|
||||||
const action = gio.SimpleAction.new(
|
|
||||||
entry[0],
|
|
||||||
entry[2],
|
|
||||||
);
|
|
||||||
defer {
|
|
||||||
action.unref();
|
|
||||||
if (entry[2]) |ptype| ptype.free();
|
|
||||||
}
|
|
||||||
|
|
||||||
_ = gio.SimpleAction.signals.activate.connect(
|
|
||||||
action,
|
|
||||||
*Self,
|
|
||||||
entry[1],
|
|
||||||
self,
|
|
||||||
.{},
|
|
||||||
);
|
|
||||||
map.addAction(action.as(gio.Action));
|
|
||||||
}
|
|
||||||
|
|
||||||
self.as(gtk.Widget).insertActionGroup(
|
|
||||||
"split-tree",
|
|
||||||
group.as(gio.ActionGroup),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new split in the given direction from the currently
|
/// Create a new split in the given direction from the currently
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue