From f37b2032c191d3ec438160ac58ca56f1eef08771 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Wed, 29 Jun 2016 14:23:14 -0400 Subject: [PATCH] eliminated the poopy-poop-sauce set/get rewrite functions --- 4coder_API.html | 54 ++++++++++++------------------------ 4coder_custom.h | 33 +++++++++++++++------- 4coder_custom_api.h | 10 +------ 4coder_default_bindings.cpp | 26 +++++++++++++---- 4coder_default_include.cpp | 11 ++++---- 4coder_helper.h | 20 +++++++++++++ 4ed.cpp | 22 +++++++++++++-- 4ed_api_implementation.cpp | 4 ++- 4ed_app_models.h | 1 + power/4coder_experiments.cpp | 1 + 10 files changed, 111 insertions(+), 71 deletions(-) diff --git a/4coder_API.html b/4coder_API.html index 841bb06a..09f6f2d3 100644 --- a/4coder_API.html +++ b/4coder_API.html @@ -114,12 +114,6 @@ This is the documentation for alpha 4.0.9 super! The documentation has been made view_post_fade
  • -view_set_paste_rewrite_ -
  • -
  • -view_get_paste_rewrite_ -
  • -
  • get_user_input
  • @@ -172,7 +166,7 @@ This is the documentation for alpha 4.0.9 super! The documentation has been made

    §2.2.0: exec_command

    void app->exec_command( -
    Application_Links *app,
    int command_id
    ) +
    Application_Links *app,
    uint64_t command_id
    )
    Parameters
    command_id
    @@ -733,22 +727,8 @@ cancels and dialogue shown in the view and displays the file.
    the color to fade from

    -
    -

    §2.2.29: view_set_paste_rewrite_

    -
    void app->view_set_paste_rewrite_( -
    Application_Links *app,
    View_Summary *view
    ) -
    -No documentation generated for this function, assume it is non-public. -

    -
    -

    §2.2.30: view_get_paste_rewrite_

    -
    int app->view_get_paste_rewrite_( -
    Application_Links *app,
    View_Summary *view
    ) -
    -No documentation generated for this function, assume it is non-public. -

    -

    §2.2.31: get_user_input

    +

    §2.2.29: get_user_input

    User_Input app->get_user_input(
    Application_Links *app,
    unsigned int get_type,
    unsigned int abort_type
    )
    @@ -766,19 +746,19 @@ command is executed an abort signal is returned. If an abort signal is ever ret command should finish execution without any more calls that preempt the command. If a get condition is met the user input is returned
    See Also
    Input_Type_Flag
    User_Input

    -

    §2.2.32: get_command_input

    +

    §2.2.30: get_command_input

    User_Input app->get_command_input(
    Application_Links *app
    )
    Return
    returns the input that triggered the command in execution.
    See Also
    User_Input

    -

    §2.2.33: get_mouse_state

    +

    §2.2.31: get_mouse_state

    Mouse_State app->get_mouse_state(
    Application_Links *app
    )
    Return
    returns the current mouse state
    See Also
    Mouse_State

    -

    §2.2.34: start_query_bar

    +

    §2.2.32: start_query_bar

    int app->start_query_bar(
    Application_Links *app,
    Query_Bar *bar,
    unsigned int flags
    )
    @@ -793,7 +773,7 @@ If a get condition is met the user input is returned
    Return
    returns non-zero on success
    Description
    The memory pointed to by bar must remain valid until a call to end_query_bar or until the command returns.

    -

    §2.2.35: end_query_bar

    +

    §2.2.33: end_query_bar

    void app->end_query_bar(
    Application_Links *app,
    Query_Bar *bar,
    unsigned int flags
    )
    @@ -807,7 +787,7 @@ until the command returns.

    Description
    bar must be a pointer previously passed to start_query_bar previously in the same command.



    -

    §2.2.37: change_theme

    +

    §2.2.35: change_theme

    void app->change_theme(
    Application_Links *app,
    char *name,
    int len
    )
    @@ -835,7 +815,7 @@ until the command returns.


    -

    §2.2.38: change_font

    +

    §2.2.36: change_font

    void app->change_font(
    Application_Links *app,
    char *name,
    int len
    )
    @@ -849,7 +829,7 @@ until the command returns.


    -

    §2.2.39: set_theme_colors

    +

    §2.2.37: set_theme_colors

    void app->set_theme_colors(
    Application_Links *app,
    Theme_Color *colors,
    int count
    )
    @@ -864,7 +844,7 @@ until the command returns.

    Description
    For each color struct in the array, the color in the style pallet is set to the color code paired with the tag.

    -

    §2.2.40: get_theme_colors

    +

    §2.2.38: get_theme_colors

    void app->get_theme_colors(
    Application_Links *app,
    Theme_Color *colors,
    int count
    )
    @@ -879,7 +859,7 @@ code paired with the tag.

    Description
    For each color struct in the array, the color field of the struct is filled with the color from the specified color in the pallet.

    -

    §2.2.41: directory_get_hot

    +

    §2.2.39: directory_get_hot

    int app->directory_get_hot(
    Application_Links *app,
    char *out,
    int capacity
    )
    @@ -897,7 +877,7 @@ accessed in the GUI. Whenever the GUI is opened it shows the hot directory. In the future this will be deprecated and eliminated in favor of more flexible directories controlled by the custom side.

    -

    §2.2.42: get_file_list

    +

    §2.2.40: get_file_list

    File_List app->get_file_list(
    Application_Links *app,
    char *dir,
    int len
    )
    @@ -913,7 +893,7 @@ directories controlled by the custom side.

    the specified directory. The File_List returned should be passed to free_file_list when it is no longer in use.
    -

    §2.2.43: free_file_list

    +

    §2.2.41: free_file_list

    void app->free_file_list(
    Application_Links *app,
    File_List list
    )
    @@ -923,7 +903,7 @@ when it is no longer in use.

    Description
    after this call the file list passed in should not be read or written to

    -

    §2.2.44: file_exists

    +

    §2.2.42: file_exists

    int app->file_exists(
    Application_Links *app,
    char *filename,
    int len
    )
    @@ -937,7 +917,7 @@ when it is no longer in use.

    Return
    returns non-zero if the file exists, returns zero if the file does not exist

    -

    §2.2.45: directory_cd

    +

    §2.2.43: directory_cd

    int app->directory_cd(
    Application_Links *app,
    char *dir,
    int *len,
    int capacity,
    char *rel_path,
    int rel_len
    )
    @@ -969,7 +949,7 @@ For instance if dir contains "C:/Users/MySelf" and rel is "Documents" the buffer "C:/Users/MySelf/Documents" and len will contain the length of that string. This call can also be used with rel set to ".." to traverse to parent folders.

    -

    §2.2.46: get_4ed_path

    +

    §2.2.44: get_4ed_path

    int app->get_4ed_path(
    Application_Links *app,
    char *out,
    int capacity
    )
    diff --git a/4coder_custom.h b/4coder_custom.h index 82466a7b..77d99ae4 100644 --- a/4coder_custom.h +++ b/4coder_custom.h @@ -2,6 +2,8 @@ #ifndef FCODER_CUSTOM_H #define FCODER_CUSTOM_H +#include + #include "4coder_version.h" #include "4coder_keycodes.h" #include "4coder_style.h" @@ -112,7 +114,9 @@ typedef struct Buffer_Identifier{ int id; } Buffer_Identifier; -enum Command_ID{ +typedef uint64_t Command_ID; + +enum{ cmdid_null, cmdid_center_view, @@ -177,6 +181,7 @@ enum Special_Hook_ID{ _hook_scroll_rule = hook_type_count, _hook_new_file, _hook_open_file, + _hook_command_caller, }; // None of the members of *_Summary structs nor any of the data pointed @@ -336,15 +341,23 @@ enum Input_Type_Flag{ #define OPEN_FILE_HOOK_SIG(name) int name(struct Application_Links *app, int buffer_id) #define SCROLL_RULE_SIG(name) int name(float target_x, float target_y, float *scroll_x, float *scroll_y, int view_id, int is_new_target, float dt) -extern "C"{ - typedef VIEW_ROUTINE_SIG(View_Routine_Function); - typedef CUSTOM_COMMAND_SIG(Custom_Command_Function); - typedef GET_BINDING_DATA(Get_Binding_Data_Function); - typedef HOOK_SIG(Hook_Function); - - typedef OPEN_FILE_HOOK_SIG(Open_File_Hook_Function); - typedef SCROLL_RULE_SIG(Scroll_Rule_Function); -} +typedef VIEW_ROUTINE_SIG(View_Routine_Function); +typedef CUSTOM_COMMAND_SIG(Custom_Command_Function); +typedef GET_BINDING_DATA(Get_Binding_Data_Function); +typedef HOOK_SIG(Hook_Function); + +typedef OPEN_FILE_HOOK_SIG(Open_File_Hook_Function); +typedef SCROLL_RULE_SIG(Scroll_Rule_Function); + +union Generic_Command{ + Command_ID cmdid; + Custom_Command_Function *command; +}; + +#define COMMAND_CALLER_HOOK(name) int name(struct Application_Links *app, Generic_Command cmd) +typedef COMMAND_CALLER_HOOK(Command_Caller_Hook_Function); + + struct Application_Links; #include "4coder_custom_api.h" diff --git a/4coder_custom_api.h b/4coder_custom_api.h index 803df366..685fc712 100644 --- a/4coder_custom_api.h +++ b/4coder_custom_api.h @@ -1,4 +1,4 @@ -#define EXEC_COMMAND_SIG(n) void n(Application_Links *app, int command_id) +#define EXEC_COMMAND_SIG(n) void n(Application_Links *app, uint64_t command_id) #define EXEC_SYSTEM_COMMAND_SIG(n) int n(Application_Links *app, View_Summary *view, Buffer_Identifier buffer, char *path, int path_len, char *command, int command_len, unsigned int flags) #define CLIPBOARD_POST_SIG(n) void n(Application_Links *app, char *str, int len) #define CLIPBOARD_COUNT_SIG(n) int n(Application_Links *app) @@ -27,8 +27,6 @@ #define VIEW_SET_HIGHLIGHT_SIG(n) int n(Application_Links *app, View_Summary *view, int start, int end, int turn_on) #define VIEW_SET_BUFFER_SIG(n) int n(Application_Links *app, View_Summary *view, int buffer_id, unsigned int flags) #define VIEW_POST_FADE_SIG(n) int n(Application_Links *app, View_Summary *view, float seconds, int start, int end, unsigned int color) -#define VIEW_SET_PASTE_REWRITE__SIG(n) void n(Application_Links *app, View_Summary *view) -#define VIEW_GET_PASTE_REWRITE__SIG(n) int n(Application_Links *app, View_Summary *view) #define GET_USER_INPUT_SIG(n) User_Input n(Application_Links *app, unsigned int get_type, unsigned int 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) @@ -75,8 +73,6 @@ extern "C"{ 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 VIEW_SET_PASTE_REWRITE__SIG(View_Set_Paste_Rewrite__Function); - typedef VIEW_GET_PASTE_REWRITE__SIG(View_Get_Paste_Rewrite__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); @@ -126,8 +122,6 @@ struct Application_Links{ View_Set_Highlight_Function *view_set_highlight; View_Set_Buffer_Function *view_set_buffer; View_Post_Fade_Function *view_post_fade; - View_Set_Paste_Rewrite__Function *view_set_paste_rewrite_; - View_Get_Paste_Rewrite__Function *view_get_paste_rewrite_; Get_User_Input_Function *get_user_input; Get_Command_Input_Function *get_command_input; Get_Mouse_State_Function *get_mouse_state; @@ -179,8 +173,6 @@ 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->view_set_paste_rewrite_ = View_Set_Paste_Rewrite_;\ -app_links->view_get_paste_rewrite_ = View_Get_Paste_Rewrite_;\ app_links->get_user_input = Get_User_Input;\ app_links->get_command_input = Get_Command_Input;\ app_links->get_mouse_state = Get_Mouse_State;\ diff --git a/4coder_default_bindings.cpp b/4coder_default_bindings.cpp index 8337d8b9..132f6d53 100644 --- a/4coder_default_bindings.cpp +++ b/4coder_default_bindings.cpp @@ -148,12 +148,10 @@ HOOK_SIG(my_start){ } OPEN_FILE_HOOK_SIG(my_file_settings){ - // NOTE(allen|a4): In hooks that want parameters, such as this file - // opened hook. The file created hook is guaranteed to have only - // and exactly one buffer parameter. In normal command callbacks - // there are no parameter buffers. + // NOTE(allen|a4.0.8): The app->get_parameter_buffer was eliminated + // and instead the buffer is passed as an explicit parameter through + // the function call. That is where buffer_id comes from here. unsigned int access = AccessProtected|AccessHidden; - //Buffer_Summary buffer = app->get_parameter_buffer(app, 0, access); Buffer_Summary buffer = app->get_buffer(app, buffer_id, access); assert(buffer.exists); @@ -184,6 +182,23 @@ OPEN_FILE_HOOK_SIG(my_file_settings){ return(0); } +// NOTE(allen|a4.0.9): All command calls can now go through this hook +// If this hook is not implemented a default behavior of calling the +// command is used. It is important to note that paste_next does not +// work without this hook. +COMMAND_CALLER_HOOK(my_command_caller){ + View_Summary view = app->get_active_view(app, AccessAll); + + view_paste_index[view.view_id].next_rewrite = false; + + exec_command(app, cmd); + + view_paste_index[view.view_id].rewrite = + view_paste_index[view.view_id].next_rewrite; + + return(0); +} + void default_keys(Bind_Helper *context){ begin_map(context, mapid_global); @@ -338,6 +353,7 @@ get_bindings(void *data, int size){ set_hook(context, hook_start, my_start); set_open_file_hook(context, my_file_settings); + set_command_caller(context, my_command_caller); set_scroll_rule(context, smooth_scroll_rule); default_keys(context); diff --git a/4coder_default_include.cpp b/4coder_default_include.cpp index e1621e32..6c6e22d1 100644 --- a/4coder_default_include.cpp +++ b/4coder_default_include.cpp @@ -275,6 +275,8 @@ CUSTOM_COMMAND_SIG(cut){ } struct View_Paste_Index{ + int rewrite; + int next_rewrite; int index; }; @@ -287,10 +289,7 @@ CUSTOM_COMMAND_SIG(paste){ if (count > 0){ View_Summary view = app->get_active_view(app, access); - // NOTE(allen): THIS is a very temporary poop-sauce - // system that I just threw in to get this working. - // Please don't start calling it anywhere. - app->view_set_paste_rewrite_(app, &view); + view_paste_index[view.view_id].next_rewrite = true; int paste_index = 0; view_paste_index[view.view_id].index = paste_index; @@ -329,8 +328,8 @@ CUSTOM_COMMAND_SIG(paste_next){ // NOTE(allen): THIS is a very temporary poop-sauce // system that I just threw in to get this working. // Please don't start calling it anywhere. - if (app->view_get_paste_rewrite_(app, &view)){ - app->view_set_paste_rewrite_(app, &view); + if (view_paste_index[view.view_id].rewrite){ + view_paste_index[view.view_id].next_rewrite = true; int paste_index = view_paste_index[view.view_id].index + 1; view_paste_index[view.view_id].index = paste_index; diff --git a/4coder_helper.h b/4coder_helper.h index 1aada635..00c9997b 100644 --- a/4coder_helper.h +++ b/4coder_helper.h @@ -196,6 +196,16 @@ set_new_file_hook(Bind_Helper *helper, Open_File_Hook_Function *func){ write_unit(helper, unit); } +inline void +set_command_caller(Bind_Helper *helper, Command_Caller_Hook_Function *func){ + Binding_Unit unit; + unit.type = unit_hook; + unit.hook.hook_id = _hook_command_caller; + unit.hook.func = (void*) func; + + write_unit(helper, unit); +} + inline void set_scroll_rule(Bind_Helper *helper, Scroll_Rule_Function *func){ Binding_Unit unit; @@ -263,6 +273,16 @@ exec_command(Application_Links *app, Custom_Command_Function *func){ func(app); } +inline void +exec_command(Application_Links *app, Generic_Command cmd){ + if (cmd.cmdid < cmdid_count){ + exec_command(app, cmd.cmdid); + } + else{ + exec_command(app, cmd.command); + } +} + inline void active_view_to_line(Application_Links *app, unsigned int access, int line_number){ View_Summary view; diff --git a/4ed.cpp b/4ed.cpp index 6e0e6d74..b4b29089 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -1005,12 +1005,24 @@ internal void command_caller(Coroutine *coroutine){ Command_In *cmd_in = (Command_In*)coroutine->in; Command_Data *cmd = cmd_in->cmd; + Models *models = cmd->models; View *view = cmd->view; - // TODO(allen): this isn't really super awesome, could have issues if - // the file view get's change out under us. view->next_mode = view_mode_zero(); - cmd_in->bind.function(cmd->system, cmd, cmd_in->bind); + if (models->command_caller){ + Generic_Command generic; + if (cmd_in->bind.function == command_user_callback){ + generic.command = cmd_in->bind.custom; + models->command_caller(&models->app_links, generic); + } + else{ + generic.cmdid = (Command_ID)cmd_in->bind.custom_id; + models->command_caller(&models->app_links, generic); + } + } + else{ + cmd_in->bind.function(cmd->system, cmd, cmd_in->bind); + } view->mode = view->next_mode; } @@ -1773,6 +1785,10 @@ App_Init_Sig(app_init){ models->hook_new_file = (Open_File_Hook_Function*)unit->hook.func; break; + case _hook_command_caller: + models->command_caller = (Command_Caller_Hook_Function*)unit->hook.func; + break; + case _hook_scroll_rule: models->scroll_rule = (Scroll_Rule_Function*)unit->hook.func; break; diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index 1cb66485..75ac0276 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -142,7 +142,7 @@ imp_get_view(Command_Data *cmd, View_Summary *view){ #define API_EXPORT API_EXPORT void -Exec_Command(Application_Links *app, int command_id)/* +Exec_Command(Application_Links *app, uint64_t command_id)/* DOC_PARAM(command_id, an integer id enumerated in 4coder_custom.h starting with cmdid) DOC(Executes the command associated with the command_id passed in) */{ @@ -1331,6 +1331,7 @@ DOC_PARAM(color, the color to fade from) return(result); } +/* API_EXPORT void View_Set_Paste_Rewrite_(Application_Links *app, View_Summary *view){ Command_Data *cmd = (Command_Data*)app->cmd_context; @@ -1350,6 +1351,7 @@ View_Get_Paste_Rewrite_(Application_Links *app, View_Summary *view){ } return(result); } +*/ API_EXPORT User_Input Get_User_Input(Application_Links *app, unsigned int get_type, unsigned int abort_type)/* diff --git a/4ed_app_models.h b/4ed_app_models.h index 80c66a69..24a9865b 100644 --- a/4ed_app_models.h +++ b/4ed_app_models.h @@ -79,6 +79,7 @@ struct Models{ Open_File_Hook_Function *hook_open_file; Open_File_Hook_Function *hook_new_file; + Command_Caller_Hook_Function *command_caller; Scroll_Rule_Function *scroll_rule; b32 keep_playing; diff --git a/power/4coder_experiments.cpp b/power/4coder_experiments.cpp index 93cb6c63..09435c06 100644 --- a/power/4coder_experiments.cpp +++ b/power/4coder_experiments.cpp @@ -273,6 +273,7 @@ get_bindings(void *data, int size){ set_hook(context, hook_start, experimental_start_hook); set_open_file_hook(context, my_file_settings); + set_command_caller(context, my_command_caller); set_scroll_rule(context, smooth_scroll_rule);