feat: pre-select current theme when opening theme panel

This commit is contained in:
CJ van den Berg 2024-12-05 22:12:13 +01:00
parent 745c4db0fe
commit cd2fec9be3
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 42 additions and 15 deletions

View file

@ -24,12 +24,18 @@ pub const Match = struct {
var previous_theme: ?[]const u8 = null;
pub fn load_entries(palette: *Type) !void {
var idx: usize = 0;
previous_theme = tui.current().theme.name;
for (Widget.themes) |theme|
for (Widget.themes) |theme| {
idx += 1;
(try palette.entries.addOne()).* = .{
.label = theme.description,
.name = theme.name,
};
if (previous_theme) |theme_name| if (std.mem.eql(u8, theme.name, theme_name)) {
palette.initial_selected = idx;
};
}
}
pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !void {
@ -49,6 +55,8 @@ fn select(menu: **Type.MenuState, button: *Type.ButtonState) void {
var iter = button.opts.label;
if (!(cbor.matchString(&iter, &description_) catch false)) return;
if (!(cbor.matchString(&iter, &name_) catch false)) return;
if (previous_theme) |prev| if (std.mem.eql(u8, prev, name_))
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);
}