file list almost works again

This commit is contained in:
Allen Webster 2016-04-03 15:45:28 -04:00
parent c877b57f65
commit 0058355089
2 changed files with 233 additions and 26 deletions

View File

@ -3571,7 +3571,7 @@ step_file_view(System_Functions *system, View *view, b32 is_active){
f32 cursor_max_y = CursorMaxY(view_file_height(view), line_height); f32 cursor_max_y = CursorMaxY(view_file_height(view), line_height);
f32 cursor_min_y = CursorMinY(min_target_y, line_height); f32 cursor_min_y = CursorMinY(min_target_y, line_height);
f32 delta = 9.f * view->font_height; f32 delta = 9.f * view->font_height;
f32 target_y; f32 target_y = 0;
if (gui_get_scroll_vars(target, view->showing_ui, &view->file_scroll)){ if (gui_get_scroll_vars(target, view->showing_ui, &view->file_scroll)){
target_y = view->file_scroll.target_y; target_y = view->file_scroll.target_y;
@ -3641,13 +3641,13 @@ step_file_view(System_Functions *system, View *view, b32 is_active){
r = full_path.size; r = full_path.size;
String message = {0}; String message = {0};
String text = {0};
switch (view->action){ switch (view->action){
case IAct_Open: message = make_lit_string("Open: "); break; case IAct_Open: message = make_lit_string("Open: "); break;
case IAct_Save_As: message = make_lit_string("Save As: "); break; case IAct_Save_As: message = make_lit_string("Save As: "); break;
case IAct_New: message = make_lit_string("New: "); break; case IAct_New: message = make_lit_string("New: "); break;
} }
gui_do_text_field(target, message, text); gui_do_text_field(target, message, hdir->string);
gui_do_file_input(target, hdir);
gui_get_scroll_vars(target, view->showing_ui, &view->gui_scroll); 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); gui_begin_scrollable(target, view->showing_ui, view->gui_scroll, 9.f * view->font_height);
@ -3701,6 +3701,168 @@ view_get_scroll_y(View *view){
return(v); return(v);
} }
struct Single_Line_Input_Step{
b8 hit_newline;
b8 hit_ctrl_newline;
b8 hit_a_character;
b8 hit_backspace;
b8 hit_esc;
b8 made_a_change;
b8 did_command;
b8 no_file_match;
};
enum Single_Line_Input_Type{
SINGLE_LINE_STRING,
SINGLE_LINE_FILE
};
struct Single_Line_Mode{
Single_Line_Input_Type type;
String *string;
Hot_Directory *hot_directory;
b32 fast_folder_select;
b32 try_to_match;
b32 case_sensitive;
};
internal Single_Line_Input_Step
app_single_line_input_core(System_Functions *system, Working_Set *working_set,
Key_Event_Data key, Single_Line_Mode mode){
Single_Line_Input_Step result = {};
if (key.keycode == key_back){
result.hit_backspace = 1;
if (mode.string->size > 0){
result.made_a_change = 1;
--mode.string->size;
switch (mode.type){
case SINGLE_LINE_STRING:
mode.string->str[mode.string->size] = 0; break;
case SINGLE_LINE_FILE:
{
char end_character = mode.string->str[mode.string->size];
if (char_is_slash(end_character)){
mode.string->size = reverse_seek_slash(*mode.string) + 1;
mode.string->str[mode.string->size] = 0;
hot_directory_set(system, mode.hot_directory, *mode.string, working_set);
}
else{
mode.string->str[mode.string->size] = 0;
}
}break;
}
}
}
else if (key.character == '\n' || key.character == '\t'){
result.made_a_change = 1;
if (key.modifiers[MDFR_CONTROL_INDEX] ||
key.modifiers[MDFR_ALT_INDEX]){
result.hit_ctrl_newline = 1;
}
else{
result.hit_newline = 1;
if (mode.fast_folder_select){
Hot_Directory_Match match;
char front_name_space[256];
String front_name = make_fixed_width_string(front_name_space);
get_front_of_directory(&front_name, *mode.string);
match =
hot_directory_first_match(mode.hot_directory, front_name, 1, 1, mode.case_sensitive);
if (mode.try_to_match && !match.filename.str){
match = hot_directory_first_match(mode.hot_directory, front_name, 1, 0, mode.case_sensitive);
}
if (match.filename.str){
if (match.is_folder){
set_last_folder(mode.string, match.filename, mode.hot_directory->slash);
hot_directory_set(system, mode.hot_directory, *mode.string, working_set);
result.hit_newline = 0;
}
else{
if (mode.try_to_match){
mode.string->size = reverse_seek_slash(*mode.string) + 1;
append(mode.string, match.filename);
}
}
}
else{
if (mode.try_to_match){
result.no_file_match = 1;
}
}
}
}
}
else if (key.keycode == key_esc){
result.hit_esc = 1;
result.made_a_change = 1;
}
else if (key.character){
result.hit_a_character = 1;
if (!key.modifiers[MDFR_CONTROL_INDEX] &&
!key.modifiers[MDFR_ALT_INDEX]){
if (mode.string->size+1 < mode.string->memory_size){
u8 new_character = (u8)key.character;
mode.string->str[mode.string->size] = new_character;
mode.string->size++;
mode.string->str[mode.string->size] = 0;
if (mode.type == SINGLE_LINE_FILE && char_is_slash(new_character)){
hot_directory_set(system, mode.hot_directory, *mode.string, working_set);
}
result.made_a_change = 1;
}
}
else{
result.did_command = 1;
result.made_a_change = 1;
}
}
return result;
}
inline Single_Line_Input_Step
app_single_line_input_step(System_Functions *system, Key_Event_Data key, String *string){
Single_Line_Mode mode = {};
mode.type = SINGLE_LINE_STRING;
mode.string = string;
return app_single_line_input_core(system, 0, key, mode);
}
inline Single_Line_Input_Step
app_single_file_input_step(System_Functions *system,
Working_Set *working_set, Key_Event_Data key,
String *string, Hot_Directory *hot_directory,
b32 fast_folder_select, b32 try_to_match, b32 case_sensitive){
Single_Line_Mode mode = {};
mode.type = SINGLE_LINE_FILE;
mode.string = string;
mode.hot_directory = hot_directory;
mode.fast_folder_select = fast_folder_select;
mode.try_to_match = try_to_match;
mode.case_sensitive = case_sensitive;
return app_single_line_input_core(system, working_set, key, mode);
}
inline Single_Line_Input_Step
app_single_number_input_step(System_Functions *system, Key_Event_Data key, String *string){
Single_Line_Input_Step result = {};
Single_Line_Mode mode = {};
mode.type = SINGLE_LINE_STRING;
mode.string = string;
char c = (char)key.character;
if (c == 0 || c == '\n' || char_is_numeric(c))
result = app_single_line_input_core(system, 0, key, mode);
return result;
}
internal i32 internal i32
do_input_file_view(System_Functions *system, Exchange *exchange, 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){
@ -3725,17 +3887,11 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
case guicom_file: case guicom_file:
{ {
f32 old_min_y = view->gui_target.scroll_updated.min_y;
f32 new_min_y = -(f32)(gui_session.clip_rect.y0 - gui_session.rect.y0); f32 new_min_y = -(f32)(gui_session.clip_rect.y0 - gui_session.rect.y0);
if (old_min_y != new_min_y){
view->gui_target.scroll_updated.min_y = new_min_y;
}
f32 old_max_y = view->gui_target.scroll_updated.max_y;
f32 new_max_y = view_compute_max_target_y(view); f32 new_max_y = view_compute_max_target_y(view);
if (old_max_y != new_max_y){
view->gui_target.scroll_updated.min_y = new_min_y;
view->gui_target.scroll_updated.max_y = new_max_y; view->gui_target.scroll_updated.max_y = new_max_y;
}
if (view->reinit_scrolling){ if (view->reinit_scrolling){
view_reinit_scrolling(view); view_reinit_scrolling(view);
@ -3746,7 +3902,25 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
is_file_scroll = 1; is_file_scroll = 1;
}break; }break;
case guicom_text_field: break; case guicom_file_input:
{
Single_Line_Input_Step step;
Key_Event_Data key;
GUI_Edit *e = (GUI_Edit*)h;
Hot_Directory *hdir = (Hot_Directory*)e->out;
Key_Summary *keys = &user_input->keys;
Working_Set *working_set = &view->models->working_set;
i32 i, count;
count = keys->count;
for (i = 0; i < count; ++i){
key = get_single_key(keys, i);
step = app_single_file_input_step(system, working_set, key, &hdir->string, hdir, 1, 1, 0);
if ((step.hit_newline || step.hit_ctrl_newline) && !step.no_file_match) result = 1;
}
}break;
case guicom_file_option: case guicom_file_option:
{ {

View File

@ -109,6 +109,11 @@ struct GUI_Interactive{
GUI_id id; GUI_id id;
}; };
struct GUI_Edit{
GUI_Header h;
void *out;
};
enum GUI_Command_Type{ enum GUI_Command_Type{
guicom_null, guicom_null,
guicom_begin_overlap, guicom_begin_overlap,
@ -118,6 +123,7 @@ enum GUI_Command_Type{
guicom_top_bar, guicom_top_bar,
guicom_file, guicom_file,
guicom_text_field, guicom_text_field,
guicom_file_input,
guicom_file_option, guicom_file_option,
guicom_scrollable, guicom_scrollable,
guicom_scrollable_top, guicom_scrollable_top,
@ -217,6 +223,17 @@ gui_push_simple_command(GUI_Target *target, i32 type){
return(result); return(result);
} }
internal GUI_Edit*
gui_push_string_edit_command(GUI_Target *target, i32 type, void *out){
GUI_Edit *result = 0;
GUI_Edit item;
item.h.type = type;
item.h.size = sizeof(item);
item.out = out;
result = (GUI_Edit*)gui_push_item(target, &item, sizeof(item));
return(result);
}
internal GUI_Interactive* internal GUI_Interactive*
gui_push_button_command(GUI_Target *target, i32 type, GUI_id id){ gui_push_button_command(GUI_Target *target, i32 type, GUI_id id){
GUI_Interactive *result = 0; GUI_Interactive *result = 0;
@ -296,6 +313,11 @@ gui_do_text_field(GUI_Target *target, String prompt, String text){
gui_push_string(target, h, text); gui_push_string(target, h, text);
} }
internal void
gui_do_file_input(GUI_Target *target, void *out){
gui_push_string_edit_command(target, guicom_file_input, out);
}
internal b32 internal b32
gui_do_file_option(GUI_Target *target, GUI_id file_id, String filename, b32 is_folder, String message){ gui_do_file_option(GUI_Target *target, GUI_id file_id, String filename, b32 is_folder, String message){
b32 result = 0; b32 result = 0;
@ -569,6 +591,10 @@ gui_interpret(GUI_Target *target, GUI_Session *session, GUI_Header *h){
end_section = section; end_section = section;
break; break;
case guicom_file_input:
always_give_to_user = 1;
break;
case guicom_file_option: case guicom_file_option:
give_to_user = 1; give_to_user = 1;
rect = gui_layout_fixed_h(session, y, session->line_height * 2); rect = gui_layout_fixed_h(session, y, session->line_height * 2);
@ -714,6 +740,13 @@ gui_read_string(void **ptr){
return(result); return(result);
} }
internal void*
gui_read_out(void **ptr){
void *result;
result = *(void**)*ptr;
*ptr = ((void**)ptr) + 1;
return(result);
}
// BOTTOM // BOTTOM