From c3e96803d26aee9e679560ea61b82889c227b5de Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Tue, 17 Dec 2019 00:11:31 -0800 Subject: [PATCH] Partial setup for binding documentations --- 4ed_app_target.cpp | 1 + custom/4coder_command_map.cpp | 180 +++++++++++++++++----------- custom/4coder_command_map.h | 84 +++++++++++++ custom/4coder_default_bindings.cpp | 154 +----------------------- custom/4coder_default_include.cpp | 1 + custom/4coder_default_map.cpp | 159 ++++++++++++++++++++++++ custom/4coder_doc_commands.cpp | 143 ++++++++++++++++++++++ custom/4coder_doc_content_types.cpp | 16 ++- custom/4coder_types.h | 71 +---------- site/4ed_site_render_main.cpp | 18 +++ 10 files changed, 537 insertions(+), 290 deletions(-) create mode 100644 custom/4coder_command_map.h create mode 100644 custom/4coder_default_map.cpp diff --git a/4ed_app_target.cpp b/4ed_app_target.cpp index 90e4528e..16e980de 100644 --- a/4ed_app_target.cpp +++ b/4ed_app_target.cpp @@ -34,6 +34,7 @@ #include "generated/font_api.h" #include "4coder_profile.h" +#include "4coder_command_map.h" #include "4ed_render_target.h" #include "4ed.h" diff --git a/custom/4coder_command_map.cpp b/custom/4coder_command_map.cpp index e8d19b15..d2114d07 100644 --- a/custom/4coder_command_map.cpp +++ b/custom/4coder_command_map.cpp @@ -1,14 +1,35 @@ /* - * Mr. 4th Dimention - Allen Webster - * - * 19.08.2015 - * - * Command management functions - * - */ +4coder_command_map.cpp - Command management functions +*/ // TOP +#if !defined(MAP_METADATA_ONLY) +#define MAP_METADATA_ONLY 0 +#endif + +#if MAP_METADATA_ONLY +#define BindingGetPtr(b) ((b).name) +#else +#define BindingGetPtr(b) ((b).custom) +#endif + +Command_Binding::Command_Binding(){ + block_zero_struct(this); +} +Command_Binding::Command_Binding(Custom_Command_Function *c){ + this->custom = c; +} +Command_Binding::Command_Binding(char *n){ + this->name = n; +} +Command_Binding::operator Custom_Command_Function*(){ + return(this->custom); +} +Command_Binding::operator char*(){ + return(this->name); +} + function u64 mapping__key(Input_Event_Kind kind, u32 sub_code){ return((((u64)kind) << 32) | sub_code); @@ -23,11 +44,13 @@ mapping__alloc_map(Mapping *mapping){ else{ result = push_array(mapping->node_arena, Command_Map, 1); } + zdll_push_back(mapping->first_map, mapping->last_map, result); return(result); } function void mapping__free_map(Mapping *mapping, Command_Map *map){ + zdll_remove(mapping->first_map, mapping->last_map, map); sll_stack_push(mapping->free_maps, map); } @@ -295,10 +318,9 @@ map_null_parent(Command_Map *map){ } function void -map__command_add_trigger(Command_Map *map, Custom_Command_Function *custom, - Command_Trigger *trigger){ +map__command_add_trigger(Command_Map *map, Command_Binding binding, Command_Trigger *trigger){ if (map != 0){ - u64 key = (u64)(PtrAsInt(custom)); + u64 key = (u64)(PtrAsInt(BindingGetPtr(binding))); Table_Lookup lookup = table_lookup(&map->cmd_to_binding_trigger, key); Command_Trigger_List *list = 0; if (!lookup.found_match){ @@ -357,10 +379,10 @@ map_trigger_as_event(Command_Trigger *trigger){ } function Command_Trigger_List -map_get_triggers_non_recursive(Mapping *mapping, Command_Map *map, Custom_Command_Function *custom){ +map_get_triggers_non_recursive(Mapping *mapping, Command_Map *map, Command_Binding binding){ Command_Trigger_List *result_ptr = 0; if (map != 0){ - u64 key = (u64)(PtrAsInt(custom)); + u64 key = (u64)(PtrAsInt(BindingGetPtr(binding))); Table_Lookup lookup = table_lookup(&map->cmd_to_binding_trigger, key); if (lookup.found_match){ u64 val = 0; @@ -373,14 +395,14 @@ map_get_triggers_non_recursive(Mapping *mapping, Command_Map *map, Custom_Comman node = next){ next = node->next; Input_Event event = map_trigger_as_event(node); - Command_Binding binding = {}; + Command_Binding this_binding = {}; if (mapping != 0){ - binding = map_get_binding_recursive(mapping, map, &event); + this_binding = map_get_binding_recursive(mapping, map, &event); } else{ - binding = map_get_binding_non_recursive(map, &event); + this_binding = map_get_binding_non_recursive(map, &event); } - if (binding.custom == custom){ + if (BindingGetPtr(this_binding) == BindingGetPtr(binding)){ sll_queue_push(list.first, list.last, node); } } @@ -395,18 +417,18 @@ map_get_triggers_non_recursive(Mapping *mapping, Command_Map *map, Custom_Comman } function Command_Trigger_List -map_get_triggers_non_recursive(Command_Map *map, Custom_Command_Function *custom){ - return(map_get_triggers_non_recursive(0, map, custom)); +map_get_triggers_non_recursive(Command_Map *map, Command_Binding binding){ + return(map_get_triggers_non_recursive(0, map, binding)); } function Command_Trigger_List -map_get_triggers_recursive(Arena *arena, Mapping *mapping, Command_Map *map, Custom_Command_Function *custom){ +map_get_triggers_recursive(Arena *arena, Mapping *mapping, Command_Map *map, Command_Binding binding){ Command_Trigger_List result = {}; if (mapping != 0){ for (i32 safety_counter = 0; map != 0 && safety_counter < 40; safety_counter += 1){ - Command_Trigger_List list = map_get_triggers_non_recursive(mapping, map, custom); + Command_Trigger_List list = map_get_triggers_non_recursive(mapping, map, binding); for (Command_Trigger *node = list.first, *next = 0; node != 0; @@ -455,7 +477,7 @@ map_get_binding_list_on_core(Command_Map *map, Core_Code code){ //////////////////////////////// function void -map_set_binding(Mapping *mapping, Command_Map *map, Custom_Command_Function *custom, u32 code1, u32 code2, Input_Modifier_Set *mods){ +map_set_binding(Mapping *mapping, Command_Map *map, Command_Binding binding, u32 code1, u32 code2, Input_Modifier_Set *mods){ if (map != 0){ u64 key = mapping__key(code1, code2); Command_Binding_List *list = map__get_or_make_list(mapping, map, key); @@ -470,38 +492,38 @@ map_set_binding(Mapping *mapping, Command_Map *map, Custom_Command_Function *cus } list->count += 1; mod_binding->mods = copy_modifier_set(&map->node_arena, mods); - mod_binding->binding.custom = custom; + mod_binding->binding = binding; Command_Trigger trigger = {}; trigger.kind = code1; trigger.sub_code = code2; trigger.mods = mod_binding->mods; - map__command_add_trigger(map, custom, &trigger); + map__command_add_trigger(map, binding, &trigger); } } function void -map_set_binding_key(Mapping *mapping, Command_Map *map, Custom_Command_Function *custom, Key_Code code, Input_Modifier_Set *modifiers){ - map_set_binding(mapping, map, custom, InputEventKind_KeyStroke, code, modifiers); +map_set_binding_key(Mapping *mapping, Command_Map *map, Command_Binding binding, Key_Code code, Input_Modifier_Set *modifiers){ + map_set_binding(mapping, map, binding, InputEventKind_KeyStroke, code, modifiers); } function void -map_set_binding_mouse(Mapping *mapping, Command_Map *map, Custom_Command_Function *custom, Mouse_Code code, Input_Modifier_Set *modifiers){ - map_set_binding(mapping, map, custom, InputEventKind_MouseButton, code, modifiers); +map_set_binding_mouse(Mapping *mapping, Command_Map *map, Command_Binding binding, Mouse_Code code, Input_Modifier_Set *modifiers){ + map_set_binding(mapping, map, binding, InputEventKind_MouseButton, code, modifiers); } function void -map_set_binding_core(Mapping *mapping, Command_Map *map, Custom_Command_Function *custom, Core_Code code, Input_Modifier_Set *modifiers){ - map_set_binding(mapping, map, custom, InputEventKind_Core, code, modifiers); +map_set_binding_core(Mapping *mapping, Command_Map *map, Command_Binding binding, Core_Code code, Input_Modifier_Set *modifiers){ + map_set_binding(mapping, map, binding, InputEventKind_Core, code, modifiers); } function void -map_set_binding_text_input(Command_Map *map, Custom_Command_Function *custom){ +map_set_binding_text_input(Command_Map *map, Command_Binding binding){ if (map != 0){ - map->text_input_command.custom = custom; + map->text_input_command = binding; Command_Trigger trigger = {}; trigger.kind = InputEventKind_TextInsert; - map__command_add_trigger(map, custom, &trigger); + map__command_add_trigger(map, binding, &trigger); } } @@ -526,15 +548,15 @@ map_get_binding_recursive(Mapping *mapping, Command_Map_ID map_id, Input_Event * } function Command_Trigger_List -map_get_triggers_non_recursive(Mapping *mapping, Command_Map_ID map_id, Custom_Command_Function *custom){ +map_get_triggers_non_recursive(Mapping *mapping, Command_Map_ID map_id, Command_Binding binding){ Command_Map *map = mapping_get_map(mapping, map_id); - return(map_get_triggers_non_recursive(map, custom)); + return(map_get_triggers_non_recursive(map, binding)); } function Command_Trigger_List -map_get_triggers_recursive(Arena *arena, Mapping *mapping, Command_Map_ID map_id, Custom_Command_Function *custom){ +map_get_triggers_recursive(Arena *arena, Mapping *mapping, Command_Map_ID map_id, Command_Binding binding){ Command_Map *map = mapping_get_map(mapping, map_id); - return(map_get_triggers_recursive(arena, mapping, map, custom)); + return(map_get_triggers_recursive(arena, mapping, map, binding)); } function void @@ -557,37 +579,37 @@ map_null_parent(Mapping *mapping, Command_Map_ID map_id){ } function void -map_set_binding(Mapping *mapping, Command_Map_ID map_id, Custom_Command_Function *custom, +map_set_binding(Mapping *mapping, Command_Map_ID map_id, Command_Binding binding, u32 code1, u32 code2, Input_Modifier_Set *modifiers){ Command_Map *map = mapping_get_map(mapping, map_id); - map_set_binding(mapping, map, custom, code1, code2, modifiers); + map_set_binding(mapping, map, binding, code1, code2, modifiers); } function void -map_set_binding_key(Mapping *mapping, Command_Map_ID map_id, Custom_Command_Function *custom, +map_set_binding_key(Mapping *mapping, Command_Map_ID map_id, Command_Binding binding, Key_Code code, Input_Modifier_Set *modifiers){ Command_Map *map = mapping_get_map(mapping, map_id); - map_set_binding_key(mapping, map, custom, code, modifiers); + map_set_binding_key(mapping, map, binding, code, modifiers); } function void -map_set_binding_mouse(Mapping *mapping, Command_Map_ID map_id, Custom_Command_Function *custom, +map_set_binding_mouse(Mapping *mapping, Command_Map_ID map_id, Command_Binding binding, Mouse_Code code, Input_Modifier_Set *modifiers){ Command_Map *map = mapping_get_map(mapping, map_id); - map_set_binding_mouse(mapping, map, custom, code, modifiers); + map_set_binding_mouse(mapping, map, binding, code, modifiers); } function void -map_set_binding_core(Mapping *mapping, Command_Map_ID map_id, Custom_Command_Function *custom, +map_set_binding_core(Mapping *mapping, Command_Map_ID map_id, Command_Binding binding, Core_Code code, Input_Modifier_Set *modifiers){ Command_Map *map = mapping_get_map(mapping, map_id); - map_set_binding_core(mapping, map, custom, code, modifiers); + map_set_binding_core(mapping, map, binding, code, modifiers); } function void -map_set_binding_text_input(Mapping *mapping, Command_Map_ID map_id, Custom_Command_Function *custom){ +map_set_binding_text_input(Mapping *mapping, Command_Map_ID map_id, Command_Binding binding){ Command_Map *map = mapping_get_map(mapping, map_id); - map_set_binding_text_input(map, custom); + map_set_binding_text_input(map, binding); } //////////////////////////////// @@ -667,7 +689,7 @@ command_trigger_stringize(Arena *arena, List_String_Const_u8 *list, Command_Trig function void map_set_binding_lv(Mapping *mapping, Command_Map *map, - Custom_Command_Function *custom, u32 code1, u32 code2, va_list args){ + Command_Binding binding, u32 code1, u32 code2, va_list args){ Input_Modifier_Set mods = {}; Key_Code mods_array[Input_MaxModifierCount]; mods.mods = mods_array; @@ -679,53 +701,77 @@ map_set_binding_lv(Mapping *mapping, Command_Map *map, mods.mods[mods.count] = v; mods.count += 1; } - return(map_set_binding(mapping, map, custom, code1, code2, &mods)); + return(map_set_binding(mapping, map, binding, code1, code2, &mods)); } + +#if MAP_METADATA_ONLY function void -map_set_binding_l(Mapping *mapping, Command_Map *map, - Custom_Command_Function *custom, u32 code1, u32 code2, ...){ +map_set_binding_l(Mapping *mapping, Command_Map *map, char *name, u32 code1, u32 code2, ...){ va_list args; va_start(args, code2); - map_set_binding_lv(mapping, map, custom, code1, code2, args); + Command_Binding binding = {}; + binding.name = name; + map_set_binding_lv(mapping, map, binding, code1, code2, args); va_end(args); } +#else +function void +map_set_binding_l(Mapping *mapping, Command_Map *map, Custom_Command_Function *custom, u32 code1, u32 code2, ...){ + va_list args; + va_start(args, code2); + Command_Binding binding = {}; + binding.custom = custom; + map_set_binding_lv(mapping, map, binding, code1, code2, args); + va_end(args); +} +#endif + +#if MAP_METADATA_ONLY +# define BindFWrap_(F) stringify(F) +#else +# define BindFWrap_(F) F +#endif #define MappingScope() Mapping *m = 0; Command_Map *map = 0 #define SelectMapping(N) m = (N) #define SelectMap(ID) map = mapping_get_or_make_map(m, (ID)) #define ParentMap(ID) map_set_parent(m, map, (ID)) -#define BindTextInput(F) map_set_binding_text_input(map, (F)) -// TODO(allen): detect compiler and apply va args extensions correctly +#define BindTextInput(F) map_set_binding_text_input(map, BindFWrap_(F)) + #if COMPILER_CL + #define Bind(F, K, ...) \ -map_set_binding_l(m, map, (F), InputEventKind_KeyStroke, (K), __VA_ARGS__, 0) +map_set_binding_l(m, map, BindFWrap_(F), InputEventKind_KeyStroke, (K), __VA_ARGS__, 0) #define BindRelease(F, K, ...) \ -map_set_binding_l(m, map, (F), InputEventKind_KeyRelease, (K), __VA_ARGS__, 0) +map_set_binding_l(m, map, BindFWrap_(F), InputEventKind_KeyRelease, (K), __VA_ARGS__, 0) #define BindMouse(F, K, ...) \ -map_set_binding_l(m, map, (F), InputEventKind_MouseButton, (K), __VA_ARGS__, 0) +map_set_binding_l(m, map, BindFWrap_(F), InputEventKind_MouseButton, (K), __VA_ARGS__, 0) #define BindMouseRelease(F, K, ...) \ -map_set_binding_l(m, map, (F), InputEventKind_MouseButtonRelease, (K), __VA_ARGS__, 0) +map_set_binding_l(m, map, BindFWrap_(F), InputEventKind_MouseButtonRelease, (K), __VA_ARGS__, 0) #define BindMouseWheel(F, ...) \ -map_set_binding_l(m, map, (F), InputEventKind_MouseWheel, 0, __VA_ARGS__, 0) +map_set_binding_l(m, map, BindFWrap_(F), InputEventKind_MouseWheel, 0, __VA_ARGS__, 0) #define BindMouseMove(F, ...) \ -map_set_binding_l(m, map, (F), InputEventKind_MouseMove, 0, __VA_ARGS__, 0) +map_set_binding_l(m, map, BindFWrap_(F), InputEventKind_MouseMove, 0, __VA_ARGS__, 0) #define BindCore(F, K, ...) \ -map_set_binding_l(m, map, (F), InputEventKind_Core, (K), __VA_ARGS__, 0) +map_set_binding_l(m, map, BindFWrap_(F), InputEventKind_Core, (K), __VA_ARGS__, 0) + #elif COMPILER_GCC + #define Bind(F, K, ...) \ -map_set_binding_l(m, map, (F), InputEventKind_KeyStroke, (K), ##__VA_ARGS__, 0) +map_set_binding_l(m, map, BindFWrap_(F), InputEventKind_KeyStroke, (K), ##__VA_ARGS__, 0) #define BindRelease(F, K, ...) \ -map_set_binding_l(m, map, (F), InputEventKind_KeyRelease, (K), ##__VA_ARGS__, 0) +map_set_binding_l(m, map, BindFWrap_(F), InputEventKind_KeyRelease, (K), ##__VA_ARGS__, 0) #define BindMouse(F, K, ...) \ -map_set_binding_l(m, map, (F), InputEventKind_MouseButton, (K), ##__VA_ARGS__, 0) +map_set_binding_l(m, map, BindFWrap_(F), InputEventKind_MouseButton, (K), ##__VA_ARGS__, 0) #define BindMouseRelease(F, K, ...) \ -map_set_binding_l(m, map, (F), InputEventKind_MouseButtonRelease, (K), ##__VA_ARGS__, 0) +map_set_binding_l(m, map, BindFWrap_(F), InputEventKind_MouseButtonRelease, (K), ##__VA_ARGS__, 0) #define BindMouseWheel(F, ...) \ -map_set_binding_l(m, map, (F), InputEventKind_MouseWheel, 0, ##__VA_ARGS__, 0) +map_set_binding_l(m, map, BindFWrap_(F), InputEventKind_MouseWheel, 0, ##__VA_ARGS__, 0) #define BindMouseMove(F, ...) \ -map_set_binding_l(m, map, (F), InputEventKind_MouseMove, 0, ##__VA_ARGS__, 0) +map_set_binding_l(m, map, BindFWrap_(F), InputEventKind_MouseMove, 0, ##__VA_ARGS__, 0) #define BindCore(F, K, ...) \ -map_set_binding_l(m, map, (F), InputEventKind_Core, (K), ##__VA_ARGS__, 0) +map_set_binding_l(m, map, BindFWrap_(F), InputEventKind_Core, (K), ##__VA_ARGS__, 0) + #else #error "Unsupported compiler" #endif diff --git a/custom/4coder_command_map.h b/custom/4coder_command_map.h new file mode 100644 index 00000000..d6ad7a96 --- /dev/null +++ b/custom/4coder_command_map.h @@ -0,0 +1,84 @@ +/* +4coder_command_map.h - Command management types +*/ + +// TOP + +#if !defined(FCODER_CODEPOINT_MAP_H) +#define FCODER_CODEPOINT_MAP_H + +typedef i64 Command_Map_ID; + +struct Command_Trigger{ + Command_Trigger *next; + Input_Event_Kind kind; + u32 sub_code; + Input_Modifier_Set mods; +}; + +struct Command_Trigger_List{ + Command_Trigger *first; + Command_Trigger *last; +}; + +struct Command_Binding{ + union{ + Custom_Command_Function *custom; + char *name; + }; + + Command_Binding(); + Command_Binding(Custom_Command_Function *c); + Command_Binding(char *n); + + operator Custom_Command_Function*(); + operator char*(); +}; + +struct Command_Modified_Binding{ + Command_Modified_Binding *next; + SNode order_node; + Input_Modifier_Set mods; + Command_Binding binding; +}; + +struct Command_Binding_List{ + Command_Binding_List *next; + SNode *first; + SNode *last; + i32 count; +}; + +struct Command_Map{ + Command_Map *next; + Command_Map *prev; + Command_Map_ID id; + Command_Map_ID parent; + Command_Binding text_input_command; + Arena node_arena; + Table_u64_u64 event_code_to_binding_list; + Table_u64_u64 cmd_to_binding_trigger; + Command_Modified_Binding *binding_first; + Command_Modified_Binding *binding_last; + Command_Binding_List *list_first; + Command_Binding_List *list_last; + + struct Binding_Unit *real_beginning; +}; + +struct Mapping{ + Arena *node_arena; + Heap heap; + Base_Allocator heap_wrapper; + Table_u64_u64 id_to_map; + Command_Map_ID id_counter; + Command_Map *first_map; + Command_Map *last_map; + Command_Map *free_maps; + Command_Modified_Binding *free_bindings; + Command_Binding_List *free_lists; +}; + +#endif + +// BOTTOM \ No newline at end of file diff --git a/custom/4coder_default_bindings.cpp b/custom/4coder_default_bindings.cpp index cea79da5..8d926fa4 100644 --- a/custom/4coder_default_bindings.cpp +++ b/custom/4coder_default_bindings.cpp @@ -8,157 +8,7 @@ #define FCODER_DEFAULT_BINDINGS_CPP #include "4coder_default_include.cpp" - -function void -setup_default_mapping(Mapping *mapping){ - MappingScope(); - SelectMapping(mapping); - - SelectMap(mapid_global); - BindCore(default_startup, CoreCode_Startup); - BindCore(default_try_exit, CoreCode_TryExit); - Bind(keyboard_macro_start_recording , KeyCode_U, KeyCode_Control); - Bind(keyboard_macro_finish_recording, KeyCode_U, KeyCode_Control, KeyCode_Shift); - Bind(keyboard_macro_replay, KeyCode_U, KeyCode_Alt); - Bind(change_active_panel, KeyCode_Comma, KeyCode_Control); - Bind(change_active_panel_backwards, KeyCode_Comma, KeyCode_Control, KeyCode_Shift); - Bind(interactive_new, KeyCode_N, KeyCode_Control); - Bind(interactive_open_or_new, KeyCode_O, KeyCode_Control); - Bind(open_in_other, KeyCode_O, KeyCode_Alt); - Bind(interactive_kill_buffer, KeyCode_K, KeyCode_Control); - Bind(interactive_switch_buffer, KeyCode_I, KeyCode_Control); - Bind(project_go_to_root_directory, KeyCode_H, KeyCode_Control); - Bind(save_all_dirty_buffers, KeyCode_S, KeyCode_Control, KeyCode_Shift); - Bind(change_to_build_panel, KeyCode_Period, KeyCode_Alt); - Bind(close_build_panel, KeyCode_Comma, KeyCode_Alt); - Bind(goto_next_jump, KeyCode_N, KeyCode_Alt); - Bind(goto_prev_jump, KeyCode_N, KeyCode_Alt, KeyCode_Shift); - Bind(build_in_build_panel, KeyCode_M, KeyCode_Alt); - Bind(goto_first_jump, KeyCode_M, KeyCode_Alt, KeyCode_Shift); - Bind(toggle_filebar, KeyCode_B, KeyCode_Alt); - Bind(execute_any_cli, KeyCode_Z, KeyCode_Alt); - Bind(execute_previous_cli, KeyCode_Z, KeyCode_Alt, KeyCode_Shift); - Bind(command_lister, KeyCode_X, KeyCode_Alt); - Bind(project_command_lister, KeyCode_X, KeyCode_Alt, KeyCode_Shift); - Bind(list_all_functions_current_buffer, KeyCode_I, KeyCode_Control, KeyCode_Shift); - Bind(project_fkey_command, KeyCode_F1); - Bind(project_fkey_command, KeyCode_F2); - Bind(project_fkey_command, KeyCode_F3); - Bind(project_fkey_command, KeyCode_F4); - Bind(project_fkey_command, KeyCode_F5); - Bind(project_fkey_command, KeyCode_F6); - Bind(project_fkey_command, KeyCode_F7); - Bind(project_fkey_command, KeyCode_F8); - Bind(project_fkey_command, KeyCode_F9); - Bind(project_fkey_command, KeyCode_F10); - Bind(project_fkey_command, KeyCode_F11); - Bind(project_fkey_command, KeyCode_F12); - Bind(project_fkey_command, KeyCode_F13); - Bind(project_fkey_command, KeyCode_F14); - Bind(project_fkey_command, KeyCode_F15); - Bind(project_fkey_command, KeyCode_F16); - Bind(exit_4coder, KeyCode_F4, KeyCode_Alt); - BindMouseWheel(mouse_wheel_scroll); - BindMouseWheel(mouse_wheel_change_face_size, KeyCode_Control); - - SelectMap(mapid_file); - ParentMap(mapid_global); - BindTextInput(write_text_input); - BindMouse(click_set_cursor_and_mark, MouseCode_Left); - BindMouseRelease(click_set_cursor, MouseCode_Left); - BindCore(click_set_cursor_and_mark, CoreCode_ClickActivateView); - BindMouseMove(click_set_cursor_if_lbutton); - Bind(delete_char, KeyCode_Delete); - Bind(backspace_char, KeyCode_Backspace); - Bind(move_up, KeyCode_Up); - Bind(move_down, KeyCode_Down); - Bind(move_left, KeyCode_Left); - Bind(move_right, KeyCode_Right); - Bind(seek_end_of_line, KeyCode_End); - Bind(seek_beginning_of_line, KeyCode_Home); - Bind(page_up, KeyCode_PageUp); - Bind(page_down, KeyCode_PageDown); - Bind(goto_beginning_of_file, KeyCode_PageUp, KeyCode_Control); - Bind(goto_end_of_file, KeyCode_PageDown, KeyCode_Control); - Bind(move_up_to_blank_line_end, KeyCode_Up, KeyCode_Control); - Bind(move_down_to_blank_line_end, KeyCode_Down, KeyCode_Control); - Bind(move_left_whitespace_boundary, KeyCode_Left, KeyCode_Control); - Bind(move_right_whitespace_boundary, KeyCode_Right, KeyCode_Control); - Bind(move_line_up, KeyCode_Up, KeyCode_Alt); - Bind(move_line_down, KeyCode_Down, KeyCode_Alt); - Bind(backspace_alpha_numeric_boundary, KeyCode_Backspace, KeyCode_Control); - Bind(delete_alpha_numeric_boundary, KeyCode_Delete, KeyCode_Control); - Bind(snipe_backward_whitespace_or_token_boundary, KeyCode_Backspace, KeyCode_Alt); - Bind(snipe_forward_whitespace_or_token_boundary, KeyCode_Delete, KeyCode_Alt); - Bind(set_mark, KeyCode_Space, KeyCode_Control); - Bind(replace_in_range, KeyCode_A, KeyCode_Control); - Bind(copy, KeyCode_C, KeyCode_Control); - Bind(delete_range, KeyCode_D, KeyCode_Control); - Bind(delete_line, KeyCode_D, KeyCode_Control, KeyCode_Shift); - Bind(center_view, KeyCode_E, KeyCode_Control); - Bind(left_adjust_view, KeyCode_E, KeyCode_Control, KeyCode_Shift); - Bind(search, KeyCode_F, KeyCode_Control); - Bind(list_all_locations, KeyCode_F, KeyCode_Control, KeyCode_Shift); - Bind(list_all_substring_locations_case_insensitive, KeyCode_F, KeyCode_Alt); - Bind(goto_line, KeyCode_G, KeyCode_Control); - Bind(list_all_locations_of_selection, KeyCode_G, KeyCode_Control, KeyCode_Shift); - Bind(snippet_lister, KeyCode_J, KeyCode_Control); - Bind(kill_buffer, KeyCode_K, KeyCode_Control, KeyCode_Shift); - Bind(duplicate_line, KeyCode_L, KeyCode_Control); - Bind(cursor_mark_swap, KeyCode_M, KeyCode_Control); - Bind(reopen, KeyCode_O, KeyCode_Control, KeyCode_Shift); - Bind(query_replace, KeyCode_Q, KeyCode_Control); - Bind(query_replace_identifier, KeyCode_Q, KeyCode_Control, KeyCode_Shift); - Bind(query_replace_selection, KeyCode_Q, KeyCode_Alt); - Bind(reverse_search, KeyCode_R, KeyCode_Control); - Bind(save, KeyCode_S, KeyCode_Control); - Bind(save_all_dirty_buffers, KeyCode_S, KeyCode_Control, KeyCode_Shift); - Bind(search_identifier, KeyCode_T, KeyCode_Control); - Bind(list_all_locations_of_identifier, KeyCode_T, KeyCode_Control, KeyCode_Shift); - Bind(paste_and_indent, KeyCode_V, KeyCode_Control); - Bind(paste_next_and_indent, KeyCode_V, KeyCode_Control, KeyCode_Shift); - Bind(cut, KeyCode_X, KeyCode_Control); - Bind(redo, KeyCode_Y, KeyCode_Control); - Bind(undo, KeyCode_Z, KeyCode_Control); - Bind(view_buffer_other_panel, KeyCode_1, KeyCode_Control); - Bind(swap_panels, KeyCode_2, KeyCode_Control); - Bind(if_read_only_goto_position, KeyCode_Return); - Bind(if_read_only_goto_position_same_panel, KeyCode_Return, KeyCode_Shift); - Bind(view_jump_list_with_lister, KeyCode_Period, KeyCode_Control, KeyCode_Shift); - - SelectMap(mapid_code); - ParentMap(mapid_file); - BindTextInput(write_text_and_auto_indent); - Bind(move_left_alpha_numeric_boundary, KeyCode_Left, KeyCode_Control); - Bind(move_right_alpha_numeric_boundary, KeyCode_Right, KeyCode_Control); - Bind(move_left_alpha_numeric_or_camel_boundary, KeyCode_Left, KeyCode_Alt); - Bind(move_right_alpha_numeric_or_camel_boundary, KeyCode_Right, KeyCode_Alt); - Bind(comment_line_toggle, KeyCode_Semicolon, KeyCode_Control); - Bind(word_complete, KeyCode_Tab); - Bind(auto_indent_range, KeyCode_Tab, KeyCode_Control); - Bind(auto_indent_line_at_cursor, KeyCode_Tab, KeyCode_Shift); - Bind(word_complete_drop_down, KeyCode_Tab, KeyCode_Shift, KeyCode_Control); - Bind(write_block, KeyCode_R, KeyCode_Alt); - Bind(write_todo, KeyCode_T, KeyCode_Alt); - Bind(write_note, KeyCode_Y, KeyCode_Alt); - Bind(list_all_locations_of_type_definition, KeyCode_D, KeyCode_Alt); - Bind(list_all_locations_of_type_definition_of_identifier, KeyCode_T, KeyCode_Alt, KeyCode_Shift); - Bind(open_long_braces, KeyCode_LeftBracket, KeyCode_Control); - Bind(open_long_braces_semicolon, KeyCode_LeftBracket, KeyCode_Control, KeyCode_Shift); - Bind(open_long_braces_break, KeyCode_RightBracket, KeyCode_Control, KeyCode_Shift); - Bind(select_surrounding_scope, KeyCode_LeftBracket, KeyCode_Alt); - Bind(select_surrounding_scope_maximal, KeyCode_LeftBracket, KeyCode_Alt, KeyCode_Shift); - Bind(select_prev_scope_absolute, KeyCode_RightBracket, KeyCode_Alt); - Bind(select_prev_top_most_scope, KeyCode_RightBracket, KeyCode_Alt, KeyCode_Shift); - Bind(select_next_scope_absolute, KeyCode_Quote, KeyCode_Alt); - Bind(select_next_scope_after_current, KeyCode_Quote, KeyCode_Alt, KeyCode_Shift); - Bind(place_in_scope, KeyCode_ForwardSlash, KeyCode_Alt); - Bind(delete_current_scope, KeyCode_Minus, KeyCode_Alt); - Bind(if0_off, KeyCode_I, KeyCode_Alt); - Bind(open_file_in_quotes, KeyCode_1, KeyCode_Alt); - Bind(open_matching_file_cpp, KeyCode_2, KeyCode_Alt); - Bind(write_zero_struct, KeyCode_0, KeyCode_Control); -} +#include "4coder_default_map.cpp" void custom_layer_init(Application_Links *app){ @@ -176,7 +26,7 @@ custom_layer_init(Application_Links *app){ // NOTE(allen): default hooks and command maps set_all_default_hooks(app); mapping_init(tctx, &framework_mapping); - setup_default_mapping(&framework_mapping); + setup_default_mapping(&framework_mapping, mapid_global, mapid_file, mapid_code); } #endif //FCODER_DEFAULT_BINDINGS diff --git a/custom/4coder_default_include.cpp b/custom/4coder_default_include.cpp index b428c2aa..929af268 100644 --- a/custom/4coder_default_include.cpp +++ b/custom/4coder_default_include.cpp @@ -31,6 +31,7 @@ #include "4coder_code_index.h" #include "4coder_draw.h" #include "4coder_insertion.h" +#include "4coder_command_map.h" #include "4coder_lister_base.h" #include "4coder_default_framework.h" #include "4coder_config.h" diff --git a/custom/4coder_default_map.cpp b/custom/4coder_default_map.cpp new file mode 100644 index 00000000..1717a299 --- /dev/null +++ b/custom/4coder_default_map.cpp @@ -0,0 +1,159 @@ +/* +4coder_default_map.cpp - Instantiate default bindings. +*/ + +// TOP + +function void +setup_default_mapping(Mapping *mapping, i64 global_id, i64 file_id, i64 code_id){ + MappingScope(); + SelectMapping(mapping); + + SelectMap(global_id); + BindCore(default_startup, CoreCode_Startup); + BindCore(default_try_exit, CoreCode_TryExit); + Bind(keyboard_macro_start_recording , KeyCode_U, KeyCode_Control); + Bind(keyboard_macro_finish_recording, KeyCode_U, KeyCode_Control, KeyCode_Shift); + Bind(keyboard_macro_replay, KeyCode_U, KeyCode_Alt); + Bind(change_active_panel, KeyCode_Comma, KeyCode_Control); + Bind(change_active_panel_backwards, KeyCode_Comma, KeyCode_Control, KeyCode_Shift); + Bind(interactive_new, KeyCode_N, KeyCode_Control); + Bind(interactive_open_or_new, KeyCode_O, KeyCode_Control); + Bind(open_in_other, KeyCode_O, KeyCode_Alt); + Bind(interactive_kill_buffer, KeyCode_K, KeyCode_Control); + Bind(interactive_switch_buffer, KeyCode_I, KeyCode_Control); + Bind(project_go_to_root_directory, KeyCode_H, KeyCode_Control); + Bind(save_all_dirty_buffers, KeyCode_S, KeyCode_Control, KeyCode_Shift); + Bind(change_to_build_panel, KeyCode_Period, KeyCode_Alt); + Bind(close_build_panel, KeyCode_Comma, KeyCode_Alt); + Bind(goto_next_jump, KeyCode_N, KeyCode_Alt); + Bind(goto_prev_jump, KeyCode_N, KeyCode_Alt, KeyCode_Shift); + Bind(build_in_build_panel, KeyCode_M, KeyCode_Alt); + Bind(goto_first_jump, KeyCode_M, KeyCode_Alt, KeyCode_Shift); + Bind(toggle_filebar, KeyCode_B, KeyCode_Alt); + Bind(execute_any_cli, KeyCode_Z, KeyCode_Alt); + Bind(execute_previous_cli, KeyCode_Z, KeyCode_Alt, KeyCode_Shift); + Bind(command_lister, KeyCode_X, KeyCode_Alt); + Bind(project_command_lister, KeyCode_X, KeyCode_Alt, KeyCode_Shift); + Bind(list_all_functions_current_buffer, KeyCode_I, KeyCode_Control, KeyCode_Shift); + Bind(project_fkey_command, KeyCode_F1); + Bind(project_fkey_command, KeyCode_F2); + Bind(project_fkey_command, KeyCode_F3); + Bind(project_fkey_command, KeyCode_F4); + Bind(project_fkey_command, KeyCode_F5); + Bind(project_fkey_command, KeyCode_F6); + Bind(project_fkey_command, KeyCode_F7); + Bind(project_fkey_command, KeyCode_F8); + Bind(project_fkey_command, KeyCode_F9); + Bind(project_fkey_command, KeyCode_F10); + Bind(project_fkey_command, KeyCode_F11); + Bind(project_fkey_command, KeyCode_F12); + Bind(project_fkey_command, KeyCode_F13); + Bind(project_fkey_command, KeyCode_F14); + Bind(project_fkey_command, KeyCode_F15); + Bind(project_fkey_command, KeyCode_F16); + Bind(exit_4coder, KeyCode_F4, KeyCode_Alt); + BindMouseWheel(mouse_wheel_scroll); + BindMouseWheel(mouse_wheel_change_face_size, KeyCode_Control); + + SelectMap(file_id); + ParentMap(global_id); + BindTextInput(write_text_input); + BindMouse(click_set_cursor_and_mark, MouseCode_Left); + BindMouseRelease(click_set_cursor, MouseCode_Left); + BindCore(click_set_cursor_and_mark, CoreCode_ClickActivateView); + BindMouseMove(click_set_cursor_if_lbutton); + Bind(delete_char, KeyCode_Delete); + Bind(backspace_char, KeyCode_Backspace); + Bind(move_up, KeyCode_Up); + Bind(move_down, KeyCode_Down); + Bind(move_left, KeyCode_Left); + Bind(move_right, KeyCode_Right); + Bind(seek_end_of_line, KeyCode_End); + Bind(seek_beginning_of_line, KeyCode_Home); + Bind(page_up, KeyCode_PageUp); + Bind(page_down, KeyCode_PageDown); + Bind(goto_beginning_of_file, KeyCode_PageUp, KeyCode_Control); + Bind(goto_end_of_file, KeyCode_PageDown, KeyCode_Control); + Bind(move_up_to_blank_line_end, KeyCode_Up, KeyCode_Control); + Bind(move_down_to_blank_line_end, KeyCode_Down, KeyCode_Control); + Bind(move_left_whitespace_boundary, KeyCode_Left, KeyCode_Control); + Bind(move_right_whitespace_boundary, KeyCode_Right, KeyCode_Control); + Bind(move_line_up, KeyCode_Up, KeyCode_Alt); + Bind(move_line_down, KeyCode_Down, KeyCode_Alt); + Bind(backspace_alpha_numeric_boundary, KeyCode_Backspace, KeyCode_Control); + Bind(delete_alpha_numeric_boundary, KeyCode_Delete, KeyCode_Control); + Bind(snipe_backward_whitespace_or_token_boundary, KeyCode_Backspace, KeyCode_Alt); + Bind(snipe_forward_whitespace_or_token_boundary, KeyCode_Delete, KeyCode_Alt); + Bind(set_mark, KeyCode_Space, KeyCode_Control); + Bind(replace_in_range, KeyCode_A, KeyCode_Control); + Bind(copy, KeyCode_C, KeyCode_Control); + Bind(delete_range, KeyCode_D, KeyCode_Control); + Bind(delete_line, KeyCode_D, KeyCode_Control, KeyCode_Shift); + Bind(center_view, KeyCode_E, KeyCode_Control); + Bind(left_adjust_view, KeyCode_E, KeyCode_Control, KeyCode_Shift); + Bind(search, KeyCode_F, KeyCode_Control); + Bind(list_all_locations, KeyCode_F, KeyCode_Control, KeyCode_Shift); + Bind(list_all_substring_locations_case_insensitive, KeyCode_F, KeyCode_Alt); + Bind(goto_line, KeyCode_G, KeyCode_Control); + Bind(list_all_locations_of_selection, KeyCode_G, KeyCode_Control, KeyCode_Shift); + Bind(snippet_lister, KeyCode_J, KeyCode_Control); + Bind(kill_buffer, KeyCode_K, KeyCode_Control, KeyCode_Shift); + Bind(duplicate_line, KeyCode_L, KeyCode_Control); + Bind(cursor_mark_swap, KeyCode_M, KeyCode_Control); + Bind(reopen, KeyCode_O, KeyCode_Control, KeyCode_Shift); + Bind(query_replace, KeyCode_Q, KeyCode_Control); + Bind(query_replace_identifier, KeyCode_Q, KeyCode_Control, KeyCode_Shift); + Bind(query_replace_selection, KeyCode_Q, KeyCode_Alt); + Bind(reverse_search, KeyCode_R, KeyCode_Control); + Bind(save, KeyCode_S, KeyCode_Control); + Bind(save_all_dirty_buffers, KeyCode_S, KeyCode_Control, KeyCode_Shift); + Bind(search_identifier, KeyCode_T, KeyCode_Control); + Bind(list_all_locations_of_identifier, KeyCode_T, KeyCode_Control, KeyCode_Shift); + Bind(paste_and_indent, KeyCode_V, KeyCode_Control); + Bind(paste_next_and_indent, KeyCode_V, KeyCode_Control, KeyCode_Shift); + Bind(cut, KeyCode_X, KeyCode_Control); + Bind(redo, KeyCode_Y, KeyCode_Control); + Bind(undo, KeyCode_Z, KeyCode_Control); + Bind(view_buffer_other_panel, KeyCode_1, KeyCode_Control); + Bind(swap_panels, KeyCode_2, KeyCode_Control); + Bind(if_read_only_goto_position, KeyCode_Return); + Bind(if_read_only_goto_position_same_panel, KeyCode_Return, KeyCode_Shift); + Bind(view_jump_list_with_lister, KeyCode_Period, KeyCode_Control, KeyCode_Shift); + + SelectMap(code_id); + ParentMap(file_id); + BindTextInput(write_text_and_auto_indent); + Bind(move_left_alpha_numeric_boundary, KeyCode_Left, KeyCode_Control); + Bind(move_right_alpha_numeric_boundary, KeyCode_Right, KeyCode_Control); + Bind(move_left_alpha_numeric_or_camel_boundary, KeyCode_Left, KeyCode_Alt); + Bind(move_right_alpha_numeric_or_camel_boundary, KeyCode_Right, KeyCode_Alt); + Bind(comment_line_toggle, KeyCode_Semicolon, KeyCode_Control); + Bind(word_complete, KeyCode_Tab); + Bind(auto_indent_range, KeyCode_Tab, KeyCode_Control); + Bind(auto_indent_line_at_cursor, KeyCode_Tab, KeyCode_Shift); + Bind(word_complete_drop_down, KeyCode_Tab, KeyCode_Shift, KeyCode_Control); + Bind(write_block, KeyCode_R, KeyCode_Alt); + Bind(write_todo, KeyCode_T, KeyCode_Alt); + Bind(write_note, KeyCode_Y, KeyCode_Alt); + Bind(list_all_locations_of_type_definition, KeyCode_D, KeyCode_Alt); + Bind(list_all_locations_of_type_definition_of_identifier, KeyCode_T, KeyCode_Alt, KeyCode_Shift); + Bind(open_long_braces, KeyCode_LeftBracket, KeyCode_Control); + Bind(open_long_braces_semicolon, KeyCode_LeftBracket, KeyCode_Control, KeyCode_Shift); + Bind(open_long_braces_break, KeyCode_RightBracket, KeyCode_Control, KeyCode_Shift); + Bind(select_surrounding_scope, KeyCode_LeftBracket, KeyCode_Alt); + Bind(select_surrounding_scope_maximal, KeyCode_LeftBracket, KeyCode_Alt, KeyCode_Shift); + Bind(select_prev_scope_absolute, KeyCode_RightBracket, KeyCode_Alt); + Bind(select_prev_top_most_scope, KeyCode_RightBracket, KeyCode_Alt, KeyCode_Shift); + Bind(select_next_scope_absolute, KeyCode_Quote, KeyCode_Alt); + Bind(select_next_scope_after_current, KeyCode_Quote, KeyCode_Alt, KeyCode_Shift); + Bind(place_in_scope, KeyCode_ForwardSlash, KeyCode_Alt); + Bind(delete_current_scope, KeyCode_Minus, KeyCode_Alt); + Bind(if0_off, KeyCode_I, KeyCode_Alt); + Bind(open_file_in_quotes, KeyCode_1, KeyCode_Alt); + Bind(open_matching_file_cpp, KeyCode_2, KeyCode_Alt); + Bind(write_zero_struct, KeyCode_0, KeyCode_Control); +} + +// BOTTOM + diff --git a/custom/4coder_doc_commands.cpp b/custom/4coder_doc_commands.cpp index 58ce3c31..aea241d4 100644 --- a/custom/4coder_doc_commands.cpp +++ b/custom/4coder_doc_commands.cpp @@ -23,5 +23,148 @@ doc_commands(Arena *arena){ return(cluster); } +function Doc_Cluster* +doc_default_bindings(Arena *arena, Mapping *mapping, i64 global_id, i64 file_id, i64 code_id){ + Doc_Cluster *cluster = new_doc_cluster(arena, "Bindings", "bindings"); + Doc_Page *page = new_doc_page(arena, cluster, "Default", "default"); + for (Command_Map *map = mapping->first_map; + map != 0; + map = map->next){ + char *map_name = ""; + if (map->id == global_id){ + map_name = "Global"; + } + else if (map->id == file_id){ + map_name = "File"; + } + else if (map->id == code_id){ + map_name = "Code"; + } + + Doc_Block *block = new_doc_block(arena, page, map_name); + Doc_Paragraph *par = new_doc_par_table(arena, block); + (void)par; + + struct Bind_Node{ + Bind_Node *next; + Input_Event_Kind kind; + u32 sub_code; + Input_Modifier_Set mods; + Command_Binding binding; + u32 j; + }; + + Bind_Node *first = 0; + Bind_Node *last = 0; + i32 node_count = 0; + + if (map->text_input_command.name != 0){ + Bind_Node *node = push_array_zero(arena, Bind_Node, 1); + sll_queue_push(first, last, node); + node_count += 1; + node->binding = map->text_input_command; + node->j = max_u32; + } + + u32 counts[] = { + KeyCode_COUNT, + KeyCode_COUNT, + MouseCode_COUNT, + MouseCode_COUNT, + 1, + 1, + CoreCode_COUNT, + }; + + u32 event_codes[] = { + InputEventKind_KeyStroke, + InputEventKind_KeyRelease, + InputEventKind_MouseButton, + InputEventKind_MouseButtonRelease, + InputEventKind_MouseWheel, + InputEventKind_MouseMove, + InputEventKind_Core, + }; + + char *mouse_wheel_name[] = {"MoveWheel"}; + char *mouse_move_name[] = {"MoveMove"}; + + char **event_names[] = { + key_code_name, + key_code_name, + mouse_code_name, + mouse_code_name, + mouse_wheel_name, + mouse_move_name, + core_code_name, + }; + + b32 is_release[] = { + false, + true, + false, + true, + false, + false, + false, + }; + + for (u32 j = 0; j < ArrayCount(counts); j += 1){ + for (u32 code = 0; code < counts[j]; code += 1){ + u64 key = mapping__key(event_codes[j], code); + Table_Lookup lookup = table_lookup(&map->event_code_to_binding_list, key); + if (lookup.found_match){ + u64 val = 0; + table_read(&map->event_code_to_binding_list, lookup, &val); + Command_Binding_List *list = (Command_Binding_List*)IntAsPtr(val); + for (SNode *snode = list->first; + snode != 0; + snode = snode->next){ + Command_Modified_Binding *mod_binding = CastFromMember(Command_Modified_Binding, order_node, snode); + + Bind_Node *node = push_array_zero(arena, Bind_Node, 1); + sll_queue_push(first, last, node); + node_count += 1; + node->kind = event_codes[j]; + node->sub_code = code; + node->mods = mod_binding->mods; + node->binding = mod_binding->binding; + node->j = j; + } + } + } + } + + Vec2_i32 table_dims = V2i32(2, node_count); + Doc_Content_List *vals = push_array_zero(arena, Doc_Content_List, table_dims.x*table_dims.y); + Bind_Node *bnode = first; + for (i32 y = 0; y < table_dims.y; y += 1, bnode = bnode->next){ + Doc_Content_List *line = &vals[y*table_dims.x]; + doc_text(arena, &line[0], "["); + if (bnode->j != max_u32){ + doc_text(arena, &line[0], event_names[bnode->j][bnode->sub_code]); + if (is_release[bnode->j]){ + doc_text(arena, &line[0], "Release"); + } + + Input_Modifier_Set *mods = &bnode->mods; + for (i32 k = 0; k < mods->count; k += 1){ + doc_text(arena, &line[0], key_code_name[mods->mods[k]]); + } + } + else{ + doc_text(arena, &line[0], "TextInput"); + } + doc_text(arena, &line[0], "]"); + + Doc_Content *content = doc_text(arena, &line[1], bnode->binding.name); + content->page_link = SCu8(bnode->binding.name); + } + + } + + return(cluster); +} + // BOTTOM diff --git a/custom/4coder_doc_content_types.cpp b/custom/4coder_doc_content_types.cpp index 04fc659e..423db68b 100644 --- a/custom/4coder_doc_content_types.cpp +++ b/custom/4coder_doc_content_types.cpp @@ -131,6 +131,13 @@ new_doc_par_single_code(Arena *arena, Doc_Block *block, String_Const_u8 contents doc_code_list_push(arena, ¶graph->code, contents, language); } +function Doc_Paragraph* +new_doc_par_table(Arena *arena, Doc_Block *block){ + Doc_Paragraph *result = new_doc_par(arena, block); + result->kind = DocParagraphKind_Table; + return(result); +} + //////////////////////////////// function void @@ -169,7 +176,7 @@ doc_logf(Arena *arena, Doc_Cluster *cluster, char *format, ...){ //////////////////////////////// -function void +function Doc_Content* doc_text(Arena *arena, Doc_Block *block, char *str){ Doc_Paragraph *par = block->last_par; if (par != 0){ @@ -183,7 +190,12 @@ doc_text(Arena *arena, Doc_Block *block, char *str){ par->kind = DocParagraphKind_Text; } - doc_content_push(arena, &par->text, SCu8(str)); + return(doc_content_push(arena, &par->text, SCu8(str))); +} + +function Doc_Content* +doc_text(Arena *arena, Doc_Content_List *list, char *string){ + return(doc_content_push(arena, list, SCu8(string))); } function void diff --git a/custom/4coder_types.h b/custom/4coder_types.h index b84026d7..f195bc3f 100644 --- a/custom/4coder_types.h +++ b/custom/4coder_types.h @@ -734,81 +734,14 @@ struct Layout_Item_List{ api(custom) typedef Layout_Item_List Layout_Function(Application_Links *app, Arena *arena, Buffer_ID buffer, Range_i64 range, Face_ID face, f32 width); -api(custom) -typedef i64 Command_Map_ID; - -api(custom) -struct Command_Trigger{ - Command_Trigger *next; - Input_Event_Kind kind; - u32 sub_code; - Input_Modifier_Set mods; -}; - -api(custom) -struct Command_Trigger_List{ - Command_Trigger *first; - Command_Trigger *last; -}; - -api(custom) -struct Command_Binding{ - Custom_Command_Function *custom; -}; - -api(custom) -struct Command_Modified_Binding{ - Command_Modified_Binding *next; - SNode order_node; - Input_Modifier_Set mods; - Command_Binding binding; -}; - -api(custom) -struct Command_Binding_List{ - Command_Binding_List *next; - SNode *first; - SNode *last; - i32 count; -}; - -api(custom) -struct Command_Map{ - Command_Map *next; - Command_Map_ID id; - Command_Map_ID parent; - Command_Binding text_input_command; - Arena node_arena; - Table_u64_u64 event_code_to_binding_list; - Table_u64_u64 cmd_to_binding_trigger; - Command_Modified_Binding *binding_first; - Command_Modified_Binding *binding_last; - Command_Binding_List *list_first; - Command_Binding_List *list_last; - - struct Binding_Unit *real_beginning; -}; - -api(custom) -struct Mapping{ - Arena *node_arena; - Heap heap; - Base_Allocator heap_wrapper; - Table_u64_u64 id_to_map; - Command_Map_ID id_counter; - Command_Map *free_maps; - Command_Modified_Binding *free_bindings; - Command_Binding_List *free_lists; -}; - api(custom) struct View_Context{ Render_Caller_Function *render_caller; Delta_Rule_Function *delta_rule; umem delta_rule_memory_size; b32 hides_buffer; - Mapping *mapping; - Command_Map_ID map_id; + struct Mapping *mapping; + i64 map_id; }; api(custom) diff --git a/site/4ed_site_render_main.cpp b/site/4ed_site_render_main.cpp index 8dc1fca8..ee3d005d 100644 --- a/site/4ed_site_render_main.cpp +++ b/site/4ed_site_render_main.cpp @@ -10,20 +10,29 @@ // TOP #include "4coder_base_types.h" +#include "4coder_events.h" +#include "4coder_table.h" #include "../4ed_api_definition.h" #include "4coder_doc_content_types.h" #include "../docs/4ed_doc_helper.h" +#include "4coder_command_map.h" #include "generated/command_metadata.h" #include "4coder_base_types.cpp" #include "4coder_stringf.cpp" +#include "4coder_hash_functions.cpp" +#include "4coder_table.cpp" +#include "4coder_events.cpp" #include "4coder_malloc_allocator.cpp" #include "../4ed_api_definition.cpp" #include "4coder_doc_content_types.cpp" #include "../docs/4ed_doc_helper.cpp" #include "4coder_file.cpp" +#define MAP_METADATA_ONLY 1 +#include "4coder_command_map.cpp" +#include "4coder_default_map.cpp" #include "generated/custom_api_constructor.cpp" #include "../docs/4ed_doc_custom_api.cpp" #include "4coder_doc_commands.cpp" @@ -507,6 +516,10 @@ render_doc_cluster_to_html(Arena *scratch, Doc_Cluster *cluster, String_Const_u8 int main(){ Arena arena = make_arena_malloc(); + Thread_Context tctx_ = {}; + thread_ctx_init(&tctx_, ThreadKind_Main, get_allocator_malloc(), get_allocator_malloc()); + Thread_Context *tctx = &tctx_; + String_Const_u8 self = string_u8_litexpr(__FILE__); umem code_pos = string_find_first(self, string_u8_litexpr("code")); String_Const_u8 root = string_prefix(self, code_pos + 5); @@ -520,10 +533,15 @@ int main(){ (void)root; + Mapping mapping = {}; + mapping_init(tctx, &mapping); + setup_default_mapping(&mapping, 1, 2, 3); + API_Definition *api_def = custom_api_construct(&arena); Doc_Cluster *cluster_array[] = { doc_custom_api(&arena, api_def), doc_commands(&arena), + doc_default_bindings(&arena, &mapping, 1, 2, 3), }; for (i32 i = 0; i < ArrayCount(cluster_array); i += 1){