Additions to GTK context menu

Add "New Window", "New Tab", and "Reset" to GTK context menu.
This commit is contained in:
Jeffrey C. Ollie
2024-07-29 12:08:29 -05:00
parent 874c4e13d2
commit 67efe7fe42
2 changed files with 18 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(
@@ -803,6 +804,9 @@ 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, "New Window", "win.new_window");
c.g_menu_append(section, "New Tab", "win.new_tab");
c.g_menu_append(section, "Split Right", "win.split_right");
c.g_menu_append(section, "Split Down", "win.split_down");
}

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);