Merge pull request #2014 from jcollie/gtk-context-menu-additions

Additions to GTK context menu
This commit is contained in:
Mitchell Hashimoto
2024-08-01 14:54:49 -07:00
committed by GitHub
2 changed files with 16 additions and 0 deletions

View File

@ -370,6 +370,7 @@ fn syncActionAccelerators(self: *App) !void {
try self.syncActionAccelerator("win.split_down", .{ .new_split = .down });
try self.syncActionAccelerator("win.copy", .{ .copy_to_clipboard = {} });
try self.syncActionAccelerator("win.paste", .{ .paste_from_clipboard = {} });
try self.syncActionAccelerator("win.reset", .{ .reset = {} });
}
fn syncActionAccelerator(
@ -811,6 +812,7 @@ fn initContextMenu(self: *App) void {
const section = c.g_menu_new();
defer c.g_object_unref(section);
c.g_menu_append_section(menu, null, @ptrCast(@alignCast(section)));
c.g_menu_append(section, "Reset", "win.reset");
c.g_menu_append(section, "Terminal Inspector", "win.toggle_inspector");
}

View File

@ -184,6 +184,7 @@ fn initActions(self: *Window) void {
.{ "toggle_inspector", &gtkActionToggleInspector },
.{ "copy", &gtkActionCopy },
.{ "paste", &gtkActionPaste },
.{ "reset", &gtkActionReset },
};
inline for (actions) |entry| {
@ -629,6 +630,19 @@ fn gtkActionPaste(
};
}
fn gtkActionReset(
_: *c.GSimpleAction,
_: *c.GVariant,
ud: ?*anyopaque,
) callconv(.C) void {
const self: *Window = @ptrCast(@alignCast(ud orelse return));
const surface = self.actionSurface() orelse return;
_ = surface.performBindingAction(.{ .reset = {} }) catch |err| {
log.warn("error performing binding action error={}", .{err});
return;
};
}
/// Returns the surface to use for an action.
fn actionSurface(self: *Window) ?*CoreSurface {
const page_idx = c.gtk_notebook_get_current_page(self.notebook);