feat(buffers): add delete_buffer command and keybinding for buffer_palette

This commit is contained in:
CJ van den Berg 2025-01-22 22:23:56 +01:00
parent a4ac3a42fd
commit 0a632416a4
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
5 changed files with 50 additions and 5 deletions

View file

@ -6,6 +6,7 @@ const command = @import("command");
const tui = @import("../../tui.zig");
pub const Type = @import("palette.zig").Create(@This());
const module_name = @typeName(@This());
pub const label = "Switch buffers";
pub const name = " buffer";
@ -43,7 +44,15 @@ fn select(menu: **Type.MenuState, button: *Type.ButtonState) void {
var file_path: []const u8 = undefined;
var iter = button.opts.label;
if (!(cbor.matchString(&iter, &file_path) catch false)) return;
tp.self_pid().send(.{ "cmd", "exit_overlay_mode" }) catch |e| menu.*.opts.ctx.logger.err("navigate", e);
tp.self_pid().send(.{ "cmd", "navigate", .{} }) catch |e| menu.*.opts.ctx.logger.err("navigate", e);
tp.self_pid().send(.{ "cmd", "navigate", .{ .file = file_path } }) catch |e| menu.*.opts.ctx.logger.err("navigate", e);
tp.self_pid().send(.{ "cmd", "exit_overlay_mode" }) catch |e| menu.*.opts.ctx.logger.err(module_name, e);
tp.self_pid().send(.{ "cmd", "navigate", .{} }) catch |e| menu.*.opts.ctx.logger.err(module_name, e);
tp.self_pid().send(.{ "cmd", "navigate", .{ .file = file_path } }) catch |e| menu.*.opts.ctx.logger.err(module_name, e);
}
pub fn delete_item(menu: *Type.MenuState, button: *Type.ButtonState) void {
var file_path: []const u8 = undefined;
var iter = button.opts.label;
if (!(cbor.matchString(&iter, &file_path) catch false)) return;
tp.self_pid().send(.{ "cmd", "exit_overlay_mode" }) catch |e| menu.*.opts.ctx.logger.err(module_name, e);
tp.self_pid().send(.{ "cmd", "delete_buffer", .{file_path} }) catch |e| menu.*.opts.ctx.logger.err(module_name, e);
}

View file

@ -428,6 +428,14 @@ pub fn Create(options: type) type {
}
pub const palette_menu_pageup_meta = .{};
pub fn palette_menu_delete_item(self: *Self, _: Ctx) Result {
if (@hasDecl(options, "delete_item")) {
const button = self.menu.get_selected() orelse return;
options.delete_item(self.menu, button);
}
}
pub const palette_menu_delete_item_meta = .{};
pub fn palette_menu_activate(self: *Self, _: Ctx) Result {
self.menu.activate_selected();
}