diff --git a/custom/4coder_config.cpp b/custom/4coder_config.cpp index bb283b16..7cff6e52 100644 --- a/custom/4coder_config.cpp +++ b/custom/4coder_config.cpp @@ -1555,11 +1555,9 @@ load_config_and_apply(Application_Links *app, Arena *out_arena, Config_Data *con change_mode(app, config->mode); global_set_setting(app, GlobalSetting_LAltLCtrlIsAltGr, config->lalt_lctrl_is_altgr); - // TODO(allen): -#if 0 - change_theme(app, config->default_theme_name.str, config->default_theme_name.size); - #endif - + Color_Table *colors = get_color_table_by_name(config->default_theme_name); + set_active_color(colors); + Face_Description description = {}; if (override_font_size != 0){ description.parameters.pt_size = override_font_size; diff --git a/custom/4coder_default_colors.cpp b/custom/4coder_default_colors.cpp index 7e9bdd53..e0820dd9 100644 --- a/custom/4coder_default_colors.cpp +++ b/custom/4coder_default_colors.cpp @@ -156,6 +156,13 @@ set_default_color_scheme(Application_Links *app){ //////////////////////////////// +function void +set_active_color(Color_Table *table){ + if (table != 0){ + active_color_table = *table; + } +} + function void save_theme(Color_Table table, String_Const_u8 name){ Color_Table_Node *node = push_array(&global_theme_arena, Color_Table_Node, 1); @@ -165,4 +172,20 @@ save_theme(Color_Table table, String_Const_u8 name){ node->table = table; } +//////////////////////////////// + +function Color_Table* +get_color_table_by_name(String_Const_u8 name){ + Color_Table *result = 0; + for (Color_Table_Node *node = global_theme_list.first; + node != 0; + node = node->next){ + if (string_match(node->name, name)){ + result = &node->table; + break; + } + } + return(result); +} + // BOTTOM diff --git a/custom/4coder_default_hooks.cpp b/custom/4coder_default_hooks.cpp index 76c0db40..38ce6ea3 100644 --- a/custom/4coder_default_hooks.cpp +++ b/custom/4coder_default_hooks.cpp @@ -11,12 +11,12 @@ CUSTOM_DOC("Default command for responding to a startup event") User_Input input = get_current_input(app); if (match_core_code(&input, CoreCode_Startup)){ String_Const_u8_Array file_names = input.event.core.file_names; + load_themes_default_folder(app); default_4coder_initialize(app, file_names); default_4coder_side_by_side_panels(app, file_names); if (global_config.automatically_load_project){ load_project(app); } - load_themes_default_folder(app); } } @@ -932,8 +932,44 @@ BUFFER_HOOK_SIG(default_begin_buffer){ } BUFFER_HOOK_SIG(default_new_file){ - // buffer_id - // no meaning for return + Scratch_Block scratch(app); + String_Const_u8 file_name = push_buffer_base_name(app, scratch, buffer_id); + if (!string_match(string_postfix(file_name, 2), string_u8_litexpr(".h"))) { + return(0); + } + + List_String_Const_u8 guard_list = {}; + for (u64 i = 0; i < file_name.size; ++i){ + u8 c[2] = {}; + u64 c_size = 1; + u8 ch = file_name.str[i]; + if (ch == '.'){ + c[0] = '_'; + } + else if (ch >= 'A' && ch <= 'Z'){ + c_size = 2; + c[0] = '_'; + c[1] = ch; + } + else if (ch >= 'a' && ch <= 'z'){ + c[0] = ch - ('a' - 'A'); + } + String_Const_u8 part = push_string_copy(scratch, SCu8(c, c_size)); + string_list_push(scratch, &guard_list, part); + } + String_Const_u8 guard = string_list_flatten(scratch, guard_list); + + Buffer_Insertion insert = begin_buffer_insertion_at_buffered(app, buffer_id, 0, scratch, KB(16)); + insertf(&insert, + "#ifndef %.*s\n" + "#define %.*s\n" + "\n" + "#endif //%.*s\n", + string_expand(guard), + string_expand(guard), + string_expand(guard)); + end_buffer_insertion(&insert); + return(0); } diff --git a/custom/4coder_insertion.cpp b/custom/4coder_insertion.cpp index e548aa29..2d250954 100644 --- a/custom/4coder_insertion.cpp +++ b/custom/4coder_insertion.cpp @@ -44,7 +44,7 @@ insert_string__no_buffering(Buffer_Insertion *insertion, String_Const_u8 string) insertion->at += string.size; } -static void +function void insert__flush(Buffer_Insertion *insertion){ Cursor *cursor = insertion->cursor; u64 pos = insertion->temp.temp_memory_cursor.pos; @@ -53,7 +53,7 @@ insert__flush(Buffer_Insertion *insertion){ end_temp(insertion->temp); } -static char* +function char* insert__reserve(Buffer_Insertion *insertion, u64 size){ char *space = push_array(insertion->cursor, char, size); if (space == 0){ @@ -63,14 +63,14 @@ insert__reserve(Buffer_Insertion *insertion, u64 size){ return(space); } -static void +function void end_buffer_insertion(Buffer_Insertion *insertion){ if (insertion->buffering){ insert__flush(insertion); } } -static void +function void insert_string(Buffer_Insertion *insertion, String_Const_u8 string){ if (!insertion->buffering){ insert_string__no_buffering(insertion, string); @@ -86,7 +86,7 @@ insert_string(Buffer_Insertion *insertion, String_Const_u8 string){ } } -static u64 +function u64 insertf(Buffer_Insertion *insertion, char *format, ...){ Scratch_Block scratch(insertion->app); va_list args; @@ -97,12 +97,12 @@ insertf(Buffer_Insertion *insertion, char *format, ...){ return(string.size); } -static void +function void insertc(Buffer_Insertion *insertion, char C){ insert_string(insertion, SCu8(&C, 1)); } -static b32 +function b32 insert_line_from_buffer(Buffer_Insertion *insertion, Buffer_ID buffer_id, i32 line, i32 truncate_at){ b32 success = is_valid_line(insertion->app, buffer_id, line); if (success){ @@ -112,7 +112,7 @@ insert_line_from_buffer(Buffer_Insertion *insertion, Buffer_ID buffer_id, i32 li return(success); } -static b32 +function b32 insert_line_from_buffer(Buffer_Insertion *insertion, Buffer_ID buffer_id, i32 line){ return(insert_line_from_buffer(insertion, buffer_id, line, 0)); }