removed save, save_as, and new from the dact system

This commit is contained in:
Allen Webster 2016-05-29 15:54:20 -04:00
parent 93a1d3931f
commit d224d8cd7b
4 changed files with 349 additions and 332 deletions

55
4ed.cpp
View File

@ -931,8 +931,6 @@ COMMAND_DECL(save){
USE_VIEW(view);
USE_FILE(file, view);
Delay *delay = &models->delay1;
char *filename = 0;
int filename_len = 0;
int buffer_id = -1;
@ -967,7 +965,8 @@ COMMAND_DECL(save){
if (file){
if (name.str){
if (!file->state.is_dummy && file_is_ready(file)){
delayed_save_as(delay, name, file);
view_save_file(system, &models->mem, &models->working_set,
file, 0, name, 1);
}
}
else{
@ -977,7 +976,7 @@ COMMAND_DECL(save){
}
}
else{
String name = {};
String name = {0};
if (filename){
name = make_string(filename, filename_len);
}
@ -988,11 +987,13 @@ COMMAND_DECL(save){
if (name.size != 0){
if (file){
if (!file->state.is_dummy && file_is_ready(file)){
delayed_save(delay, name, file);
view_save_file(system, &models->mem, &models->working_set,
file, 0, name, 0);
}
}
else{
delayed_save(delay, name);
view_save_file(system, &models->mem, &models->working_set,
0, 0, name, 0);
}
}
}
@ -4437,54 +4438,20 @@ App_Step_Sig(app_step){
}
}break;
#if 0
case DACT_SAVE:
case DACT_SAVE_AS:
{
if (!file){
if (panel){
View *view = panel->view;
Assert(view);
file = view->file_data.file;
}
else{
file = working_set_lookup_file(working_set, string);
}
}
if (file && buffer_get_sync(file) != SYNC_GOOD){
if (file_save(system, mem, file, string.str)){
if (act->type == DACT_SAVE_AS){
file_set_name(working_set, file, string.str);
}
}
}
}break;
#endif
#if 0
case DACT_NEW:
{
Editing_File *file = working_set_alloc_always(working_set, general);
file_create_empty(system, models, file, string.str);
working_set_add(system, working_set, file, general);
View *view = panel->view;
view_set_file(view, file, models);
view_show_file(view);
view->map = get_map(models, file->settings.base_map_id);
Hook_Function *new_file_fnc = models->hooks[hook_new_file];
if (new_file_fnc){
models->buffer_param_indices[models->buffer_param_count++] = file->id.id;
new_file_fnc(&models->app_links);
models->buffer_param_count = 0;
file->settings.is_initialized = 1;
}
#if BUFFER_EXPERIMENT_SCALPEL <= 0
if (file->settings.tokens_exist)
file_first_lex_parallel(system, general, file);
#endif
}break;
#endif
case DACT_SWITCH:
{

View File

@ -2,9 +2,6 @@ enum Action_Type{
DACT_OPEN,
DACT_OPEN_BACKGROUND,
DACT_SET_LINE,
DACT_SAVE_AS,
DACT_SAVE,
DACT_NEW,
DACT_SWITCH,
DACT_TRY_KILL,
DACT_KILL,
@ -130,9 +127,6 @@ delayed_action_repush(Delay *delay, Delayed_Action *act){
#define delayed_open(delay, ...) delayed_action_(delay, DACT_OPEN, ##__VA_ARGS__)
#define delayed_open_background(delay, ...) delayed_action_(delay, DACT_OPEN_BACKGROUND, ##__VA_ARGS__)
#define delayed_set_line(delay, ...) delayed_action_(delay, DACT_SET_LINE, ##__VA_ARGS__)
#define delayed_save_as(delay, ...) delayed_action_(delay, DACT_SAVE_AS, ##__VA_ARGS__)
#define delayed_save(delay, ...) delayed_action_(delay, DACT_SAVE, ##__VA_ARGS__)
#define delayed_new(delay, ...) delayed_action_(delay, DACT_NEW, ##__VA_ARGS__)
#define delayed_switch(delay, ...) delayed_action_(delay, DACT_SWITCH, ##__VA_ARGS__)
#define delayed_try_kill(delay, ...) delayed_action_(delay, DACT_TRY_KILL, ##__VA_ARGS__)
#define delayed_kill(delay, ...) delayed_action_(delay, DACT_KILL, ##__VA_ARGS__)

View File

@ -452,7 +452,13 @@ file_save(System_Functions *system, Mem_Options *mem, Editing_File *file, char *
}
Temp_Memory temp = begin_temp_memory(&mem->part);
char empty = 0;
if (max == 0){
data = &empty;
}
else{
data = (char*)push_array(&mem->part, char, max);
}
Assert(data);
if (dos_write_mode){
@ -3017,7 +3023,57 @@ view_show_file(View *view){
}
internal void
interactive_view_complete(View *view, String dest, i32 user_action){
view_save_file(System_Functions *system, Mem_Options *mem, Working_Set *working_set,
Editing_File *file, View *view, String filename, b32 save_as){
if (!file){
if (view){
file = view->file_data.file;
}
else{
file = working_set_lookup_file(working_set, filename);
}
}
if (file && buffer_get_sync(file) != SYNC_GOOD){
if (file_save(system, mem, file, filename.str)){
if (save_as){
file_set_name(working_set, file, filename.str);
}
}
}
}
internal void
view_new_file(System_Functions *system, Models *models,
View *view, String string){
Working_Set *working_set = &models->working_set;
General_Memory *general = &models->mem.general;
Editing_File *file = working_set_alloc_always(working_set, general);
file_create_empty(system, models, file, string.str);
working_set_add(system, working_set, file, general);
view_set_file(view, file, models);
view_show_file(view);
view->map = get_map(models, file->settings.base_map_id);
Hook_Function *new_file_fnc = models->hooks[hook_new_file];
if (new_file_fnc){
models->buffer_param_indices[models->buffer_param_count++] = file->id.id;
new_file_fnc(&models->app_links);
models->buffer_param_count = 0;
file->settings.is_initialized = 1;
}
#if BUFFER_EXPERIMENT_SCALPEL <= 0
if (file->settings.tokens_exist){
file_first_lex_parallel(system, general, file);
}
#endif
}
internal void
interactive_view_complete(System_Functions *system, View *view, String dest, i32 user_action){
Models *models = view->persistent.models;
Panel *panel = view->panel;
Editing_File *old_file = view->file_data.file;
@ -3029,13 +3085,15 @@ interactive_view_complete(View *view, String dest, i32 user_action){
break;
case IAct_Save_As:
delayed_save_as(&models->delay1, dest, panel);
view_save_file(system, &models->mem, &models->working_set,
0, view, dest, 1);
break;
case IAct_New:
// TODO(allen): The !char_is_slash part confuses me... let's investigate this soon.
if (dest.size > 0 &&
!char_is_slash(models->hot_directory.string.str[dest.size-1])){
delayed_new(&models->delay1, dest, panel);
view_new_file(system, models, view, dest);
}break;
case IAct_Switch:
@ -3072,19 +3130,14 @@ interactive_view_complete(View *view, String dest, i32 user_action){
break;
case 2:
// TODO(allen): This is fishy! What if the save doesn't happen this time around?
// We need to ensure delayed acts happen in order I think... or better yet destroy delayed action entirely.
delayed_save(&models->delay1, dest);
view_save_file(system, &models->mem, &models->working_set,
0, 0, dest, 0);
delayed_kill(&models->delay1, dest);
break;
}
break;
}
view_show_file(view);
// TODO(allen): This is here to prevent the key press from being passed to the
// underlying file which is a giant pain. But I want a better system.
file_view_nullify_file(view);
}
#if 0
@ -3269,7 +3322,7 @@ view_get_cursor_scroll_change_state(View *view){
internal void
view_begin_cursor_scroll_updates(View *view){
if (view->file_data.file == view->prev_context.file){
if (view->file_data.file && view->file_data.file == view->prev_context.file){
Assert(view->prev_cursor_pos == view_get_cursor_pos(view));
}
@ -3948,7 +4001,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
do_new_directory = 1;
}
else if (use_item_in_list){
interactive_view_complete(view, loop.full_path, 0);
interactive_view_complete(system, view, loop.full_path, 0);
}
}
}
@ -3958,7 +4011,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
gui_end_list(target);
if (activate_directly){
interactive_view_complete(view, hdir->string, 0);
interactive_view_complete(system, view, hdir->string, 0);
}
if (do_new_directory){
@ -4052,7 +4105,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
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);
interactive_view_complete(system, view, file->name.live_name, 0);
}
}
}
@ -4070,7 +4123,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
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);
interactive_view_complete(system, view, file->name.live_name, 0);
}
}
@ -4104,7 +4157,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
}
if (action != -1){
interactive_view_complete(view, view->dest, action);
interactive_view_complete(system, view, view->dest, action);
}
}break;
@ -4136,7 +4189,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
}
if (action != -1){
interactive_view_complete(view, view->dest, action);
interactive_view_complete(system, view, view->dest, action);
}
}break;
}

View File

@ -149,9 +149,11 @@ char *daction_enum[] = {
"OPEN",
"OPEN_BACKGROUND",
"SET_LINE",
#if 0
"SAVE_AS",
"SAVE",
"NEW",
#endif
"SWITCH",
"TRY_KILL",
"KILL",
@ -456,6 +458,7 @@ char* generate_style(){
return(filename);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
struct Function_Signature{
String name;
String ret;