themes collection evaluation, begin moving theme preset/file setting to just being based on the themes folder, rather than completely path-based

This commit is contained in:
Ryan Fleury
2025-05-02 15:52:21 -07:00
parent 644ba8d02e
commit 6c2cf98ea6
6 changed files with 127 additions and 13 deletions
+1 -1
View File
@@ -657,7 +657,7 @@ RD_CmdKindInfo rd_cmd_kind_info_table[226] =
{ str8_lit_comp("open_theme"), str8_lit_comp("Opens a theme file."), str8_lit_comp("color"), str8_lit_comp(""), (RD_CmdKindFlag_ListInUI*0)|(RD_CmdKindFlag_ListInIPCDocs*0)|(RD_CmdKindFlag_ListInTextPt*0)|(RD_CmdKindFlag_ListInTextRng*0), {(RD_QueryFlag_AllowFiles*1)|(RD_QueryFlag_AllowFolders*0)|(RD_QueryFlag_CodeInput*0)|(RD_QueryFlag_KeepOldInput*0)|(RD_QueryFlag_SelectOldInput*0)|(RD_QueryFlag_Floating*1)|(RD_QueryFlag_Required*1), RD_RegSlot_FilePath, str8_lit_comp("folder:\"$input\""), str8_lit_comp(""), CTRL_EntityKind_Null}},
{ str8_lit_comp("add_theme_color"), str8_lit_comp("Adds a new theme color."), str8_lit_comp(""), str8_lit_comp(""), (RD_CmdKindFlag_ListInUI*0)|(RD_CmdKindFlag_ListInIPCDocs*0)|(RD_CmdKindFlag_ListInTextPt*0)|(RD_CmdKindFlag_ListInTextRng*0), {(RD_QueryFlag_AllowFiles*0)|(RD_QueryFlag_AllowFolders*0)|(RD_QueryFlag_CodeInput*0)|(RD_QueryFlag_KeepOldInput*0)|(RD_QueryFlag_SelectOldInput*0)|(RD_QueryFlag_Floating*0)|(RD_QueryFlag_Required*0), RD_RegSlot_Null, str8_lit_comp(""), str8_lit_comp(""), CTRL_EntityKind_Null}},
{ str8_lit_comp("fork_loaded_theme"), str8_lit_comp("Imports all colors from the loaded color theme file or color theme preset, so they can be individually edited."), str8_lit_comp(""), str8_lit_comp(""), (RD_CmdKindFlag_ListInUI*0)|(RD_CmdKindFlag_ListInIPCDocs*0)|(RD_CmdKindFlag_ListInTextPt*0)|(RD_CmdKindFlag_ListInTextRng*0), {(RD_QueryFlag_AllowFiles*0)|(RD_QueryFlag_AllowFolders*0)|(RD_QueryFlag_CodeInput*0)|(RD_QueryFlag_KeepOldInput*0)|(RD_QueryFlag_SelectOldInput*0)|(RD_QueryFlag_Floating*0)|(RD_QueryFlag_Required*0), RD_RegSlot_Null, str8_lit_comp(""), str8_lit_comp(""), CTRL_EntityKind_Null}},
{ str8_lit_comp("save_theme"), str8_lit_comp("Saves all theme colors to a new theme file."), str8_lit_comp(""), str8_lit_comp(""), (RD_CmdKindFlag_ListInUI*0)|(RD_CmdKindFlag_ListInIPCDocs*0)|(RD_CmdKindFlag_ListInTextPt*0)|(RD_CmdKindFlag_ListInTextRng*0), {(RD_QueryFlag_AllowFiles*1)|(RD_QueryFlag_AllowFolders*0)|(RD_QueryFlag_CodeInput*0)|(RD_QueryFlag_KeepOldInput*0)|(RD_QueryFlag_SelectOldInput*0)|(RD_QueryFlag_Floating*1)|(RD_QueryFlag_Required*1), RD_RegSlot_FilePath, str8_lit_comp("folder:\"$input\""), str8_lit_comp(""), CTRL_EntityKind_Null}},
{ str8_lit_comp("save_theme"), str8_lit_comp("Saves all theme colors to a new theme file."), str8_lit_comp(""), str8_lit_comp(""), (RD_CmdKindFlag_ListInUI*0)|(RD_CmdKindFlag_ListInIPCDocs*0)|(RD_CmdKindFlag_ListInTextPt*0)|(RD_CmdKindFlag_ListInTextRng*0), {(RD_QueryFlag_AllowFiles*1)|(RD_QueryFlag_AllowFolders*0)|(RD_QueryFlag_CodeInput*0)|(RD_QueryFlag_KeepOldInput*0)|(RD_QueryFlag_SelectOldInput*0)|(RD_QueryFlag_Floating*1)|(RD_QueryFlag_Required*1), RD_RegSlot_String, str8_lit_comp(""), str8_lit_comp(""), CTRL_EntityKind_Null}},
{ str8_lit_comp("set_next_statement"), str8_lit_comp("Sets the selected thread's instruction pointer to the cursor's position."), str8_lit_comp(""), str8_lit_comp("$text_pt,"), (RD_CmdKindFlag_ListInUI*1)|(RD_CmdKindFlag_ListInIPCDocs*1)|(RD_CmdKindFlag_ListInTextPt*1)|(RD_CmdKindFlag_ListInTextRng*0), {(RD_QueryFlag_AllowFiles*0)|(RD_QueryFlag_AllowFolders*0)|(RD_QueryFlag_CodeInput*0)|(RD_QueryFlag_KeepOldInput*0)|(RD_QueryFlag_SelectOldInput*0)|(RD_QueryFlag_Floating*0)|(RD_QueryFlag_Required*0), RD_RegSlot_Null, str8_lit_comp(""), str8_lit_comp(""), CTRL_EntityKind_Null}},
{ str8_lit_comp("add_target"), str8_lit_comp("Adds a new target."), str8_lit_comp("application,executable,debug"), str8_lit_comp("$targets,"), (RD_CmdKindFlag_ListInUI*1)|(RD_CmdKindFlag_ListInIPCDocs*1)|(RD_CmdKindFlag_ListInTextPt*0)|(RD_CmdKindFlag_ListInTextRng*0), {(RD_QueryFlag_AllowFiles*1)|(RD_QueryFlag_AllowFolders*0)|(RD_QueryFlag_CodeInput*0)|(RD_QueryFlag_KeepOldInput*0)|(RD_QueryFlag_SelectOldInput*0)|(RD_QueryFlag_Floating*1)|(RD_QueryFlag_Required*1), RD_RegSlot_FilePath, str8_lit_comp("folder:\"$input\""), str8_lit_comp(""), CTRL_EntityKind_Null}},
{ str8_lit_comp("select_target"), str8_lit_comp("Selects a target."), str8_lit_comp(""), str8_lit_comp(""), (RD_CmdKindFlag_ListInUI*1)|(RD_CmdKindFlag_ListInIPCDocs*1)|(RD_CmdKindFlag_ListInTextPt*0)|(RD_CmdKindFlag_ListInTextRng*0), {(RD_QueryFlag_AllowFiles*0)|(RD_QueryFlag_AllowFolders*0)|(RD_QueryFlag_CodeInput*0)|(RD_QueryFlag_KeepOldInput*0)|(RD_QueryFlag_SelectOldInput*0)|(RD_QueryFlag_Floating*1)|(RD_QueryFlag_Required*1), RD_RegSlot_Cfg, str8_lit_comp("query:targets"), str8_lit_comp(""), CTRL_EntityKind_Null}},
+1 -1
View File
@@ -985,7 +985,7 @@ RD_CmdTable: // | | | |
{OpenTheme 0 0 0 0 `folder:\\"$input\\"` FilePath null Nil Null 1 0 0 0 0 1 1 Palette "open_theme" "Open Theme" "Opens a theme file." "color" "" }
{AddThemeColor 0 0 0 0 "" Null null Nil Null 0 0 0 0 0 0 0 Palette "add_theme_color" "Add Theme Color" "Adds a new theme color." "" "" }
{ForkLoadedTheme 0 0 0 0 "" Null null Nil Null 0 0 0 0 0 0 0 Palette "fork_loaded_theme" "Fork Loaded Theme" "Imports all colors from the loaded color theme file or color theme preset, so they can be individually edited." "" "" }
{SaveTheme 0 0 0 0 `folder:\\"$input\\"` FilePath null Nil Null 1 0 0 0 0 1 1 Save "save_theme" "Save Theme" "Saves all theme colors to a new theme file." "" "" }
{SaveTheme 0 0 0 0 "" String null Nil Null 1 0 0 0 0 1 1 Save "save_theme" "Save Theme" "Saves all theme colors to a new theme file." "" "" }
//- rjf: line operations
{SetNextStatement 1 1 1 0 "" Null null Nil Null 0 0 0 0 0 0 0 RightArrow "set_next_statement" "Set Next Statement" "Sets the selected thread's instruction pointer to the cursor's position." "" "$text_pt," }
+42 -9
View File
@@ -5819,7 +5819,7 @@ rd_window_frame(void)
if(file_cfg != &rd_nil_cfg)
{
String8 path = file_cfg->first->string;
U64 endt_us = 0;
U64 endt_us = os_now_microseconds()+100;
if(ws->frames_alive == 0)
{
endt_us = os_now_microseconds()+50000;
@@ -11304,6 +11304,31 @@ rd_frame(void)
}
}
//- rjf: add macro for themes
{
String8 names[] =
{
str8_lit("themes"),
};
for EachElement(idx, names)
{
String8 name = names[idx];
E_TypeKey type_key = e_type_key_cons(.kind = E_TypeKind_Set,
.flags = E_TypeFlag_StubSingleLineExpansion,
.name = name,
.access = E_TYPE_ACCESS_FUNCTION_NAME(themes),
.expand =
{
.info = E_TYPE_EXPAND_INFO_FUNCTION_NAME(themes),
.range = E_TYPE_EXPAND_RANGE_FUNCTION_NAME(themes),
});
E_Expr *expr = e_push_expr(scratch.arena, E_ExprKind_LeafOffset, r1u64(0, 0));
expr->type_key = type_key;
expr->space = e_space_make(RD_EvalSpaceKind_MetaQuery);
e_string2expr_map_insert(scratch.arena, macro_map, name, expr);
}
}
//- rjf: build schema types & cache (name -> type) mapping
for EachElement(idx, rd_name_schema_info_table)
{
@@ -14679,16 +14704,24 @@ rd_frame(void)
}break;
case RD_CmdKind_SaveTheme:
{
String8 dst_path = rd_regs()->file_path;
RD_Cfg *parent = rd_cfg_from_id(rd_regs()->cfg);
RD_CfgList colors = rd_cfg_child_list_from_string(scratch.arena, parent, str8_lit("theme_color"));
String8List strings = {0};
for(RD_CfgNode *n = colors.first; n != 0; n = n->next)
String8 name = rd_regs()->string;
if(name.size != 0)
{
str8_list_push(scratch.arena, &strings, rd_string_from_cfg_tree(scratch.arena, dst_path, n->v));
String8 themes_folder = push_str8f(scratch.arena, "%S/raddbg/themes", os_get_process_info()->user_program_data_path);
if(os_make_directory(themes_folder))
{
String8 dst_path = push_str8f(scratch.arena, "%S/%S", themes_folder, name);
RD_Cfg *parent = rd_cfg_from_id(rd_regs()->cfg);
RD_CfgList colors = rd_cfg_child_list_from_string(scratch.arena, parent, str8_lit("theme_color"));
String8List strings = {0};
for(RD_CfgNode *n = colors.first; n != 0; n = n->next)
{
str8_list_push(scratch.arena, &strings, rd_string_from_cfg_tree(scratch.arena, dst_path, n->v));
}
String8 data = str8_list_join(scratch.arena, &strings, 0);
os_write_data_to_file_path(dst_path, data);
}
}
String8 data = str8_list_join(scratch.arena, &strings, 0);
os_write_data_to_file_path(dst_path, data);
}break;
//- rjf: watches
+2 -1
View File
@@ -84,7 +84,8 @@ enum
RD_EvalSpaceKind_CtrlEntity = E_SpaceKind_FirstUserDefined,
RD_EvalSpaceKind_MetaQuery,
RD_EvalSpaceKind_MetaCfg,
RD_EvalSpaceKind_MetaCmd,
RD_EvalSpaceKind_MetaCmd,
RD_EvalSpaceKind_MetaTheme,
RD_EvalSpaceKind_MetaCtrlEntity,
RD_EvalSpaceKind_MetaUnattachedProcess,
};
+73
View File
@@ -84,6 +84,79 @@ E_TYPE_EXPAND_RANGE_FUNCTION_DEF(commands)
}
}
////////////////////////////////
//~ rjf: `themes` Type Hooks
E_TYPE_ACCESS_FUNCTION_DEF(themes)
{
E_IRTreeAndType result = {&e_irnode_nil};
if(expr->kind == E_ExprKind_ArrayIndex &&
expr->first->next->kind == E_ExprKind_LeafStringLiteral)
{
String8 theme_name = expr->first->next->string;
E_TypeKey theme_type = e_type_key_cons(.kind = E_TypeKind_U64, .name = str8_lit("theme"));
result.type_key = theme_type;
result.mode = E_Mode_Value;
result.root = e_irtree_set_space(arena, e_space_make(RD_EvalSpaceKind_MetaTheme), e_irtree_const_u(arena, e_id_from_string(theme_name)));
}
return result;
}
E_TYPE_EXPAND_INFO_FUNCTION_DEF(themes)
{
E_TypeExpandInfo result = {0};
{
Temp scratch = scratch_begin(&arena, 1);
//- rjf: gather presets
String8List names = {0};
for EachEnumVal(RD_ThemePreset, p)
{
String8 name = rd_theme_preset_display_string_table[p];
FuzzyMatchRangeList name_matches = fuzzy_match_find(scratch.arena, filter, name);
if(name_matches.count == name_matches.needle_part_count)
{
str8_list_push(scratch.arena, &names, name);
}
}
//- rjf: gather theme files
{
String8 theme_folder = push_str8f(scratch.arena, "%S/raddbg/themes", os_get_process_info()->user_program_data_path);
OS_FileIter *it = os_file_iter_begin(scratch.arena, theme_folder, OS_FileIterFlag_SkipFolders);
for(OS_FileInfo info = {0}; os_file_iter_next(scratch.arena, it, &info);)
{
String8 name = info.name;
FuzzyMatchRangeList name_matches = fuzzy_match_find(scratch.arena, filter, name);
if(name_matches.count == name_matches.needle_part_count)
{
str8_list_push(scratch.arena, &names, name);
}
}
os_file_iter_end(it);
}
//- rjf: flatten & build accelerator
String8Array *accel = push_array(arena, String8Array, 1);
*accel = str8_array_from_list(arena, &names);
result.user_data = accel;
result.expr_count = accel->count;
scratch_end(scratch);
}
return result;
}
E_TYPE_EXPAND_RANGE_FUNCTION_DEF(themes)
{
U64 out_idx = 0;
String8Array *accel = (String8Array *)user_data;
for(U64 idx = idx_range.min; idx < idx_range.max; idx += 1, out_idx += 1)
{
String8 name = accel->v[idx];
evals_out[out_idx] = e_eval_wrapf(eval, "$[\"%S\"]", name);
}
}
////////////////////////////////
//~ rjf: `locals` Type Hooks
+8 -1
View File
@@ -7,10 +7,17 @@
////////////////////////////////
//~ rjf: `commands` Type Hooks
E_TYPE_EXPAND_INFO_FUNCTION_DEF(commands);
E_TYPE_ACCESS_FUNCTION_DEF(commands);
E_TYPE_EXPAND_INFO_FUNCTION_DEF(commands);
E_TYPE_EXPAND_RANGE_FUNCTION_DEF(commands);
////////////////////////////////
//~ rjf: `themes` Type Hooks
E_TYPE_ACCESS_FUNCTION_DEF(themes);
E_TYPE_EXPAND_INFO_FUNCTION_DEF(themes);
E_TYPE_EXPAND_RANGE_FUNCTION_DEF(themes);
////////////////////////////////
//~ rjf: `locals` Type Hooks