diff --git a/4coder_API/4coder_types.h b/4coder_API/4coder_types.h index 1a2f8b45..c8a33a69 100644 --- a/4coder_API/4coder_types.h +++ b/4coder_API/4coder_types.h @@ -862,14 +862,6 @@ STRUCT Face_Metrics{ f32 typical_character_width; }; -/* DOC(A Buffer_Batch_Edit_Type is a type of batch operation.) */ -ENUM(i32, Buffer_Batch_Edit_Type){ - /* DOC(The BatchEdit_Normal operation is always correct but does the most work if there are tokens to correct.) */ - BatchEdit_Normal, - /* DOC(The BatchEdit_PreserveTokens operation is one in which none of the edits add, delete, or change any tokens. This usually applies when whitespace is being replaced with whitespace.) */ - BatchEdit_PreserveTokens -}; - /* DOC(Buffer_Edit describes a range of a buffer and string to replace that range. A Buffer_Edit has to be paired with a string that contains the actual text that will be replaced into the buffer.) */ STRUCT Buffer_Edit{ diff --git a/4coder_api_transition_30_31.cpp b/4coder_api_transition_30_31.cpp index 047fa544..a83eed3e 100644 --- a/4coder_api_transition_30_31.cpp +++ b/4coder_api_transition_30_31.cpp @@ -130,7 +130,7 @@ exec_system_command(Application_Links *app, View_Summary *view, Buffer_Identifie if (child_process_set_target_buffer(app, child_process_id, buffer_attach_id, set_buffer_flags)){ Buffer_Summary buffer = {}; get_buffer_summary(app, buffer_attach_id, AccessAll, &buffer); - buffer_replace_range(app, buffer_attach_id, 0, buffer.size, make_lit_string("")); + buffer_replace_range(app, buffer_attach_id, make_range(0, buffer.size), make_lit_string("")); if (HasFlag(flags, CLI_SendEndSignal)){ buffer_send_end_signal(app, buffer_attach_id); } @@ -169,7 +169,7 @@ static Buffer_Summary get_buffer_first(Application_Links *app, Access_Flag access){ Buffer_ID buffer_id = 0; Buffer_Summary buffer = {}; - if (get_buffer_first(app, access, &buffer_id)){ + if (get_buffer_next(app, 0, access, &buffer_id)){ get_buffer_summary(app, buffer_id, access, &buffer); } return(buffer); @@ -229,7 +229,7 @@ static b32 buffer_replace_range(Application_Links *app, Buffer_Summary *buffer, i32 start, i32 one_past_last, char *str, i32 len){ b32 result = false; if (buffer != 0 && buffer->exists){ - result = buffer_replace_range(app, buffer->buffer_id, start, one_past_last, make_string(str, len)); + result = buffer_replace_range(app, buffer->buffer_id, make_range(start, one_past_last), make_string(str, len)); get_buffer_summary(app, buffer->buffer_id, AccessAll, buffer); } return(result); @@ -246,10 +246,10 @@ buffer_compute_cursor(Application_Links *app, Buffer_Summary *buffer, Buffer_See } static b32 -buffer_batch_edit(Application_Links *app, Buffer_Summary *buffer, char *str, i32 str_len, Buffer_Edit *edits, i32 edit_count, Buffer_Batch_Edit_Type type){ +buffer_batch_edit(Application_Links *app, Buffer_Summary *buffer, char *str, i32 str_len, Buffer_Edit *edits, i32 edit_count, i32 type){ b32 result = false; if (buffer != 0 && buffer->exists){ - result = buffer_batch_edit(app, buffer->buffer_id, str, str_len, edits, edit_count, type); + result = buffer_batch_edit(app, buffer->buffer_id, str, edits, edit_count); get_buffer_summary(app, buffer->buffer_id, AccessAll, buffer); } return(result); diff --git a/4coder_api_transition_30_31.h b/4coder_api_transition_30_31.h index a019b8fd..ea513c04 100644 --- a/4coder_api_transition_30_31.h +++ b/4coder_api_transition_30_31.h @@ -24,6 +24,9 @@ #if !defined(REMOVE_TRANSITION_HELPER_31) +#define BatchEdit_PreserveTokens 0 +#define BatchEdit_Normal 0 + /* DOC(Buffer_Summary acts as a handle to a buffer and describes the state of the buffer.) DOC_SEE(Access_Flag) DOC_SEE(Dirty_State) */ diff --git a/4coder_auto_indent.cpp b/4coder_auto_indent.cpp index 0774fbd1..ebe60b92 100644 --- a/4coder_auto_indent.cpp +++ b/4coder_auto_indent.cpp @@ -123,7 +123,7 @@ static void set_line_indents(Application_Links *app, Partition *part, Buffer_ID buffer, i32 first_line, i32 one_past_last_line, i32 *indent_marks, Indent_Options opts){ Buffer_Batch_Edit batch = make_batch_from_indent_marks(app, part, buffer, first_line, one_past_last_line, indent_marks, opts); if (batch.edit_count > 0){ - buffer_batch_edit(app, buffer, batch.str, batch.str_len, batch.edits, batch.edit_count, BatchEdit_PreserveTokens); + buffer_batch_edit(app, buffer, batch.str, batch.edits, batch.edit_count); } } diff --git a/4coder_base_commands.cpp b/4coder_base_commands.cpp index 402787b6..33f92f27 100644 --- a/4coder_base_commands.cpp +++ b/4coder_base_commands.cpp @@ -47,7 +47,7 @@ write_character_parameter(Application_Links *app, u8 *character, u32 length){ } // NOTE(allen): perform the edit - b32 edit_success = buffer_replace_range(app, buffer, pos, pos, make_string((char*)character, length)); + b32 edit_success = buffer_replace_range(app, buffer, make_range(pos), make_string((char*)character, length)); // NOTE(allen): finish merging records if necessary if (do_merge){ @@ -96,7 +96,7 @@ CUSTOM_DOC("Deletes the character to the right of the cursor.") Full_Cursor cursor = {}; view_compute_cursor(app, &view, seek_character_pos(view.cursor.character_pos + 1), &cursor); i32 end = cursor.pos; - buffer_replace_range(app, buffer, start, end, make_lit_string("")); + buffer_replace_range(app, buffer, make_range(start, end), make_lit_string("")); } } } @@ -116,7 +116,7 @@ CUSTOM_DOC("Deletes the character to the left of the cursor.") Full_Cursor cursor = {}; view_compute_cursor(app, &view, seek_character_pos(view.cursor.character_pos - 1), &cursor); i32 start = cursor.pos; - if (buffer_replace_range(app, buffer, start, end, make_lit_string(""))){ + if (buffer_replace_range(app, buffer, make_range(start, end), make_lit_string(""))){ view_set_cursor(app, &view, seek_character_pos(view.cursor.character_pos - 1), true); } } @@ -148,7 +148,7 @@ CUSTOM_DOC("Deletes the text in the range between the cursor and the mark.") Buffer_ID buffer = 0; view_get_buffer(app, view.view_id, AccessOpen, &buffer); Range range = get_view_range(&view); - buffer_replace_range(app, buffer, range.min, range.max, make_lit_string("")); + buffer_replace_range(app, buffer, range, make_lit_string("")); } //////////////////////////////// @@ -420,7 +420,7 @@ CUSTOM_DOC("Converts all ascii text in the range between the cursor and the mark for (i32 i = 0; i < size; ++i){ mem[i] = char_to_upper(mem[i]); } - buffer_replace_range(app, buffer, range.min, range.max, make_string(mem, size)); + buffer_replace_range(app, buffer, range, make_string(mem, size)); view_set_cursor(app, &view, seek_pos(range.max), true); } } @@ -439,7 +439,7 @@ CUSTOM_DOC("Converts all ascii text in the range between the cursor and the mark for (i32 i = 0; i < size; ++i){ mem[i] = char_to_lower(mem[i]); } - buffer_replace_range(app, buffer, range.min, range.max, make_string(mem, size)); + buffer_replace_range(app, buffer, range, make_string(mem, size)); view_set_cursor(app, &view, seek_pos(range.max), true); } } @@ -506,7 +506,7 @@ CUSTOM_DOC("Removes trailing whitespace from all lines in the current buffer.") } i32 edit_count = (i32)(edit - edits); - buffer_batch_edit(app, buffer_id, 0, 0, edits, edit_count, BatchEdit_PreserveTokens); + buffer_batch_edit(app, buffer_id, 0, edits, edit_count); } } } @@ -990,7 +990,7 @@ CUSTOM_DOC("Queries the user for two strings, and replaces all occurences of the global_history_edit_group_begin(app); for (;new_pos + r.size <= range.end;){ - buffer_replace_range(app, buffer_id, new_pos, new_pos + r.size, w); + buffer_replace_range(app, buffer_id, make_range(new_pos, new_pos + r.size), w); refresh_view(app, &view); range = get_view_range(&view); pos = new_pos + w.size; @@ -1027,7 +1027,7 @@ query_replace_base(Application_Links *app, View_Summary *view, Buffer_ID buffer_ if (in.key.character == 'y' || in.key.character == 'Y' || in.key.character == '\n' || in.key.character == '\t'){ - buffer_replace_range(app, buffer_id, match.min, match.max, w); + buffer_replace_range(app, buffer_id, match, w); pos = match.start + w.size; } else{ @@ -1397,7 +1397,7 @@ CUSTOM_DOC("Swaps the line under the cursor with the line above it, and moves th } if (buffer_read_range(app, buffer, prev_line_pos, this_line_pos, swap + first_len)){ - buffer_replace_range(app, buffer, prev_line_pos, next_line_pos, make_string(swap, length)); + buffer_replace_range(app, buffer, make_range(prev_line_pos, next_line_pos), make_string(swap, length)); view_set_cursor(app, &view, seek_line_char(prev_line, 1), true); } } @@ -1443,7 +1443,7 @@ CUSTOM_DOC("Create a copy of the line on which the cursor sits.") line_string.size += 1; i32 pos = buffer_get_line_end(app, buffer_id, view.cursor.line); - buffer_replace_range(app, buffer_id, pos, pos, line_string); + buffer_replace_range(app, buffer_id, make_range(pos), line_string); } end_temp_memory(temp); } @@ -1473,7 +1473,7 @@ CUSTOM_DOC("Delete the line the on which the cursor sits.") } String zero = {}; - buffer_replace_range(app, buffer_id, start, end, zero); + buffer_replace_range(app, buffer_id, make_range(start, end), zero); end_temp_memory(temp); } diff --git a/4coder_base_types.cpp b/4coder_base_types.cpp index 79d4a836..6e6087cd 100644 --- a/4coder_base_types.cpp +++ b/4coder_base_types.cpp @@ -863,6 +863,12 @@ make_range(i32 p1, i32 p2){ return(range); } +static Range +make_range(i32 p){ + Range range = {p, p}; + return(range); +} + static Range rectify(Range range) { return(make_range(range.min, range.max)); @@ -905,6 +911,16 @@ interval_is_valid(Range range){ return(range.start <= range.one_past_last); } +static i32 +replace_range_compute_shift(i32 replace_start, i32 replace_end, i32 insert_length){ + return(insert_length - (replace_end - replace_start)); +} + +static i32 +replace_range_compute_shift(Range range, i32 insert_length){ + return(replace_range_compute_shift(range.first, range.one_past_last, insert_length)); +} + //////////////////////////////// static i32_Rect diff --git a/4coder_clipboard.cpp b/4coder_clipboard.cpp index 663a1a43..f05c1844 100644 --- a/4coder_clipboard.cpp +++ b/4coder_clipboard.cpp @@ -41,7 +41,7 @@ CUSTOM_DOC("Cut the text in the range from the cursor to the mark onto the clipb view_get_buffer(app, view.view_id, AccessOpen, &buffer); Range range = get_view_range(&view); if (post_buffer_range_to_clipboard(app, &global_part, 0, buffer, range.min, range.max)){ - buffer_replace_range(app, buffer, range.min, range.max, make_lit_string("")); + buffer_replace_range(app, buffer, range, make_lit_string("")); } } @@ -72,7 +72,7 @@ CUSTOM_DOC("At the cursor, insert the text at the top of the clipboard.") view_get_buffer(app, view.view_id, AccessOpen, &buffer); i32 pos = view.cursor.pos; - buffer_replace_range(app, buffer, pos, pos, make_string(str, len)); + buffer_replace_range(app, buffer, make_range(pos), make_string(str, len)); view_set_mark(app, &view, seek_pos(pos)); view_set_cursor(app, &view, seek_pos(pos + len), true); @@ -119,7 +119,7 @@ CUSTOM_DOC("If the previous command was paste or paste_next, replaces the paste Range range = get_view_range(&view); i32 pos = range.min; - buffer_replace_range(app, buffer, range.min, range.max, make_string(str, len)); + buffer_replace_range(app, buffer, range, make_string(str, len)); view_set_cursor(app, &view, seek_pos(pos + len), true); // TODO(allen): Send this to all views. diff --git a/4coder_combined_write_commands.cpp b/4coder_combined_write_commands.cpp index 5569cb50..bc7534f2 100644 --- a/4coder_combined_write_commands.cpp +++ b/4coder_combined_write_commands.cpp @@ -6,7 +6,7 @@ static void write_string(Application_Links *app, View_Summary *view, Buffer_ID buffer, String string){ - buffer_replace_range(app, buffer, view->cursor.pos, view->cursor.pos, string); + buffer_replace_range(app, buffer, make_range(view->cursor.pos), string); view_set_cursor(app, view, seek_pos(view->cursor.pos + string.size), 1); } @@ -46,7 +46,7 @@ long_braces(Application_Links *app, char *text, i32 size){ Buffer_ID buffer = 0; view_get_buffer(app, view.view_id, AccessOpen, &buffer); i32 pos = view.cursor.pos; - buffer_replace_range(app, buffer, pos, pos, make_string(text, size)); + buffer_replace_range(app, buffer, make_range(pos), make_string(text, size)); view_set_cursor(app, &view, seek_pos(pos + 2), true); buffer_auto_indent(app, &global_part, buffer, pos, pos + size, DEF_TAB_WIDTH, DEFAULT_INDENT_FLAGS | AutoIndent_FullTokens); move_past_lead_whitespace(app, &view, buffer); @@ -141,7 +141,7 @@ CUSTOM_DOC("Insert '//' at the beginning of the line after leading whitespace.") i32 pos = get_start_of_line_at_cursor(app, &view, buffer); b32 alread_has_comment = c_line_comment_starts_at_position(app, buffer, pos); if (!alread_has_comment){ - buffer_replace_range(app, buffer, pos, pos, make_lit_string("//")); + buffer_replace_range(app, buffer, make_range(pos), make_lit_string("//")); } } @@ -154,7 +154,7 @@ CUSTOM_DOC("If present, delete '//' at the beginning of the line after leading w i32 pos = get_start_of_line_at_cursor(app, &view, buffer); b32 alread_has_comment = c_line_comment_starts_at_position(app, buffer, pos); if (alread_has_comment){ - buffer_replace_range(app, buffer, pos, pos + 2, make_lit_string("")); + buffer_replace_range(app, buffer, make_range(pos, pos + 2), make_lit_string("")); } } @@ -167,10 +167,10 @@ CUSTOM_DOC("Turns uncommented lines into commented lines and vice versa for comm i32 pos = get_start_of_line_at_cursor(app, &view, buffer); b32 alread_has_comment = c_line_comment_starts_at_position(app, buffer, pos); if (alread_has_comment){ - buffer_replace_range(app, buffer, pos, pos + 2, make_lit_string("")); + buffer_replace_range(app, buffer, make_range(pos, pos + 2), make_lit_string("")); } else{ - buffer_replace_range(app, buffer, pos, pos, make_lit_string("//")); + buffer_replace_range(app, buffer, make_range(pos), make_lit_string("//")); } } @@ -218,7 +218,7 @@ activate_snippet(Application_Links *app, Partition *scratch, Heap *heap, Buffer_ID buffer = 0; view_get_buffer(app, view->view_id, AccessOpen, &buffer); i32 pos = view->cursor.pos; - buffer_replace_range(app, buffer, pos, pos, make_string_slowly(snippet.text)); + buffer_replace_range(app, buffer, make_range(pos), make_string_slowly(snippet.text)); view_set_cursor(app, view, seek_pos(pos + snippet.cursor_offset), true); view_set_mark(app, view, seek_pos(pos + snippet.mark_offset)); } diff --git a/4coder_default_framework.cpp b/4coder_default_framework.cpp index cc58c85f..4230d236 100644 --- a/4coder_default_framework.cpp +++ b/4coder_default_framework.cpp @@ -299,7 +299,7 @@ create_or_switch_to_buffer_by_name(Application_Links *app, char *name, i32 name_ buffer_get_size(app, search_buffer, &buffer_size); buffer_send_end_signal(app, search_buffer); - buffer_replace_range(app, search_buffer, 0, buffer_size, make_lit_string("")); + buffer_replace_range(app, search_buffer, make_range(0, buffer_size), make_lit_string("")); } else{ create_buffer(app, name_string, BufferCreate_AlwaysNew, &search_buffer); diff --git a/4coder_experiments.cpp b/4coder_experiments.cpp index e98181e0..aeae627c 100644 --- a/4coder_experiments.cpp +++ b/4coder_experiments.cpp @@ -54,7 +54,7 @@ CUSTOM_DOC("Delete characters in a rectangular region. Range testing is done by end = cursor.pos; if (success){ - buffer_replace_range(app, buffer, start, end, make_lit_string("")); + buffer_replace_range(app, buffer, make_range(start, end), make_lit_string("")); } } } @@ -72,7 +72,7 @@ pad_buffer_line(Application_Links *app, Partition *part, Buffer_ID buffer, i32 l i32 size = target - (end.character - 1); char *str = push_array(part, char, size); memset(str, ' ', size); - buffer_replace_range(app, buffer, end.pos, end.pos, make_string(str, size)); + buffer_replace_range(app, buffer, make_range(end.pos), make_string(str, size)); end_temp_memory(temp); } } @@ -159,7 +159,7 @@ CUSTOM_DOC("Begin multi-line mode. In multi-line mode characters are inserted a } i32 edit_count = (int)(edit - edits); - buffer_batch_edit(app, buffer, &str, 1, edits, edit_count, BatchEdit_Normal); + buffer_batch_edit(app, buffer, &str, edits, edit_count); end_temp_memory(temp); @@ -187,7 +187,7 @@ CUSTOM_DOC("Begin multi-line mode. In multi-line mode characters are inserted a } i32 edit_count = (int)(edit - edits); - buffer_batch_edit(app, buffer, 0, 0, edits, edit_count, BatchEdit_Normal); + buffer_batch_edit(app, buffer, 0, edits, edit_count); end_temp_memory(temp); @@ -228,7 +228,7 @@ CUSTOM_COMMAND_SIG(multi_paste){ Buffer_ID buffer = 0; view_get_buffer(app, view.view_id, AccessOpen, &buffer); Range range = get_view_range(&view); - buffer_replace_range(app, buffer, range.max, range.max, make_string(str, len + 1)); + buffer_replace_range(app, buffer, make_range(range.max), make_string(str, len + 1)); view_set_mark(app, &view, seek_pos(range.max + 1)); view_set_cursor(app, &view, seek_pos(range.max + len + 1), true); @@ -282,7 +282,7 @@ multi_paste_range(Application_Links *app, View_Summary *view, Range range, i32 p } i32 pos = range.min; - buffer_replace_range(app, buffer, range.min, range.max, make_string(str, total_size)); + buffer_replace_range(app, buffer, range, make_string(str, total_size)); finish_range.min = pos; finish_range.max = pos + total_size; view_set_mark(app, view, seek_pos(finish_range.min)); @@ -348,7 +348,7 @@ multi_paste_interactive_up_down(Application_Links *app, i32 paste_count, i32 cli if (in.abort){ Buffer_ID buffer = 0; view_get_buffer(app, view.view_id, AccessOpen, &buffer); - buffer_replace_range(app, buffer, range.min, range.max, make_lit_string("")); + buffer_replace_range(app, buffer, range, make_lit_string("")); } } @@ -522,7 +522,7 @@ CUSTOM_DOC("If the cursor is found to be on the name of a function parameter in doublebreak2:; if (closed_correctly){ - buffer_batch_edit(app, buffer, replace_string.str, replace_string.size, edits, edit_count, BatchEdit_Normal); + buffer_batch_edit(app, buffer, replace_string.str, edits, edit_count); } } } @@ -684,7 +684,7 @@ write_explicit_enum_values_parameters(Application_Links *app, Write_Explicit_Enu finished:; if (closed_correctly){ - buffer_batch_edit(app, buffer, string_base, string.size, edits, edit_count, BatchEdit_Normal); + buffer_batch_edit(app, buffer, string_base, edits, edit_count); } } } @@ -766,7 +766,7 @@ replace_all_occurrences_parameters(Application_Links *app, Heap *heap, Partition current_offset = 0; } i32 pos = target->start_pos + current_offset; - buffer_replace_range(app, target->buffer_id, pos, pos + target_string.size, new_string); + buffer_replace_range(app, target->buffer_id, make_range(pos, pos + target_string.size), new_string); current_offset += shift_per_replacement; } diff --git a/4coder_function_list.cpp b/4coder_function_list.cpp index 194cfda6..753de711 100644 --- a/4coder_function_list.cpp +++ b/4coder_function_list.cpp @@ -25,7 +25,7 @@ buffered_write_stream_flush(Application_Links *app, Buffered_Write_Stream *strea i32 buffer_size = 0; buffer_get_size(app, buffer, &buffer_size); i32 stream_size = (i32)(push_array(stream->buffering_arena, char, 0) - stream->buffer); - buffer_replace_range(app, buffer, buffer_size, buffer_size, make_string(stream->buffer, stream_size)); + buffer_replace_range(app, buffer, make_range(buffer_size), make_string(stream->buffer, stream_size)); stream->buffering_arena->pos -= stream_size; } @@ -264,7 +264,7 @@ list_all_functions(Application_Links *app, Partition *part, Buffer_ID optional_t buffer_send_end_signal(app, decls_buffer); i32 size = 0; buffer_get_size(app, decls_buffer, &size); - buffer_replace_range(app, decls_buffer, 0, size, make_lit_string("")); + buffer_replace_range(app, decls_buffer, make_range(0, size), make_lit_string("")); } Temp_Memory temp = begin_temp_memory(part); diff --git a/4coder_generated/app_functions.h b/4coder_generated/app_functions.h index e57bccd0..60114da6 100644 --- a/4coder_generated/app_functions.h +++ b/4coder_generated/app_functions.h @@ -13,14 +13,13 @@ struct Application_Links; #define CLIPBOARD_INDEX_SIG(n) b32 n(Application_Links *app, i32 clipboard_id, i32 item_index, String *string_out, i32 *required_size_out) #define CREATE_PARSE_CONTEXT_SIG(n) Parse_Context_ID n(Application_Links *app, Parser_String_And_Type *kw, u32 kw_count, Parser_String_And_Type *pp, u32 pp_count) #define GET_BUFFER_COUNT_SIG(n) i32 n(Application_Links *app) -#define GET_BUFFER_FIRST_SIG(n) b32 n(Application_Links *app, Access_Flag access, Buffer_ID *buffer_id_out) #define GET_BUFFER_NEXT_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Access_Flag access, Buffer_ID *buffer_id_out) #define GET_BUFFER_BY_NAME_SIG(n) b32 n(Application_Links *app, String name, Access_Flag access, Buffer_ID *buffer_id_out) #define GET_BUFFER_BY_FILE_NAME_SIG(n) b32 n(Application_Links *app, String file_name, Access_Flag access, Buffer_ID *buffer_id_out) #define BUFFER_READ_RANGE_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 one_past_last, char *out) -#define BUFFER_REPLACE_RANGE_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 one_past_last, String string) +#define BUFFER_REPLACE_RANGE_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Range range, String string) +#define BUFFER_BATCH_EDIT_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, char *str, Buffer_Edit *edits, i32 edit_count) #define BUFFER_COMPUTE_CURSOR_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Buffer_Seek seek, Partial_Cursor *cursor_out) -#define BUFFER_BATCH_EDIT_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, char *str, i32 str_len, Buffer_Edit *edits, i32 edit_count, Buffer_Batch_Edit_Type type) #define BUFFER_EXISTS_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id) #define BUFFER_READY_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id) #define BUFFER_GET_ACCESS_FLAGS_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Access_Flag *access_flags_out) @@ -198,14 +197,13 @@ typedef CLIPBOARD_COUNT_SIG(Clipboard_Count_Function); typedef CLIPBOARD_INDEX_SIG(Clipboard_Index_Function); typedef CREATE_PARSE_CONTEXT_SIG(Create_Parse_Context_Function); typedef GET_BUFFER_COUNT_SIG(Get_Buffer_Count_Function); -typedef GET_BUFFER_FIRST_SIG(Get_Buffer_First_Function); typedef GET_BUFFER_NEXT_SIG(Get_Buffer_Next_Function); typedef GET_BUFFER_BY_NAME_SIG(Get_Buffer_By_Name_Function); typedef GET_BUFFER_BY_FILE_NAME_SIG(Get_Buffer_By_File_Name_Function); typedef BUFFER_READ_RANGE_SIG(Buffer_Read_Range_Function); typedef BUFFER_REPLACE_RANGE_SIG(Buffer_Replace_Range_Function); -typedef BUFFER_COMPUTE_CURSOR_SIG(Buffer_Compute_Cursor_Function); typedef BUFFER_BATCH_EDIT_SIG(Buffer_Batch_Edit_Function); +typedef BUFFER_COMPUTE_CURSOR_SIG(Buffer_Compute_Cursor_Function); typedef BUFFER_EXISTS_SIG(Buffer_Exists_Function); typedef BUFFER_READY_SIG(Buffer_Ready_Function); typedef BUFFER_GET_ACCESS_FLAGS_SIG(Buffer_Get_Access_Flags_Function); @@ -385,14 +383,13 @@ Clipboard_Count_Function *clipboard_count; Clipboard_Index_Function *clipboard_index; Create_Parse_Context_Function *create_parse_context; Get_Buffer_Count_Function *get_buffer_count; -Get_Buffer_First_Function *get_buffer_first; Get_Buffer_Next_Function *get_buffer_next; Get_Buffer_By_Name_Function *get_buffer_by_name; Get_Buffer_By_File_Name_Function *get_buffer_by_file_name; Buffer_Read_Range_Function *buffer_read_range; Buffer_Replace_Range_Function *buffer_replace_range; -Buffer_Compute_Cursor_Function *buffer_compute_cursor; Buffer_Batch_Edit_Function *buffer_batch_edit; +Buffer_Compute_Cursor_Function *buffer_compute_cursor; Buffer_Exists_Function *buffer_exists; Buffer_Ready_Function *buffer_ready; Buffer_Get_Access_Flags_Function *buffer_get_access_flags; @@ -571,14 +568,13 @@ Clipboard_Count_Function *clipboard_count_; Clipboard_Index_Function *clipboard_index_; Create_Parse_Context_Function *create_parse_context_; Get_Buffer_Count_Function *get_buffer_count_; -Get_Buffer_First_Function *get_buffer_first_; Get_Buffer_Next_Function *get_buffer_next_; Get_Buffer_By_Name_Function *get_buffer_by_name_; Get_Buffer_By_File_Name_Function *get_buffer_by_file_name_; Buffer_Read_Range_Function *buffer_read_range_; Buffer_Replace_Range_Function *buffer_replace_range_; -Buffer_Compute_Cursor_Function *buffer_compute_cursor_; Buffer_Batch_Edit_Function *buffer_batch_edit_; +Buffer_Compute_Cursor_Function *buffer_compute_cursor_; Buffer_Exists_Function *buffer_exists_; Buffer_Ready_Function *buffer_ready_; Buffer_Get_Access_Flags_Function *buffer_get_access_flags_; @@ -765,14 +761,13 @@ app_links->clipboard_count_ = Clipboard_Count;\ app_links->clipboard_index_ = Clipboard_Index;\ app_links->create_parse_context_ = Create_Parse_Context;\ app_links->get_buffer_count_ = Get_Buffer_Count;\ -app_links->get_buffer_first_ = Get_Buffer_First;\ app_links->get_buffer_next_ = Get_Buffer_Next;\ app_links->get_buffer_by_name_ = Get_Buffer_By_Name;\ app_links->get_buffer_by_file_name_ = Get_Buffer_By_File_Name;\ app_links->buffer_read_range_ = Buffer_Read_Range;\ app_links->buffer_replace_range_ = Buffer_Replace_Range;\ -app_links->buffer_compute_cursor_ = Buffer_Compute_Cursor;\ app_links->buffer_batch_edit_ = Buffer_Batch_Edit;\ +app_links->buffer_compute_cursor_ = Buffer_Compute_Cursor;\ app_links->buffer_exists_ = Buffer_Exists;\ app_links->buffer_ready_ = Buffer_Ready;\ app_links->buffer_get_access_flags_ = Buffer_Get_Access_Flags;\ @@ -951,14 +946,13 @@ static b32 clipboard_count(Application_Links *app, i32 clipboard_id, i32 *count_ static b32 clipboard_index(Application_Links *app, i32 clipboard_id, i32 item_index, String *string_out, i32 *required_size_out){return(app->clipboard_index(app, clipboard_id, item_index, string_out, required_size_out));} static Parse_Context_ID create_parse_context(Application_Links *app, Parser_String_And_Type *kw, u32 kw_count, Parser_String_And_Type *pp, u32 pp_count){return(app->create_parse_context(app, kw, kw_count, pp, pp_count));} static i32 get_buffer_count(Application_Links *app){return(app->get_buffer_count(app));} -static b32 get_buffer_first(Application_Links *app, Access_Flag access, Buffer_ID *buffer_id_out){return(app->get_buffer_first(app, access, buffer_id_out));} static b32 get_buffer_next(Application_Links *app, Buffer_ID buffer_id, Access_Flag access, Buffer_ID *buffer_id_out){return(app->get_buffer_next(app, buffer_id, access, buffer_id_out));} static b32 get_buffer_by_name(Application_Links *app, String name, Access_Flag access, Buffer_ID *buffer_id_out){return(app->get_buffer_by_name(app, name, access, buffer_id_out));} static b32 get_buffer_by_file_name(Application_Links *app, String file_name, Access_Flag access, Buffer_ID *buffer_id_out){return(app->get_buffer_by_file_name(app, file_name, access, buffer_id_out));} static b32 buffer_read_range(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 one_past_last, char *out){return(app->buffer_read_range(app, buffer_id, start, one_past_last, out));} -static b32 buffer_replace_range(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 one_past_last, String string){return(app->buffer_replace_range(app, buffer_id, start, one_past_last, string));} +static b32 buffer_replace_range(Application_Links *app, Buffer_ID buffer_id, Range range, String string){return(app->buffer_replace_range(app, buffer_id, range, string));} +static b32 buffer_batch_edit(Application_Links *app, Buffer_ID buffer_id, char *str, Buffer_Edit *edits, i32 edit_count){return(app->buffer_batch_edit(app, buffer_id, str, edits, edit_count));} static b32 buffer_compute_cursor(Application_Links *app, Buffer_ID buffer_id, Buffer_Seek seek, Partial_Cursor *cursor_out){return(app->buffer_compute_cursor(app, buffer_id, seek, cursor_out));} -static b32 buffer_batch_edit(Application_Links *app, Buffer_ID buffer_id, char *str, i32 str_len, Buffer_Edit *edits, i32 edit_count, Buffer_Batch_Edit_Type type){return(app->buffer_batch_edit(app, buffer_id, str, str_len, edits, edit_count, type));} static b32 buffer_exists(Application_Links *app, Buffer_ID buffer_id){return(app->buffer_exists(app, buffer_id));} static b32 buffer_ready(Application_Links *app, Buffer_ID buffer_id){return(app->buffer_ready(app, buffer_id));} static b32 buffer_get_access_flags(Application_Links *app, Buffer_ID buffer_id, Access_Flag *access_flags_out){return(app->buffer_get_access_flags(app, buffer_id, access_flags_out));} @@ -1137,14 +1131,13 @@ static b32 clipboard_count(Application_Links *app, i32 clipboard_id, i32 *count_ static b32 clipboard_index(Application_Links *app, i32 clipboard_id, i32 item_index, String *string_out, i32 *required_size_out){return(app->clipboard_index_(app, clipboard_id, item_index, string_out, required_size_out));} static Parse_Context_ID create_parse_context(Application_Links *app, Parser_String_And_Type *kw, u32 kw_count, Parser_String_And_Type *pp, u32 pp_count){return(app->create_parse_context_(app, kw, kw_count, pp, pp_count));} static i32 get_buffer_count(Application_Links *app){return(app->get_buffer_count_(app));} -static b32 get_buffer_first(Application_Links *app, Access_Flag access, Buffer_ID *buffer_id_out){return(app->get_buffer_first_(app, access, buffer_id_out));} static b32 get_buffer_next(Application_Links *app, Buffer_ID buffer_id, Access_Flag access, Buffer_ID *buffer_id_out){return(app->get_buffer_next_(app, buffer_id, access, buffer_id_out));} static b32 get_buffer_by_name(Application_Links *app, String name, Access_Flag access, Buffer_ID *buffer_id_out){return(app->get_buffer_by_name_(app, name, access, buffer_id_out));} static b32 get_buffer_by_file_name(Application_Links *app, String file_name, Access_Flag access, Buffer_ID *buffer_id_out){return(app->get_buffer_by_file_name_(app, file_name, access, buffer_id_out));} static b32 buffer_read_range(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 one_past_last, char *out){return(app->buffer_read_range_(app, buffer_id, start, one_past_last, out));} -static b32 buffer_replace_range(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 one_past_last, String string){return(app->buffer_replace_range_(app, buffer_id, start, one_past_last, string));} +static b32 buffer_replace_range(Application_Links *app, Buffer_ID buffer_id, Range range, String string){return(app->buffer_replace_range_(app, buffer_id, range, string));} +static b32 buffer_batch_edit(Application_Links *app, Buffer_ID buffer_id, char *str, Buffer_Edit *edits, i32 edit_count){return(app->buffer_batch_edit_(app, buffer_id, str, edits, edit_count));} static b32 buffer_compute_cursor(Application_Links *app, Buffer_ID buffer_id, Buffer_Seek seek, Partial_Cursor *cursor_out){return(app->buffer_compute_cursor_(app, buffer_id, seek, cursor_out));} -static b32 buffer_batch_edit(Application_Links *app, Buffer_ID buffer_id, char *str, i32 str_len, Buffer_Edit *edits, i32 edit_count, Buffer_Batch_Edit_Type type){return(app->buffer_batch_edit_(app, buffer_id, str, str_len, edits, edit_count, type));} static b32 buffer_exists(Application_Links *app, Buffer_ID buffer_id){return(app->buffer_exists_(app, buffer_id));} static b32 buffer_ready(Application_Links *app, Buffer_ID buffer_id){return(app->buffer_ready_(app, buffer_id));} static b32 buffer_get_access_flags(Application_Links *app, Buffer_ID buffer_id, Access_Flag *access_flags_out){return(app->buffer_get_access_flags_(app, buffer_id, access_flags_out));} diff --git a/4coder_generated/command_metadata.h b/4coder_generated/command_metadata.h index 81c12c87..e1c853fd 100644 --- a/4coder_generated/command_metadata.h +++ b/4coder_generated/command_metadata.h @@ -360,12 +360,12 @@ static Command_Metadata fcoder_metacmd_table[234] = { { PROC_LINKS(lister__write_character__fixed_list, 0), "lister__write_character__fixed_list", 35, "A lister mode command that handles input for the fixed sure to kill list.", 73, "c:\\4ed\\code\\4coder_lists.cpp", 28, 256 }, { PROC_LINKS(load_project, 0), "load_project", 12, "Looks for a project.4coder file in the current directory and tries to load it. Looks in parent directories until a project file is found or there are no more parents.", 167, "c:\\4ed\\code\\4coder_project_commands.cpp", 39, 1085 }, { PROC_LINKS(make_directory_query, 0), "make_directory_query", 20, "Queries the user for a name and creates a new directory with the given name.", 76, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1319 }, -{ PROC_LINKS(miblo_decrement_basic, 0), "miblo_decrement_basic", 21, "Decrement an integer under the cursor by one.", 45, "c:\\4ed\\code\\4coder_miblo_numbers.cpp", 36, 109 }, -{ PROC_LINKS(miblo_decrement_time_stamp, 0), "miblo_decrement_time_stamp", 26, "Decrement a time stamp under the cursor by one second. (format [m]m:ss or h:mm:ss", 81, "c:\\4ed\\code\\4coder_miblo_numbers.cpp", 36, 383 }, -{ PROC_LINKS(miblo_decrement_time_stamp_minute, 0), "miblo_decrement_time_stamp_minute", 33, "Decrement a time stamp under the cursor by one minute. (format [m]m:ss or h:mm:ss", 81, "c:\\4ed\\code\\4coder_miblo_numbers.cpp", 36, 395 }, -{ PROC_LINKS(miblo_increment_basic, 0), "miblo_increment_basic", 21, "Increment an integer under the cursor by one.", 45, "c:\\4ed\\code\\4coder_miblo_numbers.cpp", 36, 93 }, -{ PROC_LINKS(miblo_increment_time_stamp, 0), "miblo_increment_time_stamp", 26, "Increment a time stamp under the cursor by one second. (format [m]m:ss or h:mm:ss", 81, "c:\\4ed\\code\\4coder_miblo_numbers.cpp", 36, 377 }, -{ PROC_LINKS(miblo_increment_time_stamp_minute, 0), "miblo_increment_time_stamp_minute", 33, "Increment a time stamp under the cursor by one minute. (format [m]m:ss or h:mm:ss", 81, "c:\\4ed\\code\\4coder_miblo_numbers.cpp", 36, 389 }, +{ PROC_LINKS(miblo_decrement_basic, 0), "miblo_decrement_basic", 21, "Decrement an integer under the cursor by one.", 45, "c:\\4ed\\code\\4coder_miblo_numbers.cpp", 36, 113 }, +{ PROC_LINKS(miblo_decrement_time_stamp, 0), "miblo_decrement_time_stamp", 26, "Decrement a time stamp under the cursor by one second. (format [m]m:ss or h:mm:ss", 81, "c:\\4ed\\code\\4coder_miblo_numbers.cpp", 36, 391 }, +{ PROC_LINKS(miblo_decrement_time_stamp_minute, 0), "miblo_decrement_time_stamp_minute", 33, "Decrement a time stamp under the cursor by one minute. (format [m]m:ss or h:mm:ss", 81, "c:\\4ed\\code\\4coder_miblo_numbers.cpp", 36, 403 }, +{ PROC_LINKS(miblo_increment_basic, 0), "miblo_increment_basic", 21, "Increment an integer under the cursor by one.", 45, "c:\\4ed\\code\\4coder_miblo_numbers.cpp", 36, 97 }, +{ PROC_LINKS(miblo_increment_time_stamp, 0), "miblo_increment_time_stamp", 26, "Increment a time stamp under the cursor by one second. (format [m]m:ss or h:mm:ss", 81, "c:\\4ed\\code\\4coder_miblo_numbers.cpp", 36, 385 }, +{ PROC_LINKS(miblo_increment_time_stamp_minute, 0), "miblo_increment_time_stamp_minute", 33, "Increment a time stamp under the cursor by one minute. (format [m]m:ss or h:mm:ss", 81, "c:\\4ed\\code\\4coder_miblo_numbers.cpp", 36, 397 }, { PROC_LINKS(mouse_wheel_change_face_size, 0), "mouse_wheel_change_face_size", 28, "Reads the state of the mouse wheel and uses it to either increase or decrease the face size.", 92, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 634 }, { PROC_LINKS(mouse_wheel_scroll, 0), "mouse_wheel_scroll", 18, "Reads the scroll wheel value from the mouse state and scrolls accordingly.", 74, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 259 }, { PROC_LINKS(move_down, 0), "move_down", 9, "Moves the cursor down one line.", 31, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 325 }, diff --git a/4coder_helper.cpp b/4coder_helper.cpp index 6084932a..a203ca61 100644 --- a/4coder_helper.cpp +++ b/4coder_helper.cpp @@ -491,11 +491,6 @@ query_user_number(Application_Links *app, Query_Bar *bar){ return(query_user_general(app, bar, true)); } -static i32 -buffer_replace_range_compute_shift(i32 start, i32 end, i32 len){ - return(len - (end - start)); -} - static char buffer_get_char(Application_Links *app, Buffer_ID buffer_id, i32 pos){ i32 buffer_size = 0; @@ -935,7 +930,7 @@ static void clear_buffer(Application_Links *app, Buffer_ID buffer_id){ i32 buffer_size = 0; buffer_get_size(app, buffer_id, &buffer_size); - buffer_replace_range(app, buffer_id, 0, buffer_size, make_lit_string("")); + buffer_replace_range(app, buffer_id, make_range(0, buffer_size), make_lit_string("")); } //////////////////////////////// @@ -1583,7 +1578,7 @@ if_view_has_highlighted_range_delete_range(Application_Links *app, View_ID view_ Range range = get_view_range(&view); Buffer_ID buffer = 0; view_get_buffer(app, view.view_id, AccessOpen, &buffer); - buffer_replace_range(app, buffer, range.min, range.max, make_lit_string("")); + buffer_replace_range(app, buffer, range, make_lit_string("")); result = true; } return(result); diff --git a/4coder_insertion.cpp b/4coder_insertion.cpp index 925b676c..6c97e713 100644 --- a/4coder_insertion.cpp +++ b/4coder_insertion.cpp @@ -36,7 +36,7 @@ begin_buffer_insertion(Application_Links *app){ static void insert_string__no_buffering(Buffer_Insertion *insertion, String string){ - buffer_replace_range(insertion->app, insertion->buffer, insertion->at, insertion->at, string); + buffer_replace_range(insertion->app, insertion->buffer, make_range(insertion->at), string); insertion->at += string.size; } diff --git a/4coder_miblo_numbers.cpp b/4coder_miblo_numbers.cpp index 12444c67..8f464fe3 100644 --- a/4coder_miblo_numbers.cpp +++ b/4coder_miblo_numbers.cpp @@ -62,7 +62,11 @@ get_numeric_string_at_cursor(Application_Links *app, Buffer_ID buffer, i32 start } struct Miblo_Number_Info{ - i32 start, end; + union{ + Range range; + i32 start; + i32 end; + }; i32 x; }; @@ -101,7 +105,7 @@ CUSTOM_DOC("Increment an integer under the cursor by one.") char str_space[1024]; String str = make_fixed_width_string(str_space); int_to_str(&str, number.x + 1); - buffer_replace_range(app, buffer, number.start, number.end, str); + buffer_replace_range(app, buffer, number.range, str); view_set_cursor(app, &view, seek_pos(number.start + str.size - 1), 1); } } @@ -117,7 +121,7 @@ CUSTOM_DOC("Decrement an integer under the cursor by one.") char str_space[1024]; String str = make_fixed_width_string(str_space); int_to_str(&str, number.x - 1); - buffer_replace_range(app, buffer, number.start, number.end, str); + buffer_replace_range(app, buffer, number.range, str); view_set_cursor(app, &view, seek_pos(number.start + str.size - 1), 1); } } @@ -274,7 +278,11 @@ timestamp_to_str(String *dest, Miblo_Timestamp t){ } struct Miblo_Timestamp_Info{ - i32 start, end; + union{ + Range range; + i32 start; + i32 end; + }; Miblo_Timestamp time; }; @@ -369,7 +377,7 @@ miblo_time_stamp_alter(Application_Links *app, i32 unit_type, i32 amt){ Miblo_Timestamp inc_timestamp = increment_timestamp(timestamp.time, unit_type, amt); timestamp_to_str(&str, inc_timestamp); - buffer_replace_range(app, buffer, timestamp.start, timestamp.end, str); + buffer_replace_range(app, buffer, timestamp.range, str); view_set_cursor(app, &view, seek_pos(timestamp.start + str.size - 1), 1); } } diff --git a/4coder_scope_commands.cpp b/4coder_scope_commands.cpp index deba813d..580eb0be 100644 --- a/4coder_scope_commands.cpp +++ b/4coder_scope_commands.cpp @@ -457,13 +457,13 @@ place_begin_and_end_on_own_lines(Application_Links *app, Partition *scratch, cha edits[1].start = range.max; edits[1].end = range.max; - buffer_batch_edit(app, buffer, str, str_size, edits, 2, BatchEdit_Normal); + buffer_batch_edit(app, buffer, str, edits, 2); view_set_cursor(app, &view, seek_pos(cursor_pos), true); view_set_mark(app, &view, seek_pos(mark_pos)); } else{ - buffer_replace_range(app, buffer, range.min, range.max, make_string(str, str_size)); + buffer_replace_range(app, buffer, range, make_string(str, str_size)); i32 center_pos = range.min + begin_len + 1; view_set_cursor(app, &view, seek_pos(center_pos), true); view_set_mark(app, &view, seek_pos(center_pos)); @@ -515,7 +515,7 @@ CUSTOM_DOC("Deletes the braces surrounding the currently selected scope. Leaves edits[1].start = bottom - 1; edits[1].end = bottom - 1 + bottom_len; - buffer_batch_edit(app, buffer, 0, 0, edits, 2, BatchEdit_Normal); + buffer_batch_edit(app, buffer, 0, edits, 2); } } @@ -780,7 +780,7 @@ CUSTOM_DOC("If a scope is currently selected, and a statement or block statement edits[1].start = range.start; edits[1].end = range.end; - buffer_batch_edit(app, buffer, edit_str, edit_len, edits, 2, BatchEdit_Normal); + buffer_batch_edit(app, buffer, edit_str, edits, 2); } } end_temp_memory(temp); diff --git a/4coder_search.cpp b/4coder_search.cpp index 54cc9b36..71970260 100644 --- a/4coder_search.cpp +++ b/4coder_search.cpp @@ -592,7 +592,7 @@ static void buffered_print_flush(Application_Links *app, Buffered_Printing *out){ i32 write_size = out->part->pos - out->temp.pos; char *str = out->part->base + out->temp.pos; - buffer_replace_range(app, out->buffer, out->pos, out->pos, make_string(str, write_size)); + buffer_replace_range(app, out->buffer, make_range(out->pos), make_string(str, write_size)); out->pos += write_size; end_temp_memory(out->temp); } @@ -1011,7 +1011,7 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with buffer_read_range(app, match.buffer, match.start, match.end, spare); if (search_hit_add(&global_heap, &complete_state.hits, &complete_state.str, spare, match_size)){ - buffer_replace_range(app, buffer, word_start, word_end, make_string(spare, match_size)); + buffer_replace_range(app, buffer, make_range(word_start, word_end), make_string(spare, match_size)); view_set_cursor(app, &view, seek_pos(word_start + match_size), true); complete_state.word_end = word_start + match_size; @@ -1031,7 +1031,7 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with match_size = word.size; char *str = word.str; - buffer_replace_range(app, buffer, word_start, word_end, make_string(str, match_size)); + buffer_replace_range(app, buffer, make_range(word_start, word_end), make_string(str, match_size)); view_set_cursor(app, &view, seek_pos(word_start + match_size), true); complete_state.word_end = word_start + match_size; diff --git a/4coder_seek.cpp b/4coder_seek.cpp index 9e59e82f..73842a86 100644 --- a/4coder_seek.cpp +++ b/4coder_seek.cpp @@ -1021,7 +1021,7 @@ current_view_boundary_delete(Application_Links *app, i32 dir, u32 flags){ view_get_buffer(app, view.view_id, AccessOpen, &buffer_id); Range range = view_buffer_boundary_range(app, &view, buffer_id, dir, flags); String zero = {}; - buffer_replace_range(app, buffer_id, range.min, range.max, zero); + buffer_replace_range(app, buffer_id, range, zero); } static void @@ -1031,7 +1031,7 @@ current_view_snipe_delete(Application_Links *app, i32 dir, u32 flags){ view_get_buffer(app, view.view_id, AccessOpen, &buffer_id); Range range = view_buffer_snipe_range(app, &view, buffer_id, dir, flags); String zero = {}; - buffer_replace_range(app, buffer_id, range.min, range.max, zero); + buffer_replace_range(app, buffer_id, range, zero); } //////////////////////////////// diff --git a/4ed.cpp b/4ed.cpp index 113a57cc..cc858d6b 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -58,14 +58,8 @@ internal void output_file_append(System_Functions *system, Models *models, Editing_File *file, String value){ if (!file->is_dummy){ i32 end = buffer_size(&file->state.buffer); - Edit edit = {}; - edit.str = value.str; - edit.length = value.size; - edit.range.first = end; - edit.range.one_past_last = end; - Edit_Behaviors behaviors = {}; - edit_single(system, models, file, edit, behaviors); + edit_single(system, models, file, make_range(end), value, behaviors); } } @@ -919,12 +913,11 @@ App_Init_Sig(app_init){ *init_files[i].ptr = file; } + File_Attributes attributes = {}; + file_create_from_string(system, models, file, make_lit_string(""), attributes); if (init_files[i].read_only){ - init_read_only_file(system, models, file); - } - else{ - File_Attributes attributes = {}; - init_normal_file(system, models, 0, 0, attributes, file); + file->settings.read_only = true; + history_free(&models->mem.heap, &file->state.history); } file->settings.never_kill = true; diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index 0d2c6c0e..9d4f56c4 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -16,76 +16,20 @@ access_test(u32 lock_flags, u32 access_flags){ return((lock_flags & ~access_flags) == 0); } -internal void -view_quit_ui(System_Functions *system, Models *models, View *view){ - Assert(view != 0); - view->ui_mode = false; - if (view->ui_quit != 0){ - view->ui_quit(&models->app_links, view_get_id(&models->live_set, view)); - } -} - -internal Editing_File* -get_file_from_identifier(System_Functions *system, Working_Set *working_set, Buffer_Identifier buffer){ - Editing_File *file = 0; - if (buffer.id != 0){ - file = working_set_get_active_file(working_set, buffer.id); - } - else if (buffer.name != 0){ - String name = make_string(buffer.name, buffer.name_len); - file = working_set_contains_name(working_set, name); - } - return(file); -} - -internal Editing_File* -imp_get_file(Models *models, Buffer_ID buffer_id){ - Working_Set *working_set = &models->working_set; - Editing_File *file = working_set_get_active_file(working_set, buffer_id); - if (file != 0 && !file_is_ready(file)){ - file = 0; - } - return(file); -} - -internal View* -imp_get_view(Models *models, View_ID view_id){ - Live_Views *live_set = &models->live_set; - View *view = 0; - view_id -= 1; - if (0 <= view_id && view_id < live_set->max){ - view = live_set->views + view_id; - if (!view->in_use){ - view = 0; - } - } - return(view); -} - -internal Panel* -imp_get_panel(Models *models, Panel_ID panel_id){ - Layout *layout = &models->layout; - Panel *panel = layout->panel_first + panel_id - 1; - if (!(layout->panel_first <= panel && panel < layout->panel_one_past_last)){ - panel = 0; - } - return(panel); -} - internal b32 -string_api_output(String val, String *out, i32 *required_size_out){ +api_string_out(String val, String *out, i32 *required_size_out){ b32 result = false; if (required_size_out != 0){ *required_size_out = val.size; } if (out != 0){ - result = append(out, val); + result = append_partial(out, val); } return(result); } internal b32 -panel_api_check_panel(Panel *panel){ +api_check_panel(Panel *panel){ b32 result = false; if (panel != 0 && panel->kind != PanelKind_Unused){ result = true; @@ -94,28 +38,28 @@ panel_api_check_panel(Panel *panel){ } internal b32 -buffer_api_check_file(Editing_File *file){ +api_check_buffer(Editing_File *file){ return(file != 0 && !file->is_dummy); } internal b32 -buffer_api_check_file_and_tokens(Editing_File *file){ - return(buffer_api_check_file(file) && file->state.token_array.tokens != 0 && file->state.tokens_complete); +api_check_buffer_and_tokens(Editing_File *file){ + return(api_check_buffer(file) && file->state.token_array.tokens != 0 && file->state.tokens_complete); } internal b32 -buffer_api_check_file(Editing_File *file, Access_Flag access){ - return(buffer_api_check_file(file) && access_test(file_get_access_flags(file), access)); +api_check_buffer(Editing_File *file, Access_Flag access){ + return(api_check_buffer(file) && access_test(file_get_access_flags(file), access)); } internal b32 -view_api_check_view(View *view){ +api_check_view(View *view){ return(view != 0 && view->in_use); } internal b32 -view_api_check_view(View *view, Access_Flag access){ - return(view_api_check_view(view) && access_test(view_get_access_flags(view), access)); +api_check_view(View *view, Access_Flag access){ + return(api_check_view(view) && access_test(view_get_access_flags(view), access)); } API_EXPORT b32 @@ -171,60 +115,17 @@ API_EXPORT b32 Create_Child_Process(Application_Links *app, String path, String command, Child_Process_ID *child_process_id_out){ Models *models = (Models*)app->cmd_context; System_Functions *system = models->system; - b32 result = false; - char *path_cstr = 0; - char *command_cstr = 0; - if (terminate_with_null(&path)){ - path_cstr = path.str; - } - else{ - String s = string_push_copy(&models->mem.part, path); - path_cstr = s.str; - } - if (terminate_with_null(&command)){ - command_cstr = command.str; - } - else{ - String s = string_push_copy(&models->mem.part, command); - command_cstr = s.str; - } - CLI_Handles cli_handles = {}; - if (system->cli_call(path_cstr, command_cstr, &cli_handles)){ - Child_Process_And_ID new_process = child_process_alloc_new(models, &models->child_processes); - *child_process_id_out = new_process.id; - new_process.process->cli = cli_handles; - result = true; - } - return(result); + return(child_process_call(models, system, path, command, child_process_id_out)); } API_EXPORT b32 Child_Process_Set_Target_Buffer(Application_Links *app, Child_Process_ID child_process_id, Buffer_ID buffer_id, Child_Process_Set_Target_Flags flags){ Models *models = (Models*)app->cmd_context; - Editing_File *file = imp_get_file(models, buffer_id); Child_Process *child_process = child_process_from_id(&models->child_processes, child_process_id); + Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; - if (buffer_api_check_file(file) && child_process != 0){ - b32 okay_if_process_has_buffer = ((flags & ChildProcessSet_FailIfProcessAlreadyAttachedToABuffer) == 0); - b32 okay_if_buffer_has_process = ((flags & ChildProcessSet_FailIfBufferAlreadyAttachedToAProcess) == 0); - - b32 process_has_buffer = (child_process->out_file != 0); - b32 buffer_has_process = (file->state.attached_child_process != 0); - - if ((!process_has_buffer || okay_if_process_has_buffer) && (!buffer_has_process || okay_if_buffer_has_process)){ - if (process_has_buffer){ - child_process->out_file->state.attached_child_process = 0; - } - if (buffer_has_process){ - Child_Process *attached_child_process = child_process_from_id(&models->child_processes, file->state.attached_child_process); - if (attached_child_process != 0){ - attached_child_process->out_file = 0; - } - } - child_process->out_file = file; - file->state.attached_child_process = child_process_id; - result = true; - } + if (api_check_buffer(file) && child_process != 0){ + result = child_process_set_target_buffer(models, child_process, file, flags); } return(result); } @@ -234,7 +135,7 @@ Buffer_Get_Attached_Child_Process(Application_Links *app, Buffer_ID buffer_id, C Models *models = (Models*)app->cmd_context; Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; - if (buffer_api_check_file(file)){ + if (api_check_buffer(file)){ *child_process_id_out = file->state.attached_child_process; result = true; } @@ -273,205 +174,6 @@ Child_Process_Get_State(Application_Links *app, Child_Process_ID child_process_i return(result); } -#if 0 -// TODO(allen): redocument -//API_EXPORT b32 -//Exec_System_Command(Application_Links *app, View_ID view_id, Buffer_Identifier buffer_id, String path, String command, Command_Line_Interface_Flag flags) -/* -DOC_PARAM(view, If the view parameter is non-null it specifies a view to display the command's output buffer, otherwise the command will still work but if there is a buffer capturing the output it will not automatically be displayed.) -DOC_PARAM(buffer_id, The buffer the command will output to is specified by the buffer parameter. See Buffer_Identifier for information on how this type specifies a buffer. If output from the command should just be ignored, then buffer_identifier(0) can be specified to indicate no output buffer.) -DOC_PARAM(path, The path parameter specifies the current working directory in which the command shall be executed. The string need not be null terminated.) -DOC_PARAM(path_len, The parameter path_len specifies the length of the path string.) -DOC_PARAM(command, The command parameter specifies the command that shall be executed. The string need not be null terminated.) -DOC_PARAM(command_len, The parameter command_len specifies the length of the command string.) -DOC_PARAM(flags, Flags for the behavior of the call are specified in the flags parameter.) -DOC_RETURN(This call returns non-zero on success.) -DOC(A call to exec_system_command executes a command as if called from the command line, and sends the output to a buffer. To output to an existing buffer, the buffer identifier can name a new buffer that does not exist, or provide the id of a buffer that does exist. If the buffer identifier uses a name for a buffer that does not exist, the buffer is created and used. If the buffer identifier uses an id that does not belong to an open buffer, then no buffer is used. - -If there in an output buffer and it is not already in an open view and the view parameter is not NULL, then the provided view will display the output buffer. - -If the view parameter is NULL, no view will switch to the output.) -DOC_SEE(Buffer_Identifier) -DOC_SEE(Command_Line_Interface_Flag) -*/{ - return(false); - Models *models = (Models*)app->cmd_context; - System_Functions *system = models->system; - App_Vars *vars = models->vars; - Partition *part = &models->mem.part; - Heap *heap = &models->mem.heap; - Working_Set *working_set = &models->working_set; - - b32 result = true; - char feedback_space[256]; - String feedback_str = make_fixed_width_string(feedback_space); - - Temp_Memory temp = begin_temp_memory(part); - - { - // NOTE(allen): Check that it is possible to store a new child process. - if (!cli_list_has_space(&vars->cli_processes)){ - append(&feedback_str, make_lit_string("ERROR: no available process slot\n")); - result = false; - goto done; - } - - // NOTE(allen): Try to get the buffer that was specified if it exists. - Editing_File *file = get_file_from_identifier(system, working_set, buffer_id); - - // NOTE(allen): If the file exists check that it is legal. - if (file != 0){ - if (file->settings.read_only == 0){ - append(&feedback_str, make_lit_string("ERROR: ")); - append(&feedback_str, file->unique_name.name); - append(&feedback_str, make_lit_string(" is not a read-only buffer\n")); - result = false; - goto done; - } - if (file->settings.never_kill){ - append(&feedback_str, make_lit_string("ERROR: The buffer ")); - append(&feedback_str, file->unique_name.name); - append(&feedback_str, make_lit_string(" is not killable")); - result = false; - goto done; - } - } - - // NOTE(allen): If the buffer is specified by name but does not already exist, then create it. - if (file == 0 && buffer_id.name != 0){ - file = working_set_alloc_always(working_set, heap, &models->lifetime_allocator); - Assert(file != 0); - - String name = push_string(part, buffer_id.name, buffer_id.name_len); - buffer_bind_name(models, heap, part, working_set, file, name); - init_read_only_file(system, models, file); - } - - // NOTE(allen): If there are conflicts in output buffer with an existing child process resolve it. - if (file != 0){ - CLI_List *list = &vars->cli_processes; - CLI_Process *proc_ptr = list->procs; - for (u32 i = 0; i < list->count; ++i, ++proc_ptr){ - if (proc_ptr->out_file == file){ - if (flags & CLI_OverlapWithConflict){ - proc_ptr->out_file = 0; - } - else{ - file = 0; - } - break; - } - } - - if (file == 0){ - append(&feedback_str, "did not begin command-line command because the target buffer is already in use\n"); - result = false; - goto done; - } - } - - // NOTE(allen): If we have an output file, prepare it for child proc output. - if (file != 0){ - //edit_clear(system, models, file); - file->is_updating = false; - file->return_code = 0; - - // TODO(allen): not sure why any of this would be needed, the cursor fixing should automatically handle it, right? -#if 0 - b32 no_views_see_file = true; - - Layout *layout = &models->layout; - for (Panel *panel = layout_get_first_open_panel(layout); - panel != 0; - panel = layout_get_next_open_panel(layout, panel)){ - View *view = panel->view; - if (view->file == file){ - Full_Cursor cursor = {}; - cursor.line = 1; - cursor.character = 1; - cursor.wrap_line = 1; - view_set_cursor(system, models, view, cursor, true); - no_views_see_file = false; - } - } - - if (no_views_see_file){ - block_zero_struct(&file->state.edit_pos_most_recent); - block_zero(file->state.edit_pos_stack, sizeof(file->state.edit_pos_stack)); - file->state.edit_pos_stack_top = -1; - } -#endif - - Edit edit = {}; - edit.range.one_past_last = buffer_size(&file->state.buffer); - - Edit_Behaviors behaviors = {}; - edit_single(system, models, file, edit, behaviors); - - if (HasFlag(flags, CLI_SendEndSignal)){ - file_end_file(models, file); - } - - file_set_unimportant(file, true); - } - - // NOTE(allen): If we have an output file and we need to bring it up in a new view, do so. - if (file != 0){ - b32 bind_to_new_view = true; - if (!(flags & CLI_AlwaysBindToView)){ - if (file_is_viewed(&models->layout, file)){ - bind_to_new_view = false; - } - } - - if (bind_to_new_view){ - View *vptr = imp_get_view(models, view_id); - if (vptr != 0){ - view_set_file(system, models, vptr, file); - view_quit_ui(system, models, vptr); - } - } - } - - // NOTE(allen): Figure out the root path for the command. - String path_string = {}; - if (path.size == 0){ - terminate_with_null(&models->hot_directory.string); - path_string = models->hot_directory.string; - } - else{ - path_string = push_string(part, path); - } - - // NOTE(allen): Figure out the command string. - String command_string = {}; - if (command.size == 0){ - command_string = make_lit_string(" echo no script specified"); - } - else{ - command_string = push_string(part, command); - } - - // NOTE(allen): Attept to execute the command. - char *path_str = path_string.str; - char *command_str = command_string.str; - b32 cursor_at_end = ((flags & CLI_CursorAtEnd) != 0); - if (!cli_list_call(system, &vars->cli_processes, path_str, command_str, file, cursor_at_end)){ - append(&feedback_str, "ERROR: Failed to make the cli call\n"); - result = false; - } - } - - done:; - if (!result){ - print_message(app, feedback_str); - } - - end_temp_memory(temp); - return(result); -} -#endif - // TODO(allen): redocument API_EXPORT b32 Clipboard_Post(Application_Links *app, i32 clipboard_id, String string) @@ -522,10 +224,7 @@ DOC_SEE(The_4coder_Clipboard) String *str = working_set_clipboard_index(&models->working_set, item_index); b32 result = false; if (str != 0){ - *required_size_out = str->size; - if (append(string_out, *str)){ - result = true; - } + result = api_string_out(*str, string_out, required_size_out); } return(result); } @@ -555,51 +254,6 @@ DOC(Gives the total number of buffers in the application.) return(result); } -internal Editing_File* -get_buffer_next__inner(Working_Set *working_set, Editing_File *file){ - if (file != 0){ - file = CastFromMember(Editing_File, main_chain_node, file->main_chain_node.next); - if (file == CastFromMember(Editing_File, main_chain_node, &working_set->used_sentinel)){ - file = 0; - } - } - else{ - if (working_set->file_count > 0){ - Node *node = working_set->used_sentinel.next; - file = CastFromMember(Editing_File, main_chain_node, node); - } - } - return(file); -} - -// TODO(allen): redocument -API_EXPORT b32 -Get_Buffer_First(Application_Links *app, Access_Flag access, Buffer_ID *buffer_id_out) -/* -DOC_PARAM(access, The access parameter determines what levels of protection this call can access.) -DOC_RETURN(This call returns the summary of the first buffer in a buffer loop.) -DOC( -This call begins a loop across all the buffers. -If the buffer returned does not exist, the loop is finished. -Buffers should not be killed durring a buffer loop. -) -DOC_SEE(Access_Flag) -DOC_SEE(get_buffer_next) -*/{ - Models *models = (Models*)app->cmd_context; - Working_Set *working_set = &models->working_set; - Editing_File *file = get_buffer_next__inner(working_set, 0); - for (;file != 0 && !access_test(file_get_access_flags(file), access);){ - file = get_buffer_next__inner(working_set, file); - } - b32 result = false; - if (file != 0){ - *buffer_id_out = file->id.id; - result = true; - } - return(result); -} - // TODO(allen): redocument API_EXPORT b32 Get_Buffer_Next(Application_Links *app, Buffer_ID buffer_id, Access_Flag access, Buffer_ID *buffer_id_out) @@ -619,18 +273,15 @@ DOC_SEE(get_buffer_first) Models *models = (Models*)app->cmd_context; Working_Set *working_set = &models->working_set; Editing_File *file = working_set_get_active_file(working_set, buffer_id); - file = get_buffer_next__inner(working_set, file); + file = file_get_next(working_set, file); for (;file != 0 && !access_test(file_get_access_flags(file), access);){ - file = get_buffer_next__inner(working_set, file); + file = file_get_next(working_set, file); } b32 result = false; if (file != 0){ *buffer_id_out = file->id.id; result = true; } - else{ - *buffer_id_out = 0; - } return(result); } @@ -652,7 +303,7 @@ DOC_SEE(Access_Flag) Working_Set *working_set = &models->working_set; Editing_File *file = working_set_contains_name(working_set, name); b32 result = false; - if (buffer_api_check_file(file, access)){ + if (api_check_buffer(file, access)){ *buffer_id_out = file->id.id; result = true; } @@ -681,7 +332,7 @@ DOC_SEE(Access_Flag) b32 result = false; if (get_canon_name(system, file_name, &canon)){ Editing_File *file = working_set_contains_canon(working_set, canon.name); - if (buffer_api_check_file(file, access)){ + if (api_check_buffer(file, access)){ *buffer_id_out = file->id.id; result = true; } @@ -706,7 +357,7 @@ DOC_SEE(4coder_Buffer_Positioning_System) Models *models = (Models*)app->cmd_context; Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; - if (buffer_api_check_file(file)){ + if (api_check_buffer(file)){ i32 size = buffer_size(&file->state.buffer); if (0 <= start && start <= one_past_last && one_past_last <= size){ buffer_stringify(&file->state.buffer, start, one_past_last, out); @@ -718,7 +369,7 @@ DOC_SEE(4coder_Buffer_Positioning_System) // TODO(allen): redocument API_EXPORT b32 -Buffer_Replace_Range(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 one_past_last, String string) +Buffer_Replace_Range(Application_Links *app, Buffer_ID buffer_id, Range range, String string) /* DOC_PARAM(buffer, This parameter specifies the buffer to edit.) DOC_PARAM(start, This parameter specifies absolute position of the first character in the replace range.) @@ -737,11 +388,10 @@ DOC_SEE(4coder_Buffer_Positioning_System) Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; i32 size = 0; - if (buffer_api_check_file(file)){ + if (api_check_buffer(file)){ size = buffer_size(&file->state.buffer); - if (0 <= start && start <= one_past_last && one_past_last <= size){ + if (0 <= range.first && range.first <= range.one_past_last && range.one_past_last <= size){ Edit_Behaviors behaviors = {}; - Range range = {start, one_past_last}; edit_single(models->system, models, file, range, string, behaviors); result = true; } @@ -749,6 +399,31 @@ DOC_SEE(4coder_Buffer_Positioning_System) return(result); } +// TODO(allen): redocument +API_EXPORT b32 +Buffer_Batch_Edit(Application_Links *app, Buffer_ID buffer_id, char *str, Buffer_Edit *edits, i32 edit_count) +/* +DOC_PARAM(buffer, The buffer on which to apply the batch of edits.) +DOC_PARAM(str, This parameter provides all of the source string for the edits in the batch.) +DOC_PARAM(str_len, This parameter specifies the length of the str string.) +DOC_PARAM(edits, This parameter provides about the source string and destination range of each edit as an array.) +DOC_PARAM(edit_count, This parameter specifies the number of Buffer_Edit structs in edits.) +DOC_PARAM(type, This prameter specifies what type of batch edit to execute.) +DOC_RETURN(This call returns non-zero if the batch edit succeeds. This call can fail if the provided buffer summary does not refer to an actual buffer in 4coder.) +DOC(Apply an array of edits all at once. This combines all the edits into one undo operation.) +DOC_SEE(Buffer_Edit) +DOC_SEE(Buffer_Batch_Edit_Type) +*/{ + Models *models = (Models*)app->cmd_context; + Editing_File *file = imp_get_file(models, buffer_id); + b32 result = false; + if (api_check_buffer(file)){ + Edit_Behaviors behaviors = {}; + result = edit_batch(models->system, models, file, str, edits, edit_count, behaviors); + } + return(result); +} + // TODO(allen): redocument API_EXPORT b32 Buffer_Compute_Cursor(Application_Links *app, Buffer_ID buffer_id, Buffer_Seek seek, Partial_Cursor *cursor_out) @@ -768,7 +443,7 @@ DOC_SEE(Partial_Cursor) Models *models = (Models*)app->cmd_context; Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; - if (buffer_api_check_file(file)){ + if (api_check_buffer(file)){ if (file->settings.unwrapped_lines && seek.type == buffer_seek_wrapped_xy){ seek.type = buffer_seek_unwrapped_xy; } @@ -779,56 +454,11 @@ DOC_SEE(Partial_Cursor) return(result); } -// TODO(allen): redocument -API_EXPORT b32 -Buffer_Batch_Edit(Application_Links *app, Buffer_ID buffer_id, char *str, i32 str_len, Buffer_Edit *edits, i32 edit_count, Buffer_Batch_Edit_Type type) -/* -DOC_PARAM(buffer, The buffer on which to apply the batch of edits.) -DOC_PARAM(str, This parameter provides all of the source string for the edits in the batch.) -DOC_PARAM(str_len, This parameter specifies the length of the str string.) -DOC_PARAM(edits, This parameter provides about the source string and destination range of each edit as an array.) -DOC_PARAM(edit_count, This parameter specifies the number of Buffer_Edit structs in edits.) -DOC_PARAM(type, This prameter specifies what type of batch edit to execute.) -DOC_RETURN(This call returns non-zero if the batch edit succeeds. This call can fail if the provided buffer summary does not refer to an actual buffer in 4coder.) -DOC(Apply an array of edits all at once. This combines all the edits into one undo operation.) -DOC_SEE(Buffer_Edit) -DOC_SEE(Buffer_Batch_Edit_Type) -*/{ - Models *models = (Models*)app->cmd_context; - Editing_File *file = imp_get_file(models, buffer_id); - b32 result = false; - if (buffer_api_check_file(file)){ - result = true; - if (edit_count > 0){ - global_history_edit_group_begin(app); - Buffer_Edit *edit_in = edits; - Buffer_Edit *one_past_last = edits + edit_count; - i32 shift = 0; - for (;edit_in < one_past_last; edit_in += 1){ - char *edit_str = str + edit_in->str_start; - i32 edit_length = edit_in->len; - Range edit_range = {edit_in->start, edit_in->end}; - i32 shift_change = edit_length - (edit_range.one_past_last - edit_range.first); - edit_range.first += shift; - edit_range.one_past_last += shift; - if (!buffer_replace_range(app, buffer_id, edit_range.first, edit_range.one_past_last, make_string(edit_str, edit_length))){ - result = false; - } - else{ - shift += shift_change; - } - } - global_history_edit_group_end(app); - } - } - return(result); -} - API_EXPORT b32 Buffer_Exists(Application_Links *app, Buffer_ID buffer_id){ Models *models = (Models*)app->cmd_context; Editing_File *file = imp_get_file(models, buffer_id); - return(buffer_api_check_file(file)); + return(api_check_buffer(file)); } API_EXPORT b32 @@ -836,7 +466,7 @@ Buffer_Ready(Application_Links *app, Buffer_ID buffer_id){ Models *models = (Models*)app->cmd_context; Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; - if (buffer_api_check_file(file)){ + if (api_check_buffer(file)){ result = file_is_ready(file); } return(result); @@ -847,7 +477,7 @@ Buffer_Get_Access_Flags(Application_Links *app, Buffer_ID buffer_id, Access_Flag Models *models = (Models*)app->cmd_context; Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; - if (buffer_api_check_file(file)){ + if (api_check_buffer(file)){ *access_flags_out = file_get_access_flags(file); result = true; } @@ -859,7 +489,7 @@ Buffer_Get_Size(Application_Links *app, Buffer_ID buffer_id, i32 *size_out){ Models *models = (Models*)app->cmd_context; Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; - if (buffer_api_check_file(file)){ + if (api_check_buffer(file)){ *size_out = buffer_size(&file->state.buffer); result = true; } @@ -871,7 +501,7 @@ Buffer_Get_Line_Count(Application_Links *app, Buffer_ID buffer_id, i32 *line_cou Models *models = (Models*)app->cmd_context; Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; - if (buffer_api_check_file(file)){ + if (api_check_buffer(file)){ *line_count_out = file->state.buffer.line_count; result = true; } @@ -883,8 +513,8 @@ Buffer_Get_Base_Buffer_Name(Application_Links *app, Buffer_ID buffer_id, String Models *models = (Models*)app->cmd_context; Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; - if (buffer_api_check_file(file)){ - result = string_api_output(file->base_name.name, name_out, required_size_out); + if (api_check_buffer(file)){ + result = api_string_out(file->base_name.name, name_out, required_size_out); } return(result); } @@ -894,8 +524,8 @@ Buffer_Get_Unique_Buffer_Name(Application_Links *app, Buffer_ID buffer_id, Strin Models *models = (Models*)app->cmd_context; Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; - if (buffer_api_check_file(file)){ - result = string_api_output(file->unique_name.name, name_out, required_size_out); + if (api_check_buffer(file)){ + result = api_string_out(file->unique_name.name, name_out, required_size_out); } return(result); } @@ -905,8 +535,8 @@ Buffer_Get_File_Name(Application_Links *app, Buffer_ID buffer_id, String *name_o Models *models = (Models*)app->cmd_context; Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; - if (buffer_api_check_file(file)){ - result = string_api_output(file->canon.name, name_out, required_size_out); + if (api_check_buffer(file)){ + result = api_string_out(file->canon.name, name_out, required_size_out); } return(result); } @@ -916,7 +546,7 @@ Buffer_Get_Dirty_State(Application_Links *app, Buffer_ID buffer_id, Dirty_State Models *models = (Models*)app->cmd_context; Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; - if (buffer_api_check_file(file)){ + if (api_check_buffer(file)){ *dirty_state_out = file->state.dirty; result = true; } @@ -928,7 +558,7 @@ Buffer_Directly_Set_Dirty_State(Application_Links *app, Buffer_ID buffer_id, Dir Models *models = (Models*)app->cmd_context; Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; - if (buffer_api_check_file(file)){ + if (api_check_buffer(file)){ file->state.dirty = dirty_state; result = true; } @@ -940,7 +570,7 @@ Buffer_Tokens_Are_Ready(Application_Links *app, Buffer_ID buffer_id){ Models *models = (Models*)app->cmd_context; Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; - if (buffer_api_check_file(file)){ + if (api_check_buffer(file)){ result = file_tokens_are_ready(file); } return(result); @@ -958,7 +588,7 @@ DOC_RETURN(returns non-zero on success) Models *models = (Models*)app->cmd_context; Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; - if (buffer_api_check_file(file)){ + if (api_check_buffer(file)){ result = true; switch (setting){ case BufferSetting_Lex: @@ -1044,7 +674,7 @@ DOC_SEE(Buffer_Setting_ID) Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; - if (buffer_api_check_file(file)){ + if (api_check_buffer(file)){ result = true; switch (setting){ case BufferSetting_Lex: @@ -1228,16 +858,6 @@ DOC_SEE(Buffer_Setting_ID) return(result); } -internal Managed_Scope -buffer_get_managed_scope__inner(Editing_File *file){ - Managed_Scope lifetime = 0; - if (file != 0){ - Assert(file->lifetime_object != 0); - lifetime = (Managed_Scope)file->lifetime_object->workspace.scope_id; - } - return(lifetime); -} - // TODO(allen): redocument API_EXPORT b32 Buffer_Get_Managed_Scope(Application_Links *app, Buffer_ID buffer_id, Managed_Scope *scope_out) @@ -1251,13 +871,10 @@ If the buffer_id does not specify a valid buffer, the returned scope is null.) Models *models = (Models*)app->cmd_context; Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; - if (buffer_api_check_file(file)){ - *scope_out = buffer_get_managed_scope__inner(file); + if (api_check_buffer(file)){ + *scope_out = file_get_managed_scope(file); result = true; } - else{ - *scope_out = 0; - } return(result); } @@ -1272,7 +889,7 @@ If the buffer does not exist or if it is not a lexed buffer, the return is zero. Models *models = (Models*)app->cmd_context; Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; - if (buffer_api_check_file_and_tokens(file)){ + if (api_check_buffer_and_tokens(file)){ *count_out = file->state.token_array.count; result = true; } @@ -1295,7 +912,7 @@ The number of output tokens will be end_token - start_token.) Models *models = (Models*)app->cmd_context; Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; - if (buffer_api_check_file_and_tokens(file)){ + if (api_check_buffer_and_tokens(file)){ Cpp_Token_Array token_array = file->state.token_array; if (0 <= start_token && start_token <= end_token && end_token <= token_array.count){ block_copy(tokens_out, token_array.tokens + start_token, sizeof(Cpp_Token)*(end_token - start_token)); @@ -1312,17 +929,17 @@ Buffer_Get_Token_Range(Application_Links *app, Buffer_ID buffer_id, Cpp_Token ** { Models *models = (Models*)app->cmd_context; Editing_File *file = imp_get_file(models, buffer_id); - Cpp_Token_Array token_array = file->state.token_array; b32 result = false; - if (file != 0 && token_array.tokens != 0 && file->state.tokens_complete){ - *first_token_out = token_array.tokens; - *one_past_last_token_out = token_array.tokens + token_array.count; + if (api_check_buffer_and_tokens(file)){ + Cpp_Token_Array token_array = file->state.token_array; + if (first_token_out != 0){ + *first_token_out = token_array.tokens; + } + if (one_past_last_token_out != 0){ + *one_past_last_token_out = token_array.tokens + token_array.count; + } result = true; } - else{ - *first_token_out = 0; - *one_past_last_token_out = 0; - } return(result); } @@ -1341,14 +958,10 @@ DOC_SEE(cpp_get_token) Models *models = (Models*)app->cmd_context; Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; - if (buffer_api_check_file_and_tokens(file)){ - Cpp_Token_Array token_array = file->state.token_array; - *get_result = cpp_get_token(token_array, pos); + if (api_check_buffer_and_tokens(file)){ + *get_result = cpp_get_token(file->state.token_array, pos); result = true; } - else{ - block_zero_struct(get_result); - } return(result); } @@ -1364,7 +977,7 @@ This is useful in cases such as clearing a buffer and refilling it with new cont Models *models = (Models*)app->cmd_context; Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; - if (buffer_api_check_file(file)){ + if (api_check_buffer(file)){ file_end_file(models, file); result = true; } @@ -1388,138 +1001,11 @@ Otherwise a buffer is created without a matching file until the buffer is saved DOC_SEE(Buffer_Create_Flag) */{ Models *models = (Models*)app->cmd_context; - System_Functions *system = models->system; - Working_Set *working_set = &models->working_set; - Heap *heap = &models->mem.heap; - Partition *part = &models->mem.part; - - b32 result = false; - - *new_buffer_id_out = 0; - - if (file_name.size > 0){ - Temp_Memory temp = begin_temp_memory(part); - - Editing_File *file = 0; - b32 do_empty_buffer = false; - Editing_File_Name canon = {}; - b32 has_canon_name = false; - b32 buffer_is_for_new_file = false; - - // NOTE(allen): Try to get the file by canon name. - if ((flags & BufferCreate_NeverAttachToFile) == 0){ - if (get_canon_name(system, file_name, &canon)){ - has_canon_name = true; - file = working_set_contains_canon(working_set, canon.name); - } - else{ - do_empty_buffer = true; - } - } - - // NOTE(allen): Try to get the file by buffer name. - if ((flags & BufferCreate_MustAttachToFile) == 0){ - if (file == 0){ - file = working_set_contains_name(working_set, file_name); - } - } - - // NOTE(allen): If there is still no file, create a new buffer. - if (file == 0){ - Plat_Handle handle = {}; - - // NOTE(allen): Figure out whether this is a new file, or an existing file. - if (!do_empty_buffer){ - if ((flags & BufferCreate_AlwaysNew) != 0){ - do_empty_buffer = true; - } - else{ - if (!system->load_handle(canon.name.str, &handle)){ - do_empty_buffer = true; - } - } - } - - if (do_empty_buffer){ - if (has_canon_name){ - buffer_is_for_new_file = true; - } - if ((flags & BufferCreate_NeverNew) == 0){ - file = working_set_alloc_always(working_set, heap, &models->lifetime_allocator); - if (file != 0){ - if (has_canon_name){ - file_bind_file_name(system, heap, working_set, file, canon.name); - } - buffer_bind_name(models, heap, part, working_set, file, front_of_directory(file_name)); - File_Attributes attributes = {}; - init_normal_file(system, models, 0, 0, attributes, file); - *new_buffer_id_out = file->id.id; - result = true; - } - } - } - else{ - File_Attributes attributes = system->load_attributes(handle); - b32 in_heap_mem = false; - char *buffer = push_array(part, char, (i32)attributes.size); - - if (buffer == 0){ - buffer = heap_array(heap, char, (i32)attributes.size); - Assert(buffer != 0); - in_heap_mem = true; - } - - if (system->load_file(handle, buffer, (i32)attributes.size)){ - system->load_close(handle); - file = working_set_alloc_always(working_set, heap, &models->lifetime_allocator); - if (file != 0){ - file_bind_file_name(system, heap, working_set, file, canon.name); - buffer_bind_name(models, heap, part, working_set, file, front_of_directory(file_name)); - init_normal_file(system, models, buffer, (i32)attributes.size, attributes, file); - *new_buffer_id_out = file->id.id; - result = true; - } - } - else{ - system->load_close(handle); - } - - if (in_heap_mem){ - heap_free(heap, buffer); - } - } - } - else{ - *new_buffer_id_out = file->id.id; - result = true; - } - - if (file != 0 && (flags & BufferCreate_JustChangedFile) != 0){ - file->state.ignore_behind_os = 1; - } - - if (file != 0 && (flags & BufferCreate_AlwaysNew) != 0){ - i32 size = buffer_size(&file->state.buffer); - if (size > 0){ - Edit edit = {}; - edit.range.one_past_last = size; - Edit_Behaviors behaviors = {}; - edit_single(system, models, file, edit, behaviors); - if (has_canon_name){ - buffer_is_for_new_file = true; - } - } - } - - if (file != 0 && buffer_is_for_new_file && (flags & BufferCreate_SuppressNewFileHook) == 0 && - models->hook_new_file != 0){ - models->hook_new_file(&models->app_links, file->id.id); - } - - end_temp_memory(temp); + Editing_File *new_file = create_file(models, file_name, flags); + if (new_file != 0 && new_buffer_id_out != 0){ + *new_buffer_id_out = new_file->id.id; } - - return(result); + return(new_file != 0); } // TODO(allen): redocument @@ -1539,7 +1025,7 @@ DOC_SEE(Buffer_Save_Flag) Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; - if (buffer_api_check_file(file)){ + if (api_check_buffer(file)){ b32 skip_save = false; if (!(flags & BufferSave_IgnoreDirtyFlag)){ if (file->state.dirty == DirtyState_UpToDate){ @@ -1581,7 +1067,7 @@ DOC_SEE(Buffer_Identifier) Working_Set *working_set = &models->working_set; Editing_File *file = imp_get_file(models, buffer_id); Buffer_Kill_Result result = BufferKillResult_DoesNotExist; - if (buffer_api_check_file(file)){ + if (api_check_buffer(file)){ if (!file->settings.never_kill){ b32 needs_to_save = file_needs_save(file); if (!needs_to_save || (flags & BufferKill_AlwaysKill) != 0){ @@ -1642,7 +1128,7 @@ Buffer_Reopen(Application_Links *app, Buffer_ID buffer_id, Buffer_Reopen_Flag fl System_Functions *system = models->system; Editing_File *file = imp_get_file(models, buffer_id); Buffer_Reopen_Result result = BufferReopenResult_Failed; - if (buffer_api_check_file(file)){ + if (api_check_buffer(file)){ if (file->canon.name.str != 0 && file->canon.name.size != 0){ Plat_Handle handle = {}; if (system->load_handle(file->canon.name.str, &handle)){ @@ -1682,7 +1168,7 @@ Buffer_Reopen(Application_Links *app, Buffer_ID buffer_id, Buffer_Reopen_Flag fl file_free(system, &models->mem.heap, &models->lifetime_allocator, file); working_set_file_default_settings(&models->working_set, file); - init_normal_file(system, models, file_memory, (i32)attributes.size, attributes, file); + file_create_from_string(system, models, file, make_string(file_memory, (i32)attributes.size), attributes); for (i32 i = 0; i < vptr_count; ++i){ view_set_file(system, models, vptrs[i], file); @@ -1718,7 +1204,7 @@ Buffer_Get_File_Attributes(Application_Links *app, Buffer_ID buffer_id, File_Att Models *models = (Models*)app->cmd_context; Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; - if (buffer_api_check_file(file)){ + if (api_check_buffer(file)){ block_copy(attributes_out, &file->attributes, sizeof(*attributes_out)); result = true; } @@ -1830,7 +1316,7 @@ DOC_SEE(Access_Flag) View *view = panel->view; Assert(view != 0); b32 result = false; - if (view_api_check_view(view, access)){ + if (api_check_view(view, access)){ *view_id_out = view_get_id(&models->live_set, view); result = true; } @@ -1843,7 +1329,7 @@ Get_Active_Panel(Application_Links *app, Panel_ID *panel_id_out){ Panel *panel = layout_get_active_panel(&models->layout); Assert(panel != 0); b32 result = false; - if (panel_api_check_panel(panel)){ + if (api_check_panel(panel)){ *panel_id_out = panel_get_id(&models->layout, panel); result = true; } @@ -1858,7 +1344,7 @@ View_Exists(Application_Links *app, View_ID view_id){ Models *models = (Models*)app->cmd_context; View *view = imp_get_view(models, view_id); b32 result = false; - if (view_api_check_view(view)){ + if (api_check_view(view)){ result = true; } return(result); @@ -1869,9 +1355,9 @@ View_Get_Buffer(Application_Links *app, View_ID view_id, Access_Flag access, Buf Models *models = (Models*)app->cmd_context; View *view = imp_get_view(models, view_id); b32 result = false; - if (view_api_check_view(view)){ + if (api_check_view(view)){ Editing_File *file = view->file; - if (buffer_api_check_file(file, access)){ + if (api_check_buffer(file, access)){ *buffer_id_out = file->id.id; result = true; } @@ -1884,7 +1370,7 @@ View_Get_Cursor_Pos(Application_Links *app, View_ID view_id, i32 *pos_out){ Models *models = (Models*)app->cmd_context; View *view = imp_get_view(models, view_id); b32 result = false; - if (view_api_check_view(view)){ + if (api_check_view(view)){ File_Edit_Positions edit_pos = view_get_edit_pos(view); *pos_out = edit_pos.cursor_pos; result = true; @@ -1897,7 +1383,7 @@ View_Get_Mark_Pos(Application_Links *app, View_ID view_id, i32 *pos_out){ Models *models = (Models*)app->cmd_context; View *view = imp_get_view(models, view_id); b32 result = false; - if (view_api_check_view(view)){ + if (api_check_view(view)){ *pos_out = view->mark; result = true; } @@ -1909,7 +1395,7 @@ View_Get_Preferred_X(Application_Links *app, View_ID view_id, f32 *preferred_x_o Models *models = (Models*)app->cmd_context; View *view = imp_get_view(models, view_id); b32 result = false; - if (view_api_check_view(view)){ + if (api_check_view(view)){ *preferred_x_out = view->preferred_x; result = true; } @@ -1921,7 +1407,7 @@ View_Get_Screen_Rect(Application_Links *app, View_ID view_id, Rect_f32 *rect_out Models *models = (Models*)app->cmd_context; b32 result = false; View *view = imp_get_view(models, view_id); - if (view_api_check_view(view)){ + if (api_check_view(view)){ *rect_out = f32R(view->panel->rect_full); result = true; } @@ -1934,7 +1420,7 @@ View_Get_Panel(Application_Links *app, View_ID view_id, Panel_ID *panel_id_out){ Layout *layout = &models->layout; b32 result = false; View *view = imp_get_view(models, view_id); - if (view_api_check_view(view)){ + if (api_check_view(view)){ Panel *panel = view->panel; *panel_id_out = panel_get_id(layout, panel); result = true; @@ -1947,7 +1433,7 @@ Panel_Get_View(Application_Links *app, Panel_ID panel_id, View_ID *view_id_out){ Models *models = (Models*)app->cmd_context; b32 result = false; Panel *panel = imp_get_panel(models, panel_id); - if (panel_api_check_panel(panel)){ + if (api_check_panel(panel)){ if (panel->kind == PanelKind_Final){ View *view = panel->view; Assert(view != 0); @@ -1963,7 +1449,7 @@ Panel_Is_Split(Application_Links *app, Panel_ID panel_id){ Models *models = (Models*)app->cmd_context; b32 result = false; Panel *panel = imp_get_panel(models, panel_id); - if (panel_api_check_panel(panel)){ + if (api_check_panel(panel)){ if (panel->kind == PanelKind_Intermediate){ result = true; } @@ -1976,7 +1462,7 @@ Panel_Is_Leaf(Application_Links *app, Panel_ID panel_id){ Models *models = (Models*)app->cmd_context; b32 result = false; Panel *panel = imp_get_panel(models, panel_id); - if (panel_api_check_panel(panel)){ + if (api_check_panel(panel)){ if (panel->kind == PanelKind_Final){ result = true; } @@ -1990,7 +1476,7 @@ Panel_Split(Application_Links *app, Panel_ID panel_id, Panel_Split_Orientation o Layout *layout = &models->layout; b32 result = false; Panel *panel = imp_get_panel(models, panel_id); - if (panel_api_check_panel(panel)){ + if (api_check_panel(panel)){ Panel *new_panel = 0; if (layout_split_panel(layout, panel, (orientation == PanelSplit_LeftAndRight), &new_panel)){ Live_Views *live_set = &models->live_set; @@ -2008,7 +1494,7 @@ Panel_Set_Split(Application_Links *app, Panel_ID panel_id, Panel_Split_Kind kind Layout *layout = &models->layout; b32 result = false; Panel *panel = imp_get_panel(models, panel_id); - if (panel_api_check_panel(panel)){ + if (api_check_panel(panel)){ if (panel->kind == PanelKind_Intermediate){ panel->split.kind = kind; switch (kind){ @@ -2042,7 +1528,7 @@ Panel_Swap_Children(Application_Links *app, Panel_ID panel_id, Panel_Split_Kind Layout *layout = &models->layout; b32 result = false; Panel *panel = imp_get_panel(models, panel_id); - if (panel_api_check_panel(panel)){ + if (api_check_panel(panel)){ if (panel->kind == PanelKind_Intermediate){ Swap(Panel*, panel->tl_panel, panel->br_panel); layout_propogate_sizes_down_from_node(layout, panel); @@ -2058,7 +1544,7 @@ Panel_Get_Parent(Application_Links *app, Panel_ID panel_id, Panel_ID *panel_id_o b32 result = false; Panel *panel = imp_get_panel(models, panel_id); *panel_id_out = 0; - if (panel_api_check_panel(panel)){ + if (api_check_panel(panel)){ *panel_id_out = panel_get_id(layout, panel->parent); result = true; } @@ -2072,7 +1558,7 @@ Panel_Get_Child(Application_Links *app, Panel_ID panel_id, Panel_Child which_chi b32 result = false; Panel *panel = imp_get_panel(models, panel_id); *panel_id_out = 0; - if (panel_api_check_panel(panel)){ + if (api_check_panel(panel)){ if (panel->kind == PanelKind_Intermediate){ Panel *child = 0; switch (which_child){ @@ -2100,7 +1586,7 @@ Panel_Get_Max(Application_Links *app, Panel_ID panel_id, Panel_ID *panel_id_out) Layout *layout = &models->layout; b32 result = false; Panel *panel = imp_get_panel(models, panel_id); - if (panel_api_check_panel(panel)){ + if (api_check_panel(panel)){ if (panel->kind == PanelKind_Intermediate){ Panel *child = panel->br_panel; *panel_id_out = panel_get_id(layout, child); @@ -2116,7 +1602,7 @@ Panel_Get_Margin(Application_Links *app, Panel_ID panel_id, i32_Rect *margins_ou Layout *layout = &models->layout; b32 result = false; Panel *panel = imp_get_panel(models, panel_id); - if (panel_api_check_panel(panel)){ + if (api_check_panel(panel)){ if (panel->kind == PanelKind_Final){ i32 margin = layout->margin; margins_out->x0 = margin; @@ -2146,7 +1632,7 @@ in the system, the call will fail.) Layout *layout = &models->layout; View *view = imp_get_view(models, view_id); b32 result = false; - if (view_api_check_view(view)){ + if (api_check_view(view)){ if (layout_close_panel(layout, view->panel)){ live_set_free_view(&models->mem.heap, &models->lifetime_allocator, &models->live_set, view); result = true; @@ -2160,7 +1646,7 @@ View_Get_Region(Application_Links *app, View_ID view_id, Rect_i32 *region_out){ Models *models = (Models*)app->cmd_context; View *view = imp_get_view(models, view_id); b32 result = false; - if (view_api_check_view(view)){ + if (api_check_view(view)){ *region_out = view->panel->rect_full; result = true; } @@ -2172,7 +1658,7 @@ View_Get_Buffer_Region(Application_Links *app, View_ID view_id, Rect_i32 *region Models *models = (Models*)app->cmd_context; View *view = imp_get_view(models, view_id); b32 result = false; - if (view_api_check_view(view)){ + if (api_check_view(view)){ *region_out = view_get_buffer_rect(models, view); result = true; } @@ -2184,7 +1670,7 @@ View_Get_Scroll_Vars(Application_Links *app, View_ID view_id, GUI_Scroll_Vars *s Models *models = (Models*)app->cmd_context; View *view = imp_get_view(models, view_id); b32 result = false; - if (view_api_check_view(view)){ + if (api_check_view(view)){ if (view->ui_mode){ *scroll_vars_out = view->ui_scroll; } @@ -2211,7 +1697,7 @@ DOC_SEE(get_active_view) Models *models = (Models*)app->cmd_context; View *view = imp_get_view(models, view_id); b32 result = false; - if (view_api_check_view(view)){ + if (api_check_view(view)){ models->layout.active_panel = view->panel; result = true; } @@ -2231,7 +1717,7 @@ DOC_RETURN(returns non-zero on success) View *view = imp_get_view(models, view_id); b32 result = false; - if (view_api_check_view(view)){ + if (api_check_view(view)){ result = true; switch (setting){ case ViewSetting_ShowWhitespace: @@ -2277,7 +1763,7 @@ DOC_SEE(View_Setting_ID) View *view = imp_get_view(models, view_id); b32 result = false; - if (view_api_check_view(view)){ + if (api_check_view(view)){ result = true; switch (setting){ case ViewSetting_ShowWhitespace: @@ -2322,7 +1808,7 @@ If the view_id does not specify a valid view, the returned scope is null.) Models *models = (Models*)app->cmd_context; View *view = imp_get_view(models, view_id); b32 result = false; - if (view_api_check_view(view)){ + if (api_check_view(view)){ Assert(view->lifetime_object != 0); *scope = (Managed_Scope)(view->lifetime_object->workspace.scope_id); result = true; @@ -2345,9 +1831,9 @@ DOC_SEE(Full_Cursor) Models *models = (Models*)app->cmd_context; View *view = imp_get_view(models, view_id); b32 result = false; - if (view_api_check_view(view)){ + if (api_check_view(view)){ Editing_File *file = view->file; - if (buffer_api_check_file(file)){ + if (api_check_buffer(file)){ if (file->settings.unwrapped_lines && seek.type == buffer_seek_wrapped_xy){ seek.type = buffer_seek_unwrapped_xy; } @@ -2376,10 +1862,10 @@ DOC_SEE(Buffer_Seek) Models *models = (Models*)app->cmd_context; View *view = imp_get_view(models, view_id); b32 result = false; - if (view_api_check_view(view)){ + if (api_check_view(view)){ Editing_File *file = view->file; Assert(file != 0); - if (buffer_api_check_file(file)){ + if (api_check_buffer(file)){ Full_Cursor cursor = file_compute_cursor(models->system, file, seek); view_set_cursor(models->system, models, view, cursor, set_preferred_x); result = true; @@ -2400,10 +1886,10 @@ DOC_SEE(GUI_Scroll_Vars) Models *models = (Models*)app->cmd_context; View *view = imp_get_view(models, view_id); b32 result = false; - if (view_api_check_view(view)){ + if (api_check_view(view)){ Editing_File *file = view->file; Assert(file != 0); - if (buffer_api_check_file(file)){ + if (api_check_buffer(file)){ if (!view->ui_mode){ view_set_scroll(models->system, models, view, scroll); } @@ -2430,10 +1916,10 @@ DOC_SEE(Buffer_Seek) View *view = imp_get_view(models, view_id); b32 result = false; - if (view_api_check_view(view)){ + if (api_check_view(view)){ Editing_File *file = view->file; Assert(file != 0); - if (buffer_api_check_file(file)){ + if (api_check_buffer(file)){ if (seek.type != buffer_seek_pos){ Full_Cursor cursor = file_compute_cursor(models->system, file, seek); view->mark = cursor.pos; @@ -2462,9 +1948,9 @@ DOC_SEE(Set_Buffer_Flag) View *view = imp_get_view(models, view_id); b32 result = false; - if (view_api_check_view(view)){ + if (api_check_view(view)){ Editing_File *file = working_set_get_active_file(&models->working_set, buffer_id); - if (buffer_api_check_file(file)){ + if (api_check_buffer(file)){ if (file != view->file){ view_set_file(models->system, models, view, file); if (!(flags & SetBuffer_KeepOriginalGUI)){ @@ -2492,7 +1978,7 @@ DOC_SEE(int_color) Models *models = (Models*)app->cmd_context; View *view = imp_get_view(models, view_id); b32 result = false; - if (view_api_check_view(view)){ + if (api_check_view(view)){ i32 size = end - start; if (size > 0){ view_post_paste_effect(view, seconds, start, size, color|0xFF000000); @@ -2516,7 +2002,7 @@ DOC_SEE(view_set_ui) Models *models = (Models*)app->cmd_context; View *view = imp_get_view(models, view_id); b32 result = false; - if (view_api_check_view(view)){ + if (api_check_view(view)){ if (!view->ui_mode){ view->ui_mode = true; result = true; @@ -2540,7 +2026,7 @@ DOC_SEE(view_set_ui) Models *models = (Models*)app->cmd_context; View *view = imp_get_view(models, view_id); b32 result = false; - if (view_api_check_view(view) && view->ui_mode){ + if (api_check_view(view) && view->ui_mode){ view_quit_ui(models->system, models, view); view->ui_mode = false; result = true; @@ -2553,7 +2039,7 @@ View_Is_In_UI_Mode(Application_Links *app, View_ID view_id){ Models *models = (Models*)app->cmd_context; View *view = imp_get_view(models, view_id); b32 result = false; - if (view_api_check_view(view)){ + if (api_check_view(view)){ result = view->ui_mode; } return(result); @@ -2577,7 +2063,7 @@ DOC_SEE(UI_Quit_Function_Type) Models *models = (Models*)app->cmd_context; View *view = imp_get_view(models, view_id); b32 result = false; - if (view_api_check_view(view)){ + if (api_check_view(view)){ view->ui_quit = quit_function; result = true; } @@ -2597,7 +2083,7 @@ DOC_SEE(view_set_ui) Models *models = (Models*)app->cmd_context; View *view = imp_get_view(models, view_id); b32 result = false; - if (view_api_check_view(view)){ + if (api_check_view(view)){ *quit_function_out = view->ui_quit; result = true; } @@ -2935,7 +2421,7 @@ DOC_SEE(Marker) { Models *models = (Models*)app->cmd_context; Editing_File *file = imp_get_file(models, buffer_id); - Managed_Scope markers_scope = buffer_get_managed_scope__inner(file); + Managed_Scope markers_scope = file_get_managed_scope(file); if (optional_extra_scope != 0){ Managed_Object scope_array[2]; scope_array[0] = markers_scope; @@ -3645,7 +3131,7 @@ Buffer_History_Get_Max_Record_Index(Application_Links *app, Buffer_ID buffer_id, Models *models = (Models*)app->cmd_context; Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; - if (buffer_api_check_file(file) && history_is_activated(&file->state.history)){ + if (api_check_buffer(file) && history_is_activated(&file->state.history)){ *index_out = history_get_record_count(&file->state.history); result = true; } @@ -3680,7 +3166,7 @@ Buffer_History_Get_Record_Info(Application_Links *app, Buffer_ID buffer_id, Hist Editing_File *file = imp_get_file(models, buffer_id); block_zero_struct(record_out); b32 result = false; - if (buffer_api_check_file(file)){ + if (api_check_buffer(file)){ History *history = &file->state.history; if (history_is_activated(history)){ i32 max_index = history_get_record_count(history); @@ -3714,7 +3200,7 @@ Buffer_History_Get_Group_Sub_Record(Application_Links *app, Buffer_ID buffer_id, Editing_File *file = imp_get_file(models, buffer_id); block_zero_struct(record_out); b32 result = false; - if (buffer_api_check_file(file)){ + if (api_check_buffer(file)){ History *history = &file->state.history; if (history_is_activated(history)){ i32 max_index = history_get_record_count(history); @@ -3753,7 +3239,7 @@ Buffer_History_Get_Current_State_Index(Application_Links *app, Buffer_ID buffer_ Models *models = (Models*)app->cmd_context; Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; - if (buffer_api_check_file(file) && history_is_activated(&file->state.history)){ + if (api_check_buffer(file) && history_is_activated(&file->state.history)){ *index_out = file_get_current_record_index(file); result = true; } @@ -3765,7 +3251,7 @@ Buffer_History_Set_Current_State_Index(Application_Links *app, Buffer_ID buffer_ Models *models = (Models*)app->cmd_context; Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; - if (buffer_api_check_file(file) && history_is_activated(&file->state.history)){ + if (api_check_buffer(file) && history_is_activated(&file->state.history)){ i32 max_index = history_get_record_count(&file->state.history); if (0 <= index && index <= max_index){ System_Functions *system = models->system; @@ -3828,7 +3314,7 @@ Buffer_History_Clear_After_Current_State(Application_Links *app, Buffer_ID buffe Models *models = (Models*)app->cmd_context; Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; - if (buffer_api_check_file(file) && history_is_activated(&file->state.history)){ + if (api_check_buffer(file) && history_is_activated(&file->state.history)){ history_dump_records_after_index(&file->state.history, file->state.current_record_index); result = true; } @@ -3918,7 +3404,7 @@ DOC_RETURN(Returns true if the given id was a valid face and the change was made Editing_File *file = imp_get_file(models, buffer_id); b32 did_change = false; - if (buffer_api_check_file(file)){ + if (api_check_buffer(file)){ System_Functions *system = models->system; Font_Pointers font = system->font.get_pointers_by_id(id); if (font.valid){ @@ -3988,7 +3474,7 @@ DOC_RETURN(On success a valid Face_ID, otherwise returns zero.) b32 result = false; if (buffer_id != 0){ Editing_File *file = imp_get_file(models, buffer_id); - if (buffer_api_check_file(file)){ + if (api_check_buffer(file)){ *face_id_out = file->settings.font_id; result = true; } @@ -4160,15 +3646,7 @@ DOC_SEE(directory_set_hot) Models *models = (Models*)app->cmd_context; Hot_Directory *hot = &models->hot_directory; hot_directory_clean_end(hot); - if (required_size_out != 0){ - *required_size_out = hot->string.size; - } - b32 result = false; - if (append(out, hot->string)){ - terminate_with_null(out); - result = true; - } - return(result); + return(api_string_out(hot->string, out, required_size_out)); } // TODO(allen): redocument @@ -4290,6 +3768,7 @@ File_Get_Attributes(Application_Links *app, String file_name, File_Attributes *a return(attributes_out->last_write_time > 0); } +// TODO(allen): remove this nonsense and make a real API here instead. // TODO(allen): redocument API_EXPORT b32 Directory_CD(Application_Links *app, String *directory, String relative_path) @@ -4320,6 +3799,7 @@ DOC_RETURN(This call returns non-zero on success.) */{ Models *models = (Models*)app->cmd_context; System_Functions *system = models->system; + // TODO(allen): rewrite this with a better OS layer API i32 required_size = system->get_4ed_path(0, 0); *required_size_out = required_size; i32 remaining_size = path_out->memory_size - path_out->size; @@ -4598,7 +4078,7 @@ Text_Layout_Buffer_Point_To_Layout_Point(Application_Links *app, Text_Layout_ID b32 result = false; if (text_layout_get(&models->text_layouts, text_layout_id, &layout)){ Editing_File *file = imp_get_file(models, layout.buffer_id); - if (buffer_api_check_file(file)){ + if (api_check_buffer(file)){ System_Functions *system = models->system; // TODO(allen): this could be computed and stored _once_ right? Full_Cursor top = file_compute_cursor(system, file, seek_line_char(layout.point.line_number, 1)); @@ -4622,7 +4102,7 @@ Text_Layout_Layout_Point_To_Buffer_Point(Application_Links *app, Text_Layout_ID b32 result = false; if (text_layout_get(&models->text_layouts, text_layout_id, &layout)){ Editing_File *file = imp_get_file(models, layout.buffer_id); - if (buffer_api_check_file(file)){ + if (api_check_buffer(file)){ System_Functions *system = models->system; // TODO(allen): this could be computed and stored _once_ right? Full_Cursor top = file_compute_cursor(system, file, seek_line_char(layout.point.line_number, 1)); @@ -4676,7 +4156,7 @@ Compute_Render_Layout(Application_Links *app, View_ID view_id, Buffer_ID buffer_ View *view = imp_get_view(models, view_id); Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; - if (view_api_check_view(view) && buffer_api_check_file(file)){ + if (api_check_view(view) && api_check_buffer(file)){ f32 line_height = (f32)view->line_height; f32 max_x = (f32)file->settings.display_width; f32 max_y = layout_dim.y + line_height; @@ -4809,7 +4289,7 @@ API_EXPORT void Draw_Render_Layout(Application_Links *app, View_ID view_id){ Models *models = (Models*)app->cmd_context; View *view = imp_get_view(models, view_id); - if (view_api_check_view(view) && models->target != 0){ + if (api_check_view(view) && models->target != 0){ render_loaded_file_in_view__inner(models, models->target, view, view->render.buffer_rect, view->render.cursor, view->render.range, view->render.items, view->render.item_count); @@ -5051,7 +4531,7 @@ Get_View_Visible_Range(Application_Links *app, View_ID view_id){ Range result = {}; Models *models = (Models*)app->cmd_context; View *view = imp_get_view(models, view_id); - if (view_api_check_view(view)){ + if (api_check_view(view)){ i32 view_height = rect_height(view->panel->rect_inner); i32 line_height = view->line_height; Full_Cursor min_cursor = view_get_render_cursor(models->system, view); diff --git a/4ed_cli.cpp b/4ed_cli.cpp index c4574022..a4ec9818 100644 --- a/4ed_cli.cpp +++ b/4ed_cli.cpp @@ -89,5 +89,62 @@ child_process_lookup_return_code(Child_Process_Container *container, Child_Proce return(result); } +//////////////////////////////// + +internal b32 +child_process_call(Models *models, System_Functions *system, String path, String command, Child_Process_ID *id_out){ + b32 result = false; + char *path_cstr = 0; + char *command_cstr = 0; + if (terminate_with_null(&path)){ + path_cstr = path.str; + } + else{ + String s = string_push_copy(&models->mem.part, path); + path_cstr = s.str; + } + if (terminate_with_null(&command)){ + command_cstr = command.str; + } + else{ + String s = string_push_copy(&models->mem.part, command); + command_cstr = s.str; + } + CLI_Handles cli_handles = {}; + if (system->cli_call(path_cstr, command_cstr, &cli_handles)){ + Child_Process_And_ID new_process = child_process_alloc_new(models, &models->child_processes); + *id_out = new_process.id; + new_process.process->cli = cli_handles; + result = true; + } + return(result); +} + +internal b32 +child_process_set_target_buffer(Models *models, Child_Process *child_process, Editing_File *file, Child_Process_Set_Target_Flags flags){ + b32 result = false; + b32 fail_if_process_has_buffer = HasFlag(flags, ChildProcessSet_FailIfProcessAlreadyAttachedToABuffer); + b32 fail_if_buffer_has_process = HasFlag(flags, ChildProcessSet_FailIfBufferAlreadyAttachedToAProcess); + b32 process_has_buffer = (child_process->out_file != 0); + b32 buffer_has_process = (file->state.attached_child_process != 0); + b32 fail = ((process_has_buffer && fail_if_process_has_buffer) || + (buffer_has_process && fail_if_buffer_has_process)); + if (!fail){ + if (process_has_buffer){ + child_process->out_file->state.attached_child_process = 0; + } + if (buffer_has_process){ + Child_Process *attached_child_process = child_process_from_id(&models->child_processes, file->state.attached_child_process); + if (attached_child_process != 0){ + attached_child_process->out_file = 0; + } + } + child_process->out_file = file; + file->state.attached_child_process = child_process->id; + result = true; + } + return(result); +} + // BOTTOM diff --git a/4ed_edit.cpp b/4ed_edit.cpp index 0319498c..d9cb65ec 100644 --- a/4ed_edit.cpp +++ b/4ed_edit.cpp @@ -230,7 +230,12 @@ edit_fix_markers(System_Functions *system, Models *models, Editing_File *file, E } internal void -edit_single(System_Functions *system, Models *models, Editing_File *file, Edit edit, Edit_Behaviors behaviors){ +edit_single(System_Functions *system, Models *models, Editing_File *file, Range range, String string, Edit_Behaviors behaviors){ + Edit edit = {}; + edit.str = string.str; + edit.length = string.size; + edit.range = range; + Mem_Options *mem = &models->mem; Heap *heap = &mem->heap; Partition *part = &mem->part; @@ -313,13 +318,34 @@ edit_single(System_Functions *system, Models *models, Editing_File *file, Edit e } } -internal void -edit_single(System_Functions *system, Models *models, Editing_File *file, Range range, String string, Edit_Behaviors behaviors){ - Edit edit = {}; - edit.str = string.str; - edit.length = string.size; - edit.range = range; - edit_single(system, models, file, edit, behaviors); +internal b32 +edit_batch(System_Functions *system, Models *models, Editing_File *file, char *str, Buffer_Edit *edits, i32 edit_count, Edit_Behaviors behaviors){ + b32 result = true; + if (edit_count > 0){ + global_history_adjust_edit_grouping_counter(&models->global_history, 1); + + Buffer_Edit *edit_in = edits; + Buffer_Edit *one_past_last = edits + edit_count; + i32 shift = 0; + for (;edit_in < one_past_last; edit_in += 1){ + String insert_string = make_string(str + edit_in->str_start, edit_in->len); + Range edit_range = {edit_in->start, edit_in->end}; + edit_range.first += shift; + edit_range.one_past_last += shift; + i32 size = buffer_size(&file->state.buffer); + if (0 <= edit_range.first && edit_range.first <= edit_range.one_past_last && edit_range.one_past_last <= size){ + edit_single(system, models, file, edit_range, insert_string, behaviors); + shift += replace_range_compute_shift(edit_range, insert_string.size); + } + else{ + result = false; + break; + } + } + + global_history_adjust_edit_grouping_counter(&models->global_history, -1); + } + return(result); } internal void @@ -341,12 +367,9 @@ edit__apply_record_forward(System_Functions *system, Models *models, Editing_Fil switch (record->kind){ case RecordKind_Single: { - Edit edit = {}; - edit.str = record->single.str_forward; - edit.length = record->single.length_forward; - edit.range.first = record->single.first; - edit.range.one_past_last = edit.range.first + record->single.length_backward; - edit_single(system, models, file, edit, behaviors_prototype); + String str = make_string(record->single.str_forward, record->single.length_forward); + Range range = {record->single.first, record->single.first + record->single.length_backward}; + edit_single(system, models, file, range, str, behaviors_prototype); }break; case RecordKind_Group: @@ -375,12 +398,9 @@ edit__apply_record_backward(System_Functions *system, Models *models, Editing_Fi switch (record->kind){ case RecordKind_Single: { - Edit edit = {}; - edit.str = record->single.str_backward; - edit.length = record->single.length_backward; - edit.range.first = record->single.first; - edit.range.one_past_last = edit.range.first + record->single.length_forward; - edit_single(system, models, file, edit, behaviors_prototype); + String str = make_string(record->single.str_backward, record->single.length_backward); + Range range = {record->single.first, record->single.first + record->single.length_forward}; + edit_single(system, models, file, range, str, behaviors_prototype); }break; case RecordKind_Group: @@ -436,5 +456,135 @@ edit_change_current_history_state(System_Functions *system, Models *models, Edit } } +//////////////////////////////// + +internal Editing_File* +create_file(Models *models, String file_name, Buffer_Create_Flag flags){ + Editing_File *result = 0; + + if (file_name.size > 0){ + System_Functions *system = models->system; + Working_Set *working_set = &models->working_set; + Heap *heap = &models->mem.heap; + Partition *part = &models->mem.part; + + Temp_Memory temp = begin_temp_memory(part); + + Editing_File *file = 0; + b32 do_empty_buffer = false; + Editing_File_Name canon = {}; + b32 has_canon_name = false; + b32 buffer_is_for_new_file = false; + + // NOTE(allen): Try to get the file by canon name. + if ((flags & BufferCreate_NeverAttachToFile) == 0){ + if (get_canon_name(system, file_name, &canon)){ + has_canon_name = true; + file = working_set_contains_canon(working_set, canon.name); + } + else{ + do_empty_buffer = true; + } + } + + // NOTE(allen): Try to get the file by buffer name. + if ((flags & BufferCreate_MustAttachToFile) == 0){ + if (file == 0){ + file = working_set_contains_name(working_set, file_name); + } + } + + // NOTE(allen): If there is still no file, create a new buffer. + if (file == 0){ + Plat_Handle handle = {}; + + // NOTE(allen): Figure out whether this is a new file, or an existing file. + if (!do_empty_buffer){ + if ((flags & BufferCreate_AlwaysNew) != 0){ + do_empty_buffer = true; + } + else{ + if (!system->load_handle(canon.name.str, &handle)){ + do_empty_buffer = true; + } + } + } + + if (do_empty_buffer){ + if (has_canon_name){ + buffer_is_for_new_file = true; + } + if (!HasFlag(flags, BufferCreate_NeverNew)){ + file = working_set_alloc_always(working_set, heap, &models->lifetime_allocator); + if (file != 0){ + if (has_canon_name){ + file_bind_file_name(system, heap, working_set, file, canon.name); + } + buffer_bind_name(models, heap, part, working_set, file, front_of_directory(file_name)); + File_Attributes attributes = {}; + file_create_from_string(system, models, file, make_lit_string(""), attributes); + result = file; + } + } + } + else{ + File_Attributes attributes = system->load_attributes(handle); + b32 in_heap_mem = false; + char *buffer = push_array(part, char, (i32)attributes.size); + + if (buffer == 0){ + buffer = heap_array(heap, char, (i32)attributes.size); + Assert(buffer != 0); + in_heap_mem = true; + } + + if (system->load_file(handle, buffer, (i32)attributes.size)){ + system->load_close(handle); + file = working_set_alloc_always(working_set, heap, &models->lifetime_allocator); + if (file != 0){ + file_bind_file_name(system, heap, working_set, file, canon.name); + buffer_bind_name(models, heap, part, working_set, file, front_of_directory(file_name)); + file_create_from_string(system, models, file, make_string(buffer, (i32)attributes.size), attributes); + result = file; + } + } + else{ + system->load_close(handle); + } + + if (in_heap_mem){ + heap_free(heap, buffer); + } + } + } + else{ + result = file; + } + + if (file != 0 && HasFlag(flags, BufferCreate_JustChangedFile)){ + file->state.ignore_behind_os = 1; + } + + if (file != 0 && HasFlag(flags, BufferCreate_AlwaysNew)){ + i32 size = buffer_size(&file->state.buffer); + if (size > 0){ + Edit_Behaviors behaviors = {}; + edit_single(system, models, file, make_range(0, size), make_lit_string(""), behaviors); + if (has_canon_name){ + buffer_is_for_new_file = true; + } + } + } + + if (file != 0 && buffer_is_for_new_file && !HasFlag(flags, BufferCreate_SuppressNewFileHook) && models->hook_new_file != 0){ + models->hook_new_file(&models->app_links, file->id.id); + } + + end_temp_memory(temp); + } + + return(result); +} + // BOTTOM diff --git a/4ed_file.cpp b/4ed_file.cpp index 161f1e71..7055c2e0 100644 --- a/4ed_file.cpp +++ b/4ed_file.cpp @@ -421,7 +421,7 @@ file_allocate_wrap_positions_as_needed(Heap *heap, Editing_File *file, i32 min_l //////////////////////////////// internal void -file_create_from_string(System_Functions *system, Models *models, Editing_File *file, String val, File_Attributes attributes, u32 flags){ +file_create_from_string(System_Functions *system, Models *models, Editing_File *file, String val, File_Attributes attributes){ Heap *heap = &models->mem.heap; Partition *part = &models->mem.part; Application_Links *app_links = &models->app_links; @@ -463,11 +463,7 @@ file_create_from_string(System_Functions *system, Models *models, Editing_File * //adjust_views_looking_at_files_to_new_cursor(system, models, file); file->lifetime_object = lifetime_alloc_object(heap, &models->lifetime_allocator, DynamicWorkspace_Buffer, file); - - file->settings.read_only = ((flags & FileCreateFlag_ReadOnly) != 0); - if (!file->settings.read_only){ - history_init(&models->app_links, &file->state.history); - } + history_init(&models->app_links, &file->state.history); // TODO(allen): do(cleanup the create and settings dance) // Right now we have this thing where we call hook_open_file, which may or may not @@ -521,19 +517,6 @@ file_free(System_Functions *system, Heap *heap, Lifetime_Allocator *lifetime_all file_unmark_edit_finished(file); } -internal void -init_normal_file(System_Functions *system, Models *models, char *buffer, i32 size, File_Attributes attributes, Editing_File *file){ - String val = make_string(buffer, size); - file_create_from_string(system, models, file, val, attributes, 0); -} - -internal void -init_read_only_file(System_Functions *system, Models *models, Editing_File *file){ - String val = {}; - File_Attributes attributes = {}; - file_create_from_string(system, models, file, val, attributes, FileCreateFlag_ReadOnly); -} - //////////////////////////////// internal i32 @@ -541,12 +524,20 @@ file_get_current_record_index(Editing_File *file){ return(file->state.current_record_index); } -//////////////////////////////// - internal b32 file_tokens_are_ready(Editing_File *file){ return(file->state.token_array.tokens != 0 && file->state.tokens_complete && !file->state.still_lexing); } +internal Managed_Scope +file_get_managed_scope(Editing_File *file){ + Managed_Scope scope = 0; + if (file != 0){ + Assert(file->lifetime_object != 0); + scope = (Managed_Scope)file->lifetime_object->workspace.scope_id; + } + return(scope); +} + // BOTTOM diff --git a/4ed_history.h b/4ed_history.h index b3855cde..25e7129e 100644 --- a/4ed_history.h +++ b/4ed_history.h @@ -32,14 +32,6 @@ struct Record{ i32 first; } single; - struct{ - Buffer_Batch_Edit_Type type; - i32 count; - char *str_base_forward; - char *str_base_backward; - Record_Batch_Slot *batch_records; - } batch; - struct{ Node children; i32 count; diff --git a/4ed_layout.cpp b/4ed_layout.cpp index 8bfe7bdb..5a92be78 100644 --- a/4ed_layout.cpp +++ b/4ed_layout.cpp @@ -455,5 +455,17 @@ panel_get_id(Layout *layout, Panel *panel){ return(id); } +//////////////////////////////// + +internal Panel* +imp_get_panel(Models *models, Panel_ID panel_id){ + Layout *layout = &models->layout; + Panel *panel = layout->panel_first + panel_id - 1; + if (!(layout->panel_first <= panel && panel < layout->panel_one_past_last)){ + panel = 0; + } + return(panel); +} + // BOTTOM diff --git a/4ed_view.cpp b/4ed_view.cpp index a7065a04..22a7557b 100644 --- a/4ed_view.cpp +++ b/4ed_view.cpp @@ -1195,26 +1195,6 @@ render_loaded_file_in_view__inner(Models *models, Render_Target *target, View *v } } -#if 0 -internal void -dont_do_core_render(Application_Links *app){} - -internal void -do_core_render(Application_Links *app){ - Models *models = (Models*)app->cmd_context; - Render_Target *target = models->target; - View *view = models->render_view; - i32_Rect rect = models->render_buffer_rect; - Full_Cursor render_cursor = models->render_cursor; - Range on_screen_range = models->render_range; - Buffer_Render_Item *items = models->render_items; - i32 item_count = models->render_item_count; - draw_push_clip(target, rect); - render_loaded_file_in_view__inner(models, target, view, rect, render_cursor, on_screen_range, items, item_count); - draw_pop_clip(target); -} -#endif - internal Full_Cursor file_get_render_cursor(System_Functions *system, Editing_File *file, f32 scroll_y){ Full_Cursor result = {}; @@ -1248,36 +1228,30 @@ view_get_render_cursor_target(System_Functions *system, View *view){ return(view_get_render_cursor(system, view, scroll_y)); } -#if 0 internal void -view_call_render_caller(Models *models, Render_Target *target, View *view, - i32_Rect rect, Full_Cursor render_cursor, Range on_screen_range, Buffer_Render_Item *items, i32 item_count, Render_Callback *core_render){ - if (models->render_caller != 0){ - View_ID view_id = view_get_id(&models->live_set, view); - models->render_view = view; - models->render_view_rect = view->panel->rect_inner; - models->render_buffer_rect = rect; - models->render_cursor = render_cursor; - models->render_range = on_screen_range; - models->render_items = items; - models->render_item_count = item_count; - - Frame_Info frame = {}; - frame.index = target->frame_index; - frame.literal_dt = target->literal_dt; - frame.animation_dt = target->animation_dt; -#if 0 - Render_Parameters params = {}; - params.view_id = view_id; - params.on_screen_range = on_screen_range; - params.buffer_region = rect; - params.do_core_render = core_render; -#endif - models->render_caller(&models->app_links, frame); - models->render_view = 0; +view_quit_ui(System_Functions *system, Models *models, View *view){ + Assert(view != 0); + view->ui_mode = false; + if (view->ui_quit != 0){ + view->ui_quit(&models->app_links, view_get_id(&models->live_set, view)); } } -#endif + +//////////////////////////////// + +internal View* +imp_get_view(Models *models, View_ID view_id){ + Live_Views *live_set = &models->live_set; + View *view = 0; + view_id -= 1; + if (0 <= view_id && view_id < live_set->max){ + view = live_set->views + view_id; + if (!view->in_use){ + view = 0; + } + } + return(view); +} // BOTTOM diff --git a/4ed_view.h b/4ed_view.h index 43f97a6f..48742ab9 100644 --- a/4ed_view.h +++ b/4ed_view.h @@ -147,10 +147,6 @@ struct View_Step_Result{ b32 consume_esc; }; -enum{ - FileCreateFlag_ReadOnly = 1, -}; - struct Render_Marker_Brush{ b8 color_noop; b8 text_color_noop; diff --git a/4ed_working_set.cpp b/4ed_working_set.cpp index 67c420b7..2014b2d2 100644 --- a/4ed_working_set.cpp +++ b/4ed_working_set.cpp @@ -120,27 +120,23 @@ internal Editing_File* working_set_index(Working_Set *working_set, Buffer_Slot_ID id){ Editing_File *result = 0; File_Array *array = 0; - if (id.part[1] >= 0 && id.part[1] < working_set->array_count){ array = working_set->file_arrays + id.part[1]; if (id.part[0] >= 0 && id.part[0] < array->size){ result = array->files + id.part[0]; } } - return(result); } internal Editing_File* working_set_index(Working_Set *working_set, i32 id){ - Editing_File *result = working_set_index(working_set, to_file_id(id)); - return(result); + return(working_set_index(working_set, to_file_id(id))); } internal Editing_File* working_set_get_active_file(Working_Set *working_set, Buffer_Slot_ID id){ - Editing_File *result = 0; - result = working_set_index(working_set, id); + Editing_File *result = working_set_index(working_set, id); if (result != 0 && result->is_dummy){ result = 0; } @@ -148,9 +144,8 @@ working_set_get_active_file(Working_Set *working_set, Buffer_Slot_ID id){ } internal Editing_File* -working_set_get_active_file(Working_Set *working_set, i32 id){ - Editing_File *result= working_set_get_active_file(working_set, to_file_id(id)); - return(result); +working_set_get_active_file(Working_Set *working_set, Buffer_ID id){ + return(working_set_get_active_file(working_set, to_file_id(id))); } internal void @@ -269,8 +264,7 @@ working_set_canon_remove(Working_Set *working_set, String name){ internal Editing_File* working_set_contains_name(Working_Set *working_set, String name){ - Editing_File *result = working_set_contains_basic(working_set, &working_set->name_table, name); - return(result); + return(working_set_contains_basic(working_set, &working_set->name_table, name)); } internal b32 @@ -284,35 +278,16 @@ working_set_remove_name(Working_Set *working_set, String name){ working_set_remove_basic(working_set, &working_set->name_table, name); } - -// TODO(allen): Pick better first options. internal Editing_File* -working_set_lookup_file(Working_Set *working_set, String string){ +get_file_from_identifier(System_Functions *system, Working_Set *working_set, Buffer_Identifier buffer){ Editing_File *file = 0; - - // TODO(allen): use the name table for this - for (Node *node = working_set->used_sentinel.next; - node != &working_set->used_sentinel; - node = node->next){ - Editing_File *nfile = CastFromMember(Editing_File, main_chain_node, node); - if (string.size == 0 || match_ss(string, nfile->unique_name.name)){ - file = nfile; - break; - } + if (buffer.id != 0){ + file = working_set_get_active_file(working_set, buffer.id); } - - if (file == 0){ - for (Node *node = working_set->used_sentinel.next; - node != &working_set->used_sentinel; - node = node->next){ - Editing_File *nfile = CastFromMember(Editing_File, main_chain_node, node); - if (string.size == 0 || has_substr_s(nfile->unique_name.name, string)){ - file = nfile; - break; - } - } + else if (buffer.name != 0){ + String name = make_string(buffer.name, buffer.name_len); + file = working_set_contains_name(working_set, name); } - return(file); } @@ -573,6 +548,23 @@ file_touch(Working_Set *working_set, Editing_File *file){ dll_insert(&working_set->used_sentinel, &file->main_chain_node); } +internal Editing_File* +file_get_next(Working_Set *working_set, Editing_File *file){ + if (file != 0){ + file = CastFromMember(Editing_File, main_chain_node, file->main_chain_node.next); + if (file == CastFromMember(Editing_File, main_chain_node, &working_set->used_sentinel)){ + file = 0; + } + } + else{ + if (working_set->file_count > 0){ + Node *node = working_set->used_sentinel.next; + file = CastFromMember(Editing_File, main_chain_node, node); + } + } + return(file); +} + internal void file_mark_edit_finished(Working_Set *working_set, Editing_File *file){ // TODO(allen): do(propogate do_not_mark_edits down the edit pipeline to here) @@ -595,5 +587,17 @@ file_unmark_edit_finished(Editing_File *file){ return(result); } +//////////////////////////////// + +internal Editing_File* +imp_get_file(Models *models, Buffer_ID buffer_id){ + Working_Set *working_set = &models->working_set; + Editing_File *file = working_set_get_active_file(working_set, buffer_id); + if (file != 0 && !file_is_ready(file)){ + file = 0; + } + return(file); +} + // BOTTOM