From 7c1931ebb066fc849ce32d47ab15b33b628a6b9a Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Sun, 3 May 2020 06:24:39 -0700 Subject: [PATCH] View change buffer hook --- 4ed_api_implementation.cpp | 8 ++++++++ 4ed_app_models.h | 1 + 4ed_view.cpp | 7 +++++++ custom/4coder_default_hooks.cpp | 6 ++++++ custom/4coder_types.h | 4 ++++ 5 files changed, 26 insertions(+) diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index 50787a52..7e6f218f 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -2218,6 +2218,10 @@ set_custom_hook(Application_Links *app, Hook_ID hook_id, Void_Func *func_ptr){ { models->layout_func = (Layout_Function*)func_ptr; }break; + case HookID_ViewChangeBuffer: + { + models->view_change_buffer = (View_Change_Buffer_Function*)func_ptr; + }break; } } @@ -2282,6 +2286,10 @@ get_custom_hook(Application_Links *app, Hook_ID hook_id){ { result = (Void_Func*)models->layout_func; }break; + case HookID_ViewChangeBuffer: + { + result = (Void_Func*)models->view_change_buffer; + }break; } return(result); } diff --git a/4ed_app_models.h b/4ed_app_models.h index d8ad515a..594c7d65 100644 --- a/4ed_app_models.h +++ b/4ed_app_models.h @@ -82,6 +82,7 @@ struct Models{ Buffer_Edit_Range_Function *buffer_edit_range; Buffer_Region_Function *buffer_region; Layout_Function *layout_func; + View_Change_Buffer_Function *view_change_buffer; Color_Table color_table_; diff --git a/4ed_view.cpp b/4ed_view.cpp index fb54ce8e..93ebe3bd 100644 --- a/4ed_view.cpp +++ b/4ed_view.cpp @@ -447,6 +447,13 @@ internal void view_set_file(Thread_Context *tctx, Models *models, View *view, Editing_File *file){ Assert(file != 0); + if (models->view_change_buffer != 0){ + Application_Links app = {}; + app.tctx = tctx; + app.cmd_context = models; + models->view_change_buffer(&app, view_get_id(&models->view_set, view), file->id); + } + Editing_File *old_file = view->file; if (old_file != 0){ file_touch(&models->working_set, old_file); diff --git a/custom/4coder_default_hooks.cpp b/custom/4coder_default_hooks.cpp index c3670845..8561095e 100644 --- a/custom/4coder_default_hooks.cpp +++ b/custom/4coder_default_hooks.cpp @@ -1038,6 +1038,11 @@ BUFFER_HOOK_SIG(default_end_buffer){ return(0); } +function void +default_view_change_buffer(Application_Links *app, View_ID view_id, Buffer_ID buffer_id){ + // do nothing +} + internal void set_all_default_hooks(Application_Links *app){ set_custom_hook(app, HookID_BufferViewerUpdate, default_view_adjust); @@ -1059,6 +1064,7 @@ set_all_default_hooks(Application_Links *app){ set_custom_hook(app, HookID_SaveFile, default_file_save); set_custom_hook(app, HookID_BufferEditRange, default_buffer_edit_range); set_custom_hook(app, HookID_BufferRegion, default_buffer_region); + set_custom_hook(app, HookID_ViewChangeBuffer, default_view_change_buffer); set_custom_hook(app, HookID_Layout, layout_unwrapped); //set_custom_hook(app, HookID_Layout, layout_wrap_anywhere); diff --git a/custom/4coder_types.h b/custom/4coder_types.h index 42affdad..d74e3d98 100644 --- a/custom/4coder_types.h +++ b/custom/4coder_types.h @@ -650,6 +650,7 @@ enum{ HookID_BufferEditRange, HookID_BufferRegion, HookID_Layout, + HookID_ViewChangeBuffer, }; api(custom) @@ -699,6 +700,9 @@ typedef void Render_Caller_Function(Application_Links *app, Frame_Info frame_inf api(custom) typedef void Whole_Screen_Render_Caller_Function(Application_Links *app, Frame_Info frame_info); +api(custom) +typedef void View_Change_Buffer_Function(Application_Links *app, View_ID view_id, Buffer_ID buffer_id); + api(custom) typedef u32 Layout_Item_Flag; enum{