View change buffer hook

This commit is contained in:
Allen Webster 2020-05-03 06:24:39 -07:00
parent 265e112cf2
commit 7c1931ebb0
5 changed files with 26 additions and 0 deletions

View File

@ -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; models->layout_func = (Layout_Function*)func_ptr;
}break; }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; result = (Void_Func*)models->layout_func;
}break; }break;
case HookID_ViewChangeBuffer:
{
result = (Void_Func*)models->view_change_buffer;
}break;
} }
return(result); return(result);
} }

View File

@ -82,6 +82,7 @@ struct Models{
Buffer_Edit_Range_Function *buffer_edit_range; Buffer_Edit_Range_Function *buffer_edit_range;
Buffer_Region_Function *buffer_region; Buffer_Region_Function *buffer_region;
Layout_Function *layout_func; Layout_Function *layout_func;
View_Change_Buffer_Function *view_change_buffer;
Color_Table color_table_; Color_Table color_table_;

View File

@ -447,6 +447,13 @@ internal void
view_set_file(Thread_Context *tctx, Models *models, View *view, Editing_File *file){ view_set_file(Thread_Context *tctx, Models *models, View *view, Editing_File *file){
Assert(file != 0); 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; Editing_File *old_file = view->file;
if (old_file != 0){ if (old_file != 0){
file_touch(&models->working_set, old_file); file_touch(&models->working_set, old_file);

View File

@ -1038,6 +1038,11 @@ BUFFER_HOOK_SIG(default_end_buffer){
return(0); return(0);
} }
function void
default_view_change_buffer(Application_Links *app, View_ID view_id, Buffer_ID buffer_id){
// do nothing
}
internal void internal void
set_all_default_hooks(Application_Links *app){ set_all_default_hooks(Application_Links *app){
set_custom_hook(app, HookID_BufferViewerUpdate, default_view_adjust); 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_SaveFile, default_file_save);
set_custom_hook(app, HookID_BufferEditRange, default_buffer_edit_range); set_custom_hook(app, HookID_BufferEditRange, default_buffer_edit_range);
set_custom_hook(app, HookID_BufferRegion, default_buffer_region); 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_unwrapped);
//set_custom_hook(app, HookID_Layout, layout_wrap_anywhere); //set_custom_hook(app, HookID_Layout, layout_wrap_anywhere);

View File

@ -650,6 +650,7 @@ enum{
HookID_BufferEditRange, HookID_BufferEditRange,
HookID_BufferRegion, HookID_BufferRegion,
HookID_Layout, HookID_Layout,
HookID_ViewChangeBuffer,
}; };
api(custom) api(custom)
@ -699,6 +700,9 @@ typedef void Render_Caller_Function(Application_Links *app, Frame_Info frame_inf
api(custom) api(custom)
typedef void Whole_Screen_Render_Caller_Function(Application_Links *app, Frame_Info frame_info); 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) api(custom)
typedef u32 Layout_Item_Flag; typedef u32 Layout_Item_Flag;
enum{ enum{