2017-01-29 00:03:23 +00:00
|
|
|
/*
|
|
|
|
4coder_default_hooks.cpp - Sets up the hooks for the default framework.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// TOP
|
|
|
|
|
2019-10-14 22:57:47 +00:00
|
|
|
CUSTOM_COMMAND_SIG(default_startup)
|
|
|
|
CUSTOM_DOC("Default command for responding to a startup event")
|
|
|
|
{
|
|
|
|
User_Input input = get_current_input(app);
|
|
|
|
if (match_core_code(&input, CoreCode_Startup)){
|
|
|
|
String_Const_u8_Array file_names = input.event.core.file_names;
|
|
|
|
default_4coder_initialize(app, file_names);
|
|
|
|
default_4coder_side_by_side_panels(app, file_names);
|
|
|
|
if (global_config.automatically_load_project){
|
|
|
|
load_project(app);
|
|
|
|
}
|
2017-03-27 22:36:42 +00:00
|
|
|
}
|
2017-01-29 00:03:23 +00:00
|
|
|
}
|
|
|
|
|
2019-10-14 22:57:47 +00:00
|
|
|
CUSTOM_COMMAND_SIG(default_try_exit)
|
|
|
|
CUSTOM_DOC("Default command for responding to a try-exit event")
|
|
|
|
{
|
|
|
|
User_Input input = get_current_input(app);
|
|
|
|
if (match_core_code(&input, CoreCode_TryExit)){
|
|
|
|
b32 do_exit = true;
|
|
|
|
if (!allow_immediate_close_without_checking_for_changes){
|
|
|
|
b32 has_unsaved_changes = false;
|
|
|
|
for (Buffer_ID buffer = get_buffer_next(app, 0, AccessAll);
|
|
|
|
buffer != 0;
|
|
|
|
buffer = get_buffer_next(app, buffer, AccessAll)){
|
|
|
|
Dirty_State dirty = buffer_get_dirty_state(app, buffer);
|
|
|
|
if (HasFlag(dirty, DirtyState_UnsavedChanges)){
|
|
|
|
has_unsaved_changes = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (has_unsaved_changes){
|
|
|
|
View_ID view = get_active_view(app, AccessAll);
|
|
|
|
do_exit = do_gui_sure_to_close_4coder(app, view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (do_exit){
|
|
|
|
// NOTE(allen): By leaving try exit unhandled we indicate
|
|
|
|
// that the core should take responsibility for handling this,
|
|
|
|
// and it will handle it by exiting 4coder. If we leave this
|
|
|
|
// event marked as handled on the other hand (for instance by
|
|
|
|
// running a confirmation GUI that cancels the exit) then 4coder
|
|
|
|
// will not exit.
|
|
|
|
leave_current_input_unhandled(app);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-10-13 20:17:22 +00:00
|
|
|
CUSTOM_COMMAND_SIG(default_view_input_handler)
|
2019-10-14 22:57:47 +00:00
|
|
|
CUSTOM_DOC("Input consumption loop for default view behavior")
|
2019-10-13 20:17:22 +00:00
|
|
|
{
|
|
|
|
for (;;){
|
|
|
|
// NOTE(allen): Get the binding from the buffer's current map
|
2019-10-14 22:57:47 +00:00
|
|
|
User_Input input = get_next_input(app, EventPropertyGroup_Any, 0);
|
2019-10-13 20:17:22 +00:00
|
|
|
if (input.abort){
|
|
|
|
break;
|
2018-10-06 01:42:56 +00:00
|
|
|
}
|
2019-10-13 20:17:22 +00:00
|
|
|
|
2019-10-14 22:57:47 +00:00
|
|
|
Event_Property event_properties = get_event_properties(&input.event);
|
|
|
|
|
|
|
|
if (suppressing_mouse && (event_properties & EventPropertyGroup_AnyMouseEvent) != 0){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-10-13 20:17:22 +00:00
|
|
|
View_ID view = get_active_view(app, AccessAll);
|
|
|
|
|
2019-10-14 02:13:15 +00:00
|
|
|
Buffer_ID buffer = view_get_buffer(app, view, AccessAll);
|
|
|
|
Managed_Scope buffer_scope = buffer_get_managed_scope(app, buffer);
|
|
|
|
Command_Map_ID *map_id_ptr =
|
|
|
|
scope_attachment(app, buffer_scope, buffer_map_id, Command_Map_ID);
|
|
|
|
if (*map_id_ptr == 0){
|
|
|
|
*map_id_ptr = mapid_file;
|
2019-10-10 22:57:02 +00:00
|
|
|
}
|
2019-10-14 02:13:15 +00:00
|
|
|
Command_Map_ID map_id = *map_id_ptr;
|
2019-10-10 22:57:02 +00:00
|
|
|
|
2019-10-13 20:17:22 +00:00
|
|
|
Command_Binding binding = map_get_binding_recursive(&framework_mapping, map_id, &input.event);
|
2019-10-10 22:57:02 +00:00
|
|
|
|
2019-10-13 20:17:22 +00:00
|
|
|
if (binding.custom == 0){
|
|
|
|
// NOTE(allen): we don't have anything to do with this input,
|
|
|
|
// leave it marked unhandled so that if there's a follow up
|
|
|
|
// event it is not blocked.
|
2019-10-14 22:57:47 +00:00
|
|
|
leave_current_input_unhandled(app);
|
2019-10-13 20:17:22 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
// NOTE(allen): before the command is called do some book keeping
|
|
|
|
Managed_Scope scope = view_get_managed_scope(app, view);
|
|
|
|
Rewrite_Type *next_rewrite = scope_attachment(app, scope, view_next_rewrite_loc, Rewrite_Type);
|
|
|
|
*next_rewrite = Rewrite_None;
|
2019-10-10 22:57:02 +00:00
|
|
|
if (fcoder_mode == FCoderMode_NotepadLike){
|
|
|
|
for (View_ID view_it = get_view_next(app, 0, AccessAll);
|
|
|
|
view_it != 0;
|
|
|
|
view_it = get_view_next(app, view_it, AccessAll)){
|
|
|
|
Managed_Scope scope_it = view_get_managed_scope(app, view_it);
|
|
|
|
b32 *snap_mark_to_cursor = scope_attachment(app, scope_it, view_snap_mark_to_cursor, b32);
|
2019-10-13 20:17:22 +00:00
|
|
|
*snap_mark_to_cursor = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE(allen): call the command
|
|
|
|
binding.custom(app);
|
|
|
|
|
|
|
|
// NOTE(allen): after the command is called do some book keeping
|
|
|
|
next_rewrite = scope_attachment(app, scope, view_next_rewrite_loc, Rewrite_Type);
|
|
|
|
if (next_rewrite != 0){
|
|
|
|
Rewrite_Type *rewrite = scope_attachment(app, scope, view_rewrite_loc, Rewrite_Type);
|
|
|
|
*rewrite = *next_rewrite;
|
|
|
|
if (fcoder_mode == FCoderMode_NotepadLike){
|
|
|
|
for (View_ID view_it = get_view_next(app, 0, AccessAll);
|
|
|
|
view_it != 0;
|
|
|
|
view_it = get_view_next(app, view_it, AccessAll)){
|
|
|
|
Managed_Scope scope_it = view_get_managed_scope(app, view_it);
|
|
|
|
b32 *snap_mark_to_cursor = scope_attachment(app, scope_it, view_snap_mark_to_cursor, b32);
|
|
|
|
if (*snap_mark_to_cursor){
|
|
|
|
i64 pos = view_get_cursor_pos(app, view_it);
|
|
|
|
view_set_mark(app, view_it, seek_pos(pos));
|
|
|
|
}
|
2019-10-10 22:57:02 +00:00
|
|
|
}
|
2018-10-06 01:42:56 +00:00
|
|
|
}
|
2018-09-30 12:14:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-01-29 00:03:23 +00:00
|
|
|
}
|
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
internal Range_i64_Array
|
2019-06-20 23:43:27 +00:00
|
|
|
get_enclosure_ranges(Application_Links *app, Arena *arena, Buffer_ID buffer, i64 pos, u32 flags){
|
|
|
|
Range_i64_Array array = {};
|
2019-06-01 23:58:28 +00:00
|
|
|
i32 max = 100;
|
2019-06-20 23:43:27 +00:00
|
|
|
array.ranges = push_array(arena, Range_i64, max);
|
2018-09-30 12:14:47 +00:00
|
|
|
for (;;){
|
2019-06-20 23:43:27 +00:00
|
|
|
Range_i64 range = {};
|
2019-10-06 05:00:46 +00:00
|
|
|
if (find_surrounding_nest(app, buffer, pos, flags, &range)){
|
2019-06-01 23:58:28 +00:00
|
|
|
array.ranges[array.count] = range;
|
|
|
|
array.count += 1;
|
2018-09-30 12:14:47 +00:00
|
|
|
pos = range.first;
|
2019-06-01 23:58:28 +00:00
|
|
|
if (array.count >= max){
|
|
|
|
break;
|
|
|
|
}
|
2018-09-30 12:14:47 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(array);
|
|
|
|
}
|
|
|
|
|
2019-08-01 02:13:36 +00:00
|
|
|
typedef i32 Range_Highlight_Kind;
|
|
|
|
enum{
|
|
|
|
RangeHighlightKind_LineHighlight,
|
|
|
|
RangeHighlightKind_CharacterHighlight,
|
|
|
|
};
|
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
internal void
|
2019-08-01 02:13:36 +00:00
|
|
|
draw_enclosures(Application_Links *app, Text_Layout_ID text_layout_id, Buffer_ID buffer,
|
|
|
|
i64 pos, u32 flags, Range_Highlight_Kind kind,
|
|
|
|
int_color *back_colors, int_color *fore_colors, i32 color_count){
|
|
|
|
Scratch_Block scratch(app);
|
2019-06-20 23:43:27 +00:00
|
|
|
Range_i64_Array ranges = get_enclosure_ranges(app, scratch, buffer, pos, flags);
|
2018-09-30 12:14:47 +00:00
|
|
|
|
2019-08-01 02:13:36 +00:00
|
|
|
i32 color_index = 0;
|
2019-08-02 20:07:08 +00:00
|
|
|
for (i32 i = ranges.count - 1; i >= 0; i -= 1){
|
2019-08-01 02:13:36 +00:00
|
|
|
Range_i64 range = ranges.ranges[i];
|
|
|
|
if (kind == RangeHighlightKind_LineHighlight){
|
2019-08-02 20:07:08 +00:00
|
|
|
Range_i64 r[2] = {};
|
|
|
|
if (i > 0){
|
|
|
|
Range_i64 inner_range = ranges.ranges[i - 1];
|
|
|
|
Range_i64 lines = get_line_range_from_pos_range(app, buffer, range);
|
|
|
|
Range_i64 inner_lines = get_line_range_from_pos_range(app, buffer, inner_range);
|
|
|
|
inner_lines.min = clamp_bot(lines.min, inner_lines.min);
|
|
|
|
inner_lines.max = clamp_top(inner_lines.max, lines.max);
|
|
|
|
inner_lines.min -= 1;
|
|
|
|
inner_lines.max += 1;
|
|
|
|
if (lines.min <= inner_lines.min){
|
|
|
|
r[0] = Ii64(lines.min, inner_lines.min);
|
|
|
|
}
|
|
|
|
if (inner_lines.max <= lines.max){
|
|
|
|
r[1] = Ii64(inner_lines.max, lines.max);
|
|
|
|
}
|
2018-09-30 12:14:47 +00:00
|
|
|
}
|
2019-08-02 20:07:08 +00:00
|
|
|
else{
|
|
|
|
r[0] = get_line_range_from_pos_range(app, buffer, range);
|
|
|
|
}
|
|
|
|
for (i32 j = 0; j < 2; j += 1){
|
|
|
|
if (r[j].min == 0){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Range_i64 line_range = r[j];
|
|
|
|
if (back_colors != 0){
|
|
|
|
draw_line_highlight(app, text_layout_id, line_range, back_colors[color_index]);
|
|
|
|
}
|
|
|
|
if (fore_colors != 0){
|
|
|
|
Range_i64 pos_range = get_pos_range_from_line_range(app, buffer, line_range);
|
|
|
|
paint_text_color(app, text_layout_id, pos_range, fore_colors[color_index]);
|
|
|
|
}
|
2019-08-01 02:13:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
if (back_colors != 0){
|
2019-10-08 17:18:20 +00:00
|
|
|
draw_character_block(app, text_layout_id, range.min, 0.f, back_colors[color_index]);
|
|
|
|
draw_character_block(app, text_layout_id, range.max - 1, 0.f, back_colors[color_index]);
|
2018-09-30 12:14:47 +00:00
|
|
|
}
|
2019-08-01 02:13:36 +00:00
|
|
|
if (fore_colors != 0){
|
2019-10-06 06:59:35 +00:00
|
|
|
paint_text_color_pos(app, text_layout_id, range.min, fore_colors[color_index]);
|
|
|
|
paint_text_color_pos(app, text_layout_id, range.max - 1, fore_colors[color_index]);
|
2018-09-30 12:14:47 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-01 02:13:36 +00:00
|
|
|
color_index += 1;
|
|
|
|
color_index = (color_index%color_count);
|
2018-09-30 12:14:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-14 22:57:47 +00:00
|
|
|
#if 0
|
2019-02-25 23:42:13 +00:00
|
|
|
static argb_color default_colors[Stag_COUNT] = {};
|
|
|
|
MODIFY_COLOR_TABLE_SIG(default_modify_color_table){
|
|
|
|
if (default_colors[Stag_NOOP] == 0){
|
|
|
|
default_colors[Stag_NOOP] = 0xFFFF00FF;
|
|
|
|
|
|
|
|
default_colors[Stag_Back] = 0xFF0C0C0C;
|
|
|
|
default_colors[Stag_Margin] = 0xFF181818;
|
|
|
|
default_colors[Stag_Margin_Hover] = 0xFF252525;
|
|
|
|
default_colors[Stag_Margin_Active] = 0xFF323232;
|
|
|
|
default_colors[Stag_List_Item] = default_colors[Stag_Margin];
|
|
|
|
default_colors[Stag_List_Item_Hover] = default_colors[Stag_Margin_Hover];
|
|
|
|
default_colors[Stag_List_Item_Active] = default_colors[Stag_Margin_Active];
|
|
|
|
default_colors[Stag_Cursor] = 0xFF00EE00;
|
|
|
|
default_colors[Stag_Highlight] = 0xFFDDEE00;
|
|
|
|
default_colors[Stag_Mark] = 0xFF494949;
|
|
|
|
default_colors[Stag_Default] = 0xFF90B080;
|
|
|
|
default_colors[Stag_At_Cursor] = default_colors[Stag_Back];
|
|
|
|
default_colors[Stag_Highlight_Cursor_Line] = 0xFF1E1E1E;
|
|
|
|
default_colors[Stag_At_Highlight] = 0xFFFF44DD;
|
|
|
|
default_colors[Stag_Comment] = 0xFF2090F0;
|
|
|
|
default_colors[Stag_Keyword] = 0xFFD08F20;
|
|
|
|
default_colors[Stag_Str_Constant] = 0xFF50FF30;
|
|
|
|
default_colors[Stag_Char_Constant] = default_colors[Stag_Str_Constant];
|
|
|
|
default_colors[Stag_Int_Constant] = default_colors[Stag_Str_Constant];
|
|
|
|
default_colors[Stag_Float_Constant] = default_colors[Stag_Str_Constant];
|
|
|
|
default_colors[Stag_Bool_Constant] = default_colors[Stag_Str_Constant];
|
|
|
|
default_colors[Stag_Include] = default_colors[Stag_Str_Constant];
|
|
|
|
default_colors[Stag_Preproc] = default_colors[Stag_Default];
|
|
|
|
default_colors[Stag_Special_Character] = 0xFFFF0000;
|
|
|
|
default_colors[Stag_Ghost_Character] = 0xFF4E5E46;
|
|
|
|
|
|
|
|
default_colors[Stag_Paste] = 0xFFDDEE00;
|
|
|
|
default_colors[Stag_Undo] = 0xFF00DDEE;
|
|
|
|
|
|
|
|
default_colors[Stag_Highlight_Junk] = 0xFF3A0000;
|
|
|
|
default_colors[Stag_Highlight_White] = 0xFF003A3A;
|
|
|
|
|
|
|
|
default_colors[Stag_Bar] = 0xFF888888;
|
|
|
|
default_colors[Stag_Base] = 0xFF000000;
|
|
|
|
default_colors[Stag_Pop1] = 0xFF3C57DC;
|
|
|
|
default_colors[Stag_Pop2] = 0xFFFF0000;
|
|
|
|
|
|
|
|
default_colors[Stag_Back_Cycle_1] = 0x10A00000;
|
|
|
|
default_colors[Stag_Back_Cycle_2] = 0x0C00A000;
|
|
|
|
default_colors[Stag_Back_Cycle_3] = 0x0C0000A0;
|
|
|
|
default_colors[Stag_Back_Cycle_4] = 0x0CA0A000;
|
|
|
|
default_colors[Stag_Text_Cycle_1] = 0xFFA00000;
|
|
|
|
default_colors[Stag_Text_Cycle_2] = 0xFF00A000;
|
|
|
|
default_colors[Stag_Text_Cycle_3] = 0xFF0030B0;
|
|
|
|
default_colors[Stag_Text_Cycle_4] = 0xFFA0A000;
|
2019-02-27 21:14:25 +00:00
|
|
|
|
|
|
|
default_colors[Stag_Line_Numbers_Back] = 0xFF101010;
|
|
|
|
default_colors[Stag_Line_Numbers_Text] = 0xFF404040;
|
2019-02-25 23:42:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Color_Table color_table = {};
|
|
|
|
color_table.vals = default_colors;
|
|
|
|
color_table.count = ArrayCount(default_colors);
|
|
|
|
return(color_table);
|
|
|
|
}
|
2019-10-14 22:57:47 +00:00
|
|
|
#endif
|
2019-02-25 23:42:13 +00:00
|
|
|
|
2019-10-15 03:26:00 +00:00
|
|
|
function Rect_f32_Pair
|
|
|
|
layout_file_bar_on_top(Rect_f32 rect, f32 line_height){
|
|
|
|
return(rect_split_top_bottom(rect, line_height + 2.f));
|
|
|
|
}
|
|
|
|
|
|
|
|
function Rect_f32_Pair
|
|
|
|
layout_file_bar_on_bot(Rect_f32 rect, f32 line_height){
|
|
|
|
return(rect_split_top_bottom_neg(rect, line_height + 2.f));
|
|
|
|
}
|
|
|
|
|
2019-10-14 22:57:47 +00:00
|
|
|
function Rect_f32
|
2019-10-15 03:26:00 +00:00
|
|
|
default_buffer_region(Application_Links *app, View_ID view_id, Rect_f32 region){
|
|
|
|
region = rect_inner(region, 3.f);
|
|
|
|
|
2019-06-19 02:31:59 +00:00
|
|
|
Buffer_ID buffer = view_get_buffer(app, view_id, AccessAll);
|
2019-06-20 04:45:58 +00:00
|
|
|
Face_ID face_id = get_face_id(app, buffer);
|
|
|
|
Face_Metrics metrics = get_face_metrics(app, face_id);
|
2019-10-15 03:26:00 +00:00
|
|
|
f32 line_height = metrics.line_height;
|
2019-02-27 05:49:35 +00:00
|
|
|
|
|
|
|
// file bar
|
2019-10-15 03:26:00 +00:00
|
|
|
b64 showing_file_bar = false;
|
|
|
|
if (view_get_setting(app, view_id, ViewSetting_ShowFileBar, &showing_file_bar) &&
|
|
|
|
showing_file_bar){
|
|
|
|
Rect_f32_Pair pair = layout_file_bar_on_top(region, line_height);
|
|
|
|
region = pair.b;
|
2019-02-27 05:49:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// query bar
|
|
|
|
{
|
|
|
|
Query_Bar *space[32];
|
|
|
|
Query_Bar_Ptr_Array query_bars = {};
|
|
|
|
query_bars.ptrs = space;
|
|
|
|
if (get_active_query_bars(app, view_id, ArrayCount(space), &query_bars)){
|
2019-10-15 03:26:00 +00:00
|
|
|
f32 widget_height = (line_height + 2)*query_bars.count;
|
|
|
|
region.y0 += widget_height;
|
2019-02-27 05:49:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-27 21:14:25 +00:00
|
|
|
// line number margins
|
|
|
|
if (global_config.show_line_number_margins){
|
2019-10-09 14:40:50 +00:00
|
|
|
i64 line_count = buffer_get_line_count(app, buffer);
|
|
|
|
i64 line_count_digit_count = digit_count_from_integer(line_count, 10);
|
|
|
|
i32 margin_width = i32_ceil32((f32)line_count_digit_count*metrics.normal_advance);
|
2019-10-15 03:26:00 +00:00
|
|
|
region.x0 += margin_width + 2;
|
2019-02-27 21:14:25 +00:00
|
|
|
}
|
|
|
|
|
2019-10-15 03:26:00 +00:00
|
|
|
return(region);
|
2019-02-27 05:49:35 +00:00
|
|
|
}
|
|
|
|
|
2019-09-28 23:45:50 +00:00
|
|
|
internal int_color
|
2019-09-28 23:56:34 +00:00
|
|
|
get_token_color_cpp(Token token){
|
2019-09-28 23:45:50 +00:00
|
|
|
int_color result = Stag_Default;
|
2019-09-30 03:05:16 +00:00
|
|
|
switch (token.kind){
|
|
|
|
case TokenBaseKind_Preprocessor:
|
|
|
|
{
|
|
|
|
result = Stag_Preproc;
|
|
|
|
}break;
|
|
|
|
case TokenBaseKind_Keyword:
|
|
|
|
{
|
|
|
|
result = Stag_Keyword;
|
|
|
|
}break;
|
|
|
|
case TokenBaseKind_Comment:
|
|
|
|
{
|
|
|
|
result = Stag_Comment;
|
|
|
|
}break;
|
|
|
|
case TokenBaseKind_LiteralString:
|
|
|
|
{
|
|
|
|
result = Stag_Str_Constant;
|
|
|
|
}break;
|
|
|
|
case TokenBaseKind_LiteralInteger:
|
|
|
|
{
|
|
|
|
result = Stag_Int_Constant;
|
|
|
|
}break;
|
|
|
|
case TokenBaseKind_LiteralFloat:
|
|
|
|
{
|
|
|
|
result = Stag_Float_Constant;
|
|
|
|
}break;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
switch (token.sub_kind){
|
|
|
|
case TokenCppKind_LiteralTrue:
|
|
|
|
case TokenCppKind_LiteralFalse:
|
|
|
|
{
|
|
|
|
result = Stag_Bool_Constant;
|
|
|
|
}break;
|
|
|
|
case TokenCppKind_LiteralCharacter:
|
|
|
|
case TokenCppKind_LiteralCharacterWide:
|
|
|
|
case TokenCppKind_LiteralCharacterUTF8:
|
|
|
|
case TokenCppKind_LiteralCharacterUTF16:
|
|
|
|
case TokenCppKind_LiteralCharacterUTF32:
|
|
|
|
{
|
|
|
|
result = Stag_Char_Constant;
|
|
|
|
}break;
|
|
|
|
case TokenCppKind_PPIncludeFile:
|
|
|
|
{
|
|
|
|
result = Stag_Include;
|
|
|
|
}break;
|
|
|
|
}
|
|
|
|
}break;
|
2019-09-28 23:45:50 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
internal void
|
2019-10-14 06:58:49 +00:00
|
|
|
default_render_caller(Application_Links *app, Frame_Info frame_info, View_ID view_id){
|
|
|
|
View_ID active_view = get_active_view(app, AccessAll);
|
|
|
|
b32 is_active_view = (active_view == view_id);
|
|
|
|
|
|
|
|
Rect_f32 view_rect = view_get_screen_rect(app, view_id);
|
|
|
|
Rect_f32 inner = rect_inner(view_rect, 3);
|
|
|
|
draw_rectangle(app, view_rect, 0.f,
|
|
|
|
get_margin_color(is_active_view?UIHighlight_Active:UIHighlight_None));
|
|
|
|
draw_rectangle(app, inner, 0.f, Stag_Back);
|
2019-03-31 18:55:26 +00:00
|
|
|
|
2019-10-14 06:58:49 +00:00
|
|
|
Rect_f32 prev_clip = draw_set_clip(app, inner);
|
|
|
|
|
|
|
|
Buffer_ID buffer = view_get_buffer(app, view_id, AccessAll);
|
2019-06-20 04:45:58 +00:00
|
|
|
Face_ID face_id = get_face_id(app, buffer);
|
|
|
|
Face_Metrics face_metrics = get_face_metrics(app, face_id);
|
2019-04-06 21:13:49 +00:00
|
|
|
f32 line_height = face_metrics.line_height;
|
|
|
|
|
2019-10-14 06:58:49 +00:00
|
|
|
// NOTE(allen): Frame
|
|
|
|
Rect_f32 r_cursor = inner;
|
2019-03-30 21:51:56 +00:00
|
|
|
|
2019-10-14 06:58:49 +00:00
|
|
|
// NOTE(allen): Filebar
|
|
|
|
b64 showing_file_bar = false;
|
|
|
|
if (view_get_setting(app, view_id, ViewSetting_ShowFileBar, &showing_file_bar) && showing_file_bar){
|
|
|
|
Rect_f32 bar = r_cursor;
|
|
|
|
bar.y1 = bar.y0 + line_height + 2.f;
|
|
|
|
r_cursor.y0 = bar.y1;
|
|
|
|
|
|
|
|
draw_rectangle(app, bar, 0.f, Stag_Bar);
|
|
|
|
|
|
|
|
Fancy_Color base_color = fancy_id(Stag_Base);
|
|
|
|
Fancy_Color pop2_color = fancy_id(Stag_Pop2);
|
|
|
|
|
|
|
|
Scratch_Block scratch(app);
|
|
|
|
|
|
|
|
i64 cursor_position = view_get_cursor_pos(app, view_id);
|
|
|
|
Buffer_Cursor cursor = view_compute_cursor(app, view_id, seek_pos(cursor_position));
|
|
|
|
|
|
|
|
Fancy_String_List list = {};
|
|
|
|
String_Const_u8 unique_name = push_buffer_unique_name(app, scratch, buffer);
|
|
|
|
push_fancy_string(scratch, &list, base_color, unique_name);
|
|
|
|
push_fancy_stringf(scratch, &list, base_color, " - Row: %3.lld Col: %3.lld -", cursor.line, cursor.col);
|
|
|
|
|
|
|
|
b64 is_dos_mode = false;
|
|
|
|
if (buffer_get_setting(app, buffer, BufferSetting_Eol, &is_dos_mode)){
|
|
|
|
if (is_dos_mode){
|
|
|
|
push_fancy_string(scratch, &list, base_color, string_u8_litexpr(" dos"));
|
2019-09-28 23:45:50 +00:00
|
|
|
}
|
2019-10-14 06:58:49 +00:00
|
|
|
else{
|
|
|
|
push_fancy_string(scratch, &list, base_color, string_u8_litexpr(" nix"));
|
2019-09-28 23:45:50 +00:00
|
|
|
}
|
|
|
|
}
|
2019-10-14 06:58:49 +00:00
|
|
|
else{
|
|
|
|
push_fancy_string(scratch, &list, base_color, string_u8_litexpr(" ???"));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Dirty_State dirty = buffer_get_dirty_state(app, buffer);
|
|
|
|
u8 space[3];
|
|
|
|
String_u8 str = Su8(space, 0, 3);
|
|
|
|
if (dirty != 0){
|
|
|
|
string_append(&str, string_u8_litexpr(" "));
|
2018-09-27 20:15:32 +00:00
|
|
|
}
|
2019-10-14 06:58:49 +00:00
|
|
|
if (HasFlag(dirty, DirtyState_UnsavedChanges)){
|
|
|
|
string_append(&str, string_u8_litexpr("*"));
|
2018-09-27 20:15:32 +00:00
|
|
|
}
|
2019-10-14 06:58:49 +00:00
|
|
|
if (HasFlag(dirty, DirtyState_UnloadedChanges)){
|
|
|
|
string_append(&str, string_u8_litexpr("!"));
|
|
|
|
}
|
|
|
|
push_fancy_string(scratch, &list, pop2_color, str.string);
|
2018-09-30 12:14:47 +00:00
|
|
|
}
|
2019-10-14 06:58:49 +00:00
|
|
|
|
|
|
|
Vec2 p = bar.p0 + V2(0.f, 2.f);
|
|
|
|
draw_fancy_string(app, face_id, list.first, p, Stag_Default, 0);
|
2018-09-30 12:14:47 +00:00
|
|
|
}
|
|
|
|
|
2019-10-15 03:26:00 +00:00
|
|
|
Rect_f32 buffer_rect = default_buffer_region(app, view_id, view_rect);
|
2019-10-14 06:58:49 +00:00
|
|
|
Buffer_Scroll scroll = view_get_buffer_scroll(app, view_id);
|
2019-10-15 03:26:00 +00:00
|
|
|
|
|
|
|
Buffer_Point_Delta_Result delta = delta_apply(app, view_id,
|
|
|
|
frame_info.animation_dt, scroll);
|
|
|
|
if (!block_match_struct(&scroll.position, &delta.point)){
|
|
|
|
block_copy_struct(&scroll.position, &delta.point);
|
|
|
|
view_set_buffer_scroll(app, view_id, scroll, SetBufferScroll_NoCursorChange);
|
|
|
|
}
|
|
|
|
if (delta.still_animating){
|
|
|
|
animate_in_n_milliseconds(app, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
// NOTE(allen): clamp scroll target and position; smooth scroll rule
|
|
|
|
{
|
|
|
|
Vec2_f32 pending = view_point_difference(app, view_id, scroll.target, scroll.position);
|
|
|
|
if (!near_zero(pending, 0.5f)){
|
|
|
|
// TODO(allen): use the real delta rule from the context
|
|
|
|
Vec2_f32 partial = pending;
|
|
|
|
scroll.position = view_move_buffer_point(app, view_id, scroll.position, partial);
|
|
|
|
animate_in_n_milliseconds(app, 0);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
scroll.position = scroll.target;
|
|
|
|
}
|
|
|
|
view_set_buffer_scroll(app, view_id, scroll, SetBufferScroll_NoCursorChange);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-10-14 06:58:49 +00:00
|
|
|
Buffer_Point buffer_point = scroll.position;
|
|
|
|
Text_Layout_ID text_layout_id = text_layout_create(app, buffer, buffer_rect, buffer_point);
|
|
|
|
Interval_i64 visible_range = text_layout_get_visible_range(app, text_layout_id);
|
|
|
|
|
|
|
|
Scratch_Block scratch(app);
|
2019-08-01 02:13:36 +00:00
|
|
|
|
2019-08-03 21:18:40 +00:00
|
|
|
{
|
2019-10-14 06:58:49 +00:00
|
|
|
Rect_f32 prev_clip_sub = draw_set_clip(app, buffer_rect);
|
|
|
|
|
|
|
|
// NOTE(allen): Token colorizing
|
|
|
|
Token_Array token_array = get_token_array_from_buffer(app, buffer);
|
|
|
|
if (token_array.tokens != 0){
|
|
|
|
i64 first_index = token_index_from_pos(&token_array, visible_range.first);
|
|
|
|
Token_Iterator_Array it = token_iterator_index(buffer, &token_array, first_index);
|
|
|
|
for (;;){
|
|
|
|
Token *token = token_it_read(&it);
|
|
|
|
if (token->pos >= visible_range.one_past_last){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
int_color color = get_token_color_cpp(*token);
|
|
|
|
paint_text_color(app, text_layout_id, Ii64_size(token->pos, token->size), color);
|
|
|
|
|
|
|
|
if (!token_it_inc_non_whitespace(&it)){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE(allen): Scan for TODOs and NOTEs
|
|
|
|
if (global_config.use_comment_keyword){
|
2019-09-04 05:31:35 +00:00
|
|
|
Temp_Memory temp = begin_temp(scratch);
|
2019-10-14 06:58:49 +00:00
|
|
|
String_Const_u8 tail = push_buffer_range(app, scratch, buffer, visible_range);
|
|
|
|
i32 index = 0;
|
|
|
|
for (;tail.size > 0; tail = string_skip(tail, 1), index += 1){
|
|
|
|
if (string_match(string_prefix(tail, 4), string_u8_litexpr("NOTE"))){
|
|
|
|
Interval_i64 range = Ii64_size(visible_range.first + index, 4);
|
|
|
|
paint_text_color(app, text_layout_id, range, Stag_Text_Cycle_2);
|
|
|
|
tail = string_skip(tail, 3);
|
|
|
|
index += 3;
|
|
|
|
}
|
|
|
|
else if (string_match(string_prefix(tail, 4), string_u8_litexpr("TODO"))){
|
|
|
|
Interval_i64 range = Ii64_size(visible_range.first + index, 4);
|
|
|
|
paint_text_color(app, text_layout_id, range, Stag_Text_Cycle_1);
|
|
|
|
tail = string_skip(tail, 3);
|
|
|
|
index += 3;
|
|
|
|
}
|
2019-08-03 21:18:40 +00:00
|
|
|
}
|
2019-09-04 05:31:35 +00:00
|
|
|
end_temp(temp);
|
2019-08-03 21:18:40 +00:00
|
|
|
}
|
2019-10-14 06:58:49 +00:00
|
|
|
|
|
|
|
i64 cursor_pos = view_get_cursor_pos(app, view_id);
|
|
|
|
i64 mark_pos = view_get_mark_pos(app, view_id);
|
|
|
|
|
|
|
|
// NOTE(allen): Scope highlight
|
|
|
|
if (do_matching_enclosure_highlight){
|
|
|
|
static const i32 color_count = 4;
|
|
|
|
int_color colors[color_count];
|
|
|
|
for (u16 i = 0; i < color_count; i += 1){
|
|
|
|
colors[i] = Stag_Back_Cycle_1 + i;
|
2019-08-02 20:07:08 +00:00
|
|
|
}
|
2019-10-14 06:58:49 +00:00
|
|
|
draw_enclosures(app, text_layout_id, buffer,
|
|
|
|
cursor_pos, FindNest_Scope, RangeHighlightKind_LineHighlight,
|
|
|
|
colors, 0, color_count);
|
2019-08-02 20:07:08 +00:00
|
|
|
}
|
2019-10-14 06:58:49 +00:00
|
|
|
|
|
|
|
// NOTE(allen): Error highlight
|
|
|
|
{
|
|
|
|
String_Const_u8 name = string_u8_litexpr("*compilation*");
|
|
|
|
Buffer_ID compilation_buffer = get_buffer_by_name(app, name, AccessAll);
|
|
|
|
if (compilation_buffer != 0){
|
|
|
|
Managed_Scope scopes[2];
|
|
|
|
scopes[0] = buffer_get_managed_scope(app, compilation_buffer);
|
|
|
|
scopes[1] = buffer_get_managed_scope(app, buffer);
|
|
|
|
Managed_Scope comp_scope = get_managed_scope_with_multiple_dependencies(app, scopes, ArrayCount(scopes));
|
|
|
|
Managed_Object *markers_object = scope_attachment(app, comp_scope, sticky_jump_marker_handle, Managed_Object);
|
|
|
|
|
|
|
|
Temp_Memory temp = begin_temp(scratch);
|
|
|
|
i32 count = managed_object_get_item_count(app, *markers_object);
|
|
|
|
Marker *markers = push_array(scratch, Marker, count);
|
|
|
|
managed_object_load_data(app, *markers_object, 0, count, markers);
|
|
|
|
for (i32 i = 0; i < count; i += 1){
|
|
|
|
i64 line_number = get_line_number_from_pos(app, buffer, markers[i].pos);
|
|
|
|
draw_line_highlight(app, text_layout_id, line_number,
|
|
|
|
Stag_Highlight_Junk);
|
|
|
|
}
|
|
|
|
end_temp(temp);
|
|
|
|
}
|
2019-08-02 20:07:08 +00:00
|
|
|
}
|
2019-10-14 06:58:49 +00:00
|
|
|
|
|
|
|
// NOTE(allen): Color parens
|
|
|
|
if (do_matching_paren_highlight){
|
|
|
|
i64 pos = cursor_pos;
|
|
|
|
if (buffer_get_char(app, buffer, pos) == '('){
|
|
|
|
pos += 1;
|
2019-08-02 20:07:08 +00:00
|
|
|
}
|
2019-10-14 06:58:49 +00:00
|
|
|
else if (pos > 0){
|
|
|
|
if (buffer_get_char(app, buffer, pos - 1) == ')'){
|
|
|
|
pos -= 1;
|
2019-08-02 20:07:08 +00:00
|
|
|
}
|
|
|
|
}
|
2019-10-14 06:58:49 +00:00
|
|
|
static const i32 color_count = 4;
|
|
|
|
int_color colors[color_count];
|
|
|
|
for (u16 i = 0; i < color_count; i += 1){
|
|
|
|
colors[i] = Stag_Text_Cycle_1 + i;
|
|
|
|
}
|
|
|
|
draw_enclosures(app, text_layout_id, buffer,
|
|
|
|
cursor_pos, FindNest_Paren, RangeHighlightKind_CharacterHighlight,
|
|
|
|
0, colors, color_count);
|
2019-08-02 20:07:08 +00:00
|
|
|
}
|
2019-10-14 06:58:49 +00:00
|
|
|
|
|
|
|
// NOTE(allen): Line highlight
|
|
|
|
if (highlight_line_at_cursor && is_active_view){
|
|
|
|
i64 line_number = get_line_number_from_pos(app, buffer, cursor_pos);
|
|
|
|
draw_line_highlight(app, text_layout_id, line_number, Stag_Highlight_Cursor_Line);
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE(allen): Roundness
|
|
|
|
f32 cursor_roundness = 4.f;
|
|
|
|
f32 mark_thickness = 2.f;
|
|
|
|
|
|
|
|
// NOTE(allen): Highlight range
|
|
|
|
b32 has_highlight_range = false;
|
|
|
|
{
|
|
|
|
Managed_Scope scope = view_get_managed_scope(app, view_id);
|
|
|
|
Buffer_ID *highlight_buffer = scope_attachment(app, scope, view_highlight_buffer, Buffer_ID);
|
|
|
|
if (*highlight_buffer != 0){
|
|
|
|
if (*highlight_buffer != buffer){
|
|
|
|
view_disable_highlight_range(app, view_id);
|
2019-08-01 02:13:36 +00:00
|
|
|
}
|
|
|
|
else{
|
2019-10-14 06:58:49 +00:00
|
|
|
has_highlight_range = true;
|
|
|
|
Managed_Object *highlight = scope_attachment(app, scope, view_highlight_range, Managed_Object);
|
|
|
|
Marker marker_range[2];
|
|
|
|
if (managed_object_load_data(app, *highlight, 0, 2, marker_range)){
|
|
|
|
Range_i64 range = Ii64(marker_range[0].pos, marker_range[1].pos);
|
|
|
|
draw_character_block(app, text_layout_id, range, cursor_roundness, Stag_Highlight);
|
|
|
|
paint_text_color(app, text_layout_id, range, Stag_At_Highlight);
|
|
|
|
}
|
2018-09-30 12:14:47 +00:00
|
|
|
}
|
2019-10-14 06:58:49 +00:00
|
|
|
}
|
2018-09-30 12:14:47 +00:00
|
|
|
}
|
2019-10-14 06:58:49 +00:00
|
|
|
|
|
|
|
// NOTE(allen): Cursor and mark
|
|
|
|
if (!has_highlight_range){
|
|
|
|
switch (fcoder_mode){
|
|
|
|
case FCoderMode_Original:
|
|
|
|
{
|
|
|
|
if (is_active_view){
|
|
|
|
draw_character_block(app, text_layout_id, cursor_pos,
|
|
|
|
cursor_roundness, Stag_Cursor);
|
|
|
|
paint_text_color_pos(app, text_layout_id, cursor_pos,
|
|
|
|
Stag_At_Cursor);
|
|
|
|
draw_character_wire_frame(app, text_layout_id, mark_pos,
|
|
|
|
cursor_roundness, mark_thickness,
|
|
|
|
Stag_Mark);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
draw_character_wire_frame(app, text_layout_id, mark_pos,
|
|
|
|
cursor_roundness, mark_thickness,
|
|
|
|
Stag_Mark);
|
|
|
|
draw_character_wire_frame(app, text_layout_id, cursor_pos,
|
|
|
|
cursor_roundness, mark_thickness,
|
|
|
|
Stag_Cursor);
|
|
|
|
}
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case FCoderMode_NotepadLike:
|
|
|
|
{
|
|
|
|
if (cursor_pos != mark_pos){
|
|
|
|
Range_i64 range = Ii64(cursor_pos, mark_pos);
|
|
|
|
draw_character_block(app, text_layout_id, range,
|
|
|
|
cursor_roundness, Stag_Highlight);
|
|
|
|
paint_text_color(app, text_layout_id, range, Stag_At_Highlight);
|
|
|
|
}
|
|
|
|
draw_character_i_bar(app, text_layout_id, cursor_pos, Stag_Cursor);
|
|
|
|
}break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-08 17:18:20 +00:00
|
|
|
draw_text_layout(app, text_layout_id);
|
2019-10-14 06:58:49 +00:00
|
|
|
draw_set_clip(app, prev_clip_sub);
|
2019-10-08 17:18:20 +00:00
|
|
|
}
|
2018-09-22 23:45:24 +00:00
|
|
|
|
2019-02-25 23:42:13 +00:00
|
|
|
// NOTE(allen): FPS HUD
|
|
|
|
if (show_fps_hud){
|
|
|
|
static const i32 history_depth = 10;
|
|
|
|
static f32 history_literal_dt[history_depth] = {};
|
|
|
|
static f32 history_animation_dt[history_depth] = {};
|
|
|
|
static i32 history_frame_index[history_depth] = {};
|
|
|
|
|
2019-03-31 18:55:26 +00:00
|
|
|
i32 wrapped_index = frame_info.index%history_depth;
|
|
|
|
history_literal_dt[wrapped_index] = frame_info.literal_dt;
|
|
|
|
history_animation_dt[wrapped_index] = frame_info.animation_dt;
|
|
|
|
history_frame_index[wrapped_index] = frame_info.index;
|
2019-02-25 23:42:13 +00:00
|
|
|
|
2019-06-19 02:31:59 +00:00
|
|
|
Rect_f32 hud_rect = view_get_screen_rect(app, view_id);
|
2019-04-06 21:13:49 +00:00
|
|
|
hud_rect.y0 = hud_rect.y1 - line_height*(f32)(history_depth);
|
2019-10-08 17:18:20 +00:00
|
|
|
draw_rectangle(app, hud_rect, 0.f, 0xFF000000);
|
|
|
|
draw_rectangle_outline(app, hud_rect, 0.f, 1.f, 0xFFFFFFFF);
|
2019-02-25 23:42:13 +00:00
|
|
|
|
|
|
|
Vec2 p = hud_rect.p0;
|
|
|
|
|
|
|
|
Range ranges[2];
|
|
|
|
ranges[0].first = wrapped_index;
|
|
|
|
ranges[0].one_past_last = -1;
|
|
|
|
ranges[1].first = history_depth - 1;
|
|
|
|
ranges[1].one_past_last = wrapped_index;
|
|
|
|
for (i32 i = 0; i < 2; i += 1){
|
|
|
|
Range r = ranges[i];
|
2019-04-06 21:13:49 +00:00
|
|
|
for (i32 j = r.first; j > r.one_past_last; j -= 1, p.y += line_height){
|
2019-02-25 23:42:13 +00:00
|
|
|
f32 dts[2];
|
|
|
|
dts[0] = history_literal_dt[j];
|
|
|
|
dts[1] = history_animation_dt[j];
|
|
|
|
i32 frame_index = history_frame_index[j];
|
|
|
|
|
|
|
|
Fancy_String_List list = {};
|
2019-06-01 23:58:28 +00:00
|
|
|
push_fancy_stringf(scratch, &list, pink , "FPS: ");
|
|
|
|
push_fancy_stringf(scratch, &list, green, "[");
|
|
|
|
push_fancy_stringf(scratch, &list, white, "%5d", frame_index);
|
|
|
|
push_fancy_stringf(scratch, &list, green, "]: ");
|
2019-02-25 23:42:13 +00:00
|
|
|
|
|
|
|
for (i32 k = 0; k < 2; k += 1){
|
|
|
|
f32 dt = dts[k];
|
|
|
|
if (dt == 0.f){
|
2019-06-01 23:58:28 +00:00
|
|
|
push_fancy_stringf(scratch, &list, white, "----------");
|
2019-02-25 23:42:13 +00:00
|
|
|
}
|
|
|
|
else{
|
2019-06-01 23:58:28 +00:00
|
|
|
push_fancy_stringf(scratch, &list, white, "%10.6f", dt);
|
2019-02-25 23:42:13 +00:00
|
|
|
}
|
2019-06-01 23:58:28 +00:00
|
|
|
push_fancy_stringf(scratch, &list, green, " | ");
|
2019-02-25 23:42:13 +00:00
|
|
|
}
|
|
|
|
|
2019-04-06 21:13:49 +00:00
|
|
|
draw_fancy_string(app, face_id, list.first, p, Stag_Default, 0, 0, V2(1.f, 0.f));
|
2019-02-25 23:42:13 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-01 06:14:31 +00:00
|
|
|
|
|
|
|
animate_in_n_milliseconds(app, 1000);
|
2019-02-25 23:42:13 +00:00
|
|
|
}
|
|
|
|
|
2019-08-24 01:52:01 +00:00
|
|
|
// NOTE(allen): Query Bars
|
|
|
|
{
|
|
|
|
Query_Bar *space[32];
|
|
|
|
Query_Bar_Ptr_Array query_bars = {};
|
|
|
|
query_bars.ptrs = space;
|
|
|
|
if (get_active_query_bars(app, view_id, ArrayCount(space), &query_bars)){
|
|
|
|
for (i32 i = 0; i < query_bars.count; i += 1){
|
|
|
|
Query_Bar *query_bar = query_bars.ptrs[i];
|
|
|
|
|
|
|
|
Rect_f32 bar = r_cursor;
|
|
|
|
bar.y1 = bar.y0 + line_height + 2.f;
|
|
|
|
r_cursor.y0 = bar.y1;
|
|
|
|
|
|
|
|
Temp_Memory temp = begin_temp(scratch);
|
|
|
|
Fancy_String_List list = {};
|
|
|
|
|
|
|
|
Fancy_Color default_color = fancy_id(Stag_Default);
|
|
|
|
Fancy_Color pop1_color = fancy_id(Stag_Pop1);
|
|
|
|
|
|
|
|
push_fancy_string(scratch, &list, pop1_color , query_bar->prompt);
|
|
|
|
push_fancy_string(scratch, &list, default_color, query_bar->string);
|
|
|
|
|
|
|
|
Vec2 p = bar.p0 + V2(0.f, 2.f);
|
|
|
|
draw_fancy_string(app, face_id, list.first, p, Stag_Default, 0);
|
|
|
|
|
|
|
|
end_temp(temp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE(allen): Line Numbers
|
|
|
|
if (global_config.show_line_number_margins){
|
2019-10-07 03:53:10 +00:00
|
|
|
i64 line_count = buffer_get_line_count(app, buffer);
|
|
|
|
i64 line_count_digit_count = digit_count_from_integer(line_count, 10);
|
2019-08-24 01:52:01 +00:00
|
|
|
// TODO(allen): I need a "digit width"
|
|
|
|
f32 zero = get_string_advance(app, face_id, string_u8_litexpr("0"));
|
2019-10-07 03:53:10 +00:00
|
|
|
f32 margin_width = ((f32)line_count_digit_count)*zero;
|
2019-08-24 01:52:01 +00:00
|
|
|
|
|
|
|
Rect_f32 left_margin = r_cursor;
|
2019-10-07 03:53:10 +00:00
|
|
|
left_margin.x1 = left_margin.x0 + margin_width + 2.f;
|
2019-08-24 01:52:01 +00:00
|
|
|
r_cursor.x0 = left_margin.x1;
|
|
|
|
|
2019-10-08 17:18:20 +00:00
|
|
|
draw_rectangle(app, left_margin, 0.f, Stag_Line_Numbers_Back);
|
2019-08-24 01:52:01 +00:00
|
|
|
|
2019-10-14 06:58:49 +00:00
|
|
|
Rect_f32 prev_clip_line_numbers = draw_set_clip(app, left_margin);
|
2019-08-24 01:52:01 +00:00
|
|
|
|
|
|
|
Fancy_Color line_color = fancy_id(Stag_Line_Numbers_Text);
|
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
Buffer_Cursor cursor = view_compute_cursor(app, view_id, seek_pos(visible_range.first));
|
2019-10-07 03:53:10 +00:00
|
|
|
i64 line_number = cursor.line;
|
2019-09-02 18:59:36 +00:00
|
|
|
for (;cursor.pos <= visible_range.one_past_last;){
|
2019-10-07 03:53:10 +00:00
|
|
|
if (line_number > line_count){
|
2019-08-24 01:52:01 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-10-07 03:53:10 +00:00
|
|
|
Range_f32 line_y = text_layout_line_on_screen(app, text_layout_id, line_number);
|
|
|
|
Vec2_f32 p = V2f32(left_margin.x0, line_y.min);
|
|
|
|
Temp_Memory_Block temp(scratch);
|
|
|
|
Fancy_String *line_string = push_fancy_stringf(scratch, line_color, "%*lld", line_count_digit_count, line_number);
|
|
|
|
draw_fancy_string(app, face_id, line_string, p, Stag_Margin_Active, 0);
|
|
|
|
line_number += 1;
|
2019-08-24 01:52:01 +00:00
|
|
|
}
|
|
|
|
|
2019-10-14 06:58:49 +00:00
|
|
|
draw_set_clip(app, prev_clip_line_numbers);
|
2019-08-24 01:52:01 +00:00
|
|
|
}
|
2019-10-07 03:53:10 +00:00
|
|
|
|
|
|
|
text_layout_free(app, text_layout_id);
|
2019-08-16 02:53:11 +00:00
|
|
|
|
2019-10-08 17:18:20 +00:00
|
|
|
draw_set_clip(app, prev_clip);
|
2019-03-31 18:55:26 +00:00
|
|
|
}
|
|
|
|
|
2017-01-29 00:03:23 +00:00
|
|
|
HOOK_SIG(default_view_adjust){
|
2019-10-15 03:26:00 +00:00
|
|
|
// NOTE(allen): Called whenever the view layout/sizes have been modified,
|
|
|
|
// including by full window resize.
|
2019-02-24 07:22:16 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2017-11-30 23:25:49 +00:00
|
|
|
BUFFER_NAME_RESOLVER_SIG(default_buffer_name_resolution){
|
2017-12-01 18:04:07 +00:00
|
|
|
if (conflict_count > 1){
|
|
|
|
// List of unresolved conflicts
|
2019-06-01 23:58:28 +00:00
|
|
|
Scratch_Block scratch(app);
|
2017-11-30 23:25:49 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
i32 *unresolved = push_array(scratch, i32, conflict_count);
|
2019-02-26 23:08:42 +00:00
|
|
|
i32 unresolved_count = conflict_count;
|
|
|
|
for (i32 i = 0; i < conflict_count; ++i){
|
2017-12-01 18:04:07 +00:00
|
|
|
unresolved[i] = i;
|
|
|
|
}
|
2017-11-30 23:25:49 +00:00
|
|
|
|
2017-12-01 18:04:07 +00:00
|
|
|
// Resolution Loop
|
2019-02-26 23:08:42 +00:00
|
|
|
i32 x = 0;
|
2017-12-01 18:04:07 +00:00
|
|
|
for (;;){
|
|
|
|
// Resolution Pass
|
|
|
|
++x;
|
2019-02-26 23:08:42 +00:00
|
|
|
for (i32 i = 0; i < unresolved_count; ++i){
|
|
|
|
i32 conflict_index = unresolved[i];
|
2017-12-01 18:04:07 +00:00
|
|
|
Buffer_Name_Conflict_Entry *conflict = &conflicts[conflict_index];
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
umem size = conflict->base_name.size;
|
|
|
|
size = clamp_top(size, conflict->unique_name_capacity);
|
|
|
|
conflict->unique_name_len_in_out = size;
|
2019-09-27 23:56:05 +00:00
|
|
|
block_copy(conflict->unique_name_in_out, conflict->base_name.str, size);
|
2017-12-01 18:04:07 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
if (conflict->file_name.str != 0){
|
2019-10-05 20:28:08 +00:00
|
|
|
Temp_Memory_Block temp(scratch);
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8 uniqueifier = {};
|
2018-10-10 04:40:30 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8 file_name = string_remove_last_folder(conflict->file_name);
|
|
|
|
if (file_name.size > 0){
|
|
|
|
file_name = string_chop(file_name, 1);
|
|
|
|
u8 *end = file_name.str + file_name.size;
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 past_the_end = false;
|
|
|
|
for (i32 j = 0; j < x; ++j){
|
2019-06-01 23:58:28 +00:00
|
|
|
file_name = string_remove_last_folder(file_name);
|
2018-10-10 04:40:30 +00:00
|
|
|
if (j + 1 < x){
|
2019-06-01 23:58:28 +00:00
|
|
|
file_name = string_chop(file_name, 1);
|
2018-10-10 04:40:30 +00:00
|
|
|
}
|
2019-06-01 23:58:28 +00:00
|
|
|
if (file_name.size == 0){
|
2018-10-10 04:40:30 +00:00
|
|
|
if (j + 1 < x){
|
|
|
|
past_the_end = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-12-01 18:04:07 +00:00
|
|
|
}
|
2019-06-01 23:58:28 +00:00
|
|
|
u8 *start = file_name.str + file_name.size;
|
2018-10-10 04:40:30 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
uniqueifier = SCu8(start, end);
|
2018-10-10 04:40:30 +00:00
|
|
|
if (past_the_end){
|
2019-06-18 22:56:09 +00:00
|
|
|
uniqueifier = push_u8_stringf(scratch, "%.*s~%d",
|
2019-06-01 23:58:28 +00:00
|
|
|
string_expand(uniqueifier), i);
|
2017-12-01 18:04:07 +00:00
|
|
|
}
|
|
|
|
}
|
2018-10-10 04:40:30 +00:00
|
|
|
else{
|
2019-06-18 22:56:09 +00:00
|
|
|
uniqueifier = push_u8_stringf(scratch, "%d", i);
|
2018-10-10 04:40:30 +00:00
|
|
|
}
|
2017-12-01 18:04:07 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
String_u8 builder = Su8(conflict->unique_name_in_out,
|
|
|
|
conflict->unique_name_len_in_out,
|
|
|
|
conflict->unique_name_capacity);
|
|
|
|
string_append(&builder, string_u8_litexpr(" <"));
|
|
|
|
string_append(&builder, uniqueifier);
|
|
|
|
string_append(&builder, string_u8_litexpr(">"));
|
2017-12-01 19:13:36 +00:00
|
|
|
conflict->unique_name_len_in_out = builder.size;
|
2017-12-01 18:04:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Conflict Check Pass
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 has_conflicts = false;
|
|
|
|
for (i32 i = 0; i < unresolved_count; ++i){
|
|
|
|
i32 conflict_index = unresolved[i];
|
2017-12-01 18:04:07 +00:00
|
|
|
Buffer_Name_Conflict_Entry *conflict = &conflicts[conflict_index];
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8 conflict_name = SCu8(conflict->unique_name_in_out,
|
|
|
|
conflict->unique_name_len_in_out);
|
2017-12-01 18:04:07 +00:00
|
|
|
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 hit_conflict = false;
|
2019-06-01 23:58:28 +00:00
|
|
|
if (conflict->file_name.str != 0){
|
2019-02-26 23:08:42 +00:00
|
|
|
for (i32 j = 0; j < unresolved_count; ++j){
|
2017-12-01 18:04:07 +00:00
|
|
|
if (i == j) continue;
|
|
|
|
|
2019-02-26 23:08:42 +00:00
|
|
|
i32 conflict_j_index = unresolved[j];
|
2017-12-01 18:04:07 +00:00
|
|
|
Buffer_Name_Conflict_Entry *conflict_j = &conflicts[conflict_j_index];
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8 conflict_name_j = SCu8(conflict_j->unique_name_in_out,
|
|
|
|
conflict_j->unique_name_len_in_out);
|
|
|
|
|
|
|
|
if (string_match(conflict_name, conflict_name_j)){
|
2017-12-01 18:04:07 +00:00
|
|
|
hit_conflict = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hit_conflict){
|
|
|
|
has_conflicts = true;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
--unresolved_count;
|
|
|
|
unresolved[i] = unresolved[unresolved_count];
|
|
|
|
--i;
|
|
|
|
}
|
2017-11-30 23:25:49 +00:00
|
|
|
}
|
2017-12-01 18:04:07 +00:00
|
|
|
|
|
|
|
if (!has_conflicts){
|
2017-11-30 23:25:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-29 02:13:46 +00:00
|
|
|
internal void
|
|
|
|
do_full_lex(Application_Links *app, Buffer_ID buffer_id){
|
|
|
|
Scratch_Block scratch(app);
|
|
|
|
String_Const_u8 contents = push_whole_buffer(app, scratch, buffer_id);
|
|
|
|
Token_List list = lex_full_input_cpp(scratch, contents);
|
|
|
|
|
|
|
|
Managed_Scope scope = buffer_get_managed_scope(app, buffer_id);
|
|
|
|
Base_Allocator *allocator = managed_scope_allocator(app, scope);
|
|
|
|
Token_Array tokens = {};
|
|
|
|
tokens.tokens = base_array(allocator, Token, list.total_count);
|
|
|
|
tokens.count = list.total_count;
|
|
|
|
tokens.max = list.total_count;
|
|
|
|
token_fill_memory_from_list(tokens.tokens, &list);
|
|
|
|
|
|
|
|
Token_Array *tokens_ptr = scope_attachment(app, scope, attachment_tokens, Token_Array);
|
|
|
|
block_copy_struct(tokens_ptr, &tokens);
|
|
|
|
}
|
|
|
|
|
2019-09-04 05:31:35 +00:00
|
|
|
BUFFER_HOOK_SIG(default_file_settings){
|
2019-02-26 19:59:57 +00:00
|
|
|
b32 treat_as_code = false;
|
|
|
|
b32 lex_without_strings = false;
|
2019-09-04 05:31:35 +00:00
|
|
|
(void)(lex_without_strings);
|
2017-01-29 00:03:23 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8_Array extensions = global_config.code_exts;
|
2017-02-26 21:44:40 +00:00
|
|
|
|
2019-10-01 02:06:21 +00:00
|
|
|
Scratch_Block scratch(app);
|
2019-04-04 08:25:16 +00:00
|
|
|
|
2019-06-02 03:07:57 +00:00
|
|
|
String_Const_u8 file_name = push_buffer_file_name(app, scratch, buffer_id);
|
2019-04-04 08:25:16 +00:00
|
|
|
|
2019-09-04 05:31:35 +00:00
|
|
|
if (file_name.size > 0){
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8 ext = string_file_extension(file_name);
|
2019-02-26 23:08:42 +00:00
|
|
|
for (i32 i = 0; i < extensions.count; ++i){
|
2019-06-01 23:58:28 +00:00
|
|
|
if (string_match(ext, extensions.strings[i])){
|
2019-09-04 05:31:35 +00:00
|
|
|
|
|
|
|
if (string_match(ext, string_u8_litexpr("cpp")) ||
|
|
|
|
string_match(ext, string_u8_litexpr("h")) ||
|
|
|
|
string_match(ext, string_u8_litexpr("c")) ||
|
|
|
|
string_match(ext, string_u8_litexpr("hpp")) ||
|
|
|
|
string_match(ext, string_u8_litexpr("cc"))){
|
|
|
|
treat_as_code = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
2017-02-26 21:44:40 +00:00
|
|
|
treat_as_code = true;
|
2017-05-21 01:22:20 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
if (string_match(ext, string_u8_litexpr("cs"))){
|
2017-05-21 01:22:20 +00:00
|
|
|
if (parse_context_language_cs == 0){
|
|
|
|
init_language_cs(app);
|
|
|
|
}
|
|
|
|
parse_context_id = parse_context_language_cs;
|
|
|
|
}
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
if (string_match(ext, string_u8_litexpr("java"))){
|
2017-05-21 01:22:20 +00:00
|
|
|
if (parse_context_language_java == 0){
|
|
|
|
init_language_java(app);
|
|
|
|
}
|
|
|
|
parse_context_id = parse_context_language_java;
|
|
|
|
}
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
if (string_match(ext, string_u8_litexpr("rs"))){
|
2017-05-21 01:22:20 +00:00
|
|
|
if (parse_context_language_rust == 0){
|
|
|
|
init_language_rust(app);
|
|
|
|
}
|
|
|
|
parse_context_id = parse_context_language_rust;
|
2017-11-27 21:13:17 +00:00
|
|
|
lex_without_strings = true;
|
2017-05-21 01:22:20 +00:00
|
|
|
}
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
if (string_match(ext, string_u8_litexpr("cpp")) ||
|
|
|
|
string_match(ext, string_u8_litexpr("h")) ||
|
|
|
|
string_match(ext, string_u8_litexpr("c")) ||
|
|
|
|
string_match(ext, string_u8_litexpr("hpp")) ||
|
|
|
|
string_match(ext, string_u8_litexpr("cc"))){
|
2017-11-08 04:41:45 +00:00
|
|
|
if (parse_context_language_cpp == 0){
|
|
|
|
init_language_cpp(app);
|
|
|
|
}
|
|
|
|
parse_context_id = parse_context_language_cpp;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(NAME): Real GLSL highlighting
|
2019-06-01 23:58:28 +00:00
|
|
|
if (string_match(ext, string_u8_litexpr("glsl"))){
|
2017-06-12 17:40:54 +00:00
|
|
|
if (parse_context_language_cpp == 0){
|
|
|
|
init_language_cpp(app);
|
|
|
|
}
|
|
|
|
parse_context_id = parse_context_language_cpp;
|
|
|
|
}
|
|
|
|
|
2017-06-30 01:13:20 +00:00
|
|
|
// TODO(NAME): Real Objective-C highlighting
|
2019-06-01 23:58:28 +00:00
|
|
|
if (string_match(ext, string_u8_litexpr("m"))){
|
2017-06-30 01:13:20 +00:00
|
|
|
if (parse_context_language_cpp == 0){
|
|
|
|
init_language_cpp(app);
|
|
|
|
}
|
|
|
|
parse_context_id = parse_context_language_cpp;
|
|
|
|
}
|
2019-09-04 05:31:35 +00:00
|
|
|
#endif
|
2017-06-30 01:13:20 +00:00
|
|
|
|
2017-02-26 21:44:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-01-29 00:03:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-10 18:21:47 +00:00
|
|
|
Command_Map_ID map_id = (treat_as_code)?(default_code_map):(mapid_file);
|
2019-10-10 22:57:02 +00:00
|
|
|
Managed_Scope scope = buffer_get_managed_scope(app, buffer_id);
|
|
|
|
Command_Map_ID *map_id_ptr = scope_attachment(app, scope, buffer_map_id, Command_Map_ID);
|
|
|
|
*map_id_ptr = map_id;
|
2017-01-29 00:03:23 +00:00
|
|
|
|
2018-09-07 22:39:33 +00:00
|
|
|
// NOTE(allen): Decide buffer settings
|
2019-02-26 19:59:57 +00:00
|
|
|
b32 wrap_lines = true;
|
|
|
|
b32 use_virtual_whitespace = false;
|
|
|
|
b32 use_lexer = false;
|
2019-09-04 05:31:35 +00:00
|
|
|
if (treat_as_code){
|
2018-09-07 22:39:33 +00:00
|
|
|
wrap_lines = global_config.enable_code_wrapping;
|
|
|
|
use_virtual_whitespace = global_config.enable_virtual_whitespace;
|
|
|
|
use_lexer = true;
|
|
|
|
}
|
2019-04-04 08:25:16 +00:00
|
|
|
|
2019-06-02 03:07:57 +00:00
|
|
|
String_Const_u8 buffer_name = push_buffer_base_name(app, scratch, buffer_id);
|
2019-06-01 23:58:28 +00:00
|
|
|
if (string_match(buffer_name, string_u8_litexpr("*compilation*"))){
|
2018-09-07 22:39:33 +00:00
|
|
|
wrap_lines = false;
|
|
|
|
}
|
2019-09-04 05:31:35 +00:00
|
|
|
|
|
|
|
if (use_lexer){
|
2019-09-29 02:13:46 +00:00
|
|
|
do_full_lex(app, buffer_id);
|
2018-09-07 22:39:33 +00:00
|
|
|
}
|
|
|
|
|
2017-01-29 00:03:23 +00:00
|
|
|
// no meaning for return
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2019-09-04 05:31:35 +00:00
|
|
|
BUFFER_HOOK_SIG(default_new_file){
|
2019-04-04 08:25:16 +00:00
|
|
|
// buffer_id
|
2019-09-29 02:13:46 +00:00
|
|
|
// no meaning for return
|
2017-02-26 21:44:40 +00:00
|
|
|
return(0);
|
2017-02-26 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
2019-09-04 05:31:35 +00:00
|
|
|
BUFFER_HOOK_SIG(default_file_save){
|
2019-06-19 02:31:59 +00:00
|
|
|
b32 is_virtual = false;
|
2018-05-12 07:20:37 +00:00
|
|
|
if (global_config.automatically_indent_text_on_save &&
|
2019-10-08 01:42:23 +00:00
|
|
|
is_virtual){
|
|
|
|
auto_indent_buffer(app, buffer_id, buffer_range(app, buffer_id));
|
2017-01-29 00:03:23 +00:00
|
|
|
}
|
|
|
|
// no meaning for return
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2019-10-14 22:57:47 +00:00
|
|
|
BUFFER_EDIT_RANGE_SIG(default_buffer_edit_range){
|
2019-04-04 08:25:16 +00:00
|
|
|
// buffer_id, range, text
|
2019-09-29 02:13:46 +00:00
|
|
|
|
|
|
|
Interval_i64 replace_range = Ii64(range.first, range.first + text.size);
|
|
|
|
i64 insert_size = range_size(range);
|
|
|
|
i64 text_shift = replace_range_shift(replace_range, insert_size);
|
|
|
|
|
|
|
|
Scratch_Block scratch(app);
|
|
|
|
|
|
|
|
Managed_Scope scope = buffer_get_managed_scope(app, buffer_id);
|
|
|
|
Token_Array *ptr = scope_attachment(app, scope, attachment_tokens, Token_Array);
|
|
|
|
if (ptr != 0 && ptr->tokens != 0){
|
|
|
|
i64 token_index_first = token_relex_first(ptr, range.first, 1);
|
|
|
|
i64 token_index_resync_guess = token_relex_resync(ptr, range.one_past_last, 16);
|
|
|
|
|
|
|
|
Token *token_first = ptr->tokens + token_index_first;
|
|
|
|
Token *token_resync = ptr->tokens + token_index_resync_guess;
|
|
|
|
|
2019-09-30 04:27:16 +00:00
|
|
|
Interval_i64 relex_range = Ii64(token_first->pos,
|
|
|
|
token_resync->pos + token_resync->size + text_shift);
|
2019-09-29 02:13:46 +00:00
|
|
|
String_Const_u8 partial_text = push_buffer_range(app, scratch, buffer_id, relex_range);
|
|
|
|
|
|
|
|
Token_List relex_list = lex_full_input_cpp(scratch, partial_text);
|
|
|
|
if (relex_range.one_past_last < buffer_get_size(app, buffer_id)){
|
|
|
|
token_drop_eof(&relex_list);
|
|
|
|
}
|
|
|
|
|
2019-09-30 04:27:16 +00:00
|
|
|
Token_Relex relex = token_relex(relex_list, relex_range.first - text_shift,
|
2019-09-29 02:13:46 +00:00
|
|
|
ptr->tokens, token_index_first, token_index_resync_guess);
|
|
|
|
|
|
|
|
Base_Allocator *allocator = managed_scope_allocator(app, scope);
|
|
|
|
|
|
|
|
if (relex.successful_resync){
|
|
|
|
i64 token_index_resync = relex.first_resync_index;
|
|
|
|
|
|
|
|
Interval_i64 head = Ii64(0, token_index_first);
|
2019-09-30 04:27:16 +00:00
|
|
|
Interval_i64 replaced = Ii64(token_index_first, token_index_resync);
|
2019-09-29 02:13:46 +00:00
|
|
|
Interval_i64 tail = Ii64(token_index_resync, ptr->count);
|
2019-09-30 04:27:16 +00:00
|
|
|
i64 resynced_count = (token_index_resync_guess + 1) - token_index_resync;
|
|
|
|
i64 relexed_count = relex_list.total_count - resynced_count;
|
|
|
|
i64 tail_shift = relexed_count - (token_index_resync - token_index_first);
|
2019-09-29 02:13:46 +00:00
|
|
|
|
|
|
|
i64 new_tokens_count = ptr->count + tail_shift;
|
|
|
|
Token *new_tokens = base_array(allocator, Token, new_tokens_count);
|
|
|
|
|
|
|
|
Token *old_tokens = ptr->tokens;
|
|
|
|
block_copy_array_shift(new_tokens, old_tokens, head, 0);
|
2019-09-30 04:27:16 +00:00
|
|
|
token_fill_memory_from_list(new_tokens + replaced.first, &relex_list, relexed_count);
|
|
|
|
for (i64 i = 0, index = replaced.first; i < relexed_count; i += 1, index += 1){
|
|
|
|
new_tokens[index].pos += relex_range.first;
|
|
|
|
}
|
2019-09-29 02:13:46 +00:00
|
|
|
for (i64 i = tail.first; i < tail.one_past_last; i += 1){
|
|
|
|
old_tokens[i].pos += text_shift;
|
|
|
|
}
|
|
|
|
block_copy_array_shift(new_tokens, ptr->tokens, tail, tail_shift);
|
|
|
|
|
|
|
|
base_free(allocator, ptr->tokens);
|
|
|
|
|
|
|
|
ptr->tokens = new_tokens;
|
|
|
|
ptr->count = new_tokens_count;
|
|
|
|
ptr->max = new_tokens_count;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
scratch.restore();
|
|
|
|
base_free(allocator, ptr->tokens);
|
|
|
|
do_full_lex(app, buffer_id);
|
|
|
|
}
|
2019-09-30 04:27:16 +00:00
|
|
|
|
2019-09-30 04:51:53 +00:00
|
|
|
#if 0
|
|
|
|
// NOTE(allen): Assert correctness of relex results. Enable this code
|
|
|
|
// to track down corruption of the token data.
|
2019-09-30 04:27:16 +00:00
|
|
|
{
|
|
|
|
String_Const_u8 full = push_whole_buffer(app, scratch, buffer_id);
|
|
|
|
Token_List list = lex_full_input_cpp(scratch, full);
|
|
|
|
Token_Array array = token_array_from_list(scratch, &list);
|
|
|
|
Assert(array.count == ptr->count);
|
|
|
|
Token *token_a = array.tokens;
|
|
|
|
Token *token_b = ptr->tokens;
|
|
|
|
for (i64 i = 0; i < array.count; i += 1, token_a += 1, token_b += 1){
|
|
|
|
Assert(block_match_struct(token_a, token_b));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2019-01-31 12:38:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// no meaning for return
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2019-09-04 05:31:35 +00:00
|
|
|
BUFFER_HOOK_SIG(default_end_file){
|
2019-06-01 23:58:28 +00:00
|
|
|
Scratch_Block scratch(app);
|
2019-06-02 03:07:57 +00:00
|
|
|
String_Const_u8 buffer_name = push_buffer_unique_name(app, scratch, buffer_id);
|
2019-08-13 19:37:25 +00:00
|
|
|
String_Const_u8 str = push_u8_stringf(scratch, "Ending file: %s\n", buffer_name.str);
|
2019-06-01 23:58:28 +00:00
|
|
|
print_message(app, str);
|
2017-04-18 15:41:49 +00:00
|
|
|
// no meaning for return
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
internal void
|
2019-10-10 22:57:02 +00:00
|
|
|
set_all_default_hooks(Application_Links *app){
|
2019-10-14 22:57:47 +00:00
|
|
|
#if 0
|
2019-10-10 22:57:02 +00:00
|
|
|
set_custom_hook(app, HookID_Exit, default_exit);
|
|
|
|
set_custom_hook(app, HookID_Start, default_start);
|
|
|
|
set_custom_hook(app, HookID_FileExternallyModified, default_file_externally_modified);
|
2019-10-14 22:57:47 +00:00
|
|
|
set_custom_hook(app, HookID_InputFilter, default_suppress_mouse_filter);
|
|
|
|
set_custom_hook(app, HookID_ModifyColorTable, default_modify_color_table);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
set_custom_hook(app, HookID_BufferViewerUpdate, default_view_adjust);
|
2017-04-18 15:41:49 +00:00
|
|
|
|
2019-10-13 20:17:22 +00:00
|
|
|
set_custom_hook(app, HookID_ViewEventHandler, default_view_input_handler);
|
2019-10-10 22:57:02 +00:00
|
|
|
set_custom_hook(app, HookID_RenderCaller, default_render_caller);
|
2019-10-15 03:26:00 +00:00
|
|
|
#if 0
|
|
|
|
set_custom_hook(app, HookID_DeltaRule, original_delta);
|
|
|
|
set_custom_hook_memory_size(app, HookID_DeltaRule,
|
|
|
|
delta_ctx_size(original_delta_memory_size));
|
|
|
|
#else
|
|
|
|
set_custom_hook(app, HookID_DeltaRule, fixed_time_cubic_delta);
|
|
|
|
set_custom_hook_memory_size(app, HookID_DeltaRule,
|
|
|
|
delta_ctx_size(fixed_time_cubic_delta_memory_size));
|
|
|
|
#endif
|
2019-10-10 22:57:02 +00:00
|
|
|
set_custom_hook(app, HookID_BufferNameResolver, default_buffer_name_resolution);
|
2019-10-14 22:57:47 +00:00
|
|
|
|
|
|
|
set_custom_hook(app, HookID_BeginBuffer, default_file_settings);
|
|
|
|
set_custom_hook(app, HookID_EndBuffer, end_file_close_jump_list);
|
|
|
|
set_custom_hook(app, HookID_NewFile, default_new_file);
|
|
|
|
set_custom_hook(app, HookID_SaveFile, default_file_save);
|
|
|
|
set_custom_hook(app, HookID_BufferEditRange, default_buffer_edit_range);
|
2019-10-15 03:26:00 +00:00
|
|
|
set_custom_hook(app, HookID_BufferRegion, default_buffer_region);
|
2017-01-29 00:03:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// BOTTOM
|
|
|
|
|