feat(project): add close_project command bound to del in recent projects list

This commit is contained in:
CJ van den Berg 2025-02-09 20:39:32 +01:00
parent 90192ddf3c
commit 88ca1cd343
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
3 changed files with 46 additions and 0 deletions

View file

@ -2,8 +2,10 @@ const std = @import("std");
const cbor = @import("cbor");
const tp = @import("thespian");
const project_manager = @import("project_manager");
const command = @import("command");
pub const Type = @import("palette.zig").Create(@This());
const module_name = @typeName(@This());
pub const label = "Search projects";
pub const name = " project";
@ -44,6 +46,10 @@ pub fn load_entries(palette: *Type) !usize {
return 1;
}
pub fn clear_entries(palette: *Type) void {
palette.entries.clearRetainingCapacity();
}
pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !void {
var value = std.ArrayList(u8).init(palette.allocator);
defer value.deinit();
@ -62,3 +68,11 @@ fn select(menu: **Type.MenuState, button: *Type.ButtonState) void {
tp.self_pid().send(.{ "cmd", "exit_overlay_mode" }) catch |e| menu.*.opts.ctx.logger.err("open_recent_project", e);
tp.self_pid().send(.{ "cmd", "change_project", .{name_} }) catch |e| menu.*.opts.ctx.logger.err("open_recent_project", e);
}
pub fn delete_item(menu: *Type.MenuState, button: *Type.ButtonState) bool {
var name_: []const u8 = undefined;
var iter = button.opts.label;
if (!(cbor.matchString(&iter, &name_) catch false)) return false;
command.executeName("close_project", command.fmt(.{name_})) catch |e| menu.*.opts.ctx.logger.err(module_name, e);
return true; //refresh list
}