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_VIEW(view);
USE_FILE(file, view); USE_FILE(file, view);
Delay *delay = &models->delay1;
char *filename = 0; char *filename = 0;
int filename_len = 0; int filename_len = 0;
int buffer_id = -1; int buffer_id = -1;
@ -967,7 +965,8 @@ COMMAND_DECL(save){
if (file){ if (file){
if (name.str){ if (name.str){
if (!file->state.is_dummy && file_is_ready(file)){ 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{ else{
@ -977,7 +976,7 @@ COMMAND_DECL(save){
} }
} }
else{ else{
String name = {}; String name = {0};
if (filename){ if (filename){
name = make_string(filename, filename_len); name = make_string(filename, filename_len);
} }
@ -988,11 +987,13 @@ COMMAND_DECL(save){
if (name.size != 0){ if (name.size != 0){
if (file){ if (file){
if (!file->state.is_dummy && file_is_ready(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{ 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; }break;
#if 0
case DACT_SAVE: case DACT_SAVE:
case DACT_SAVE_AS: 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; }break;
#endif
#if 0
case DACT_NEW: 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; }break;
#endif
case DACT_SWITCH: case DACT_SWITCH:
{ {

View File

@ -2,9 +2,6 @@ enum Action_Type{
DACT_OPEN, DACT_OPEN,
DACT_OPEN_BACKGROUND, DACT_OPEN_BACKGROUND,
DACT_SET_LINE, DACT_SET_LINE,
DACT_SAVE_AS,
DACT_SAVE,
DACT_NEW,
DACT_SWITCH, DACT_SWITCH,
DACT_TRY_KILL, DACT_TRY_KILL,
DACT_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(delay, ...) delayed_action_(delay, DACT_OPEN, ##__VA_ARGS__)
#define delayed_open_background(delay, ...) delayed_action_(delay, DACT_OPEN_BACKGROUND, ##__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_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_switch(delay, ...) delayed_action_(delay, DACT_SWITCH, ##__VA_ARGS__)
#define delayed_try_kill(delay, ...) delayed_action_(delay, DACT_TRY_KILL, ##__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__) #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); Temp_Memory temp = begin_temp_memory(&mem->part);
data = (char*)push_array(&mem->part, char, max); char empty = 0;
if (max == 0){
data = &empty;
}
else{
data = (char*)push_array(&mem->part, char, max);
}
Assert(data); Assert(data);
if (dos_write_mode){ if (dos_write_mode){
@ -2567,7 +2573,7 @@ compute_this_indent(Buffer *buffer, Indent_Parse_State indent,
default: default:
if (indent.current_indent > 0){ if (indent.current_indent > 0){
if (!(prev_token.flags & CPP_TFLAG_PP_BODY || if (!(prev_token.flags & CPP_TFLAG_PP_BODY ||
prev_token.flags & CPP_TFLAG_PP_DIRECTIVE)){ prev_token.flags & CPP_TFLAG_PP_DIRECTIVE)){
switch (prev_token.type){ switch (prev_token.type){
case CPP_TOKEN_BRACKET_OPEN: case CPP_TOKEN_BRACKET_OPEN:
case CPP_TOKEN_BRACE_OPEN: case CPP_TOKEN_BRACE_CLOSE: case CPP_TOKEN_BRACE_OPEN: case CPP_TOKEN_BRACE_CLOSE:
@ -2595,7 +2601,7 @@ compute_this_indent(Buffer *buffer, Indent_Parse_State indent,
internal i32* internal i32*
get_line_indentation_marks(Partition *part, Buffer *buffer, Cpp_Token_Stack tokens, get_line_indentation_marks(Partition *part, Buffer *buffer, Cpp_Token_Stack tokens,
i32 line_start, i32 line_end, i32 tab_width){ i32 line_start, i32 line_end, i32 tab_width){
i32 indent_mark_count = line_end - line_start; i32 indent_mark_count = line_end - line_start;
i32 *indent_marks = push_array(part, i32, indent_mark_count); i32 *indent_marks = push_array(part, i32, indent_mark_count);
@ -2741,7 +2747,7 @@ get_line_indentation_marks(Partition *part, Buffer *buffer, Cpp_Token_Stack toke
i32 char_pos = T.start - start; i32 char_pos = T.start - start;
Hard_Start_Result hard_start = buffer_find_hard_start( Hard_Start_Result hard_start = buffer_find_hard_start(
buffer, start, tab_width); buffer, start, tab_width);
i32 line_pos = hard_start.char_pos - start; i32 line_pos = hard_start.char_pos - start;
@ -2770,7 +2776,7 @@ get_line_indentation_marks(Partition *part, Buffer *buffer, Cpp_Token_Stack toke
internal Make_Batch_Result internal Make_Batch_Result
make_batch_from_indent_marks(Partition *part, Buffer *buffer, i32 line_start, i32 line_end, make_batch_from_indent_marks(Partition *part, Buffer *buffer, i32 line_start, i32 line_end,
i32 *indent_marks, Indent_Options opts){ i32 *indent_marks, Indent_Options opts){
Make_Batch_Result result = {0}; Make_Batch_Result result = {0};
@ -2796,7 +2802,7 @@ make_batch_from_indent_marks(Partition *part, Buffer *buffer, i32 line_start, i3
if (correct_indentation == -1) correct_indentation = hard_start.indent_pos; if (correct_indentation == -1) correct_indentation = hard_start.indent_pos;
if ((hard_start.all_whitespace && hard_start.char_pos > start) || if ((hard_start.all_whitespace && hard_start.char_pos > start) ||
!hard_start.all_space || correct_indentation != hard_start.indent_pos){ !hard_start.all_space || correct_indentation != hard_start.indent_pos){
Buffer_Edit new_edit; Buffer_Edit new_edit;
new_edit.str_start = str_size; new_edit.str_start = str_size;
str_size += correct_indentation; str_size += correct_indentation;
@ -2831,7 +2837,7 @@ make_batch_from_indent_marks(Partition *part, Buffer *buffer, i32 line_start, i3
internal void internal void
view_auto_tab_tokens(System_Functions *system, Models *models, view_auto_tab_tokens(System_Functions *system, Models *models,
View *view, i32 start, i32 end, Indent_Options opts){ View *view, i32 start, i32 end, Indent_Options opts){
#if BUFFER_EXPERIMENT_SCALPEL <= 0 #if BUFFER_EXPERIMENT_SCALPEL <= 0
Editing_File *file = view->file_data.file; Editing_File *file = view->file_data.file;
Mem_Options *mem = &models->mem; Mem_Options *mem = &models->mem;
@ -2863,8 +2869,8 @@ view_auto_tab_tokens(System_Functions *system, Models *models,
char *inv_str = (char*)part->base + part->pos; char *inv_str = (char*)part->base + part->pos;
Edit_Spec spec = Edit_Spec spec =
file_compute_whitespace_edit(mem, file, view->recent->cursor.pos, file_compute_whitespace_edit(mem, file, view->recent->cursor.pos,
batch.edits, batch.str_base, batch.str_size, batch.edits, batch.str_base, batch.str_size,
inverse_array, inv_str, part->max - part->pos, batch.edit_count); inverse_array, inv_str, part->max - part->pos, batch.edit_count);
file_do_white_batch_edit(system, models, view->file_data.file, spec, hist_normal); file_do_white_batch_edit(system, models, view->file_data.file, spec, hist_normal);
} }
@ -2975,8 +2981,8 @@ view_show_config(View *view, Command_Map *gui_map){
inline void inline void
view_show_interactive(System_Functions *system, View *view, view_show_interactive(System_Functions *system, View *view,
Command_Map *gui_map, Interactive_Action action, Command_Map *gui_map, Interactive_Action action,
Interactive_Interaction interaction, String query){ Interactive_Interaction interaction, String query){
Models *models = view->persistent.models; Models *models = view->persistent.models;
@ -3017,7 +3023,57 @@ view_show_file(View *view){
} }
internal void 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; Models *models = view->persistent.models;
Panel *panel = view->panel; Panel *panel = view->panel;
Editing_File *old_file = view->file_data.file; Editing_File *old_file = view->file_data.file;
@ -3029,13 +3085,15 @@ interactive_view_complete(View *view, String dest, i32 user_action){
break; break;
case IAct_Save_As: 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; break;
case IAct_New: case IAct_New:
// TODO(allen): The !char_is_slash part confuses me... let's investigate this soon.
if (dest.size > 0 && if (dest.size > 0 &&
!char_is_slash(models->hot_directory.string.str[dest.size-1])){ !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; }break;
case IAct_Switch: case IAct_Switch:
@ -3072,19 +3130,14 @@ interactive_view_complete(View *view, String dest, i32 user_action){
break; break;
case 2: case 2:
// TODO(allen): This is fishy! What if the save doesn't happen this time around? view_save_file(system, &models->mem, &models->working_set,
// We need to ensure delayed acts happen in order I think... or better yet destroy delayed action entirely. 0, 0, dest, 0);
delayed_save(&models->delay1, dest);
delayed_kill(&models->delay1, dest); delayed_kill(&models->delay1, dest);
break; break;
} }
break; break;
} }
view_show_file(view); 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 #if 0
@ -3269,7 +3322,7 @@ view_get_cursor_scroll_change_state(View *view){
internal void internal void
view_begin_cursor_scroll_updates(View *view){ 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)); 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; do_new_directory = 1;
} }
else if (use_item_in_list){ 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); gui_end_list(target);
if (activate_directly){ if (activate_directly){
interactive_view_complete(view, hdir->string, 0); interactive_view_complete(system, view, hdir->string, 0);
} }
if (do_new_directory){ 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); id.id[0] = (u64)(file);
if (gui_do_file_option(target, id, file->name.live_name, 0, message)){ 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); id.id[0] = (u64)(file);
if (gui_do_file_option(target, id, file->name.live_name, 0, message)){ 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){ if (action != -1){
interactive_view_complete(view, view->dest, action); interactive_view_complete(system, view, view->dest, action);
} }
}break; }break;
@ -4136,7 +4189,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
} }
if (action != -1){ if (action != -1){
interactive_view_complete(view, view->dest, action); interactive_view_complete(system, view, view->dest, action);
} }
}break; }break;
} }

View File

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