diff --git a/4coder_base_commands.cpp b/4coder_base_commands.cpp index 008d571a..2aa17656 100644 --- a/4coder_base_commands.cpp +++ b/4coder_base_commands.cpp @@ -434,7 +434,7 @@ CUSTOM_COMMAND_SIG(basic_change_active_panel) CUSTOM_DOC("Change the currently active panel, moving to the panel with the next highest view_id. Will not skipe the build panel if it is open.") { View_Summary view = get_active_view(app, AccessAll); - get_view_next_looped(app, &view, AccessAll); + get_next_view_looped_all_panels(app, &view, AccessAll); set_active_view(app, &view); } @@ -1362,7 +1362,7 @@ CUSTOM_DOC("Reads a filename from surrounding '\"' characters and attempts to op remove_last_folder(&file_name); append(&file_name, make_string(short_file_name, size)); - view = get_next_active_panel(app, &view); + view = get_next_view_looped_primary_panels(app, &view, AccessAll); if (view.exists){ if (view_open_file(app, &view, file_name.str, file_name.size, true)){ set_active_view(app, &view); @@ -1380,7 +1380,7 @@ CUSTOM_DOC("If the current file is a *.cpp or *.h, attempts to open the correspo Buffer_Summary new_buffer = {0}; if (get_cpp_matching_file(app, buffer, &new_buffer)){ - get_view_next_looped(app, &view, AccessAll); + get_next_view_looped_primary_panels(app, &view, AccessAll); view_set_buffer(app, &view, new_buffer.buffer_id, 0); set_active_view(app, &view); } diff --git a/4coder_build_commands.cpp b/4coder_build_commands.cpp index 1c17b1ea..6e17dc24 100644 --- a/4coder_build_commands.cpp +++ b/4coder_build_commands.cpp @@ -168,21 +168,19 @@ CUSTOM_DOC("Looks for a build.bat, build.sh, or makefile in the current and pare static View_Summary get_or_open_build_panel(Application_Links *app){ View_Summary view = {0}; - Buffer_Summary buffer = GET_COMP_BUFFER(app); if (buffer.exists){ view = get_first_view_with_buffer(app, buffer.buffer_id); } if (!view.exists){ - view = open_special_note_view(app); + view = open_build_footer_panel(app); } - return(view); } static void set_fancy_compilation_buffer_font(Application_Links *app){ - Buffer_Summary comp_buffer = get_buffer_by_name(app, literal("*compilation*"), AccessAll); + Buffer_Summary comp_buffer = GET_COMP_BUFFER(app); set_buffer_face_by_name(app, &comp_buffer, literal("Inconsolata")); } @@ -205,22 +203,13 @@ CUSTOM_DOC("Looks for a build.bat, build.sh, or makefile in the current and pare CUSTOM_COMMAND_SIG(close_build_panel) CUSTOM_DOC("If the special build panel is open, closes it.") { - close_special_note_view(app); + close_build_footer_panel(app); } CUSTOM_COMMAND_SIG(change_to_build_panel) CUSTOM_DOC("If the special build panel is open, makes the build panel the active panel.") { - View_Summary view = open_special_note_view(app, false); - - if (!view.exists){ - Buffer_Summary buffer = GET_COMP_BUFFER(app); - if (buffer.exists){ - view = open_special_note_view(app); - view_set_buffer(app, &view, buffer.buffer_id, 0); - } - } - + View_Summary view = get_or_open_build_panel(app); if (view.exists){ set_active_view(app, &view); } diff --git a/4coder_clipboard.cpp b/4coder_clipboard.cpp index b35dac4d..9c67e02a 100644 --- a/4coder_clipboard.cpp +++ b/4coder_clipboard.cpp @@ -51,10 +51,9 @@ CUSTOM_DOC("At the cursor, insert the text at the top of the clipboard.") if (count > 0){ View_Summary view = get_active_view(app, access); - view_paste_index[view.view_id].next_rewrite = RewritePaste; - + view_set_variable(app, &view, view_next_rewrite_loc, RewritePaste); int32_t paste_index = 0; - view_paste_index[view.view_id].index = paste_index; + view_set_variable(app, &view, view_paste_index_loc, paste_index); int32_t len = clipboard_index(app, 0, paste_index, 0, 0); char *str = 0; @@ -89,11 +88,14 @@ CUSTOM_DOC("If the previous command was paste or paste_next, replaces the paste if (count > 0){ View_Summary view = get_active_view(app, access); - if (view_paste_index[view.view_id].rewrite == RewritePaste){ - view_paste_index[view.view_id].next_rewrite = RewritePaste; - - int32_t paste_index = view_paste_index[view.view_id].index + 1; - view_paste_index[view.view_id].index = paste_index; + uint64_t rewrite = 0; + view_get_variable(app, &view, view_rewrite_loc, &rewrite); + if (rewrite == RewritePaste){ + view_set_variable(app, &view, view_next_rewrite_loc, RewritePaste); + uint64_t prev_paste_index = 0; + view_get_variable(app, &view, view_paste_index_loc, &prev_paste_index); + int32_t paste_index = (int32_t)prev_paste_index + 1; + view_set_variable(app, &view, view_paste_index_loc, paste_index); int32_t len = clipboard_index(app, 0, paste_index, 0, 0); char *str = 0; diff --git a/4coder_default_framework.cpp b/4coder_default_framework.cpp index 0e9427b7..9fad4fa7 100644 --- a/4coder_default_framework.cpp +++ b/4coder_default_framework.cpp @@ -52,36 +52,59 @@ new_view_settings(Application_Links *app, View_Summary *view){ } } +//////////////////////////////// + static void -close_special_note_view(Application_Links *app){ - View_Summary special_view = get_view(app, special_note_view_id, AccessAll); - if (special_view.exists){ - close_view(app, &special_view); - } - special_note_view_id = 0; +view_set_passive(Application_Links *app, View_Summary *view, bool32 value){ + view_set_variable(app, view, view_is_passive_loc, (uint64_t)value); +} + +static bool32 +view_get_is_passive(Application_Links *app, View_Summary *view){ + uint64_t is_passive = 0; + view_get_variable(app, view, view_is_passive_loc, &is_passive); + return(is_passive != 0); } static View_Summary -open_special_note_view(Application_Links *app, bool32 create_if_not_exist = true){ - View_Summary special_view = get_view(app, special_note_view_id, AccessAll); +open_footer_panel(Application_Links *app, View_Summary *view){ + View_Summary special_view = open_view(app, view, ViewSplit_Bottom); + new_view_settings(app, &special_view); + view_set_split_proportion(app, &special_view, .2f); + view_set_passive(app, &special_view, true); + return(special_view); +} + +//////////////////////////////// + +static void +close_build_footer_panel(Application_Links *app){ + View_Summary special_view = get_view(app, build_footer_panel_view_id, AccessAll); + if (special_view.exists){ + close_view(app, &special_view); + } + build_footer_panel_view_id = 0; +} + +static View_Summary +open_build_footer_panel(Application_Links *app, bool32 create_if_not_exist = true){ + View_Summary special_view = get_view(app, build_footer_panel_view_id, AccessAll); if (create_if_not_exist && !special_view.exists){ View_Summary view = get_active_view(app, AccessAll); - special_view = open_view(app, &view, ViewSplit_Bottom); - new_view_settings(app, &special_view); - view_set_split_proportion(app, &special_view, .2f); + special_view = open_footer_panel(app, &view); set_active_view(app, &view); - special_note_view_id = special_view.view_id; + build_footer_panel_view_id = special_view.view_id; } return(special_view); } static View_Summary -get_next_active_panel(Application_Links *app, View_Summary *view_start){ +get_next_view_looped_primary_panels(Application_Links *app, View_Summary *view_start, Access_Flag access){ View_ID original_view_id = view_start->view_id; View_Summary view = *view_start; do{ - get_view_next_looped(app, &view, AccessAll); - if (view.view_id != special_note_view_id){ + get_next_view_looped_all_panels(app, &view, access); + if (!view_get_is_passive(app, &view)){ break; } }while(view.view_id != original_view_id); @@ -92,12 +115,12 @@ get_next_active_panel(Application_Links *app, View_Summary *view_start){ } static View_Summary -get_prev_active_panel(Application_Links *app, View_Summary *view_start){ +get_prev_view_looped_primary_panels(Application_Links *app, View_Summary *view_start, Access_Flag access){ View_ID original_view_id = view_start->view_id; View_Summary view = *view_start; do{ - get_view_prev_looped(app, &view, AccessAll); - if (view.view_id != special_note_view_id){ + get_prev_view_looped_all_panels(app, &view, access); + if (!view_get_is_passive(app, &view)){ break; } }while(view.view_id != original_view_id); @@ -111,7 +134,7 @@ CUSTOM_COMMAND_SIG(change_active_panel) CUSTOM_DOC("Change the currently active panel, moving to the panel with the next highest view_id.") { View_Summary view = get_active_view(app, AccessAll); - view = get_next_active_panel(app, &view); + view = get_next_view_looped_primary_panels(app, &view, AccessAll); if (view.exists){ set_active_view(app, &view); } @@ -121,7 +144,7 @@ CUSTOM_COMMAND_SIG(change_active_panel_backwards) CUSTOM_DOC("Change the currently active panel, moving to the panel with the next lowest view_id.") { View_Summary view = get_active_view(app, AccessAll); - view = get_prev_active_panel(app, &view); + view = get_prev_view_looped_primary_panels(app, &view, AccessAll); if (view.exists){ set_active_view(app, &view); } @@ -221,6 +244,11 @@ default_4coder_initialize(Application_Links *app, int32_t override_font_size, bo load_folder_of_themes_into_live_set(app, &global_part, "themes"); load_config_and_apply(app, &global_part, &global_config, override_font_size, override_hinting); + + view_rewrite_loc = create_view_variable(app, "DEFAULT.rewrite" , (uint64_t)0); + view_next_rewrite_loc = create_view_variable(app, "DEFAULT.next_rewrite", (uint64_t)0); + view_paste_index_loc = create_view_variable(app, "DEFAULT.paste_index" , (uint64_t)0); + view_is_passive_loc = create_view_variable(app, "DEFAULT.is_passive" , (uint64_t)false); } static void diff --git a/4coder_default_framework.h b/4coder_default_framework.h index f6bbec24..c2c8c357 100644 --- a/4coder_default_framework.h +++ b/4coder_default_framework.h @@ -20,12 +20,6 @@ enum Rewrite_Type{ RewriteWordComplete }; -struct View_Paste_Index{ - int32_t rewrite; - int32_t next_rewrite; - int32_t index; -}; - //////////////////////////////// struct ID_Based_Jump_Location{ diff --git a/4coder_default_framework_variables.cpp b/4coder_default_framework_variables.cpp index c4b2a04f..aab46e83 100644 --- a/4coder_default_framework_variables.cpp +++ b/4coder_default_framework_variables.cpp @@ -25,11 +25,13 @@ static char locked_buffer_space[256]; static String locked_buffer = make_fixed_width_string(locked_buffer_space); -static View_ID special_note_view_id = 0; +static View_ID build_footer_panel_view_id = 0; -View_Paste_Index view_paste_index_[16]; -View_Paste_Index *view_paste_index = view_paste_index_ - 1; +static int32_t view_rewrite_loc = 0; +static int32_t view_next_rewrite_loc = 0; +static int32_t view_paste_index_loc = 0; +static int32_t view_is_passive_loc = 0; static char out_buffer_space[1024]; diff --git a/4coder_default_hooks.cpp b/4coder_default_hooks.cpp index eae953e2..ab5b8e3a 100644 --- a/4coder_default_hooks.cpp +++ b/4coder_default_hooks.cpp @@ -43,9 +43,11 @@ START_HOOK_SIG(default_start){ COMMAND_CALLER_HOOK(default_command_caller){ View_Summary view = get_active_view(app, AccessAll); - view_paste_index[view.view_id].next_rewrite = 0; + view_set_variable(app, &view, view_next_rewrite_loc, 0); exec_command(app, cmd); - view_paste_index[view.view_id].rewrite = view_paste_index[view.view_id].next_rewrite; + uint64_t next_rewrite = 0; + view_get_variable(app, &view, view_next_rewrite_loc, &next_rewrite); + view_set_variable(app, &view, view_rewrite_loc, next_rewrite); return(0); } diff --git a/4coder_generated/app_functions.h b/4coder_generated/app_functions.h index ab001a9e..37fce504 100644 --- a/4coder_generated/app_functions.h +++ b/4coder_generated/app_functions.h @@ -49,6 +49,9 @@ struct Application_Links; #define VIEW_SET_HIGHLIGHT_SIG(n) bool32 n(Application_Links *app, View_Summary *view, int32_t start, int32_t end, bool32 turn_on) #define VIEW_SET_BUFFER_SIG(n) bool32 n(Application_Links *app, View_Summary *view, Buffer_ID buffer_id, Set_Buffer_Flag flags) #define VIEW_POST_FADE_SIG(n) bool32 n(Application_Links *app, View_Summary *view, float seconds, int32_t start, int32_t end, int_color color) +#define CREATE_VIEW_VARIABLE_SIG(n) int32_t n(Application_Links *app, char *null_terminated_name, uint64_t default_value) +#define VIEW_SET_VARIABLE_SIG(n) bool32 n(Application_Links *app, View_Summary *view, int32_t location, uint64_t value) +#define VIEW_GET_VARIABLE_SIG(n) bool32 n(Application_Links *app, View_Summary *view, int32_t location, uint64_t *value_out) #define GET_USER_INPUT_SIG(n) User_Input n(Application_Links *app, Input_Type_Flag get_type, Input_Type_Flag abort_type) #define GET_COMMAND_INPUT_SIG(n) User_Input n(Application_Links *app) #define GET_MOUSE_STATE_SIG(n) Mouse_State n(Application_Links *app) @@ -135,6 +138,9 @@ typedef VIEW_SET_MARK_SIG(View_Set_Mark_Function); typedef VIEW_SET_HIGHLIGHT_SIG(View_Set_Highlight_Function); typedef VIEW_SET_BUFFER_SIG(View_Set_Buffer_Function); typedef VIEW_POST_FADE_SIG(View_Post_Fade_Function); +typedef CREATE_VIEW_VARIABLE_SIG(Create_View_Variable_Function); +typedef VIEW_SET_VARIABLE_SIG(View_Set_Variable_Function); +typedef VIEW_GET_VARIABLE_SIG(View_Get_Variable_Function); typedef GET_USER_INPUT_SIG(Get_User_Input_Function); typedef GET_COMMAND_INPUT_SIG(Get_Command_Input_Function); typedef GET_MOUSE_STATE_SIG(Get_Mouse_State_Function); @@ -223,6 +229,9 @@ View_Set_Mark_Function *view_set_mark; View_Set_Highlight_Function *view_set_highlight; View_Set_Buffer_Function *view_set_buffer; View_Post_Fade_Function *view_post_fade; +Create_View_Variable_Function *create_view_variable; +View_Set_Variable_Function *view_set_variable; +View_Get_Variable_Function *view_get_variable; Get_User_Input_Function *get_user_input; Get_Command_Input_Function *get_command_input; Get_Mouse_State_Function *get_mouse_state; @@ -310,6 +319,9 @@ View_Set_Mark_Function *view_set_mark_; View_Set_Highlight_Function *view_set_highlight_; View_Set_Buffer_Function *view_set_buffer_; View_Post_Fade_Function *view_post_fade_; +Create_View_Variable_Function *create_view_variable_; +View_Set_Variable_Function *view_set_variable_; +View_Get_Variable_Function *view_get_variable_; Get_User_Input_Function *get_user_input_; Get_Command_Input_Function *get_command_input_; Get_Mouse_State_Function *get_mouse_state_; @@ -405,6 +417,9 @@ app_links->view_set_mark_ = View_Set_Mark;\ app_links->view_set_highlight_ = View_Set_Highlight;\ app_links->view_set_buffer_ = View_Set_Buffer;\ app_links->view_post_fade_ = View_Post_Fade;\ +app_links->create_view_variable_ = Create_View_Variable;\ +app_links->view_set_variable_ = View_Set_Variable;\ +app_links->view_get_variable_ = View_Get_Variable;\ app_links->get_user_input_ = Get_User_Input;\ app_links->get_command_input_ = Get_Command_Input;\ app_links->get_mouse_state_ = Get_Mouse_State;\ @@ -492,6 +507,9 @@ static inline bool32 view_set_mark(Application_Links *app, View_Summary *view, B static inline bool32 view_set_highlight(Application_Links *app, View_Summary *view, int32_t start, int32_t end, bool32 turn_on){return(app->view_set_highlight(app, view, start, end, turn_on));} static inline bool32 view_set_buffer(Application_Links *app, View_Summary *view, Buffer_ID buffer_id, Set_Buffer_Flag flags){return(app->view_set_buffer(app, view, buffer_id, flags));} static inline bool32 view_post_fade(Application_Links *app, View_Summary *view, float seconds, int32_t start, int32_t end, int_color color){return(app->view_post_fade(app, view, seconds, start, end, color));} +static inline int32_t create_view_variable(Application_Links *app, char *null_terminated_name, uint64_t default_value){return(app->create_view_variable(app, null_terminated_name, default_value));} +static inline bool32 view_set_variable(Application_Links *app, View_Summary *view, int32_t location, uint64_t value){return(app->view_set_variable(app, view, location, value));} +static inline bool32 view_get_variable(Application_Links *app, View_Summary *view, int32_t location, uint64_t *value_out){return(app->view_get_variable(app, view, location, value_out));} static inline User_Input get_user_input(Application_Links *app, Input_Type_Flag get_type, Input_Type_Flag abort_type){return(app->get_user_input(app, get_type, abort_type));} static inline User_Input get_command_input(Application_Links *app){return(app->get_command_input(app));} static inline Mouse_State get_mouse_state(Application_Links *app){return(app->get_mouse_state(app));} @@ -579,6 +597,9 @@ static inline bool32 view_set_mark(Application_Links *app, View_Summary *view, B static inline bool32 view_set_highlight(Application_Links *app, View_Summary *view, int32_t start, int32_t end, bool32 turn_on){return(app->view_set_highlight_(app, view, start, end, turn_on));} static inline bool32 view_set_buffer(Application_Links *app, View_Summary *view, Buffer_ID buffer_id, Set_Buffer_Flag flags){return(app->view_set_buffer_(app, view, buffer_id, flags));} static inline bool32 view_post_fade(Application_Links *app, View_Summary *view, float seconds, int32_t start, int32_t end, int_color color){return(app->view_post_fade_(app, view, seconds, start, end, color));} +static inline int32_t create_view_variable(Application_Links *app, char *null_terminated_name, uint64_t default_value){return(app->create_view_variable_(app, null_terminated_name, default_value));} +static inline bool32 view_set_variable(Application_Links *app, View_Summary *view, int32_t location, uint64_t value){return(app->view_set_variable_(app, view, location, value));} +static inline bool32 view_get_variable(Application_Links *app, View_Summary *view, int32_t location, uint64_t *value_out){return(app->view_get_variable_(app, view, location, value_out));} static inline User_Input get_user_input(Application_Links *app, Input_Type_Flag get_type, Input_Type_Flag abort_type){return(app->get_user_input_(app, get_type, abort_type));} static inline User_Input get_command_input(Application_Links *app){return(app->get_command_input_(app));} static inline Mouse_State get_mouse_state(Application_Links *app){return(app->get_mouse_state_(app));} diff --git a/4coder_generated/command_metadata.h b/4coder_generated/command_metadata.h index 94610f4e..d23a64e6 100644 --- a/4coder_generated/command_metadata.h +++ b/4coder_generated/command_metadata.h @@ -205,24 +205,24 @@ int32_t source_name_len; int32_t line_number; }; static Command_Metadata fcoder_metacmd_table[184] = { -{ PROC_LINKS(allow_mouse, 0), "allow_mouse", 11, "Shows the mouse and causes all mouse input to be processed normally.", 68, "w:\\4ed\\code\\4coder_default_framework.cpp", 43, 168 }, +{ PROC_LINKS(allow_mouse, 0), "allow_mouse", 11, "Shows the mouse and causes all mouse input to be processed normally.", 68, "w:\\4ed\\code\\4coder_default_framework.cpp", 43, 191 }, { PROC_LINKS(auto_tab_line_at_cursor, 0), "auto_tab_line_at_cursor", 23, "Auto-indents the line on which the cursor sits.", 47, "w:\\4ed\\code\\4coder_auto_indent.cpp", 37, 722 }, { PROC_LINKS(auto_tab_range, 0), "auto_tab_range", 14, "Auto-indents the range between the cursor and the mark.", 55, "w:\\4ed\\code\\4coder_auto_indent.cpp", 37, 733 }, { PROC_LINKS(auto_tab_whole_file, 0), "auto_tab_whole_file", 19, "Audo-indents the entire current buffer.", 39, "w:\\4ed\\code\\4coder_auto_indent.cpp", 37, 712 }, { PROC_LINKS(backspace_char, 0), "backspace_char", 14, "Deletes the character to the left of the cursor.", 48, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 67 }, { PROC_LINKS(backspace_word, 0), "backspace_word", 14, "Delete characters between the cursor position and the first alphanumeric boundary to the left.", 94, "w:\\4ed\\code\\4coder_seek.cpp", 30, 1247 }, { PROC_LINKS(basic_change_active_panel, 0), "basic_change_active_panel", 25, "Change the currently active panel, moving to the panel with the next highest view_id. Will not skipe the build panel if it is open.", 132, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 433 }, -{ PROC_LINKS(build_in_build_panel, 0), "build_in_build_panel", 20, "Looks for a build.bat, build.sh, or makefile in the current and parent directories. Runs the first that it finds and prints the output to *compilation*. Puts the *compilation* buffer in a panel at the footer of the current view.", 230, "w:\\4ed\\code\\4coder_build_commands.cpp", 40, 189 }, +{ PROC_LINKS(build_in_build_panel, 0), "build_in_build_panel", 20, "Looks for a build.bat, build.sh, or makefile in the current and parent directories. Runs the first that it finds and prints the output to *compilation*. Puts the *compilation* buffer in a panel at the footer of the current view.", 230, "w:\\4ed\\code\\4coder_build_commands.cpp", 40, 187 }, { PROC_LINKS(build_search, 0), "build_search", 12, "Looks for a build.bat, build.sh, or makefile in the current and parent directories. Runs the first that it finds and prints the output to *compilation*.", 153, "w:\\4ed\\code\\4coder_build_commands.cpp", 40, 155 }, { PROC_LINKS(center_view, 0), "center_view", 11, "Centers the view vertically on the line on which the cursor sits.", 65, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 120 }, -{ PROC_LINKS(change_active_panel, 0), "change_active_panel", 19, "Change the currently active panel, moving to the panel with the next highest view_id.", 85, "w:\\4ed\\code\\4coder_default_framework.cpp", 43, 110 }, -{ PROC_LINKS(change_active_panel_backwards, 0), "change_active_panel_backwards", 29, "Change the currently active panel, moving to the panel with the next lowest view_id.", 84, "w:\\4ed\\code\\4coder_default_framework.cpp", 43, 120 }, -{ PROC_LINKS(change_to_build_panel, 0), "change_to_build_panel", 21, "If the special build panel is open, makes the build panel the active panel.", 75, "w:\\4ed\\code\\4coder_build_commands.cpp", 40, 211 }, +{ PROC_LINKS(change_active_panel, 0), "change_active_panel", 19, "Change the currently active panel, moving to the panel with the next highest view_id.", 85, "w:\\4ed\\code\\4coder_default_framework.cpp", 43, 133 }, +{ PROC_LINKS(change_active_panel_backwards, 0), "change_active_panel_backwards", 29, "Change the currently active panel, moving to the panel with the next lowest view_id.", 84, "w:\\4ed\\code\\4coder_default_framework.cpp", 43, 143 }, +{ PROC_LINKS(change_to_build_panel, 0), "change_to_build_panel", 21, "If the special build panel is open, makes the build panel the active panel.", 75, "w:\\4ed\\code\\4coder_build_commands.cpp", 40, 209 }, { PROC_LINKS(clean_all_lines, 0), "clean_all_lines", 15, "Removes trailing whitespace from all lines in the current buffer.", 65, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 368 }, { PROC_LINKS(click_set_cursor, 0), "click_set_cursor", 16, "Sets the cursor position to the mouse position.", 47, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 174 }, { PROC_LINKS(click_set_mark, 0), "click_set_mark", 14, "Sets the mark position to the mouse position.", 45, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 187 }, { PROC_LINKS(close_all_code, 0), "close_all_code", 14, "Closes any buffer with a filename ending with an extension configured to be recognized as a code file type.", 107, "w:\\4ed\\code\\4coder_project_commands.cpp", 42, 1048 }, -{ PROC_LINKS(close_build_panel, 0), "close_build_panel", 17, "If the special build panel is open, closes it.", 46, "w:\\4ed\\code\\4coder_build_commands.cpp", 40, 205 }, +{ PROC_LINKS(close_build_panel, 0), "close_build_panel", 17, "If the special build panel is open, closes it.", 46, "w:\\4ed\\code\\4coder_build_commands.cpp", 40, 203 }, { PROC_LINKS(close_panel, 0), "close_panel", 11, "Closes the currently active panel if it is not the only panel open.", 67, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 441 }, { PROC_LINKS(copy, 0), "copy", 4, "Copy the text in the range from the cursor to the mark onto the clipboard.", 74, "w:\\4ed\\code\\4coder_clipboard.cpp", 35, 26 }, { PROC_LINKS(cursor_mark_swap, 0), "cursor_mark_swap", 16, "Swaps the position of the cursor and the mark.", 46, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 95 }, @@ -310,14 +310,14 @@ static Command_Metadata fcoder_metacmd_table[184] = { { PROC_LINKS(open_long_braces_break, 0), "open_long_braces_break", 22, "At the cursor, insert a '{' and '}break;' separated by a blank line.", 68, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 49, 74 }, { PROC_LINKS(open_long_braces_semicolon, 0), "open_long_braces_semicolon", 26, "At the cursor, insert a '{' and '};' separated by a blank line.", 63, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 49, 66 }, { PROC_LINKS(open_matching_file_cpp, 0), "open_matching_file_cpp", 22, "If the current file is a *.cpp or *.h, attempts to open the corresponding *.h or *.cpp file in the other view.", 110, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 1375 }, -{ PROC_LINKS(open_panel_hsplit, 0), "open_panel_hsplit", 17, "Create a new panel by horizontally splitting the active panel.", 62, "w:\\4ed\\code\\4coder_default_framework.cpp", 43, 139 }, -{ PROC_LINKS(open_panel_vsplit, 0), "open_panel_vsplit", 17, "Create a new panel by vertically splitting the active panel.", 60, "w:\\4ed\\code\\4coder_default_framework.cpp", 43, 130 }, +{ PROC_LINKS(open_panel_hsplit, 0), "open_panel_hsplit", 17, "Create a new panel by horizontally splitting the active panel.", 62, "w:\\4ed\\code\\4coder_default_framework.cpp", 43, 162 }, +{ PROC_LINKS(open_panel_vsplit, 0), "open_panel_vsplit", 17, "Create a new panel by vertically splitting the active panel.", 60, "w:\\4ed\\code\\4coder_default_framework.cpp", 43, 153 }, { PROC_LINKS(page_down, 0), "page_down", 9, "Scrolls the view down one view height and moves the cursor down one view height.", 80, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 288 }, { PROC_LINKS(page_up, 0), "page_up", 7, "Scrolls the view up one view height and moves the cursor up one view height.", 76, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 279 }, { PROC_LINKS(paste, 0), "paste", 5, "At the cursor, insert the text at the top of the clipboard.", 59, "w:\\4ed\\code\\4coder_clipboard.cpp", 35, 46 }, -{ PROC_LINKS(paste_and_indent, 0), "paste_and_indent", 16, "Paste from the top of clipboard and run auto-indent on the newly pasted text.", 77, "w:\\4ed\\code\\4coder_clipboard.cpp", 35, 128 }, -{ PROC_LINKS(paste_next, 0), "paste_next", 10, "If the previous command was paste or paste_next, replaces the paste range with the next text down on the clipboard, otherwise operates as the paste command.", 156, "w:\\4ed\\code\\4coder_clipboard.cpp", 35, 84 }, -{ PROC_LINKS(paste_next_and_indent, 0), "paste_next_and_indent", 21, "Paste the next item on the clipboard and run auto-indent on the newly pasted text.", 82, "w:\\4ed\\code\\4coder_clipboard.cpp", 35, 135 }, +{ PROC_LINKS(paste_and_indent, 0), "paste_and_indent", 16, "Paste from the top of clipboard and run auto-indent on the newly pasted text.", 77, "w:\\4ed\\code\\4coder_clipboard.cpp", 35, 130 }, +{ PROC_LINKS(paste_next, 0), "paste_next", 10, "If the previous command was paste or paste_next, replaces the paste range with the next text down on the clipboard, otherwise operates as the paste command.", 156, "w:\\4ed\\code\\4coder_clipboard.cpp", 35, 83 }, +{ PROC_LINKS(paste_next_and_indent, 0), "paste_next_and_indent", 21, "Paste the next item on the clipboard and run auto-indent on the newly pasted text.", 82, "w:\\4ed\\code\\4coder_clipboard.cpp", 35, 137 }, { PROC_LINKS(place_in_scope, 0), "place_in_scope", 14, "Wraps the code contained in the range between cursor and mark with a new curly brace scope.", 91, "w:\\4ed\\code\\4coder_scope_commands.cpp", 40, 481 }, { PROC_LINKS(project_fkey_command, 0), "project_fkey_command", 20, "Run an 'fkey command' configured in a project.4coder file. Determines the index of the 'fkey command' by which function key or numeric key was pressed to trigger the command.", 175, "w:\\4ed\\code\\4coder_project_commands.cpp", 42, 1078 }, { PROC_LINKS(project_go_to_root_directory, 0), "project_go_to_root_directory", 28, "Changes 4coder's hot directory to the root directory of the currently loaded project. With no loaded project nothing hapepns.", 125, "w:\\4ed\\code\\4coder_project_commands.cpp", 42, 1103 }, @@ -325,7 +325,7 @@ static Command_Metadata fcoder_metacmd_table[184] = { { PROC_LINKS(query_replace_identifier, 0), "query_replace_identifier", 24, "Queries the user for a string, and incrementally replace every occurence of the word or token found at the cursor with the specified string.", 140, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 932 }, { PROC_LINKS(query_replace_selection, 0), "query_replace_selection", 23, "Queries the user for a string, and incrementally replace every occurence of the string found in the selected range with the specified string.", 141, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 950 }, { PROC_LINKS(redo, 0), "redo", 4, "Advances forewards through the undo history.", 44, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 1438 }, -{ PROC_LINKS(remap_interactive, 0), "remap_interactive", 17, "Switch to a named key binding map.", 34, "w:\\4ed\\code\\4coder_default_framework.cpp", 43, 188 }, +{ PROC_LINKS(remap_interactive, 0), "remap_interactive", 17, "Switch to a named key binding map.", 34, "w:\\4ed\\code\\4coder_default_framework.cpp", 43, 211 }, { PROC_LINKS(rename_file_query, 0), "rename_file_query", 17, "Queries the user for a new name and renames the file of the current buffer, altering the buffer's name too.", 107, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 1078 }, { PROC_LINKS(reopen, 0), "reopen", 6, "Reopen the current buffer from the hard drive.", 46, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 1474 }, { PROC_LINKS(replace_in_range, 0), "replace_in_range", 16, "Queries the user for two strings, and replaces all occurences of the first string in the range between the cursor and the mark with the second string.", 150, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 810 }, @@ -368,14 +368,14 @@ static Command_Metadata fcoder_metacmd_table[184] = { { PROC_LINKS(show_scrollbar, 0), "show_scrollbar", 14, "Sets the current view to show it's scrollbar.", 45, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 450 }, { PROC_LINKS(snipe_token_or_word, 0), "snipe_token_or_word", 19, "Delete a single, whole token on or to the left of the cursor and post it to the clipboard.", 90, "w:\\4ed\\code\\4coder_seek.cpp", 30, 1259 }, { PROC_LINKS(snipe_token_or_word_right, 0), "snipe_token_or_word_right", 25, "Delete a single, whole token on or to the right of the cursor and post it to the clipboard.", 91, "w:\\4ed\\code\\4coder_seek.cpp", 30, 1265 }, -{ PROC_LINKS(suppress_mouse, 0), "suppress_mouse", 14, "Hides the mouse and causes all mosue input (clicks, position, wheel) to be ignored.", 83, "w:\\4ed\\code\\4coder_default_framework.cpp", 43, 162 }, +{ PROC_LINKS(suppress_mouse, 0), "suppress_mouse", 14, "Hides the mouse and causes all mosue input (clicks, position, wheel) to be ignored.", 83, "w:\\4ed\\code\\4coder_default_framework.cpp", 43, 185 }, { PROC_LINKS(swap_buffers_between_panels, 0), "swap_buffers_between_panels", 27, "Set the other non-active panel to view the buffer that the active panel views, and switch to that panel.", 104, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 1399 }, { PROC_LINKS(to_lowercase, 0), "to_lowercase", 12, "Converts all ascii text in the range between the cursor and the mark to lowercase.", 82, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 348 }, { PROC_LINKS(to_uppercase, 0), "to_uppercase", 12, "Converts all ascii text in the range between the cursor and the mark to uppercase.", 82, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 328 }, { PROC_LINKS(toggle_filebar, 0), "toggle_filebar", 14, "Toggles the visibility status of the current view's filebar.", 60, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 478 }, -{ PROC_LINKS(toggle_fullscreen, 0), "toggle_fullscreen", 17, "Toggle fullscreen mode on or off. The change(s) do not take effect until the next frame.", 89, "w:\\4ed\\code\\4coder_default_framework.cpp", 43, 180 }, +{ PROC_LINKS(toggle_fullscreen, 0), "toggle_fullscreen", 17, "Toggle fullscreen mode on or off. The change(s) do not take effect until the next frame.", 89, "w:\\4ed\\code\\4coder_default_framework.cpp", 43, 203 }, { PROC_LINKS(toggle_line_wrap, 0), "toggle_line_wrap", 16, "Toggles the current buffer's line wrapping status.", 50, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 487 }, -{ PROC_LINKS(toggle_mouse, 0), "toggle_mouse", 12, "Toggles the mouse suppression mode, see suppress_mouse and allow_mouse.", 71, "w:\\4ed\\code\\4coder_default_framework.cpp", 43, 174 }, +{ PROC_LINKS(toggle_mouse, 0), "toggle_mouse", 12, "Toggles the mouse suppression mode, see suppress_mouse and allow_mouse.", 71, "w:\\4ed\\code\\4coder_default_framework.cpp", 43, 197 }, { PROC_LINKS(toggle_show_whitespace, 0), "toggle_show_whitespace", 22, "Toggles the current buffer's whitespace visibility status.", 58, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 554 }, { PROC_LINKS(toggle_virtual_whitespace, 0), "toggle_virtual_whitespace", 25, "Toggles the current buffer's virtual whitespace status.", 55, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 543 }, { PROC_LINKS(undo, 0), "undo", 4, "Advances backwards through the undo history.", 44, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 1432 }, diff --git a/4coder_helper.cpp b/4coder_helper.cpp index e7b3e087..63aaeb90 100644 --- a/4coder_helper.cpp +++ b/4coder_helper.cpp @@ -619,7 +619,7 @@ get_view_last(Application_Links *app, uint32_t access){ } static void -get_view_next_looped(Application_Links *app, View_Summary *view, uint32_t access){ +get_next_view_looped_all_panels(Application_Links *app, View_Summary *view, uint32_t access){ get_view_next(app, view, access); if (!view->exists){ *view = get_view_first(app, access); @@ -627,7 +627,7 @@ get_view_next_looped(Application_Links *app, View_Summary *view, uint32_t access } static void -get_view_prev_looped(Application_Links *app, View_Summary *view, uint32_t access){ +get_prev_view_looped_all_panels(Application_Links *app, View_Summary *view, uint32_t access){ get_view_prev(app, view, access); if (!view->exists){ *view = get_view_last(app, access); diff --git a/4coder_search.cpp b/4coder_search.cpp index 08ee3af6..9a580df7 100644 --- a/4coder_search.cpp +++ b/4coder_search.cpp @@ -828,10 +828,12 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with if (buffer.exists){ int32_t do_init = false; - if (view_paste_index[view.view_id].rewrite != RewriteWordComplete){ + uint64_t rewrite = 0; + view_get_variable(app, &view, view_rewrite_loc, &rewrite); + if (rewrite != RewriteWordComplete){ do_init = true; } - view_paste_index[view.view_id].next_rewrite = RewriteWordComplete; + view_set_variable(app, &view, view_next_rewrite_loc, RewriteWordComplete); if (!complete_state.initialized){ do_init = true; } diff --git a/4ed.cpp b/4ed.cpp index 90ac7a54..9352a4c7 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -1179,6 +1179,8 @@ App_Init_Sig(app_init){ memset(models->app_links.memory, 0, wanted_size); } + dynamic_variables_init(&models->view_variable_layout); + // NOTE(allen): file setup working_set_init(&models->working_set, partition, &vars->models.mem.general); models->working_set.default_display_width = DEFAULT_DISPLAY_WIDTH; diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index da7404a3..d1f4ff66 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -2138,6 +2138,53 @@ DOC_SEE(int_color) return(result); } +API_EXPORT int32_t +Create_View_Variable(Application_Links *app, char *null_terminated_name, uint64_t default_value){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + Models *models = cmd->models; + String name = make_string_slowly(null_terminated_name); + return(dynamic_variables_lookup_or_create(&models->mem.general, + &models->view_variable_layout, name, default_value)); +} + +API_EXPORT bool32 +View_Set_Variable(Application_Links *app, View_Summary *view, int32_t location, uint64_t value){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + View *vptr = imp_get_view(cmd, view); + bool32 result = false; + if (vptr != 0){ + Models *models = cmd->models; + u64 *ptr = 0; + if (dynamic_variables_get_ptr(&models->mem.general, + &models->view_variable_layout, + &vptr->transient.dynamic_vars, + location, &ptr)){ + result = true; + *ptr = value; + } + } + return(result); +} + +API_EXPORT bool32 +View_Get_Variable(Application_Links *app, View_Summary *view, int32_t location, uint64_t *value_out){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + View *vptr = imp_get_view(cmd, view); + bool32 result = false; + if (vptr != 0){ + Models *models = cmd->models; + u64 *ptr = 0; + if (dynamic_variables_get_ptr(&models->mem.general, + &models->view_variable_layout, + &vptr->transient.dynamic_vars, + location, &ptr)){ + result = true; + *value_out = *ptr; + } + } + return(result); +} + API_EXPORT User_Input Get_User_Input(Application_Links *app, Input_Type_Flag get_type, Input_Type_Flag abort_type) /* diff --git a/4ed_app_models.h b/4ed_app_models.h index ffc39936..1ba21497 100644 --- a/4ed_app_models.h +++ b/4ed_app_models.h @@ -81,6 +81,8 @@ struct Models{ Live_Views live_set; Parse_Context_Memory parse_context_memory; + Dynamic_Variable_Layout view_variable_layout; + Editing_File *message_buffer; Editing_File *scratch_buffer; diff --git a/4ed_app_target.cpp b/4ed_app_target.cpp index 8407b81e..cf4df9d2 100644 --- a/4ed_app_target.cpp +++ b/4ed_app_target.cpp @@ -60,6 +60,7 @@ #include "4ed_cli.h" #include "4ed_gui.h" #include "4ed_layout.h" +#include "4ed_dynamic_variables.h" #include "4ed_view.h" #include "4ed_app_models.h" @@ -79,6 +80,7 @@ #include "4ed_hot_directory.cpp" #include "4ed_cli.cpp" #include "4ed_gui.cpp" +#include "4ed_dynamic_variables.cpp" #include "4ed_layout.cpp" #include "4coder_buffer_seek_constructors.cpp" #include "4ed_view.cpp" diff --git a/4ed_dynamic_variables.cpp b/4ed_dynamic_variables.cpp new file mode 100644 index 00000000..c1166630 --- /dev/null +++ b/4ed_dynamic_variables.cpp @@ -0,0 +1,102 @@ +/* + * Mr. 4th Dimention - Allen Webster + * + * 22.06.2018 + * + * Dynamic variable system + * + */ + +// TOP + +internal void +dynamic_variables_init(Dynamic_Variable_Layout *layout){ + dll_init_sentinel(&layout->sentinel); + layout->location_counter = 1; +} + +internal i32 +dynamic_variables_lookup_or_create(General_Memory *general, Dynamic_Variable_Layout *layout, + String name, u64 default_value){ + for (Dynamic_Variable_Slot *slot = layout->sentinel.next; + slot != &layout->sentinel; + slot = slot->next){ + if (match(slot->name, name)){ + return(slot->location); + } + } + int32_t alloc_size = name.size + 1 + sizeof(Dynamic_Variable_Slot); + void *ptr = general_memory_allocate(general, alloc_size); + if (ptr != 0){ + Dynamic_Variable_Slot *new_slot = (Dynamic_Variable_Slot*)ptr; + char *c_str = (char*)(new_slot + 1); + String str = make_string_cap(c_str, 0, name.size + 1); + copy(&str, name); + terminate_with_null(&str); + new_slot->name = str; + new_slot->default_value = default_value; + new_slot->location = layout->location_counter++; + dll_insert_back(&layout->sentinel, new_slot); + return(new_slot->location); + } + return(0); +} + +internal void +dynamic_variables_block_init(General_Memory *general, Dynamic_Variable_Block *block){ + i32 max = 64; + block->val_array = (u64*)general_memory_allocate(general, sizeof(u64)*max); + block->count = 0; + block->max = max; +} + +internal void +dynamic_variables_block_free(General_Memory *general, Dynamic_Variable_Block *block){ + general_memory_free(general, block->val_array); +} + +internal void +dynamic_variables_block_grow_max_to(General_Memory *general, i32 new_max, Dynamic_Variable_Block *block){ + u64 *new_array = (u64*)general_memory_allocate(general, sizeof(u64)*new_max); + memcpy(new_array, block->val_array, sizeof(u64)*block->count); + general_memory_free(general, block->val_array); + block->val_array = new_array; +} + +internal void +dynamic_variables_block_fill_unset_values(Dynamic_Variable_Layout *layout, Dynamic_Variable_Block *block, + i32 one_past_last_index){ + i32 first_location = block->count + 1; + i32 one_past_last_location = one_past_last_index + 1; + block->count = one_past_last_index; + for (Dynamic_Variable_Slot *slot = layout->sentinel.next; + slot != &layout->sentinel; + slot = slot->next){ + if (first_location <= slot->location && slot->location < one_past_last_location){ + block->val_array[slot->location - 1] = slot->default_value; + } + } +} + +internal b32 +dynamic_variables_get_ptr(General_Memory *general, + Dynamic_Variable_Layout *layout, Dynamic_Variable_Block *block, + i32 location, u64 **ptr_out){ + b32 result = false; + if (location > 0 && location < layout->location_counter){ + i32 index = location - 1; + if (index >= block->count){ + i32 minimum_max = layout->location_counter - 1; + if (block->max < minimum_max){ + dynamic_variables_block_grow_max_to(general, minimum_max*2, block); + } + dynamic_variables_block_fill_unset_values(layout, block, index + 1); + } + *ptr_out = block->val_array + index; + result = true; + } + return(result); +} + +// BOTTOM + diff --git a/4ed_dynamic_variables.h b/4ed_dynamic_variables.h new file mode 100644 index 00000000..3de8b14c --- /dev/null +++ b/4ed_dynamic_variables.h @@ -0,0 +1,37 @@ +/* + * Mr. 4th Dimention - Allen Webster + * + * 22.06.2018 + * + * Dynamic variable system + * + */ + +// TOP + +#if !defined(FRED_DYNAMIC_VARIABLES_H) +#define FRED_DYNAMIC_VARIABLES_H + +struct Dynamic_Variable_Slot{ + Dynamic_Variable_Slot *next; + Dynamic_Variable_Slot *prev; + String name; + u64 default_value; + i32 location; +}; + +struct Dynamic_Variable_Layout{ + Dynamic_Variable_Slot sentinel; + i32 location_counter; +}; + +struct Dynamic_Variable_Block{ + u64 *val_array; + i32 count; + i32 max; +}; + +#endif + +// BOTTOM + diff --git a/4ed_view.cpp b/4ed_view.cpp index 6fe327cf..5ca75d22 100644 --- a/4ed_view.cpp +++ b/4ed_view.cpp @@ -36,6 +36,8 @@ live_set_alloc_view(General_Memory *general, Live_Views *live_set, Panel *panel) gui_mem = advance_to_alignment(gui_mem); result.view->transient.gui_target.push = make_part(gui_mem, gui_mem_size); + dynamic_variables_block_init(general, &result.view->transient.dynamic_vars); + return(result); } @@ -52,6 +54,8 @@ live_set_free_view(General_Memory *general, Live_Views *live_set, View *view){ live_set->free_sentinel.transient.next = view; view->transient.next->transient.prev = view; view->transient.in_use = false; + + dynamic_variables_block_free(general, &view->transient.dynamic_vars); } //////////////////////////////// diff --git a/4ed_view.h b/4ed_view.h index 75c02521..2b7cdc63 100644 --- a/4ed_view.h +++ b/4ed_view.h @@ -87,6 +87,7 @@ struct View_Transient{ i32 map; File_Viewing_Data file_data; + Dynamic_Variable_Block dynamic_vars; i32_Rect file_region_prev; i32_Rect file_region; diff --git a/languages/4coder_language_cpp.h b/languages/4coder_language_cpp.h index e19ab9a0..48fc20b4 100644 --- a/languages/4coder_language_cpp.h +++ b/languages/4coder_language_cpp.h @@ -47,6 +47,7 @@ init_language_cpp(Application_Links *app){ PSAT("long" , CPP_TOKEN_KEY_MODIFIER), PSAT("short" , CPP_TOKEN_KEY_MODIFIER), PSAT("unsigned" , CPP_TOKEN_KEY_MODIFIER), + PSAT("signed" , CPP_TOKEN_KEY_MODIFIER), PSAT("const" , CPP_TOKEN_KEY_QUALIFIER), PSAT("volatile" , CPP_TOKEN_KEY_QUALIFIER),