Merge branch 'master' into zig-0.14
This commit is contained in:
commit
43b14d9147
5 changed files with 77 additions and 5 deletions
|
@ -274,6 +274,21 @@ const cmds = struct {
|
|||
}
|
||||
pub const open_project_dir_meta: Meta = .{ .arguments = &.{.string} };
|
||||
|
||||
pub fn close_project(_: *Self, ctx: Ctx) Result {
|
||||
var project_dir: []const u8 = undefined;
|
||||
if (!try ctx.args.match(.{tp.extract(&project_dir)}))
|
||||
return;
|
||||
project_manager.close(project_dir) catch |e| switch (e) {
|
||||
error.CloseCurrentProject => {
|
||||
const logger = log.logger("project");
|
||||
defer logger.deinit();
|
||||
logger.print_err("project", "cannot close current project", .{});
|
||||
},
|
||||
else => return e,
|
||||
};
|
||||
}
|
||||
pub const close_project_meta: Meta = .{ .arguments = &.{.string} };
|
||||
|
||||
pub fn change_project(self: *Self, ctx: Ctx) Result {
|
||||
var project_dir: []const u8 = undefined;
|
||||
if (!try ctx.args.match(.{tp.extract(&project_dir)}))
|
||||
|
|
|
@ -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";
|
||||
|
@ -11,6 +13,7 @@ pub const description = "project";
|
|||
|
||||
pub const Entry = struct {
|
||||
label: []const u8,
|
||||
open: bool,
|
||||
};
|
||||
|
||||
pub const Match = struct {
|
||||
|
@ -31,18 +34,28 @@ pub fn load_entries(palette: *Type) !usize {
|
|||
var len = try cbor.decodeArrayHeader(&iter);
|
||||
while (len > 0) : (len -= 1) {
|
||||
var name_: []const u8 = undefined;
|
||||
if (try cbor.matchValue(&iter, cbor.extract(&name_))) {
|
||||
(try palette.entries.addOne()).* = .{ .label = try palette.allocator.dupe(u8, name_) };
|
||||
} else return error.InvalidMessageField;
|
||||
var open: bool = false;
|
||||
if (try cbor.decodeArrayHeader(&iter) != 2)
|
||||
return error.InvalidMessageField;
|
||||
if (!try cbor.matchValue(&iter, cbor.extract(&name_)))
|
||||
return error.InvalidMessageField;
|
||||
if (!try cbor.matchValue(&iter, cbor.extract(&open)))
|
||||
return error.InvalidMessageField;
|
||||
(try palette.entries.addOne()).* = .{ .label = try palette.allocator.dupe(u8, name_), .open = open };
|
||||
}
|
||||
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();
|
||||
const writer = value.writer();
|
||||
try cbor.writeValue(writer, entry.label);
|
||||
try cbor.writeValue(writer, if (entry.open) "-" else "");
|
||||
try cbor.writeValue(writer, matches orelse &[_]usize{});
|
||||
try palette.menu.add_item_with_handler(value.items, select);
|
||||
palette.items += 1;
|
||||
|
@ -55,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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue