diff --git a/4coder_default_bindings.cpp b/4coder_default_bindings.cpp index bde2db45..941aa2f0 100644 --- a/4coder_default_bindings.cpp +++ b/4coder_default_bindings.cpp @@ -272,10 +272,8 @@ HOOK_SIG(my_file_settings){ return(0); } -typedef void (Extension_Bindings)(Bind_Helper *context); - void -default_keys(Bind_Helper *context, Extension_Bindings *extension = 0){ +default_keys(Bind_Helper *context){ begin_map(context, mapid_global); bind(context, 'p', MDFR_CTRL, cmdid_open_panel_vsplit); @@ -423,10 +421,6 @@ default_keys(Bind_Helper *context, Extension_Bindings *extension = 0){ bind(context, '\n', MDFR_SHIFT, write_and_auto_tab); bind(context, ' ', MDFR_SHIFT, cmdid_write_character); - if (extension != 0){ - extension(context); - } - end_map(context); } diff --git a/4ed.cpp b/4ed.cpp index c7e67b99..4bb005d9 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -1222,7 +1222,7 @@ COMMAND_DECL(auto_tab_range){ int r_start = 0, r_end = 0; int start_set = 0, end_set = 0; Indent_Options opts; - opts.empty_blank_lines = 1; + opts.empty_blank_lines = 0; opts.use_tabs = 0; opts.tab_width = 4; @@ -3199,7 +3199,7 @@ App_Init_Sig(app_init){ { i32 i; - panel_max_count = models->layout.panel_max_count = 16; + panel_max_count = models->layout.panel_max_count = MAX_VIEWS; divider_max_count = panel_max_count - 1; models->layout.panel_count = 0; @@ -4347,9 +4347,7 @@ App_Step_Sig(app_step){ case DACT_TOUCH_FILE: { if (file){ - Assert(!file->state.is_dummy); - dll_remove(&file->node); - dll_insert(&models->working_set.used_sentinel, &file->node); + touch_file(working_set, file); } }break; diff --git a/4ed.h b/4ed.h index a1f12b23..33d14324 100644 --- a/4ed.h +++ b/4ed.h @@ -12,6 +12,8 @@ #ifndef FRED_H #define FRED_H +#define MAX_VIEWS 16 + struct Application_Memory{ void *vars_memory; i32 vars_memory_size; diff --git a/4ed_file.cpp b/4ed_file.cpp index c3153e49..86bbdeb4 100644 --- a/4ed_file.cpp +++ b/4ed_file.cpp @@ -484,6 +484,13 @@ working_set_lookup_file(Working_Set *working_set, String string){ return (file); } +internal void +touch_file(Working_Set *working_set, Editing_File *file){ + Assert(!file->state.is_dummy); + dll_remove(&file->node); + dll_insert(&working_set->used_sentinel, &file->node); +} + // Hot Directory struct Hot_Directory{ diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index 366207a9..f0b39e46 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -3754,8 +3754,8 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su Absolutes absolutes; Editing_File *file; - File_Node *node, *used_nodes; Working_Set *working_set = &models->working_set; + Editing_Layout *layout = &models->layout; GUI_Item_Update update = {0}; { @@ -3788,39 +3788,79 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su &keys, &view->list_i, &update); } - used_nodes = &working_set->used_sentinel; - for (dll_items(node, used_nodes)){ - file = (Editing_File*)node; - Assert(!file->state.is_dummy); - - message = string_zero(); - switch (buffer_get_sync(file)){ - case SYNC_BEHIND_OS: message = message_unsynced; break; - case SYNC_UNSAVED: message = message_unsaved; break; + { + Partition *part = &models->mem.part; + Temp_Memory temp = begin_temp_memory(part); + File_Node *node = 0, *used_nodes = 0; + Editing_File **reserved_files = 0; + i32 reserved_top = 0, i = 0; + View_Iter iter = {0}; + + partition_align(part, sizeof(i32)); + reserved_files = (Editing_File**)partition_current(part); + + used_nodes = &working_set->used_sentinel; + for (dll_items(node, used_nodes)){ + file = (Editing_File*)node; + Assert(!file->state.is_dummy); + + if (filename_match(view->dest, &absolutes, file->name.live_name, 1)){ + iter = file_view_iter_init(layout, file, 0); + if (file_view_iter_good(iter)){ + reserved_files[reserved_top++] = file; + } + else{ + if (file->name.live_name.str[0] == '*'){ + reserved_files[reserved_top++] = file; + } + else{ + message = string_zero(); + switch (buffer_get_sync(file)){ + case SYNC_BEHIND_OS: message = message_unsynced; break; + case SYNC_UNSAVED: message = message_unsaved; break; + } + + id.id[0] = (u64)(file); + if (gui_do_file_option(target, id, file->name.live_name, 0, message)){ + interactive_view_complete(view, file->name.live_name, 0); + } + } + } + } } - - if (filename_match(view->dest, &absolutes, file->name.live_name, 1)){ + + for (i = 0; i < reserved_top; ++i){ + file = reserved_files[i]; + + message = string_zero(); + switch (buffer_get_sync(file)){ + case SYNC_BEHIND_OS: message = message_unsynced; break; + case SYNC_UNSAVED: message = message_unsaved; break; + } + id.id[0] = (u64)(file); if (gui_do_file_option(target, id, file->name.live_name, 0, message)){ interactive_view_complete(view, file->name.live_name, 0); } } + + end_temp_memory(temp); } - + gui_end_list(target); - + gui_end_scrollable(target); }break; - + case IInt_Sure_To_Close: { i32 action = -1; - + String empty_str = {0}; String message = make_lit_string("There is one or more files unsaved changes, close anyway?"); - + gui_do_text_field(target, message, empty_str); - + id.id[0] = (u64)('y'); message = make_lit_string("(Y)es"); if (gui_do_fixed_option(target, id, message, 'y')){ @@ -3915,11 +3955,11 @@ click_button_input(GUI_Target *target, GUI_Session *session, Input_Summary *user internal b32 scroll_button_input(GUI_Target *target, GUI_Session *session, Input_Summary *user_input, - GUI_id id, b32 *is_animating){ + GUI_id id, b32 *is_animating){ b32 result = 0; i32 mx = user_input->mouse.x; i32 my = user_input->mouse.y; - + if (hit_check(mx, my, session->rect)){ target->hover = id; if (user_input->mouse.l){ @@ -3937,13 +3977,13 @@ scroll_button_input(GUI_Target *target, GUI_Session *session, Input_Summary *use internal b32 do_input_file_view(System_Functions *system, Exchange *exchange, - View *view, i32_Rect rect, b32 is_active, Input_Summary *user_input){ - + View *view, i32_Rect rect, b32 is_active, + Input_Summary *user_input){ b32 is_animating = 0; b32 is_file_scroll = 0; - GUI_Session gui_session; - GUI_Header *h; + GUI_Session gui_session = {0}; + GUI_Header *h = 0; GUI_Target *target = &view->gui_target; GUI_Interpret_Result interpret_result = {0}; @@ -3952,13 +3992,10 @@ do_input_file_view(System_Functions *system, Exchange *exchange, target->active = gui_id_zero(); for (h = (GUI_Header*)target->push.base; - h->type; - h = NextHeader(h)){ + h->type; + h = NextHeader(h)){ interpret_result = gui_interpret(target, &gui_session, h); - - // TODO(allen): If something is auto hot or auto activated and - // not on screen do some sort of scrolling towards it. - + switch (h->type){ case guicom_file_option: case guicom_fixed_option: @@ -3986,7 +4023,8 @@ do_input_file_view(System_Functions *system, Exchange *exchange, case guicom_file: { - f32 new_min_y = -(f32)(gui_session_get_eclipsed_y(&gui_session) - gui_session.rect.y0); + f32 new_min_y = -(f32)(gui_session_get_eclipsed_y(&gui_session) - + gui_session.rect.y0); f32 new_max_y = view_compute_max_target_y(view); view->gui_target.scroll_updated.min_y = new_min_y; @@ -4001,7 +4039,7 @@ do_input_file_view(System_Functions *system, Exchange *exchange, } is_file_scroll = 1; }break; - + case guicom_color_button: case guicom_font_button: case guicom_button: @@ -4330,7 +4368,7 @@ draw_file_loaded(View *view, i32_Rect rect, b32 is_active, Render_Target *target } if (item->glyphid != 0){ font_draw_glyph(target, font_id, (u8)item->glyphid, - item->x0, item->y0, char_color); + item->x0, item->y0, char_color); } prev_ind = ind; } diff --git a/power/4coder_experiments.cpp b/power/4coder_experiments.cpp index ca05e8dc..bfc959b8 100644 --- a/power/4coder_experiments.cpp +++ b/power/4coder_experiments.cpp @@ -353,11 +353,16 @@ int get_bindings(void *data, int size){ set_hook(context, hook_start, experimental_start_hook); set_hook(context, hook_open_file, my_file_settings); - + set_scroll_rule(context, smooth_scroll_rule); - default_keys(context, 0); + default_keys(context); + // NOTE(allen|4.0.6): Command maps can be opened more than + // once so that you can extend existing maps very easily. + // You can also use the helper "restart_map" instead of + // begin_map to clear everything that was in the map and + // bind new things instead. begin_map(context, mapid_file); bind(context, 'k', MDFR_ALT, kill_rect); end_map(context);