From 95135173740070b4e8de4c729f647298b20fcac7 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Wed, 4 May 2016 12:22:57 -0400 Subject: [PATCH] start of arrow navigation plan --- 4coder_version.h | 2 +- 4ed.cpp | 13 ++++---- 4ed_file_view.cpp | 85 +++++++++++++++++++++++++++++++---------------- 4ed_gui.cpp | 53 +++++++++++++++++++++++++++-- 4 files changed, 114 insertions(+), 39 deletions(-) diff --git a/4coder_version.h b/4coder_version.h index 78045aae..36f62975 100644 --- a/4coder_version.h +++ b/4coder_version.h @@ -1,6 +1,6 @@ #define MAJOR 4 #define MINOR 0 -#define PATCH 2 +#define PATCH 3 #define VN__(a,b,c) #a"."#b"."#c #define VN_(a,b,c) VN__(a,b,c) diff --git a/4ed.cpp b/4ed.cpp index 24bb21d1..f49ea0c4 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -4157,30 +4157,29 @@ App_Step_Sig(app_step){ b32 remove = 0; b32 failed = 0; binding = vars->sys_app_bindings + i; - + byte *data; i32 size, max; Editing_File *ed_file; Editing_File_Preload preload_settings; char *filename; - + Working_Set *working_set = &models->working_set; - + if (exchange_file_ready(exchange, binding->sys_id, &data, &size, &max)){ ed_file = working_set_get_active_file(working_set, binding->app_id); Assert(ed_file); - + filename = exchange_file_filename(exchange, binding->sys_id); preload_settings = ed_file->preload; if (data){ String val = make_string((char*)data, size); - // TODO(allen): reduce to just passing models file_create_from_string(system, models, ed_file, filename, val); - + if (ed_file->settings.tokens_exist){ file_first_lex_parallel(system, general, ed_file); } - + if ((binding->success & SysAppCreateView) && binding->panel != 0){ view_file_in_panel(cmd, binding->panel, ed_file); } diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index af24a2f2..7f616e1a 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -76,6 +76,7 @@ struct View{ GUI_Target gui_target; void *gui_mem; GUI_Scroll_Vars gui_scroll; + i32 list_i; Interactive_Interaction interaction; Interactive_Action action; @@ -497,13 +498,6 @@ view_measure_wraps(System_Functions *system, view->line_count = line_count; } -internal void* -alloc_for_buffer(void *context, int *size){ - *size = LargeRoundUp(*size, Kbytes(4)); - void *data = general_memory_allocate((General_Memory*)context, *size, BUBBLE_BUFFER); - return data; -} - internal void file_create_from_string(System_Functions *system, Models *models, Editing_File *file, char *filename, String val, b8 read_only = 0){ @@ -550,6 +544,7 @@ file_create_from_string(System_Functions *system, Models *models, file->settings.read_only = read_only; if (!read_only){ + // TODO(allen): Redo undo system (if you don't mind the pun) i32 request_size = Kbytes(64); file->state.undo.undo.max = request_size; file->state.undo.undo.strings = (u8*)general_memory_allocate(general, request_size, BUBBLE_UNDO_STRING); @@ -2642,6 +2637,7 @@ view_show_interactive(System_Functions *system, View *view, view->action = action; view->interaction = interaction; view->dest = make_fixed_width_string(view->dest_); + view->list_i = 0; view->map_for_file = view->map; view->map = gui_map; @@ -2657,7 +2653,7 @@ view_show_theme(View *view, Command_Map *gui_map){ view->showing_ui = VUI_Theme; view->color_mode = CV_Mode_Library; view->color = super_color_create(0xFF000000); - view->current_color_editing = -1; + view->current_color_editing = 0; } @@ -2739,7 +2735,7 @@ interactive_view_complete(View *view, String dest, i32 user_action){ view_show_file(view, 0); // TODO(allen): This is here to prevent the key press from being passed to the - // underlying file which is a giant pain. + // underlying file which is a giant pain. But I want a better system. view->file = 0; } @@ -3932,41 +3928,74 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su Exhaustive_File_Loop loop; Exhaustive_File_Info file_info; - GUI_id file_option_id, str_edit_id; - i32 i; - b32 do_new_directory = 0; + GUI_id id; + GUI_Item_Update update = {0}; Hot_Directory *hdir = &models->hot_directory; + b32 do_new_directory = 0; + i32 i = 0; gui_do_text_field(target, message, hdir->string); - str_edit_id.id[0] = (u64)(hdir); - if (gui_do_file_input(target, str_edit_id, hdir)){ + id.id[0] = (u64)(hdir); + if (gui_do_file_input(target, id, hdir)){ interactive_view_complete(view, hdir->string, 0); } gui_get_scroll_vars(target, view->showing_ui, &view->gui_scroll); gui_begin_scrollable(target, view->showing_ui, view->gui_scroll, 9.f * view->font_height); - begin_exhaustive_loop(&loop, hdir); - for (i = 0; i < loop.count; ++i){ - file_info = get_exhaustive_info(system, &models->working_set, &loop, i); + id.id[0] = (u64)(hdir) + 1; + if (gui_begin_list(target, id, view->list_i, 0, &update)){ + if (update.has_adjustment){ + view->list_i = update.adjustment_value; + } - if (file_info.name_match){ - file_option_id.id[0] = (u64)(file_info.info); - if (gui_do_file_option(target, file_option_id, - file_info.info->filename, file_info.is_folder, file_info.message)){ - if (file_info.is_folder){ - append(&hdir->string, file_info.info->filename); - append(&hdir->string, "/"); - do_new_directory = 1; - } - else{ - interactive_view_complete(view, loop.full_path, 0); + b32 indirectly_activate = 0; + for (i32 j = 0; j < keys.count; ++j){ + i16 key = keys.keys[j].keycode; + switch (key){ + case key_up: + --view->list_i; + break; + + case key_down: + ++view->list_i; + break; + + case '\n': + indirectly_activate = 1; + break; + } + } + + gui_rollback(target, &update); + gui_begin_list(target, id, view->list_i, indirectly_activate, 0); + } + + { + begin_exhaustive_loop(&loop, hdir); + for (i = 0; i < loop.count; ++i){ + file_info = get_exhaustive_info(system, &models->working_set, &loop, i); + + if (file_info.name_match){ + id.id[0] = (u64)(file_info.info); + if (gui_do_file_option(target, id, + file_info.info->filename, file_info.is_folder, file_info.message)){ + if (file_info.is_folder){ + append(&hdir->string, file_info.info->filename); + append(&hdir->string, "/"); + do_new_directory = 1; + } + else{ + interactive_view_complete(view, loop.full_path, 0); + } } } } } + gui_end_list(target); + if (do_new_directory){ hot_directory_reload(system, hdir, &models->working_set); } diff --git a/4ed_gui.cpp b/4ed_gui.cpp index f81dde6c..e16058a3 100644 --- a/4ed_gui.cpp +++ b/4ed_gui.cpp @@ -145,6 +145,9 @@ struct GUI_Target{ struct GUI_Item_Update{ i32 partition_point; + b32 activate; + b32 has_adjustment; + i32 adjustment_value; }; struct GUI_Header{ @@ -177,6 +180,8 @@ enum GUI_Command_Type{ guicom_color_button, guicom_font_button, guicom_text_with_cursor, + guicom_begin_list, + guicom_end_list, guicom_file_option, guicom_fixed_option, guicom_button, @@ -228,9 +233,23 @@ gui_rollback(GUI_Target *target, GUI_Item_Update *update){ } internal void -gui_fill_item_update(GUI_Item_Update *update, GUI_Target *target, GUI_Header *h){ +gui_fill_item_update(GUI_Item_Update *update, GUI_Target *target, GUI_Header *h, + b32 activate){ if (update){ update->partition_point = (i32)((char*)h - (char*)target->push.base); + update->activate = activate; + update->has_adjustment = 0; + } +} + +internal void +gui_fill_item_update(GUI_Item_Update *update, GUI_Target *target, GUI_Header *h, + b32 active, i32 adjustment_value){ + if (update){ + update->partition_point = (i32)((char*)h - (char*)target->push.base); + update->activate = active; + update->has_adjustment = 1; + update->adjustment_value = adjustment_value; } } @@ -398,13 +417,16 @@ gui_do_text_field(GUI_Target *target, String prompt, String text){ internal b32 gui_do_text_with_cursor(GUI_Target *target, i32 pos, String text, GUI_Item_Update *update){ - b32 result = 1; + b32 result = 0; GUI_Header *h = gui_push_simple_command(target, guicom_text_with_cursor); gui_push_string(target, h, text); gui_push_item(target, h, &pos, sizeof(i32)); result = target->has_keys; - gui_fill_item_update(update, target, h); + if (result){ + gui_fill_item_update(update, target, h, 0); + } + return(result); } @@ -460,6 +482,31 @@ gui_do_font_button(GUI_Target *target, GUI_id id, i16 font_id, String text){ return(result); } +internal b32 +gui_begin_list(GUI_Target *target, GUI_id id, i32 list_i, b32 activate_item, GUI_Item_Update *update){ + b32 result = 0; + b32 active = 0; + GUI_Interactive *b = gui_push_button_command(target, guicom_begin_list, id); + GUI_Header *h = (GUI_Header*)b; + + result = target->has_keys; + if (gui_id_eq(id, target->active)){ + active = 1; + result = 1; + } + + if (result){ + gui_fill_item_update(update, target, h, active); + } + + return(result); +} + +internal void +gui_end_list(GUI_Target *target){ + gui_push_simple_command(target, guicom_end_list); +} + internal b32 gui_do_file_option(GUI_Target *target, GUI_id id, String filename, b32 is_folder, String message){ b32 result = 0;