diff --git a/4coder_default_bindings.cpp b/4coder_default_bindings.cpp index 80919503..0ca989ed 100644 --- a/4coder_default_bindings.cpp +++ b/4coder_default_bindings.cpp @@ -76,7 +76,7 @@ CUSTOM_COMMAND_SIG(move_down_10){ x = view.preferred_x; if (view.unwrapped_lines){ - y = view.cursor.wrapped_y; + y = view.cursor.unwrapped_y; } else{ y = view.cursor.wrapped_y; diff --git a/4ed.cpp b/4ed.cpp index 2cd65d03..b5096d2d 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -85,6 +85,9 @@ struct App_Vars{ Complete_State complete_state; Command_Data command_data; + + File_Slot slots[32]; + char filename_space[32 * FileNameMax]; }; enum Coroutine_Type{ @@ -3213,6 +3216,41 @@ App_Init_Sig(app_init){ partition = &models->mem.part; target->partition = partition; + { + //exchange + File_Slot *slots = vars->slots; + i32 max = ArrayCount(vars->slots); + { + char *filename_space; + i32 i; + + exchange->file.max = max; + exchange->file.available = file_slot_zero(); + exchange->file.available.next = &exchange->file.available; + exchange->file.available.prev = &exchange->file.available; + + exchange->file.active = file_slot_zero(); + exchange->file.active.next = &exchange->file.active; + exchange->file.active.prev = &exchange->file.active; + + exchange->file.free_list = file_slot_zero(); + exchange->file.free_list.next = &exchange->file.free_list; + exchange->file.free_list.prev = &exchange->file.free_list; + + exchange->file.files = slots; + memset(slots, 0, sizeof(File_Slot)*max); + + filename_space = vars->filename_space; + + File_Slot *slot = slots; + for (i = 0; i < exchange->file.max; ++i, ++slot){ + ex__file_insert(&exchange->file.available, slot); + slot->filename = filename_space; + filename_space += FileNameMax; + } + } + } + { i32 i; @@ -4380,18 +4418,85 @@ App_Step_Sig(app_step){ } }break; } - + if (mouse_in_edit_area && mouse_panel != 0 && mouse->press_l){ models->layout.active_panel = (i32)(mouse_panel - models->layout.panels); } - + update_command_data(vars, cmd); + Temp_Memory file_temp = begin_temp_memory(&models->mem.part); + + // NOTE(allen): Simulate what use to happen on the system side + // for processing file exchange. + { + File_Slot *file; + int d = 0; + + for (file = exchange->file.active.next; + file != &exchange->file.active; + file = file->next){ + ++d; + + if (file->flags & FEx_Save){ + Assert((file->flags & FEx_Request) == 0); + file->flags &= (~FEx_Save); + if (system->file_save(file->filename, + (char*)file->data, file->size)){ + file->flags |= FEx_Save_Complete; + } + else{ + file->flags |= FEx_Save_Failed; + } + app_result.animating = 1; + } + + if (file->flags & FEx_Request){ + Assert((file->flags & FEx_Save) == 0); + file->flags &= (~FEx_Request); + + File_Loading loading = system->file_load_begin(file->filename); + + if (loading.exists){ + char *data = push_array(&models->mem.part, char, loading.size); + if (system->file_load_end(loading, data)){ + file->flags |= FEx_Ready; + file->data = (byte*)data; + file->size = loading.size; + } + } + else{ + system->file_load_end(loading, 0); + file->flags |= FEx_Not_Exist; + } + + app_result.animating = 1; + } + } + + int free_list_count = 0; + for (file = exchange->file.free_list.next; + file != &exchange->file.free_list; + file = file->next){ + ++free_list_count; + } + + if (exchange->file.free_list.next != &exchange->file.free_list){ + Assert(free_list_count != 0); + ex__insert_range(exchange->file.free_list.next, + exchange->file.free_list.prev, + &exchange->file.available); + exchange->file.num_active -= free_list_count; + } + + ex__check(&exchange->file); + } + // NOTE(allen): processing sys app bindings { Mem_Options *mem = &models->mem; General_Memory *general = &mem->general; - + for (i32 i = 0; i < vars->sys_app_count; ++i){ Sys_App_Binding *binding; b32 remove = 0; @@ -4478,6 +4583,8 @@ App_Step_Sig(app_step){ } } + end_temp_memory(file_temp); + // NOTE(allen): process as many delayed actions as possible if (models->delay1.count > 0){ Working_Set *working_set = &models->working_set; diff --git a/4ed_exchange.cpp b/4ed_exchange.cpp index 615381c2..6603f9b7 100644 --- a/4ed_exchange.cpp +++ b/4ed_exchange.cpp @@ -17,6 +17,17 @@ ex__file_insert(File_Slot *pos, File_Slot *file){ file->prev = pos; } +void +ex__insert_range(File_Slot *start, File_Slot *end, File_Slot *pos){ + end->next->prev = start->prev; + start->prev->next = end->next; + + end->next = pos->next; + start->prev = pos; + pos->next->prev = end; + pos->next = start; +} + internal void ex__file_remove(File_Slot *file){ file->next->prev = file->prev; diff --git a/system_shared.cpp b/system_shared.cpp index 0cb88d90..5a8fff84 100644 --- a/system_shared.cpp +++ b/system_shared.cpp @@ -66,6 +66,7 @@ sysshared_filter_real_files(char **files, i32 *file_count){ *file_count = j; } +#if 0 void ex__file_insert(File_Slot *pos, File_Slot *file){ file->next = pos->next; @@ -140,6 +141,7 @@ sysshared_init_file_exchange( if (filename_space_out) *filename_space_out = filename_space; } +#endif internal Partition sysshared_scratch_partition(i32 size){ diff --git a/win32_4ed.cpp b/win32_4ed.cpp index 11b2be16..d0a8df4d 100644 --- a/win32_4ed.cpp +++ b/win32_4ed.cpp @@ -1906,9 +1906,11 @@ int main(int argc, char **argv){ } } } - + +#if 0 File_Slot file_slots[32]; sysshared_init_file_exchange(&exchange_vars, file_slots, ArrayCount(file_slots), 0); +#endif win32vars.app.init(win32vars.system, &win32vars.target, &memory_vars, &exchange_vars, @@ -2056,6 +2058,7 @@ int main(int argc, char **argv){ win32vars.first = 0; +#if 0 { File_Slot *file; int d = 0; @@ -2113,6 +2116,7 @@ int main(int argc, char **argv){ ex__check(&exchange_vars.file); } +#endif i64 timer_end = system_time(); i64 end_target = (timer_start + frame_useconds);