feat: use palatte instance specific name and icon
This commit is contained in:
parent
4a04b44fef
commit
7b877de6d7
4 changed files with 25 additions and 19 deletions
|
@ -8,6 +8,8 @@ const command = @import("../../command.zig");
|
|||
pub const Type = @import("palette.zig").Create(@This());
|
||||
|
||||
pub const label = "Search commands";
|
||||
pub const name = " command";
|
||||
pub const description = "command";
|
||||
|
||||
pub const Entry = struct {
|
||||
name: []const u8,
|
||||
|
@ -99,17 +101,17 @@ pub fn restore_state(palette: *Type) !void {
|
|||
const data = buffer[0..size];
|
||||
|
||||
defer sort_by_used_time(palette);
|
||||
var name: []const u8 = undefined;
|
||||
var name_: []const u8 = undefined;
|
||||
var used_time: i64 = undefined;
|
||||
var iter: []const u8 = data;
|
||||
while (cbor.matchValue(&iter, .{
|
||||
tp.extract(&name),
|
||||
tp.extract(&name_),
|
||||
tp.extract(&used_time),
|
||||
}) catch |e| switch (e) {
|
||||
error.CborTooShort => return,
|
||||
else => return e,
|
||||
}) {
|
||||
const id = command.getId(name) orelse continue;
|
||||
const id = command.getId(name_) orelse continue;
|
||||
set_used_time(palette, id, used_time);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@ const tui = @import("../../tui.zig");
|
|||
pub const Type = @import("palette.zig").Create(@This());
|
||||
|
||||
pub const label = "Search projects";
|
||||
pub const name = " project";
|
||||
pub const description = "project";
|
||||
|
||||
pub const Entry = struct {
|
||||
name: []const u8,
|
||||
|
@ -31,9 +33,9 @@ pub fn load_entries(palette: *Type) !void {
|
|||
var iter: []const u8 = rsp.buf;
|
||||
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()).* = .{ .name = try palette.a.dupe(u8, name) };
|
||||
var name_: []const u8 = undefined;
|
||||
if (try cbor.matchValue(&iter, cbor.extract(&name_))) {
|
||||
(try palette.entries.addOne()).* = .{ .name = try palette.a.dupe(u8, name_) };
|
||||
} else return error.InvalidMessageField;
|
||||
}
|
||||
}
|
||||
|
@ -51,9 +53,9 @@ pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !v
|
|||
}
|
||||
|
||||
fn select(menu: **Type.MenuState, button: *Type.ButtonState) void {
|
||||
var name: []const u8 = undefined;
|
||||
var name_: []const u8 = undefined;
|
||||
var iter = button.opts.label;
|
||||
if (!(cbor.matchString(&iter, &name) catch false)) return;
|
||||
if (!(cbor.matchString(&iter, &name_) catch false)) return;
|
||||
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);
|
||||
tp.self_pid().send(.{ "cmd", "change_project", .{name_} }) catch |e| menu.*.opts.ctx.logger.err("open_recent_project", e);
|
||||
}
|
||||
|
|
|
@ -82,8 +82,8 @@ pub fn Create(options: type) type {
|
|||
try mv.floating_views.add(self.menu.container_widget);
|
||||
return .{
|
||||
.handler = EventHandler.to_owned(self),
|
||||
.name = " command",
|
||||
.description = "command",
|
||||
.name = options.name,
|
||||
.description = options.description,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,8 @@ const tui = @import("../../tui.zig");
|
|||
pub const Type = @import("palette.zig").Create(@This());
|
||||
|
||||
pub const label = "Search themes";
|
||||
pub const name = " theme";
|
||||
pub const description = "theme";
|
||||
|
||||
pub const Entry = struct {
|
||||
name: []const u8,
|
||||
|
@ -39,24 +41,24 @@ pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !v
|
|||
}
|
||||
|
||||
fn select(menu: **Type.MenuState, button: *Type.ButtonState) void {
|
||||
var name: []const u8 = undefined;
|
||||
var name_: []const u8 = undefined;
|
||||
var iter = button.opts.label;
|
||||
if (!(cbor.matchString(&iter, &name) catch false)) return;
|
||||
if (!(cbor.matchString(&iter, &name_) catch false)) return;
|
||||
tp.self_pid().send(.{ "cmd", "exit_overlay_mode" }) catch |e| menu.*.opts.ctx.logger.err("theme_palette", e);
|
||||
tp.self_pid().send(.{ "cmd", "set_theme", .{name} }) catch |e| menu.*.opts.ctx.logger.err("theme_palette", e);
|
||||
tp.self_pid().send(.{ "cmd", "set_theme", .{name_} }) catch |e| menu.*.opts.ctx.logger.err("theme_palette", e);
|
||||
}
|
||||
|
||||
pub fn updated(palette: *Type, button_: ?*Type.ButtonState) !void {
|
||||
const button = button_ orelse return cancel(palette);
|
||||
var name: []const u8 = undefined;
|
||||
var name_: []const u8 = undefined;
|
||||
var iter = button.opts.label;
|
||||
if (!(cbor.matchString(&iter, &name) catch false)) return;
|
||||
tp.self_pid().send(.{ "cmd", "set_theme", .{name} }) catch |e| palette.logger.err("theme_palette upated", e);
|
||||
if (!(cbor.matchString(&iter, &name_) catch false)) return;
|
||||
tp.self_pid().send(.{ "cmd", "set_theme", .{name_} }) catch |e| palette.logger.err("theme_palette upated", e);
|
||||
}
|
||||
|
||||
pub fn cancel(palette: *Type) !void {
|
||||
if (previous_theme) |name| if (!std.mem.eql(u8, name, tui.current().theme.name)) {
|
||||
if (previous_theme) |name_| if (!std.mem.eql(u8, name_, tui.current().theme.name)) {
|
||||
previous_theme = null;
|
||||
tp.self_pid().send(.{ "cmd", "set_theme", .{name} }) catch |e| palette.logger.err("theme_palette cancel", e);
|
||||
tp.self_pid().send(.{ "cmd", "set_theme", .{name_} }) catch |e| palette.logger.err("theme_palette cancel", e);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue