diff --git a/4coder_custom.cpp b/4coder_custom.cpp index 24e5a93e..b3f5bc8c 100644 --- a/4coder_custom.cpp +++ b/4coder_custom.cpp @@ -74,11 +74,11 @@ CUSTOM_COMMAND_SIG(write_decrement){ static void long_braces(Application_Links *app, char *text, int size){ - File_View_Summary view; + View_Summary view; Buffer_Summary buffer; int pos; - view = app->get_active_file_view(app); + view = app->get_active_view(app); buffer = app->get_buffer(app, view.buffer_id); pos = view.cursor.pos; @@ -110,7 +110,7 @@ CUSTOM_COMMAND_SIG(open_long_braces_break){ } CUSTOM_COMMAND_SIG(paren_wrap){ - File_View_Summary view; + View_Summary view; Buffer_Summary buffer; char text1[] = "("; @@ -122,7 +122,7 @@ CUSTOM_COMMAND_SIG(paren_wrap){ Range range; int pos; - view = app->get_active_file_view(app); + view = app->get_active_view(app); buffer = app->get_active_buffer(app); range = get_range(&view); @@ -134,7 +134,7 @@ CUSTOM_COMMAND_SIG(paren_wrap){ } CUSTOM_COMMAND_SIG(if0_off){ - File_View_Summary view; + View_Summary view; Buffer_Summary buffer; char text1[] = "#if 0\n"; @@ -146,7 +146,7 @@ CUSTOM_COMMAND_SIG(if0_off){ Range range; int pos; - view = app->get_active_file_view(app); + view = app->get_active_view(app); buffer = app->get_active_buffer(app); range = get_range(&view); @@ -158,7 +158,7 @@ CUSTOM_COMMAND_SIG(if0_off){ push_parameter(app, par_range_end, pos); exec_command(app, cmdid_auto_tab_range); - app->refresh_file_view(app, &view); + app->refresh_view(app, &view); range = get_range(&view); pos = range.max; @@ -170,15 +170,15 @@ CUSTOM_COMMAND_SIG(if0_off){ } CUSTOM_COMMAND_SIG(backspace_word){ - File_View_Summary view; + View_Summary view; Buffer_Summary buffer; int pos2, pos1; - view = app->get_active_file_view(app); + view = app->get_active_view(app); pos2 = view.cursor.pos; exec_command(app, cmdid_seek_alphanumeric_left); - app->refresh_file_view(app, &view); + app->refresh_view(app, &view); pos1 = view.cursor.pos; buffer = app->get_buffer(app, view.buffer_id); @@ -186,7 +186,7 @@ CUSTOM_COMMAND_SIG(backspace_word){ } CUSTOM_COMMAND_SIG(switch_to_compilation){ - File_View_Summary view; + View_Summary view; Buffer_Summary buffer; char name[] = "*compilation*"; @@ -194,17 +194,17 @@ CUSTOM_COMMAND_SIG(switch_to_compilation){ // TODO(allen): This will only work for file views for now. Fix up this // view nonsense so that view types aren't such an issue. - view = app->get_active_file_view(app); + view = app->get_active_view(app); buffer = app->get_buffer_by_name(app, name, name_size); app->view_set_buffer(app, &view, buffer.buffer_id); } CUSTOM_COMMAND_SIG(move_up_10){ - File_View_Summary view; + View_Summary view; float x, y; - view = app->get_active_file_view(app); + view = app->get_active_view(app); x = view.preferred_x; if (view.unwrapped_lines){ @@ -220,10 +220,10 @@ CUSTOM_COMMAND_SIG(move_up_10){ } CUSTOM_COMMAND_SIG(move_down_10){ - File_View_Summary view; + View_Summary view; float x, y; - view = app->get_active_file_view(app); + view = app->get_active_view(app); x = view.preferred_x; if (view.unwrapped_lines){ @@ -239,12 +239,12 @@ CUSTOM_COMMAND_SIG(move_down_10){ } CUSTOM_COMMAND_SIG(open_file_in_quotes){ - File_View_Summary view; + View_Summary view; Buffer_Summary buffer; char short_file_name[128]; int pos, start, end, size; - view = app->get_active_file_view(app); + view = app->get_active_view(app); buffer = app->get_buffer(app, view.buffer_id); pos = view.cursor.pos; app->buffer_seek_delimiter(app, &buffer, pos, '"', 1, &end); @@ -290,7 +290,7 @@ CUSTOM_COMMAND_SIG(reverse_search); static void isearch(Application_Links *app, int start_reversed){ - File_View_Summary view; + View_Summary view; Buffer_Summary buffer; User_Input in; Query_Bar bar; @@ -301,7 +301,7 @@ isearch(Application_Links *app, int start_reversed){ int reverse = start_reversed; int pos; - view = app->get_active_file_view(app); + view = app->get_active_view(app); buffer = app->get_buffer(app, view.buffer_id); pos = view.cursor.pos; @@ -408,18 +408,18 @@ CUSTOM_COMMAND_SIG(reverse_search){ } CUSTOM_COMMAND_SIG(rewrite_as_single_caps){ - File_View_Summary view; + View_Summary view; Buffer_Summary buffer; Range range; String string; int is_first, i; exec_command(app, cmdid_seek_token_left); - view = app->get_active_file_view(app); + view = app->get_active_view(app); range.min = view.cursor.pos; exec_command(app, cmdid_seek_token_right); - app->refresh_file_view(app, &view); + app->refresh_view(app, &view); range.max = view.cursor.pos; string.str = (char*)app->memory; @@ -486,9 +486,9 @@ CUSTOM_COMMAND_SIG(replace_in_range){ w = with.string; Buffer_Summary buffer; - File_View_Summary view; + View_Summary view; - view = app->get_active_file_view(app); + view = app->get_active_view(app); buffer = app->get_buffer(app, view.buffer_id); Range range = get_range(&view); @@ -525,7 +525,7 @@ CUSTOM_COMMAND_SIG(query_replace){ Query_Bar bar; Buffer_Summary buffer; - File_View_Summary view; + View_Summary view; int pos, new_pos; bar.prompt = make_lit_string("Replace? (y)es, (n)ext, (esc)\n"); @@ -533,7 +533,7 @@ CUSTOM_COMMAND_SIG(query_replace){ app->start_query_bar(app, &bar, 0); - view = app->get_active_file_view(app); + view = app->get_active_view(app); buffer = app->get_buffer(app, view.buffer_id); pos = view.cursor.pos; diff --git a/4coder_custom.h b/4coder_custom.h index 7d7fea81..fdacf685 100644 --- a/4coder_custom.h +++ b/4coder_custom.h @@ -122,7 +122,7 @@ struct Buffer_Summary{ int map_id; }; -struct File_View_Summary{ +struct View_Summary{ int exists; int view_id; int buffer_id; @@ -196,14 +196,14 @@ struct Application_Links; // File view manipulation #define GET_VIEW_MAX_INDEX_SIG(name) int name(Application_Links *context) -#define GET_FILE_VIEW_SIG(name) File_View_Summary name(Application_Links *context, int index) -#define GET_ACTIVE_FILE_VIEW_SIG(name) File_View_Summary name(Application_Links *context) +#define GET_VIEW_SIG(name) View_Summary name(Application_Links *context, int index) +#define GET_ACTIVE_VIEW_SIG(name) View_Summary name(Application_Links *context) -#define REFRESH_FILE_VIEW_SIG(name) int name(Application_Links *context, File_View_Summary *view) -#define VIEW_SET_CURSOR_SIG(name) int name(Application_Links *context, File_View_Summary *view, Buffer_Seek seek, int set_preferred_x) -#define VIEW_SET_MARK_SIG(name) int name(Application_Links *context, File_View_Summary *view, Buffer_Seek seek) -#define VIEW_SET_HIGHLIGHT_SIG(name) int name(Application_Links *context, File_View_Summary *view, int start, int end, int turn_on) -#define VIEW_SET_BUFFER_SIG(name) int name(Application_Links *context, File_View_Summary *view, int buffer_id) +#define REFRESH_VIEW_SIG(name) int name(Application_Links *context, View_Summary *view) +#define VIEW_SET_CURSOR_SIG(name) int name(Application_Links *context, View_Summary *view, Buffer_Seek seek, int set_preferred_x) +#define VIEW_SET_MARK_SIG(name) int name(Application_Links *context, View_Summary *view, Buffer_Seek seek) +#define VIEW_SET_HIGHLIGHT_SIG(name) int name(Application_Links *context, View_Summary *view, int start, int end, int turn_on) +#define VIEW_SET_BUFFER_SIG(name) int name(Application_Links *context, View_Summary *view, int buffer_id) // Directly get user input #define EventOnAnyKey 0x1 @@ -252,10 +252,10 @@ extern "C"{ // View manipulation typedef GET_VIEW_MAX_INDEX_SIG(Get_View_Max_Index_Function); - typedef GET_FILE_VIEW_SIG(Get_File_View_Function); - typedef GET_ACTIVE_FILE_VIEW_SIG(Get_Active_File_View_Function); + typedef GET_VIEW_SIG(Get_View_Function); + typedef GET_ACTIVE_VIEW_SIG(Get_Active_View_Function); - typedef REFRESH_FILE_VIEW_SIG(Refresh_File_View_Function); + typedef REFRESH_VIEW_SIG(Refresh_View_Function); typedef VIEW_SET_CURSOR_SIG(View_Set_Cursor_Function); typedef VIEW_SET_MARK_SIG(View_Set_Mark_Function); typedef VIEW_SET_HIGHLIGHT_SIG(View_Set_Highlight_Function); @@ -302,10 +302,10 @@ struct Application_Links{ // View manipulation Get_View_Max_Index_Function *get_view_max_index; - Get_File_View_Function *get_file_view; - Get_Active_File_View_Function *get_active_file_view; + Get_View_Function *get_view; + Get_Active_View_Function *get_active_view; - Refresh_File_View_Function *refresh_file_view; + Refresh_View_Function *refresh_view; View_Set_Cursor_Function *view_set_cursor; View_Set_Mark_Function *view_set_mark; View_Set_Highlight_Function *view_set_highlight; diff --git a/4coder_helper.h b/4coder_helper.h index 87bf9f0e..79431b9a 100644 --- a/4coder_helper.h +++ b/4coder_helper.h @@ -216,7 +216,7 @@ push_directory(Application_Links *app){ #endif inline Range -get_range(File_View_Summary *view){ +get_range(View_Summary *view){ Range range; range = make_range(view->cursor.pos, view->mark.pos); return(range); @@ -236,8 +236,8 @@ exec_command(Application_Links *app, Custom_Command_Function *func){ inline void active_view_to_line(Application_Links *app, int line_number){ - File_View_Summary view; - view = app->get_active_file_view(app); + View_Summary view; + view = app->get_active_view(app); // NOTE(allen|a3.4.4): We don't have to worry about whether this is a valid line number. // When it's not possible to place a cursor at the position for whatever reason it will set the diff --git a/4ed.cpp b/4ed.cpp index 76f29788..cf829a9f 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -177,7 +177,6 @@ globalvar Application_Links app_links; #define USE_MEM(n) Mem_Options *n = command->mem #define USE_PANEL(n) Panel *n = command->panel #define USE_VIEW(n) View *n = command->view -#define USE_FILE_VIEW(n) File_View *n = view_to_file_view(command->view) #define USE_FILE(n,v) Editing_File *n = 0; if (v) { (n) = (v)->file; } #define USE_WORKING_SET(n) Working_Set *n = command->working_set #define USE_LAYOUT(n) Editing_Layout *n = command->layout @@ -189,9 +188,7 @@ globalvar Application_Links app_links; #define USE_EXCHANGE(n) Exchange *n = command->exchange #define USE_FONT_SET(n) Font_Set *n = command->vars->font_set; -#define REQ_VIEW(n) View *n = command->view; if (!n) return -#define REQ_FILE_VIEW(n) File_View *n = view_to_file_view(command->view); if (!n) return -#define REQ_OPEN_FILE_VIEW(n) File_View *n = view_to_file_view(command->view); if (!n || n->locked) return +#define REQ_OPEN_VIEW(n) View *n = command->view; if (n->locked) return #define REQ_FILE_HISTORY(n,v) Editing_File *n = (v)->file; if (!n || !buffer_good(&n->state.buffer) || n->state.is_dummy || !n->state.undo.undo.edits) return #define REQ_FILE_LOADING(n,v) Editing_File *n = (v)->file; if (!n || n->state.is_dummy) return #define REQ_FILE(n,v) Editing_File *n = (v)->file; if (!n || !buffer_good(&n->state.buffer) || n->state.is_dummy) return @@ -242,7 +239,7 @@ param_stack_end(Partition *part){ return (Command_Parameter*)((char*)part->base + part->pos); } -internal File_View* +internal View* panel_make_empty(System_Functions *system, Exchange *exchange, App_Vars *vars, Style *style, Style_Font *global_font, Panel *panel){ @@ -251,7 +248,7 @@ panel_make_empty(System_Functions *system, Exchange *exchange, Working_Set *working_set = &vars->working_set; Delay *delay = &vars->delay1; - File_View *file_view; + View *file_view; View_And_ID new_view; Assert(panel->view == 0); @@ -273,7 +270,7 @@ COMMAND_DECL(null){ COMMAND_DECL(write_character){ ProfileMomentFunction(); - REQ_OPEN_FILE_VIEW(view); + REQ_OPEN_VIEW(view); REQ_FILE(file, view); USE_LAYOUT(layout); USE_MEM(mem); @@ -292,7 +289,7 @@ COMMAND_DECL(write_character){ COMMAND_DECL(seek_whitespace_right){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); i32 pos = buffer_seek_whitespace_right(&file->state.buffer, view->cursor.pos); @@ -301,7 +298,7 @@ COMMAND_DECL(seek_whitespace_right){ COMMAND_DECL(seek_whitespace_left){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); i32 pos = buffer_seek_whitespace_left(&file->state.buffer, view->cursor.pos); @@ -310,7 +307,7 @@ COMMAND_DECL(seek_whitespace_left){ COMMAND_DECL(seek_whitespace_up){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); i32 pos = buffer_seek_whitespace_up(&file->state.buffer, view->cursor.pos); @@ -319,7 +316,7 @@ COMMAND_DECL(seek_whitespace_up){ COMMAND_DECL(seek_whitespace_down){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); i32 pos = buffer_seek_whitespace_down(&file->state.buffer, view->cursor.pos); @@ -357,7 +354,7 @@ seek_token_right(Cpp_Token_Stack *tokens, i32 pos){ COMMAND_DECL(seek_token_left){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); if (file->state.tokens_complete){ @@ -368,7 +365,7 @@ COMMAND_DECL(seek_token_left){ COMMAND_DECL(seek_token_right){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); if (file->state.tokens_complete){ @@ -379,7 +376,7 @@ COMMAND_DECL(seek_token_right){ COMMAND_DECL(seek_white_or_token_right){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); i32 token_pos, white_pos; @@ -395,7 +392,7 @@ COMMAND_DECL(seek_white_or_token_right){ COMMAND_DECL(seek_white_or_token_left){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); i32 token_pos, white_pos; @@ -411,7 +408,7 @@ COMMAND_DECL(seek_white_or_token_left){ COMMAND_DECL(seek_alphanumeric_right){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); i32 pos = buffer_seek_alphanumeric_right(&file->state.buffer, view->cursor.pos); @@ -420,7 +417,7 @@ COMMAND_DECL(seek_alphanumeric_right){ COMMAND_DECL(seek_alphanumeric_left){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); i32 pos = buffer_seek_alphanumeric_left(&file->state.buffer, view->cursor.pos); @@ -429,7 +426,7 @@ COMMAND_DECL(seek_alphanumeric_left){ COMMAND_DECL(seek_alphanumeric_or_camel_right){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); i32 pos = buffer_seek_alphanumeric_or_camel_right(&file->state.buffer, view->cursor.pos); @@ -438,7 +435,7 @@ COMMAND_DECL(seek_alphanumeric_or_camel_right){ COMMAND_DECL(seek_alphanumeric_or_camel_left){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); i32 pos = buffer_seek_alphanumeric_or_camel_left(&file->state.buffer, view->cursor.pos); @@ -447,7 +444,7 @@ COMMAND_DECL(seek_alphanumeric_or_camel_left){ COMMAND_DECL(word_complete){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); USE_LAYOUT(layout); USE_MEM(mem); @@ -603,7 +600,7 @@ COMMAND_DECL(word_complete){ COMMAND_DECL(set_mark){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); view->mark = (i32)view->cursor.pos; @@ -611,7 +608,7 @@ COMMAND_DECL(set_mark){ COMMAND_DECL(copy){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); USE_WORKING_SET(working_set); USE_MEM(mem); @@ -647,7 +644,7 @@ COMMAND_DECL(copy){ COMMAND_DECL(cut){ ProfileMomentFunction(); - REQ_OPEN_FILE_VIEW(view); + REQ_OPEN_VIEW(view); REQ_FILE(file, view); USE_WORKING_SET(working_set); USE_LAYOUT(layout); @@ -690,7 +687,7 @@ COMMAND_DECL(cut){ COMMAND_DECL(paste){ ProfileMomentFunction(); - REQ_OPEN_FILE_VIEW(view); + REQ_OPEN_VIEW(view); REQ_FILE(file, view); USE_WORKING_SET(working_set); USE_LAYOUT(layout); @@ -698,7 +695,7 @@ COMMAND_DECL(paste){ Panel *panel, *used_panels; String *src; - File_View *current_view; + View *current_view; i32 pos_left, next_cursor_pos; if (working_set->clipboard_size > 0){ @@ -715,7 +712,7 @@ COMMAND_DECL(paste){ used_panels = &layout->used_sentinel; for (dll_items(panel, used_panels)){ - current_view = view_to_file_view(panel->view); + current_view = panel->view; if (current_view->file == file){ view_post_paste_effect(current_view, 20, pos_left, src->size, @@ -727,7 +724,7 @@ COMMAND_DECL(paste){ COMMAND_DECL(paste_next){ ProfileMomentFunction(); - REQ_OPEN_FILE_VIEW(view); + REQ_OPEN_VIEW(view); REQ_FILE(file, view); USE_WORKING_SET(working_set); USE_LAYOUT(layout); @@ -750,7 +747,7 @@ COMMAND_DECL(paste_next){ used_panels = &layout->used_sentinel; for (dll_items(panel, used_panels)){ - File_View *current_view = view_to_file_view(panel->view); + View *current_view = panel->view; if (current_view->file == file){ view_post_paste_effect(current_view, 20, range.start, src->size, @@ -765,7 +762,7 @@ COMMAND_DECL(paste_next){ COMMAND_DECL(delete_range){ ProfileMomentFunction(); - REQ_OPEN_FILE_VIEW(view); + REQ_OPEN_VIEW(view); REQ_FILE(file, view); USE_LAYOUT(layout); USE_MEM(mem); @@ -782,7 +779,7 @@ COMMAND_DECL(delete_range){ COMMAND_DECL(timeline_scrub){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE_HISTORY(file, view); view_set_widget(view, FWIDG_TIMELINES); @@ -792,7 +789,7 @@ COMMAND_DECL(timeline_scrub){ COMMAND_DECL(undo){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE_HISTORY(file, view); USE_LAYOUT(layout); USE_MEM(mem); @@ -802,7 +799,7 @@ COMMAND_DECL(undo){ COMMAND_DECL(redo){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE_HISTORY(file, view); USE_LAYOUT(layout); USE_MEM(mem); @@ -812,7 +809,7 @@ COMMAND_DECL(redo){ COMMAND_DECL(history_backward){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE_HISTORY(file, view); USE_LAYOUT(layout); USE_MEM(mem); @@ -822,7 +819,7 @@ COMMAND_DECL(history_backward){ COMMAND_DECL(history_forward){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE_HISTORY(file, view); USE_LAYOUT(layout); USE_MEM(mem); @@ -833,7 +830,7 @@ COMMAND_DECL(history_forward){ #if UseFileHistoryDump COMMAND_DECL(save_history){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); USE_MEM(mem); @@ -843,10 +840,10 @@ COMMAND_DECL(save_history){ COMMAND_DECL(interactive_new){ ProfileMomentFunction(); - USE_FILE_VIEW(fview); + USE_VIEW(view); USE_VARS(vars); - view_show_interactive(system, fview, &vars->map_ui, + view_show_interactive(system, view, &vars->map_ui, IAct_New, IInt_Sys_File_List, make_lit_string("New: ")); } @@ -936,9 +933,7 @@ COMMAND_DECL(interactive_open){ View *view = panel->view; Assert(view); - File_View *fview = view_to_file_view(view); - - view_show_interactive(system, fview, &vars->map_ui, + view_show_interactive(system, view, &vars->map_ui, IAct_Open, IInt_Sys_File_List, make_lit_string("Open: ")); } } @@ -957,7 +952,7 @@ view_file_in_panel(Command_Data *cmd, Panel *panel, Editing_File *file){ Partition old_part; Temp_Memory temp; View *old_view; - File_View *file_view; + View *file_view; file_view = file_view_init(panel->view, layout, working_set, delay, &vars->settings, &vars->hot_directory, mem, &vars->styles); @@ -985,7 +980,7 @@ view_file_in_panel(Command_Data *cmd, Panel *panel, Editing_File *file){ // the cursor position correct COMMAND_DECL(reopen){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); USE_EXCHANGE(exchange); USE_WORKING_SET(working_set); @@ -1010,7 +1005,7 @@ COMMAND_DECL(reopen){ COMMAND_DECL(save){ ProfileMomentFunction(); - USE_FILE_VIEW(view); + USE_VIEW(view); USE_FILE(file, view); USE_DELAY(delay); USE_WORKING_SET(working_set); @@ -1061,7 +1056,7 @@ COMMAND_DECL(save){ COMMAND_DECL(interactive_save_as){ ProfileMomentFunction(); - USE_FILE_VIEW(fview); + USE_VIEW(fview); USE_VARS(vars); view_show_interactive(system, fview, &vars->map_ui, @@ -1082,7 +1077,7 @@ COMMAND_DECL(change_active_panel){ COMMAND_DECL(interactive_switch_buffer){ ProfileMomentFunction(); - USE_FILE_VIEW(fview); + USE_VIEW(fview); USE_VARS(vars); view_show_interactive(system, fview, &vars->map_ui, @@ -1091,7 +1086,7 @@ COMMAND_DECL(interactive_switch_buffer){ COMMAND_DECL(interactive_kill_buffer){ ProfileMomentFunction(); - USE_FILE_VIEW(fview); + USE_VIEW(fview); USE_VARS(vars); view_show_interactive(system, fview, &vars->map_ui, @@ -1100,16 +1095,16 @@ COMMAND_DECL(interactive_kill_buffer){ COMMAND_DECL(kill_buffer){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); USE_DELAY(delay); - delayed_try_kill(delay, file->name.live_name, view->view_base.panel); + delayed_try_kill(delay, file->name.live_name, view->panel); } COMMAND_DECL(toggle_line_wrap){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); Relative_Scrolling scrolling = view_get_relative_scrolling(view); @@ -1133,14 +1128,14 @@ COMMAND_DECL(toggle_line_wrap){ COMMAND_DECL(toggle_show_whitespace){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); view->show_whitespace = !view->show_whitespace; } COMMAND_DECL(toggle_tokens){ #if BUFFER_EXPERIMENT_SCALPEL <= 0 ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); USE_MEM(mem); @@ -1155,7 +1150,7 @@ COMMAND_DECL(toggle_tokens){ internal void case_change_range(System_Functions *system, - Mem_Options *mem, File_View *view, Editing_File *file, + Mem_Options *mem, View *view, Editing_File *file, u8 a, u8 z, u8 char_delta){ #if BUFFER_EXPERIMENT_SCALPEL <= 0 Range range = make_range(view->cursor.pos, view->mark); @@ -1186,7 +1181,7 @@ case_change_range(System_Functions *system, COMMAND_DECL(to_uppercase){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); USE_MEM(mem); case_change_range(system, mem, view, file, 'a', 'z', (u8)('A' - 'a')); @@ -1194,7 +1189,7 @@ COMMAND_DECL(to_uppercase){ COMMAND_DECL(to_lowercase){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); USE_MEM(mem); case_change_range(system, mem, view, file, 'A', 'Z', (u8)('a' - 'A')); @@ -1202,7 +1197,7 @@ COMMAND_DECL(to_lowercase){ COMMAND_DECL(clean_all_lines){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); USE_LAYOUT(layout); USE_MEM(mem); @@ -1212,7 +1207,7 @@ COMMAND_DECL(clean_all_lines){ COMMAND_DECL(eol_dosify){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); file->settings.dos_write_mode = 1; @@ -1221,7 +1216,7 @@ COMMAND_DECL(eol_dosify){ COMMAND_DECL(eol_nixify){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); file->settings.dos_write_mode = 0; @@ -1230,7 +1225,7 @@ COMMAND_DECL(eol_nixify){ COMMAND_DECL(auto_tab_range){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); USE_LAYOUT(layout); USE_MEM(mem); @@ -1271,7 +1266,7 @@ COMMAND_DECL(auto_tab_range){ COMMAND_DECL(auto_tab_line_at_cursor){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); USE_LAYOUT(layout); USE_MEM(mem); @@ -1297,7 +1292,7 @@ COMMAND_DECL(auto_tab_line_at_cursor){ COMMAND_DECL(auto_tab_whole_file){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); USE_LAYOUT(layout); USE_MEM(mem); @@ -1450,7 +1445,7 @@ COMMAND_DECL(close_panel){ COMMAND_DECL(move_left){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); i32 pos = view->cursor.pos; @@ -1460,7 +1455,7 @@ COMMAND_DECL(move_left){ COMMAND_DECL(move_right){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); i32 size = buffer_size(&file->state.buffer); @@ -1471,7 +1466,7 @@ COMMAND_DECL(move_right){ COMMAND_DECL(delete){ ProfileMomentFunction(); - REQ_OPEN_FILE_VIEW(view); + REQ_OPEN_VIEW(view); REQ_FILE(file, view); USE_LAYOUT(layout); USE_MEM(mem); @@ -1493,7 +1488,7 @@ COMMAND_DECL(delete){ COMMAND_DECL(backspace){ ProfileMomentFunction(); - REQ_OPEN_FILE_VIEW(view); + REQ_OPEN_VIEW(view); REQ_FILE(file, view); USE_LAYOUT(layout); USE_MEM(mem); @@ -1516,7 +1511,7 @@ COMMAND_DECL(backspace){ COMMAND_DECL(move_up){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); USE_FONT_SET(font_set); USE_FONT(global_font); @@ -1532,7 +1527,7 @@ COMMAND_DECL(move_up){ COMMAND_DECL(move_down){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); USE_FONT_SET(font_set); USE_FONT(global_font); @@ -1546,7 +1541,7 @@ COMMAND_DECL(move_down){ COMMAND_DECL(seek_end_of_line){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); i32 pos = view_find_end_of_line(view, view->cursor.pos); @@ -1555,7 +1550,7 @@ COMMAND_DECL(seek_end_of_line){ COMMAND_DECL(seek_beginning_of_line){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE(file, view); i32 pos = view_find_beginning_of_line(view, view->cursor.pos); @@ -1564,7 +1559,7 @@ COMMAND_DECL(seek_beginning_of_line){ COMMAND_DECL(page_down){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); f32 height = view_compute_height(view); f32 max_target_y = view_compute_max_target_y(view); @@ -1578,7 +1573,7 @@ COMMAND_DECL(page_down){ COMMAND_DECL(page_up){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); f32 height = view_compute_height(view); @@ -1591,7 +1586,7 @@ COMMAND_DECL(page_up){ COMMAND_DECL(open_color_tweaker){ ProfileMomentFunction(); - USE_FILE_VIEW(fview); + USE_VIEW(fview); USE_VARS(vars); view_show_theme(fview, &vars->map_ui); @@ -1599,7 +1594,7 @@ COMMAND_DECL(open_color_tweaker){ COMMAND_DECL(open_config){ ProfileMomentFunction(); - USE_FILE_VIEW(fview); + USE_VIEW(fview); USE_VARS(vars); view_show_config(fview, &vars->map_ui); @@ -1607,7 +1602,7 @@ COMMAND_DECL(open_config){ COMMAND_DECL(open_menu){ ProfileMomentFunction(); - USE_FILE_VIEW(fview); + USE_VIEW(fview); USE_VARS(vars); view_show_menu(fview, &vars->map_ui); @@ -1615,20 +1610,19 @@ COMMAND_DECL(open_menu){ COMMAND_DECL(close_minor_view){ ProfileMomentFunction(); - REQ_VIEW(view); - USE_FILE_VIEW(fview); + USE_VIEW(view); USE_VARS(vars); Command_Map *map = &vars->map_top; - if (fview->file){ - map = app_get_map(vars, fview->file->settings.base_map_id); + if (view->file){ + map = app_get_map(vars, view->file->settings.base_map_id); } - view_show_file(fview, map); + view_show_file(view, map); } COMMAND_DECL(cursor_mark_swap){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); i32 pos = view->cursor.pos; view_cursor_move(view, view->mark); @@ -1642,7 +1636,7 @@ COMMAND_DECL(user_callback){ COMMAND_DECL(set_settings){ ProfileMomentFunction(); - REQ_FILE_VIEW(view); + USE_VIEW(view); REQ_FILE_LOADING(file, view); USE_VARS(vars); USE_MEM(mem); @@ -1756,8 +1750,8 @@ build(System_Functions *system, Mem_Options *mem, if (!(flags & CLI_AlwaysBindToView)){ Panel *panel = layout->panels; for (i32 i = 0; i < layout->panel_count; ++i, ++panel){ - File_View *fview = view_to_file_view(panel->view); - if (fview && fview->file == file){ + View *view = panel->view; + if (view->file == file){ bind_to_new_view = 0; break; } @@ -1902,7 +1896,7 @@ fill_buffer_summary(Buffer_Summary *buffer, Editing_File *file, Working_Set *wor } internal void -fill_view_summary(File_View_Summary *view, File_View *file_view, Live_Views *live_set, Working_Set *working_set){ +fill_view_summary(View_Summary *view, View *file_view, Live_Views *live_set, Working_Set *working_set){ view->exists = 1; view->view_id = (int)((char*)file_view - (char*)live_set->views) / live_set->stride; if (file_view->file){ @@ -2006,12 +2000,12 @@ extern "C"{ GET_ACTIVE_BUFFER_SIG(external_get_active_buffer){ Command_Data *cmd = (Command_Data*)context->cmd_context; - File_View *view; + View *view; Editing_File *file; Working_Set *working_set; Buffer_Summary buffer = {}; - view = view_to_file_view(cmd->view); + view = cmd->view; if (view){ file = view->file; working_set = cmd->working_set; @@ -2213,41 +2207,35 @@ extern "C"{ return(max); } - GET_FILE_VIEW_SIG(external_get_file_view){ + GET_VIEW_SIG(external_get_view){ Command_Data *cmd = (Command_Data*)context->cmd_context; Live_Views *live_set = cmd->live_set; int max = live_set->max; View *vptr; - File_View *file_view; - File_View_Summary view = {}; + View_Summary view = {}; if (index >= 0 && index < max){ vptr = (View*)((char*)live_set->views + live_set->stride*index); - file_view = view_to_file_view(vptr); - if (file_view){ - fill_view_summary(&view, file_view, cmd->live_set, cmd->working_set); - } + fill_view_summary(&view, vptr, cmd->live_set, cmd->working_set); } return(view); } - GET_ACTIVE_FILE_VIEW_SIG(external_get_active_file_view){ + GET_ACTIVE_VIEW_SIG(external_get_active_view){ Command_Data *cmd = (Command_Data*)context->cmd_context; - File_View_Summary view = {}; - File_View *file_view; - - file_view = view_to_file_view(cmd->view); - if (file_view){ - fill_view_summary(&view, file_view, cmd->live_set, cmd->working_set); - } - + View_Summary view = {}; + View *vptr; + + vptr = cmd->view; + fill_view_summary(&view, vptr, cmd->live_set, cmd->working_set); + return(view); } - REFRESH_FILE_VIEW_SIG(external_refresh_file_view){ + REFRESH_VIEW_SIG(external_refresh_view){ int result; - *view = external_get_file_view(context, view->view_id); + *view = external_get_view(context, view->view_id); result = view->exists; return(result); } @@ -2256,21 +2244,17 @@ extern "C"{ Command_Data *cmd = (Command_Data*)context->cmd_context; Live_Views *live_set; View *vptr; - File_View *file_view; int result = 0; - + if (view->exists){ live_set = cmd->live_set; vptr = (View*)((char*)live_set->views + live_set->stride * view->view_id); - file_view = view_to_file_view(vptr); - if (file_view){ - result = 1; - file_view->cursor = view_compute_cursor(file_view, seek); - if (set_preferred_x){ - file_view->preferred_x = view_get_cursor_x(file_view); - } - fill_view_summary(view, file_view, cmd->live_set, cmd->working_set); + result = 1; + vptr->cursor = view_compute_cursor(vptr, seek); + if (set_preferred_x){ + vptr->preferred_x = view_get_cursor_x(vptr); } + fill_view_summary(view, vptr, cmd->live_set, cmd->working_set); } return(result); @@ -2280,25 +2264,21 @@ extern "C"{ Command_Data *cmd = (Command_Data*)context->cmd_context; Live_Views *live_set; View *vptr; - File_View *file_view; Full_Cursor cursor; int result = 0; if (view->exists){ live_set = cmd->live_set; vptr = (View*)((char*)live_set->views + live_set->stride * view->view_id); - file_view = view_to_file_view(vptr); - if (file_view){ - result = 1; - if (seek.type != buffer_seek_pos){ - cursor = view_compute_cursor(file_view, seek); - file_view->mark = cursor.pos; - } - else{ - file_view->mark = seek.pos; - } - fill_view_summary(view, file_view, cmd->live_set, cmd->working_set); + result = 1; + if (seek.type != buffer_seek_pos){ + cursor = view_compute_cursor(vptr, seek); + vptr->mark = cursor.pos; } + else{ + vptr->mark = seek.pos; + } + fill_view_summary(view, vptr, cmd->live_set, cmd->working_set); } return(result); @@ -2308,23 +2288,19 @@ extern "C"{ Command_Data *cmd = (Command_Data*)context->cmd_context; Live_Views *live_set; View *vptr; - File_View *file_view; int result = 0; if (view->exists){ live_set = cmd->live_set; vptr = (View*)((char*)live_set->views + live_set->stride * view->view_id); - file_view = view_to_file_view(vptr); - if (file_view){ - result = 1; - if (turn_on){ - view_set_temp_highlight(file_view, start, end); - } - else{ - file_view->show_temp_highlight = 0; - } - fill_view_summary(view, file_view, cmd->live_set, cmd->working_set); + result = 1; + if (turn_on){ + view_set_temp_highlight(vptr, start, end); } + else{ + vptr->show_temp_highlight = 0; + } + fill_view_summary(view, vptr, cmd->live_set, cmd->working_set); } return(result); @@ -2334,7 +2310,6 @@ extern "C"{ Command_Data *cmd = (Command_Data*)context->cmd_context; Live_Views *live_set; View *vptr; - File_View *file_view; Editing_File *file; Working_Set *working_set; int max, result = 0; @@ -2342,20 +2317,17 @@ extern "C"{ if (view->exists){ live_set = cmd->live_set; vptr = (View*)((char*)live_set->views + live_set->stride * view->view_id); - file_view = view_to_file_view(vptr); - if (file_view){ - working_set = cmd->working_set; - max = working_set->file_index_count; - if (buffer_id >= 0 && buffer_id < max){ - file = working_set->files + buffer_id; - if (!file->state.is_dummy){ - view_set_file(file_view, file, cmd->vars->font_set, cmd->style, cmd->global_font, - cmd->system, cmd->vars->hooks[hook_open_file], &app_links); - } + working_set = cmd->working_set; + max = working_set->file_index_count; + if (buffer_id >= 0 && buffer_id < max){ + file = working_set->files + buffer_id; + if (!file->state.is_dummy){ + view_set_file(vptr, file, cmd->vars->font_set, cmd->style, cmd->global_font, + cmd->system, cmd->vars->hooks[hook_open_file], &app_links); } - - fill_view_summary(view, file_view, cmd->live_set, cmd->working_set); } + + fill_view_summary(view, vptr, cmd->live_set, cmd->working_set); } return(result); @@ -2380,15 +2352,11 @@ extern "C"{ Command_Data *cmd = (Command_Data*)context->cmd_context; Query_Slot *slot = 0; View *vptr; - File_View *file_view; vptr = cmd->view; - file_view = view_to_file_view(vptr); - if (file_view){ - slot = alloc_query_slot(&file_view->query_set); - slot->query_bar = bar; - } + slot = alloc_query_slot(&vptr->query_set); + slot->query_bar = bar; return(slot != 0); } @@ -2396,14 +2364,9 @@ extern "C"{ END_QUERY_BAR_SIG(external_end_query_bar){ Command_Data *cmd = (Command_Data*)context->cmd_context; View *vptr; - File_View *file_view; vptr = cmd->view; - file_view = view_to_file_view(vptr); - - if (file_view){ - free_query_slot(&file_view->query_set, bar); - } + free_query_slot(&vptr->query_set, bar); } } @@ -2417,13 +2380,12 @@ command_caller(Coroutine *coroutine){ Command_In *cmd_in = (Command_In*)coroutine->in; Command_Data *cmd = cmd_in->cmd; 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. - File_View *fview = view_to_file_view(view); - if (fview) fview->next_mode = {}; + view->next_mode = {}; cmd_in->bind.function(cmd->system, cmd, cmd_in->bind); - fview = view_to_file_view(view); - if (fview) fview->mode = fview->next_mode; + view->mode = view->next_mode; } internal void @@ -2454,10 +2416,10 @@ app_links_init(System_Functions *system, void *data, int size){ app_links.buffer_replace_range = external_buffer_replace_range; app_links.get_view_max_index = external_get_view_max_index; - app_links.get_file_view = external_get_file_view; - app_links.get_active_file_view = external_get_active_file_view; + app_links.get_view = external_get_view; + app_links.get_active_view = external_get_active_view; - app_links.refresh_file_view = external_refresh_file_view; + app_links.refresh_view = external_refresh_view; app_links.view_set_cursor = external_view_set_cursor; app_links.view_set_mark = external_view_set_mark; app_links.view_set_highlight = external_view_set_highlight; @@ -3026,7 +2988,7 @@ App_Init_Sig(app_init){ View *v = 0; i32 i = 0; i32 max = 0; - i32 view_size = sizeof(File_View); + i32 view_size = sizeof(View); vars->live_set.count = 0; vars->live_set.max = panel_max_count; @@ -3390,15 +3352,13 @@ App_Step_Sig(app_step){ Panel *panel, *used_panels; View *view; - File_View *fview; used_panels = &vars->layout.used_sentinel; for (dll_items(panel, used_panels)){ view = panel->view; - fview = view_to_file_view(view); - Assert(fview); - if (fview->file == out_file){ - view_cursor_move(fview, new_cursor); + Assert(view); + if (view->file == out_file){ + view_cursor_move(view, new_cursor); } } } @@ -3416,7 +3376,7 @@ App_Step_Sig(app_step){ i32 current_height = target->height; Panel *panel, *used_panels; - File_View *fview; + View *view; vars->layout.full_width = current_width; vars->layout.full_height = current_height; @@ -3426,11 +3386,11 @@ App_Step_Sig(app_step){ used_panels = &vars->layout.used_sentinel; for (dll_items(panel, used_panels)){ - fview = view_to_file_view(panel->view); - Assert(fview); + view = panel->view; + Assert(view); // TODO(allen): All responses to a panel changing size should // be handled in the same place. - view_change_size(system, &vars->mem.general, fview); + view_change_size(system, &vars->mem.general, view); } app_result.redraw = 1; @@ -3637,9 +3597,8 @@ App_Step_Sig(app_step){ // TOOD(allen): Deduplicate // TODO(allen): Allow a view to clean up however it wants after a command // finishes, or after transfering to another view mid command. - File_View *fview = view_to_file_view(view); - if (fview != 0 && vars->command_coroutine == 0){ - init_query_set(&fview->query_set); + if (view != 0 && vars->command_coroutine == 0){ + init_query_set(&view->query_set); } if (vars->command_coroutine == 0) break; } @@ -3703,9 +3662,8 @@ App_Step_Sig(app_step){ // TOOD(allen): Deduplicate // TODO(allen): Allow a view to clean up however it wants after a command finishes, // or after transfering to another view mid command. - File_View *fview = view_to_file_view(view); - if (fview != 0 && vars->command_coroutine == 0){ - init_query_set(&fview->query_set); + if (view != 0 && vars->command_coroutine == 0){ + init_query_set(&view->query_set); } } } @@ -4008,7 +3966,7 @@ App_Step_Sig(app_step){ } if (!ed_file->state.is_dummy){ - for (File_View_Iter iter = file_view_iter_init(&vars->layout, ed_file, 0); + for (View_Iter iter = file_view_iter_init(&vars->layout, ed_file, 0); file_view_iter_good(iter); iter = file_view_iter_next(iter)){ view_measure_wraps(system, general, iter.view); @@ -4053,7 +4011,6 @@ App_Step_Sig(app_step){ Style *style = &vars->style; Style_Font *global_font = &vars->global_font; Working_Set *working_set = &vars->working_set; - Live_Views *live_set = &vars->live_set; Mem_Options *mem = &vars->mem; General_Memory *general = &vars->mem.general; @@ -4123,8 +4080,7 @@ App_Step_Sig(app_step){ // TODO(allen): deduplicate Editing_File *file = 0; if (panel){ - File_View *fview = view_to_file_view(panel->view); - file = fview->file; + file = panel->view->file; } else if (string.str && string.size > 0){ file = working_set_lookup_file(working_set, string); @@ -4144,8 +4100,7 @@ App_Step_Sig(app_step){ // TODO(allen): deduplicate Editing_File *file = 0; if (panel){ - File_View *fview = view_to_file_view(panel->view); - file = fview->file; + file = panel->view->file; } else if (string.str && string.size > 0){ file = working_set_lookup_file(working_set, string); @@ -4166,11 +4121,9 @@ App_Step_Sig(app_step){ if (!file){ if (panel){ View *view; - File_View *fview; view = panel->view; - fview = view_to_file_view(view); - Assert(fview); - file = fview->file; + Assert(view); + file = view->file; } else{ file = working_set_lookup_file(working_set, string); @@ -4199,9 +4152,8 @@ App_Step_Sig(app_step){ table_add(&working_set->table, file.file->name.source_path, file.index); View *view = panel->view; - File_View *fview = view_to_file_view(view); - view_set_file(fview, file.file, vars->font_set, style, global_font, + view_set_file(view, file.file, vars->font_set, style, global_font, system, vars->hooks[hook_open_file], &app_links); view->map = app_get_map(vars, file.file->settings.base_map_id); #if BUFFER_EXPERIMENT_SCALPEL <= 0 @@ -4215,9 +4167,8 @@ App_Step_Sig(app_step){ Editing_File *file = working_set_lookup_file(working_set, string); if (file){ View *view = panel->view; - File_View *fview = view_to_file_view(view); - view_set_file(fview, file, vars->font_set, style, global_font, + view_set_file(view, file, vars->font_set, style, global_font, system, vars->hooks[hook_open_file], &app_links); view->map = app_get_map(vars, file->settings.base_map_id); } @@ -4228,7 +4179,7 @@ App_Step_Sig(app_step){ Editing_File *file = working_set_lookup_file(working_set, string); if (file){ table_remove(&working_set->table, file->name.source_path); - kill_file(system, exchange, general, file, live_set, &vars->layout); + kill_file(system, exchange, general, file, &vars->layout); } }break; @@ -4245,18 +4196,17 @@ App_Step_Sig(app_step){ view = (vars->layout.panels + vars->layout.active_panel)->view; } - File_View *fview = view_to_file_view(view); - Assert(fview); + Assert(view); if (file){ if (buffer_needs_save(file)){ - view_show_interactive(system, fview, &vars->map_ui, + view_show_interactive(system, view, &vars->map_ui, IAct_Sure_To_Kill, IInt_Sure_To_Kill, make_lit_string("Are you sure?")); - copy(&fview->dest, file->name.live_name); + copy(&view->dest, file->name.live_name); } else{ table_remove(&working_set->table, file->name.source_path); - kill_file(system, exchange, general, file, live_set, &vars->layout); + kill_file(system, exchange, general, file, &vars->layout); } } }break; diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index fff6ab93..bb020db0 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -9,6 +9,23 @@ // TOP +enum View_Message{ + VMSG_STEP, + VMSG_DRAW, + VMSG_RESIZE, + VMSG_STYLE_CHANGE, + VMSG_FREE +}; + +struct View; +#define Do_View_Sig(name) \ + i32 (name)(System_Functions *system, Exchange *exchange, \ + View *view, i32_Rect rect, View *active, \ + View_Message message, Render_Target *target, \ + Input_Summary *user_input, Input_Summary *active_input) + +typedef Do_View_Sig(Do_View_Function); + enum Interactive_Action{ IAct_Open, IAct_Save_As, @@ -24,7 +41,7 @@ enum Interactive_Interaction{ IInt_Sure_To_Kill }; -struct File_View_Mode{ +struct View_Mode{ i8 rewrite; }; @@ -34,16 +51,16 @@ struct Incremental_Search{ i32 pos; }; -enum File_View_Widget_Type{ +enum View_Widget_Type{ FWIDG_NONE, FWIDG_TIMELINES, // never below this FWIDG_TYPE_COUNT }; -struct File_View_Widget{ +struct View_Widget{ UI_State state; - File_View_Widget_Type type; + View_Widget_Type type; i32 height_; struct{ b32 undo_line; @@ -69,8 +86,14 @@ enum Color_View_Mode{ CV_Mode_Adjusting }; -struct File_View{ - View view_base; +struct View{ + View *next, *prev; + + Panel *panel; + Command_Map *map; + Do_View_Function *do_view; + Scroll_Rule_Function *scroll_rule; + i32 id; Editing_File *file; @@ -100,7 +123,7 @@ struct File_View{ i32 user_action; // theme stuff - File_View *hot_file_view; + View *hot_file_view; u32 *palette; i32 palette_size; Color_View_Mode color_mode; @@ -132,8 +155,8 @@ struct File_View{ i32 temp_highlight_end_pos; b32 show_temp_highlight; - File_View_Mode mode, next_mode; - File_View_Widget widget; + View_Mode mode, next_mode; + View_Widget widget; Query_Set query_set; @@ -149,10 +172,27 @@ struct File_View{ Command_Map *map_for_file; }; -inline File_View* -view_to_file_view(View *view){ - File_View* result = (File_View*)view; - return result; +struct View_And_ID{ + View *view; + i32 id; +}; + +inline void +view_set_first(View *new_view, Panel *panel){ + new_view->panel = panel; + panel->view = new_view; +} + +inline f32 +view_compute_width(View *view){ + Panel *panel = view->panel; + return (f32)(panel->inner.x1 - panel->inner.x0); +} + +inline f32 +view_compute_height(View *view){ + Panel *panel = view->panel; + return (f32)(panel->inner.y1 - panel->inner.y0); } inline i32 @@ -432,7 +472,7 @@ view_wrapped_line_span(f32 line_width, f32 max_width){ } internal i32 -view_compute_lowest_line(File_View *view){ +view_compute_lowest_line(View *view){ i32 lowest_line = 0; i32 last_line = view->line_count - 1; if (last_line > 0){ @@ -456,7 +496,7 @@ view_compute_lowest_line(File_View *view){ internal void view_measure_wraps(System_Functions *system, - General_Memory *general, File_View *view){ + General_Memory *general, View *view){ ProfileMomentFunction(); Buffer_Type *buffer; @@ -1165,7 +1205,7 @@ file_post_history(General_Memory *general, Editing_File *file, #endif inline Full_Cursor -view_compute_cursor_from_pos(File_View *view, i32 pos){ +view_compute_cursor_from_pos(View *view, i32 pos){ Editing_File *file = view->file; Render_Font *font = get_font_info(view->font_set, view->global_font->font_id)->font; @@ -1179,7 +1219,7 @@ view_compute_cursor_from_pos(File_View *view, i32 pos){ } inline Full_Cursor -view_compute_cursor_from_unwrapped_xy(File_View *view, f32 seek_x, f32 seek_y, b32 round_down = 0){ +view_compute_cursor_from_unwrapped_xy(View *view, f32 seek_x, f32 seek_y, b32 round_down = 0){ Editing_File *file = view->file; Render_Font *font = get_font_info(view->font_set, view->global_font->font_id)->font; @@ -1195,7 +1235,7 @@ view_compute_cursor_from_unwrapped_xy(File_View *view, f32 seek_x, f32 seek_y, b } internal Full_Cursor -view_compute_cursor_from_wrapped_xy(File_View *view, f32 seek_x, f32 seek_y, +view_compute_cursor_from_wrapped_xy(View *view, f32 seek_x, f32 seek_y, b32 round_down = 0){ Editing_File *file = view->file; Render_Font *font = get_font_info(view->font_set, view->global_font->font_id)->font; @@ -1212,7 +1252,7 @@ view_compute_cursor_from_wrapped_xy(File_View *view, f32 seek_x, f32 seek_y, } internal Full_Cursor -view_compute_cursor_from_line_pos(File_View *view, i32 line, i32 pos){ +view_compute_cursor_from_line_pos(View *view, i32 line, i32 pos){ Editing_File *file = view->file; Render_Font *font = get_font_info(view->font_set, view->global_font->font_id)->font; @@ -1227,7 +1267,7 @@ view_compute_cursor_from_line_pos(File_View *view, i32 line, i32 pos){ } inline Full_Cursor -view_compute_cursor(File_View *view, Buffer_Seek seek){ +view_compute_cursor(View *view, Buffer_Seek seek){ Full_Cursor result = {}; switch(seek.type){ @@ -1252,7 +1292,7 @@ view_compute_cursor(File_View *view, Buffer_Seek seek){ } inline Full_Cursor -view_compute_cursor_from_xy(File_View *view, f32 seek_x, f32 seek_y){ +view_compute_cursor_from_xy(View *view, f32 seek_x, f32 seek_y){ Full_Cursor result; if (view->unwrapped_lines) result = view_compute_cursor_from_unwrapped_xy(view, seek_x, seek_y); else result = view_compute_cursor_from_wrapped_xy(view, seek_x, seek_y); @@ -1260,14 +1300,14 @@ view_compute_cursor_from_xy(File_View *view, f32 seek_x, f32 seek_y){ } inline void -view_set_temp_highlight(File_View *view, i32 pos, i32 end_pos){ +view_set_temp_highlight(View *view, i32 pos, i32 end_pos){ view->temp_highlight = view_compute_cursor_from_pos(view, pos); view->temp_highlight_end_pos = end_pos; view->show_temp_highlight = 1; } inline i32 -view_get_cursor_pos(File_View *view){ +view_get_cursor_pos(View *view){ i32 result; if (view->show_temp_highlight){ result = view->temp_highlight.pos; @@ -1279,7 +1319,7 @@ view_get_cursor_pos(File_View *view){ } inline f32 -view_get_cursor_x(File_View *view){ +view_get_cursor_x(View *view){ f32 result; Full_Cursor *cursor; if (view->show_temp_highlight){ @@ -1298,7 +1338,7 @@ view_get_cursor_x(File_View *view){ } inline f32 -view_get_cursor_y(File_View *view){ +view_get_cursor_y(View *view){ Full_Cursor *cursor; f32 result; @@ -1314,7 +1354,7 @@ view_get_cursor_y(File_View *view){ internal void view_set_file( // NOTE(allen): These parameters are always meaningful - File_View *view, + View *view, Editing_File *file, Font_Set *set, Style *style, @@ -1332,7 +1372,7 @@ view_set_file( f32 cursor_x, cursor_y; f32 target_x, target_y; - panel = view->view_base.panel; + panel = view->panel; // NOTE(allen): This is actually more like view_set_style right? fnt_info = get_font_info(set, global_font->font_id); @@ -1406,7 +1446,7 @@ struct Relative_Scrolling{ }; internal Relative_Scrolling -view_get_relative_scrolling(File_View *view){ +view_get_relative_scrolling(View *view){ Relative_Scrolling result; f32 cursor_x, cursor_y; cursor_x = view_get_cursor_x(view); @@ -1419,7 +1459,7 @@ view_get_relative_scrolling(File_View *view){ } internal void -view_set_relative_scrolling(File_View *view, Relative_Scrolling scrolling){ +view_set_relative_scrolling(View *view, Relative_Scrolling scrolling){ f32 cursor_x, cursor_y; cursor_x = view_get_cursor_x(view); cursor_y = view_get_cursor_y(view); @@ -1428,7 +1468,7 @@ view_set_relative_scrolling(File_View *view, Relative_Scrolling scrolling){ } inline void -view_cursor_move(File_View *view, Full_Cursor cursor){ +view_cursor_move(View *view, Full_Cursor cursor){ view->cursor = cursor; view->preferred_x = view_get_cursor_x(view); view->file->state.cursor_pos = view->cursor.pos; @@ -1436,13 +1476,13 @@ view_cursor_move(File_View *view, Full_Cursor cursor){ } inline void -view_cursor_move(File_View *view, i32 pos){ +view_cursor_move(View *view, i32 pos){ Full_Cursor cursor = view_compute_cursor_from_pos(view, pos); view_cursor_move(view, cursor); } inline void -view_cursor_move(File_View *view, f32 x, f32 y, b32 round_down = 0){ +view_cursor_move(View *view, f32 x, f32 y, b32 round_down = 0){ Full_Cursor cursor; if (view->unwrapped_lines){ cursor = view_compute_cursor_from_unwrapped_xy(view, x, y, round_down); @@ -1454,20 +1494,20 @@ view_cursor_move(File_View *view, f32 x, f32 y, b32 round_down = 0){ } inline void -view_cursor_move(File_View *view, i32 line, i32 pos){ +view_cursor_move(View *view, i32 line, i32 pos){ Full_Cursor cursor = view_compute_cursor_from_line_pos(view, line, pos); view_cursor_move(view, cursor); } inline void -view_set_widget(File_View *view, File_View_Widget_Type type){ +view_set_widget(View *view, View_Widget_Type type){ view->widget.type = type; } inline i32_Rect -view_widget_rect(File_View *view, i32 font_height){ - Panel *panel = view->view_base.panel; +view_widget_rect(View *view, i32 font_height){ + Panel *panel = view->panel; i32_Rect result = panel->inner; if (view->file){ @@ -1728,12 +1768,12 @@ file_edit_cursor_fix(System_Functions *system, f32 y_offset = 0, y_position = 0; i32 cursor_count = 0; - File_View *view; + View *view; Panel *panel, *used_panels; used_panels = &layout->used_sentinel; for (dll_items(panel, used_panels)){ - view = view_to_file_view(panel->view); + view = panel->view; if (view->file == file){ view_measure_wraps(system, general, view); write_cursor_with_index(cursors, &cursor_count, view->cursor.pos); @@ -1757,7 +1797,7 @@ file_edit_cursor_fix(System_Functions *system, cursor_count = 0; for (dll_items(panel, used_panels)){ - view = view_to_file_view(panel->view); + view = panel->view; if (view && view->file == file){ view_cursor_move(view, cursors[cursor_count++].pos); view->preferred_x = view_get_cursor_x(view); @@ -1835,7 +1875,7 @@ file_do_single_edit(System_Functions *system, used_panels = &layout->used_sentinel; for (dll_items(panel, used_panels)){ - File_View *view = view_to_file_view(panel->view); + View *view = panel->view; if (view->file == file){ view_measure_wraps(system, general, view); } @@ -1857,7 +1897,7 @@ file_do_single_edit(System_Functions *system, } internal void -view_do_white_batch_edit(System_Functions *system, Mem_Options *mem, File_View *view, Editing_File *file, +view_do_white_batch_edit(System_Functions *system, Mem_Options *mem, View *view, Editing_File *file, Editing_Layout *layout, Edit_Spec spec, History_Mode history_mode){ if (view->locked) return; #if BUFFER_EXPERIMENT_SCALPEL <= 3 @@ -1957,7 +1997,7 @@ file_replace_range(System_Functions *system, inline void view_replace_range(System_Functions *system, - Mem_Options *mem, File_View *view, Editing_Layout *layout, + Mem_Options *mem, View *view, Editing_Layout *layout, i32 start, i32 end, char *str, i32 len, i32 next_cursor){ if (view->locked) return; Edit_Spec spec = {}; @@ -1972,7 +2012,7 @@ view_replace_range(System_Functions *system, } inline void -view_post_paste_effect(File_View *view, i32 ticks, i32 start, i32 size, u32 color){ +view_post_paste_effect(View *view, i32 ticks, i32 start, i32 size, u32 color){ Editing_File *file = view->file; file->state.paste_effect.start = start; @@ -1984,7 +2024,7 @@ view_post_paste_effect(File_View *view, i32 ticks, i32 start, i32 size, u32 colo internal void view_undo_redo(System_Functions *system, - Mem_Options *mem, Editing_Layout *layout, File_View *view, Editing_File *file, + Mem_Options *mem, Editing_Layout *layout, View *view, Editing_File *file, Edit_Stack *stack, Edit_Type expected_type){ if (view->locked) return; if (file && stack->edit_count > 0){ @@ -2016,13 +2056,13 @@ view_undo_redo(System_Functions *system, } inline void -view_undo(System_Functions *system, Mem_Options *mem, Editing_Layout *layout, File_View *view){ +view_undo(System_Functions *system, Mem_Options *mem, Editing_Layout *layout, View *view){ Editing_File *file = view->file; view_undo_redo(system, mem, layout, view, file, &file->state.undo.undo, ED_UNDO); } inline void -view_redo(System_Functions *system, Mem_Options *mem, Editing_Layout *layout, File_View *view){ +view_redo(System_Functions *system, Mem_Options *mem, Editing_Layout *layout, View *view){ Editing_File *file = view->file; view_undo_redo(system, mem, layout, view, file, &file->state.undo.redo, ED_REDO); } @@ -2092,7 +2132,7 @@ file_dump_history(System_Functions *system, Mem_Options *mem, Editing_File *file #endif internal void -view_history_step(System_Functions *system, Mem_Options *mem, Editing_Layout *layout, File_View *view, History_Mode history_mode){ +view_history_step(System_Functions *system, Mem_Options *mem, Editing_Layout *layout, View *view, History_Mode history_mode){ if (view->locked) return; Assert(history_mode != hist_normal); @@ -2148,7 +2188,7 @@ view_history_step(System_Functions *system, Mem_Options *mem, Editing_Layout *la // TODO(allen): write these as streamed operations internal i32 -view_find_end_of_line(File_View *view, i32 pos){ +view_find_end_of_line(View *view, i32 pos){ #if BUFFER_EXPERIMENT_SCALPEL <= 0 Editing_File *file = view->file; char *data = file->state.buffer.data; @@ -2159,7 +2199,7 @@ view_find_end_of_line(File_View *view, i32 pos){ } internal i32 -view_find_beginning_of_line(File_View *view, i32 pos){ +view_find_beginning_of_line(View *view, i32 pos){ #if BUFFER_EXPERIMENT_SCALPEL <= 0 Editing_File *file = view->file; char *data = file->state.buffer.data; @@ -2173,7 +2213,7 @@ view_find_beginning_of_line(File_View *view, i32 pos){ } internal i32 -view_find_beginning_of_next_line(File_View *view, i32 pos){ +view_find_beginning_of_next_line(View *view, i32 pos){ #if BUFFER_EXPERIMENT_SCALPEL <= 0 Editing_File *file = view->file; char *data = file->state.buffer.data; @@ -2289,7 +2329,7 @@ file_compute_whitespace_edit(Mem_Options *mem, Editing_File *file, i32 cursor_po } internal void -view_clean_whitespace(System_Functions *system, Mem_Options *mem, File_View *view, Editing_Layout *layout){ +view_clean_whitespace(System_Functions *system, Mem_Options *mem, View *view, Editing_Layout *layout){ Editing_File *file = view->file; Assert(file && !file->state.is_dummy); Partition *part = &mem->part; @@ -2347,7 +2387,7 @@ view_clean_whitespace(System_Functions *system, Mem_Options *mem, File_View *vie internal void view_auto_tab_tokens(System_Functions *system, - Mem_Options *mem, File_View *view, Editing_Layout *layout, + Mem_Options *mem, View *view, Editing_Layout *layout, i32 start, i32 end, b32 empty_blank_lines){ #if BUFFER_EXPERIMENT_SCALPEL <= 0 Editing_File *file = view->file; @@ -2609,7 +2649,7 @@ view_compute_max_target_y(i32 lowest_line, i32 line_height, real32 view_height){ } internal real32 -view_compute_max_target_y(File_View *view){ +view_compute_max_target_y(View *view){ i32 lowest_line = view_compute_lowest_line(view); i32 line_height = view->font_height; real32 view_height = view_compute_height(view); @@ -2619,8 +2659,7 @@ view_compute_max_target_y(File_View *view){ } internal void -remeasure_file_view(System_Functions *system, View *view_, i32_Rect rect){ - File_View *view = (File_View*)view_; +remeasure_file_view(System_Functions *system, View *view, i32_Rect rect){ if (file_is_ready(view->file)){ Relative_Scrolling relative = view_get_relative_scrolling(view); view_measure_wraps(system, &view->mem->general, view); @@ -2631,7 +2670,7 @@ remeasure_file_view(System_Functions *system, View *view_, i32_Rect rect){ } internal void -undo_shit(System_Functions *system, File_View *view, UI_State *state, UI_Layout *layout, +undo_shit(System_Functions *system, View *view, UI_State *state, UI_Layout *layout, i32 total_count, i32 undo_count, i32 scrub_max){ Editing_File *file = view->file; @@ -2690,7 +2729,7 @@ undo_shit(System_Functions *system, File_View *view, UI_State *state, UI_Layout } internal void -draw_file_view_queries(File_View *view, UI_State *state, UI_Layout *layout){ +draw_file_view_queries(View *view, UI_State *state, UI_Layout *layout){ Widget_ID wid; Query_Slot *slot; Query_Bar *bar; @@ -2704,29 +2743,29 @@ draw_file_view_queries(File_View *view, UI_State *state, UI_Layout *layout){ } inline void -view_show_menu(File_View *fview, Command_Map *gui_map){ +view_show_menu(View *fview, Command_Map *gui_map){ fview->ui_state = {}; - fview->map_for_file = fview->view_base.map; - fview->view_base.map = gui_map; + fview->map_for_file = fview->map; + fview->map = gui_map; fview->locked = 1; fview->showing_ui = VUI_Menu; } inline void -view_show_config(File_View *fview, Command_Map *gui_map){ +view_show_config(View *fview, Command_Map *gui_map){ fview->ui_state = {}; - fview->map_for_file = fview->view_base.map; - fview->view_base.map = gui_map; + fview->map_for_file = fview->map; + fview->map = gui_map; fview->locked = 1; fview->showing_ui = VUI_Config; } inline void -view_show_interactive(System_Functions *system, File_View *fview, Command_Map *gui_map, +view_show_interactive(System_Functions *system, View *fview, Command_Map *gui_map, Interactive_Action action, Interactive_Interaction interaction, String query){ fview->ui_state = {}; - fview->map_for_file = fview->view_base.map; - fview->view_base.map = gui_map; + fview->map_for_file = fview->map; + fview->map = gui_map; fview->locked = 1; fview->showing_ui = VUI_Interactive; fview->action = action; @@ -2741,31 +2780,31 @@ view_show_interactive(System_Functions *system, File_View *fview, Command_Map *g } inline void -view_show_theme(File_View *fview, Command_Map *gui_map){ +view_show_theme(View *fview, Command_Map *gui_map){ fview->ui_state = {}; - fview->map_for_file = fview->view_base.map; - fview->view_base.map = gui_map; + fview->map_for_file = fview->map; + fview->map = gui_map; fview->locked = 1; fview->showing_ui = VUI_Theme; fview->color_mode = CV_Mode_Library; } inline void -view_show_file(File_View *fview, Command_Map *file_map){ +view_show_file(View *fview, Command_Map *file_map){ fview->ui_state = {}; if (file_map){ - fview->view_base.map = file_map; + fview->map = file_map; } else{ - fview->view_base.map = fview->map_for_file; + fview->map = fview->map_for_file; } fview->locked = 0; fview->showing_ui = VUI_None; } internal void -interactive_view_complete(File_View *view){ - Panel *panel = view->view_base.panel; +interactive_view_complete(View *view){ + Panel *panel = view->panel; switch (view->action){ case IAct_Open: delayed_open(view->delay, view->hot_directory->string, panel); @@ -2808,8 +2847,8 @@ interactive_view_complete(File_View *view){ } internal void -update_highlighting(File_View *view){ - File_View *file_view = view->hot_file_view; +update_highlighting(View *view){ + View *file_view = view->hot_file_view; if (!file_view){ view->highlight = {}; return; @@ -2888,7 +2927,7 @@ update_highlighting(File_View *view){ internal b32 theme_library_shit(System_Functions *system, Exchange *exchange, - File_View *view, UI_State *state, UI_Layout *layout){ + View *view, UI_State *state, UI_Layout *layout){ Mem_Options *mem = view->mem; @@ -3139,7 +3178,7 @@ theme_library_shit(System_Functions *system, Exchange *exchange, } internal b32 -theme_adjusting_shit(File_View *view, UI_State *state, UI_Layout *layout){ +theme_adjusting_shit(View *view, UI_State *state, UI_Layout *layout){ update_highlighting(view); Style *style = view->style; @@ -3270,12 +3309,11 @@ theme_adjusting_shit(File_View *view, UI_State *state, UI_Layout *layout){ internal b32 theme_shit(System_Functions *system, Exchange *exchange, - File_View *view, View *active, UI_State *state, UI_Layout *layout){ + View *view, View *active, UI_State *state, UI_Layout *layout){ b32 result = 0; - File_View *factive = view_to_file_view(active); - if (view != factive){ - view->hot_file_view = factive; + if (view != active){ + view->hot_file_view = active; } switch (view->color_mode){ @@ -3301,7 +3339,7 @@ theme_shit(System_Functions *system, Exchange *exchange, } internal b32 -interactive_shit(System_Functions *system, File_View *view, UI_State *state, UI_Layout *layout){ +interactive_shit(System_Functions *system, View *view, UI_State *state, UI_Layout *layout){ b32 result = 0; b32 new_dir = 0; b32 complete = 0; @@ -3388,22 +3426,22 @@ interactive_shit(System_Functions *system, File_View *view, UI_State *state, UI_ } internal void -menu_shit(File_View *view, UI_State *state, UI_Layout *layout){ +menu_shit(View *view, UI_State *state, UI_Layout *layout){ i32 id = 0; do_label(state, layout, literal("Menu"), 2.f); if (do_list_option(++id, state, layout, make_lit_string("Theme Options"))){ - view_show_theme(view, view->view_base.map); + view_show_theme(view, view->map); } if (do_list_option(++id, state, layout, make_lit_string("Keyboard Layout Options"))){ - view_show_config(view, view->view_base.map); + view_show_config(view, view->map); } } internal void -config_shit(File_View *view, UI_State *state, UI_Layout *layout){ +config_shit(View *view, UI_State *state, UI_Layout *layout){ i32 id = 0; do_label(state, layout, literal("Config"), 2.f); @@ -3415,7 +3453,7 @@ config_shit(File_View *view, UI_State *state, UI_Layout *layout){ } internal void -do_file_bar(File_View *view, Editing_File *file, UI_Layout *layout, Render_Target *target){ +do_file_bar(View *view, Editing_File *file, UI_Layout *layout, Render_Target *target){ Interactive_Bar bar; Style_Font *font = view->global_font; i32 line_height = view->font_height; @@ -3469,11 +3507,10 @@ do_file_bar(File_View *view, Editing_File *file, UI_Layout *layout, Render_Targe } internal i32 -step_file_view(System_Functions *system, Exchange *exchange, View *view_, i32_Rect rect, +step_file_view(System_Functions *system, Exchange *exchange, View *view, i32_Rect rect, b32 is_active, Input_Summary *user_input){ i32 result = 0; - File_View *view = (File_View*)view_; Editing_File *file = view->file; i32 widget_height = 0; @@ -3573,10 +3610,10 @@ step_file_view(System_Functions *system, Exchange *exchange, View *view_, i32_Re if (view->target_x != view->prev_target_x) is_new_target = 1; if (view->target_y != view->prev_target_y) is_new_target = 1; - if (view_->scroll_rule( + if (view->scroll_rule( view->target_x, view->target_y, &view->scroll_x, &view->scroll_y, - view_->id, is_new_target)){ + view->id, is_new_target)){ result = 1; } @@ -3645,7 +3682,7 @@ step_file_view(System_Functions *system, Exchange *exchange, View *view_, i32_Re } internal i32 -draw_file_loaded(File_View *view, i32_Rect rect, b32 is_active, Render_Target *target){ +draw_file_loaded(View *view, i32_Rect rect, b32 is_active, Render_Target *target){ Editing_File *file = view->file; Style *style = view->style; i32 line_height = view->font_height; @@ -3813,9 +3850,9 @@ draw_file_loaded(File_View *view, i32_Rect rect, b32 is_active, Render_Target *t internal i32 draw_file_view(System_Functions *system, Exchange *exchange, - View *view_, View *active, i32_Rect rect, b32 is_active, + View *view, View *active, i32_Rect rect, b32 is_active, Render_Target *target, Input_Summary *user_input){ - File_View *view = (File_View*)view_; + Editing_File *file = view->file; i32 result = 0; @@ -3906,21 +3943,20 @@ draw_file_view(System_Functions *system, Exchange *exchange, } internal void -kill_file( - System_Functions *system, Exchange *exchange, +kill_file(System_Functions *system, Exchange *exchange, General_Memory *general, Editing_File *file, - Live_Views *live_set, Editing_Layout *layout){ + Editing_Layout *layout){ - File_View *fview; + View *view; Panel *panel, *used_panels; used_panels = &layout->used_sentinel; for (dll_items(panel, used_panels)){ - fview = view_to_file_view(panel->view); - Assert(fview); - if (fview->file == file){ - fview->file = 0; + view = panel->view; + Assert(view); + if (view->file == file){ + view->file = 0; } } @@ -3930,9 +3966,8 @@ kill_file( inline void free_file_view(View *view){ - File_View *fview = (File_View*)view; - if (fview->line_wrap_y) - general_memory_free(&fview->mem->general, fview->line_wrap_y); + if (view->line_wrap_y) + general_memory_free(&view->mem->general, view->line_wrap_y); } internal @@ -3960,7 +3995,7 @@ Do_View_Sig(do_file_view){ return result; } -internal File_View* +internal View* file_view_init(View *view, Editing_Layout *layout, Working_Set *working_set, Delay *delay, App_Settings *settings, Hot_Directory *hot_directory, @@ -3968,42 +4003,41 @@ file_view_init(View *view, Editing_Layout *layout, view->do_view = do_file_view; - File_View *result = (File_View*)view; - result->layout = layout; - result->working_set = working_set; - result->delay = delay; - result->settings = settings; - result->hot_directory = hot_directory; - result->mem = mem; - result->styles = styles; + view->layout = layout; + view->working_set = working_set; + view->delay = delay; + view->settings = settings; + view->hot_directory = hot_directory; + view->mem = mem; + view->styles = styles; - result->scrub_max = 1; + view->scrub_max = 1; // TODO(allen): Make "interactive" mode customizable just like the query bars! - result->query = make_fixed_width_string(result->query_); - result->dest = make_fixed_width_string(result->dest_); + view->query = make_fixed_width_string(view->query_); + view->dest = make_fixed_width_string(view->dest_); - init_query_set(&result->query_set); + init_query_set(&view->query_set); - return(result); + return(view); } -struct File_View_Iter{ - File_View *view; +struct View_Iter{ + View *view; Editing_File *file; - File_View *skip; + View *skip; Panel *used_panels; Panel *panel; }; -internal File_View_Iter -file_view_iter_next(File_View_Iter iter){ +internal View_Iter +file_view_iter_next(View_Iter iter){ Panel *panel; - File_View *file_view; + View *file_view; for (panel = iter.panel; panel != iter.used_panels; panel = panel->next){ - file_view = view_to_file_view(panel->view); + file_view = panel->view; if (file_view != iter.skip && file_view->file == iter.file){ iter.view = file_view; break; @@ -4013,9 +4047,9 @@ file_view_iter_next(File_View_Iter iter){ return(iter); } -internal File_View_Iter -file_view_iter_init(Editing_Layout *layout, Editing_File *file, File_View *skip){ - File_View_Iter result; +internal View_Iter +file_view_iter_init(Editing_Layout *layout, Editing_File *file, View *skip){ + View_Iter result; result.used_panels = &layout->used_sentinel; result.panel = result.used_panels->next; result.file = file; @@ -4025,7 +4059,7 @@ file_view_iter_init(Editing_Layout *layout, Editing_File *file, File_View *skip) } internal b32 -file_view_iter_good(File_View_Iter iter){ +file_view_iter_good(View_Iter iter){ b32 result = 1; if (iter.panel != iter.used_panels) result = 0; return(result); @@ -4227,12 +4261,51 @@ search_next_match(Partition *part, Search_Set *set, Search_Iter *iter_){ } inline void -view_change_size(System_Functions *system, General_Memory *general, File_View *view){ +view_change_size(System_Functions *system, General_Memory *general, View *view){ if (view->file){ view_measure_wraps(system, general, view); view->cursor = view_compute_cursor_from_pos(view, view->cursor.pos); } } +struct Live_Views{ + void *views; + View free_sentinel; + i32 count, max; + i32 stride; +}; + +internal View* +live_set_get_view(Live_Views *live_set, i32 id){ + void *result = ((char*)live_set->views + id); + return (View*)result; +} + +internal View_And_ID +live_set_alloc_view(Live_Views *live_set, Scroll_Rule_Function *scroll_rule){ + View_And_ID result = {}; + + Assert(live_set->count < live_set->max); + ++live_set->count; + + result.view = live_set->free_sentinel.next; + result.id = (i32)((char*)result.view - (char*)live_set->views); + result.view->id = result.id; + + dll_remove(result.view); + memset(result.view, 0, live_set->stride); + result.view->scroll_rule = scroll_rule; + + return(result); +} + +inline void +live_set_free_view(System_Functions *system, Exchange *exchange, Live_Views *live_set, View *view){ + Assert(live_set->count > 0); + --live_set->count; + view->do_view(system, exchange, view, {}, 0, VMSG_FREE, 0, {}, 0); + dll_insert(&live_set->free_sentinel, view); +} + // BOTTOM diff --git a/4ed_layout.cpp b/4ed_layout.cpp index f76cc2af..81d20fa9 100644 --- a/4ed_layout.cpp +++ b/4ed_layout.cpp @@ -309,97 +309,5 @@ layout_refit(Editing_Layout *layout, i32 prev_width, i32 prev_height){ layout_fix_all_panels(layout); } -enum View_Message{ - VMSG_STEP, - VMSG_DRAW, - VMSG_RESIZE, - VMSG_STYLE_CHANGE, - VMSG_FREE -}; - -struct View; -#define Do_View_Sig(name) \ - i32 (name)(System_Functions *system, Exchange *exchange, \ - View *view, i32_Rect rect, View *active, \ - View_Message message, Render_Target *target, \ - Input_Summary *user_input, Input_Summary *active_input) - -typedef Do_View_Sig(Do_View_Function); - -struct View{ - View *next, *prev; - - Panel *panel; - Command_Map *map; - Do_View_Function *do_view; - Scroll_Rule_Function *scroll_rule; - i32 id; -}; - -struct Live_Views{ - void *views; - View free_sentinel; - i32 count, max; - i32 stride; -}; - -struct View_And_ID{ - View *view; - i32 id; -}; - -internal View* -live_set_get_view(Live_Views *live_set, i32 id){ - void *result = ((char*)live_set->views + id); - return (View*)result; -} - -internal View_And_ID -live_set_alloc_view(Live_Views *live_set, Scroll_Rule_Function *scroll_rule){ - View_And_ID result = {}; - - Assert(live_set->count < live_set->max); - ++live_set->count; - - result.view = live_set->free_sentinel.next; - result.id = (i32)((char*)result.view - (char*)live_set->views); - result.view->id = result.id; - - dll_remove(result.view); - memset(result.view, 0, live_set->stride); - result.view->scroll_rule = scroll_rule; - - return(result); -} - -inline void -live_set_free_view(System_Functions *system, Exchange *exchange, Live_Views *live_set, View *view){ - Assert(live_set->count > 0); - --live_set->count; - view->do_view(system, exchange, view, {}, 0, VMSG_FREE, 0, {}, 0); - dll_insert(&live_set->free_sentinel, view); -} - -inline void -view_set_first(View *new_view, Panel *panel){ - new_view->panel = panel; - panel->view = new_view; -} - -inline f32 -view_base_compute_width(View *view){ - Panel *panel = view->panel; - return (f32)(panel->inner.x1 - panel->inner.x0); -} - -inline f32 -view_base_compute_height(View *view){ - Panel *panel = view->panel; - return (f32)(panel->inner.y1 - panel->inner.y0); -} - -#define view_compute_width(view) (view_base_compute_width(&(view)->view_base)) -#define view_compute_height(view) (view_base_compute_height(&(view)->view_base)) - // BOTTOM