-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path4coder_qol_hooks.cpp
122 lines (98 loc) · 4.4 KB
/
4coder_qol_hooks.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
CUSTOM_COMMAND_SIG(qol_startup)
CUSTOM_DOC("QOL command for responding to a startup event")
{
ProfileScope(app, "qol startup");
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;
load_themes_default_folder(app);
default_4coder_initialize(app, file_names);
default_4coder_side_by_side_panels(app, file_names);
/// NOTE(BYP): Not ideal, but I'd rather simplify others testing 4coder_qol
String_ID global_map_id = vars_save_string_lit("keys_global");
String_ID file_map_id = vars_save_string_lit("keys_file");
String_ID code_map_id = vars_save_string_lit("keys_code");
qol_setup_default_mapping(&framework_mapping, global_map_id, file_map_id, code_map_id);
qol_setup_essential_mapping(&framework_mapping, global_map_id, file_map_id, code_map_id);
TAB_setup_default_mapping(&framework_mapping, global_map_id, file_map_id, code_map_id);
b32 auto_load = def_get_config_b32(vars_save_string_lit("automatically_load_project"));
if (auto_load){
load_project(app);
}
qol_temp_buffer = create_buffer(app, string_u8_litexpr("*qol_temp*"),
BufferCreate_Background | BufferCreate_AlwaysNew | BufferCreate_NeverAttachToFile);
buffer_set_setting(app, qol_temp_buffer, BufferSetting_Unimportant, true);
buffer_set_setting(app, qol_temp_buffer, BufferSetting_Unkillable, true);
buffer_set_setting(app, qol_temp_buffer, BufferSetting_ReadOnly, false);
TAB_startup_inner(app);
qol_lister_init(app);
}
{
def_audio_init();
}
{
def_enable_virtual_whitespace = def_get_config_b32(vars_save_string_lit("enable_virtual_whitespace"));
clear_all_layouts(app);
}
Face_Description desc = get_global_face_description(app);
desc.parameters.pt_size -= 4;
qol_small_face = try_create_new_face(app, &desc);
{
String_Const_u8 non_word_chars = string_u8_litexpr(" \t\n/\\()\"':,.;<>~!@#$%^&*|+=[]{}`?-");
for (u64 i = 0; i < non_word_chars.size; i += 1){
Character_Predicate pred = character_predicate_from_character(non_word_chars.str[i]);
character_predicate_non_word = character_predicate_or(&pred, &character_predicate_non_word);
}
character_predicate_word = character_predicate_not(&character_predicate_non_word);
}
Scratch_Block scratch(app);
set_active_color(get_color_table_by_name(def_get_config_string(scratch, vars_save_string_lit("default_theme_name"))));
qol_cur_colors = qol_color_table_init(app);
qol_nxt_colors = qol_color_table_init(app);
qol_color_table_copy(qol_cur_colors, active_color_table);
qol_color_table_copy(qol_nxt_colors, active_color_table);
}
function void
qol_tick(Application_Links *app, Frame_Info frame_info){
default_tick(app, frame_info);
f32 dt = frame_info.animation_dt;
qol_interp(qol_cur_cursor_pos, qol_nxt_cursor_pos, dt, 1e-14f);
if (!near_zero(qol_cur_cursor_pos - qol_nxt_cursor_pos, 0.5f)){
animate_in_n_milliseconds(app, 0);
}
qol_tick_colors(app, frame_info);
qol_tick_lister(app, frame_info);
MC_tick_inner(app, frame_info);
TAB_tick_inner(app, frame_info);
}
BUFFER_HOOK_SIG(qol_file_save){
default_file_save(app, buffer_id);
Scratch_Block scratch(app);
String_Const_u8 path = push_buffer_file_name(app, scratch, buffer_id);
String_Const_u8 name = string_front_of_path(path);
if (qol_is_theme_file(name)){
Color_Table color_table = make_color_table(app, &global_theme_arena);
Config *config = theme_parse__buffer(app, scratch, buffer_id, &global_theme_arena, &color_table);
String_Const_u8 error_text = config_stringize_errors(app, scratch, config);
comp_error(app, error_text);
if (error_text.size > 0){
print_message(app, error_text);
}
else{
qol_color_table_copy(qol_nxt_colors, color_table);
}
}
if (string_match(name, string_u8_litexpr("config.4coder"))){
View_ID view = get_active_view(app, Access_Always);
view_enqueue_command_function(app, view, qol_reload_config);
}
if (string_match(name, string_u8_litexpr("project.4coder"))){
View_ID view = get_active_view(app, Access_Always);
view_enqueue_command_function(app, view, qol_reload_project);
}
if (string_match(name, string_u8_litexpr("bindings.4coder"))){
View_ID view = get_active_view(app, Access_Always);
view_enqueue_command_function(app, view, qol_reload_bindings);
}
return 0;
}