Added hard exit API; fixed exit menus

master
Allen Webster 2020-01-02 14:37:01 -08:00
parent eb1bf82bec
commit 13ee76effe
13 changed files with 36 additions and 20 deletions

11
4ed.cpp
View File

@ -201,6 +201,7 @@ App_Read_Command_Line_Sig(app_read_command_line){
App_Init_Sig(app_init){
Models *models = (Models*)base_ptr;
models->keep_playing = true;
models->hard_exit = false;
models->config_api = api;
models->virtual_event_arena = reserve_arena(tctx);
@ -727,13 +728,9 @@ App_Step_Sig(app_step){
}
// NOTE(allen): if the exit signal has been sent, run the exit hook.
if (input->trying_to_kill){
models->keep_playing = false;
}
if (!models->keep_playing){
if (co_send_core_event(tctx, models, CoreCode_TryExit)){
if (!models->keep_playing || input->trying_to_kill){
co_send_core_event(tctx, models, CoreCode_TryExit);
models->keep_playing = true;
}
}
// NOTE(allen): rendering
@ -806,7 +803,7 @@ App_Step_Sig(app_step){
models->prev_mouse_panel = mouse_panel;
app_result.lctrl_lalt_is_altgr = models->settings.lctrl_lalt_is_altgr;
app_result.perform_kill = !models->keep_playing;
app_result.perform_kill = models->hard_exit;
app_result.animating = models->animate_next_frame;
if (models->animate_next_frame){
// NOTE(allen): Silence the timer, because we're going to do another frame right away anyways.

View File

@ -2761,6 +2761,13 @@ send_exit_signal(Application_Links *app)
models->keep_playing = false;
}
api(custom) function void
hard_exit(Application_Links *app)
{
Models *models = (Models*)app->cmd_context;
models->hard_exit = true;
}
api(custom) function void
set_window_title(Application_Links *app, String_Const_u8 title)
{

View File

@ -105,7 +105,8 @@ struct Models{
Hot_Directory hot_directory;
b32 keep_playing;
b8 keep_playing;
b8 hard_exit;
b32 has_new_title;
char *title_space;

View File

@ -65,7 +65,7 @@ CUSTOM_DOC("Inserts whatever text was used to trigger this command.")
}
CUSTOM_COMMAND_SIG(write_space)
CUSTOM_DOC("Inserts an underscore.")
CUSTOM_DOC("Inserts a space.")
{
write_text(app, string_u8_litexpr(" "));
}

View File

@ -63,7 +63,7 @@ standard_build_exec_command(Application_Links *app, View_ID view, String_Const_u
standard_build_exec_flags);
}
static b32
function b32
standard_search_and_build_from_dir(Application_Links *app, View_ID view, String_Const_u8 start_dir){
Scratch_Block scratch(app);
@ -83,7 +83,7 @@ standard_search_and_build_from_dir(Application_Links *app, View_ID view, String_
// NOTE(allen): Build
String_Const_u8 path = string_remove_last_folder(full_file_path);
#if OS_WINDOWS
String_Const_u8 command = push_u8_stringf(scratch, "%.*s/%.*s",
String_Const_u8 command = push_u8_stringf(scratch, "\"%.*s/%.*s\"",
string_expand(path),
string_expand(cmd_string));
#elif OS_LINUX || OS_MAC

View File

@ -29,12 +29,16 @@ CUSTOM_DOC("Queries for an output buffer name and system command, runs the syste
bar_out.string = SCu8(out_buffer_space, (u64)0);
bar_out.string_capacity = sizeof(out_buffer_space);
if (!query_user_string(app, &bar_out)) return;
bar_out.string.size = clamp_top(bar_out.string.size, sizeof(out_buffer_space) - 1);
out_buffer_space[bar_out.string.size] = 0;
Query_Bar bar_cmd = {};
bar_cmd.prompt = string_u8_litexpr("Command: ");
bar_cmd.string = SCu8(command_space, (u64)0);
bar_cmd.string_capacity = sizeof(command_space);
if (!query_user_string(app, &bar_cmd)) return;
bar_cmd.string.size = clamp_top(bar_cmd.string.size, sizeof(command_space) - 1);
command_space[bar_cmd.string.size] = 0;
String_Const_u8 hot = push_hot_directory(app, scratch);
{

View File

@ -43,13 +43,7 @@ CUSTOM_DOC("Default command for responding to a try-exit event")
}
}
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);
hard_exit(app);
}
}
}

View File

@ -285,7 +285,7 @@ static Command_Metadata fcoder_metacmd_table[229] = {
{ PROC_LINKS(default_file_externally_modified, 0), false, "default_file_externally_modified", 32, "Notes the external modification of attached files by printing a message.", 72, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1796 },
{ PROC_LINKS(default_startup, 0), false, "default_startup", 15, "Default command for responding to a startup event", 49, "w:\\4ed\\code\\custom\\4coder_default_hooks.cpp", 43, 7 },
{ PROC_LINKS(default_try_exit, 0), false, "default_try_exit", 16, "Default command for responding to a try-exit event", 50, "w:\\4ed\\code\\custom\\4coder_default_hooks.cpp", 43, 23 },
{ PROC_LINKS(default_view_input_handler, 0), false, "default_view_input_handler", 26, "Input consumption loop for default view behavior", 48, "w:\\4ed\\code\\custom\\4coder_default_hooks.cpp", 43, 57 },
{ PROC_LINKS(default_view_input_handler, 0), false, "default_view_input_handler", 26, "Input consumption loop for default view behavior", 48, "w:\\4ed\\code\\custom\\4coder_default_hooks.cpp", 43, 51 },
{ PROC_LINKS(delete_alpha_numeric_boundary, 0), false, "delete_alpha_numeric_boundary", 29, "Delete characters between the cursor position and the first alphanumeric boundary to the right.", 95, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 162 },
{ PROC_LINKS(delete_char, 0), false, "delete_char", 11, "Deletes the character to the right of the cursor.", 49, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 79 },
{ PROC_LINKS(delete_current_scope, 0), false, "delete_current_scope", 20, "Deletes the braces surrounding the currently selected scope. Leaves the contents within the scope.", 99, "w:\\4ed\\code\\custom\\4coder_scope_commands.cpp", 44, 112 },
@ -474,7 +474,7 @@ static Command_Metadata fcoder_metacmd_table[229] = {
{ PROC_LINKS(write_block, 0), false, "write_block", 11, "At the cursor, insert a block comment.", 38, "w:\\4ed\\code\\custom\\4coder_combined_write_commands.cpp", 53, 94 },
{ PROC_LINKS(write_hack, 0), false, "write_hack", 10, "At the cursor, insert a '// HACK' comment, includes user name if it was specified in config.4coder.", 99, "w:\\4ed\\code\\custom\\4coder_combined_write_commands.cpp", 53, 82 },
{ PROC_LINKS(write_note, 0), false, "write_note", 10, "At the cursor, insert a '// NOTE' comment, includes user name if it was specified in config.4coder.", 99, "w:\\4ed\\code\\custom\\4coder_combined_write_commands.cpp", 53, 88 },
{ PROC_LINKS(write_space, 0), false, "write_space", 11, "Inserts an underscore.", 22, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 67 },
{ PROC_LINKS(write_space, 0), false, "write_space", 11, "Inserts a space.", 16, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 67 },
{ PROC_LINKS(write_text_and_auto_indent, 0), false, "write_text_and_auto_indent", 26, "Inserts text and auto-indents the line on which the cursor sits if any of the text contains 'layout punctuation' such as ;:{}()[]# and new lines.", 145, "w:\\4ed\\code\\custom\\4coder_auto_indent.cpp", 41, 395 },
{ PROC_LINKS(write_text_input, 0), false, "write_text_input", 16, "Inserts whatever text was used to trigger this command.", 55, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 59 },
{ PROC_LINKS(write_todo, 0), false, "write_todo", 10, "At the cursor, insert a '// TODO' comment, includes user name if it was specified in config.4coder.", 99, "w:\\4ed\\code\\custom\\4coder_combined_write_commands.cpp", 53, 76 },

View File

@ -156,6 +156,7 @@ vtable->try_release_face = try_release_face;
vtable->push_hot_directory = push_hot_directory;
vtable->set_hot_directory = set_hot_directory;
vtable->send_exit_signal = send_exit_signal;
vtable->hard_exit = hard_exit;
vtable->set_window_title = set_window_title;
vtable->draw_string_oriented = draw_string_oriented;
vtable->get_string_advance = get_string_advance;
@ -336,6 +337,7 @@ try_release_face = vtable->try_release_face;
push_hot_directory = vtable->push_hot_directory;
set_hot_directory = vtable->set_hot_directory;
send_exit_signal = vtable->send_exit_signal;
hard_exit = vtable->hard_exit;
set_window_title = vtable->set_window_title;
draw_string_oriented = vtable->draw_string_oriented;
get_string_advance = vtable->get_string_advance;

View File

@ -154,6 +154,7 @@
#define custom_push_hot_directory_sig() String_Const_u8 custom_push_hot_directory(Application_Links* app, Arena* arena)
#define custom_set_hot_directory_sig() void custom_set_hot_directory(Application_Links* app, String_Const_u8 string)
#define custom_send_exit_signal_sig() void custom_send_exit_signal(Application_Links* app)
#define custom_hard_exit_sig() void custom_hard_exit(Application_Links* app)
#define custom_set_window_title_sig() void custom_set_window_title(Application_Links* app, String_Const_u8 title)
#define custom_draw_string_oriented_sig() Vec2_f32 custom_draw_string_oriented(Application_Links* app, Face_ID font_id, ARGB_Color color, String_Const_u8 str, Vec2_f32 point, u32 flags, Vec2_f32 delta)
#define custom_get_string_advance_sig() f32 custom_get_string_advance(Application_Links* app, Face_ID font_id, String_Const_u8 str)
@ -330,6 +331,7 @@ typedef b32 custom_try_release_face_type(Application_Links* app, Face_ID id, Fac
typedef String_Const_u8 custom_push_hot_directory_type(Application_Links* app, Arena* arena);
typedef void custom_set_hot_directory_type(Application_Links* app, String_Const_u8 string);
typedef void custom_send_exit_signal_type(Application_Links* app);
typedef void custom_hard_exit_type(Application_Links* app);
typedef void custom_set_window_title_type(Application_Links* app, String_Const_u8 title);
typedef Vec2_f32 custom_draw_string_oriented_type(Application_Links* app, Face_ID font_id, ARGB_Color color, String_Const_u8 str, Vec2_f32 point, u32 flags, Vec2_f32 delta);
typedef f32 custom_get_string_advance_type(Application_Links* app, Face_ID font_id, String_Const_u8 str);
@ -507,6 +509,7 @@ custom_try_release_face_type *try_release_face;
custom_push_hot_directory_type *push_hot_directory;
custom_set_hot_directory_type *set_hot_directory;
custom_send_exit_signal_type *send_exit_signal;
custom_hard_exit_type *hard_exit;
custom_set_window_title_type *set_window_title;
custom_draw_string_oriented_type *draw_string_oriented;
custom_get_string_advance_type *get_string_advance;
@ -685,6 +688,7 @@ internal b32 try_release_face(Application_Links* app, Face_ID id, Face_ID replac
internal String_Const_u8 push_hot_directory(Application_Links* app, Arena* arena);
internal void set_hot_directory(Application_Links* app, String_Const_u8 string);
internal void send_exit_signal(Application_Links* app);
internal void hard_exit(Application_Links* app);
internal void set_window_title(Application_Links* app, String_Const_u8 title);
internal Vec2_f32 draw_string_oriented(Application_Links* app, Face_ID font_id, ARGB_Color color, String_Const_u8 str, Vec2_f32 point, u32 flags, Vec2_f32 delta);
internal f32 get_string_advance(Application_Links* app, Face_ID font_id, String_Const_u8 str);
@ -863,6 +867,7 @@ global custom_try_release_face_type *try_release_face = 0;
global custom_push_hot_directory_type *push_hot_directory = 0;
global custom_set_hot_directory_type *set_hot_directory = 0;
global custom_send_exit_signal_type *send_exit_signal = 0;
global custom_hard_exit_type *hard_exit = 0;
global custom_set_window_title_type *set_window_title = 0;
global custom_draw_string_oriented_type *draw_string_oriented = 0;
global custom_get_string_advance_type *get_string_advance = 0;

View File

@ -906,6 +906,10 @@ API_Call *call = api_call_with_location(arena, result, string_u8_litexpr("send_e
api_param(arena, call, "Application_Links*", "app");
}
{
API_Call *call = api_call_with_location(arena, result, string_u8_litexpr("hard_exit"), string_u8_litexpr("void"), string_u8_litexpr(""));
api_param(arena, call, "Application_Links*", "app");
}
{
API_Call *call = api_call_with_location(arena, result, string_u8_litexpr("set_window_title"), string_u8_litexpr("void"), string_u8_litexpr(""));
api_param(arena, call, "Application_Links*", "app");
api_param(arena, call, "String_Const_u8", "title");

View File

@ -154,6 +154,7 @@ api(custom) function b32 try_release_face(Application_Links* app, Face_ID id, Fa
api(custom) function String_Const_u8 push_hot_directory(Application_Links* app, Arena* arena);
api(custom) function void set_hot_directory(Application_Links* app, String_Const_u8 string);
api(custom) function void send_exit_signal(Application_Links* app);
api(custom) function void hard_exit(Application_Links* app);
api(custom) function void set_window_title(Application_Links* app, String_Const_u8 title);
api(custom) function Vec2_f32 draw_string_oriented(Application_Links* app, Face_ID font_id, ARGB_Color color, String_Const_u8 str, Vec2_f32 point, u32 flags, Vec2_f32 delta);
api(custom) function f32 get_string_advance(Application_Links* app, Face_ID font_id, String_Const_u8 str);

View File

@ -640,6 +640,7 @@ win32_keycode_init(void){
keycode_lookup_table[VK_SPACE] = KeyCode_Space;
keycode_lookup_table[VK_OEM_3] = KeyCode_Tick;
keycode_lookup_table[VK_OEM_MINUS] = KeyCode_Minus;
keycode_lookup_table[VK_OEM_PLUS] = KeyCode_Equal;
keycode_lookup_table[VK_OEM_4] = KeyCode_LeftBracket;
keycode_lookup_table[VK_OEM_6] = KeyCode_RightBracket;
keycode_lookup_table[VK_OEM_1] = KeyCode_Semicolon;