Deduplicated fallback dispatch code

master
Allen Webster 2019-10-19 18:32:38 -07:00
parent 323782f7f7
commit 2d8653754d
8 changed files with 100 additions and 66 deletions

View File

@ -150,13 +150,56 @@ get_next_view_after_active(Application_Links *app, Access_Flag access){
////////////////////////////////
static void
call_after_ui_shutdown(Application_Links *app, View_ID view, Custom_Command_Function *func){
call_after_ctx_shutdown(Application_Links *app, View_ID view, Custom_Command_Function *func){
Managed_Scope scope = view_get_managed_scope(app, view);
Custom_Command_Function **call_next =
scope_attachment(app, scope, view_call_next, Custom_Command_Function*);
*call_next = func;
}
function Fallback_Dispatch_Result
fallback_command_dispatch(Application_Links *app, Mapping *mapping, Command_Map *map,
User_Input *in){
Fallback_Dispatch_Result result = {};
if (mapping != 0 && map != 0){
Command_Binding binding = map_get_binding_recursive(mapping, map, &in->event);
if (binding.custom != 0){
Command_Metadata *metadata = get_command_metadata(binding.custom);
if (metadata != 0){
if (metadata->is_ui){
result.code = FallbackDispatch_DelayedUICall;
result.func = binding.custom;
}
else{
binding.custom(app);
result.code = FallbackDispatch_DidCall;
}
}
else{
binding.custom(app);
result.code = FallbackDispatch_DidCall;
}
}
}
return(result);
}
function b32
ui_fallback_command_dispatch(Application_Links *app, View_ID view,
Mapping *mapping, Command_Map *map, User_Input *in){
b32 result = false;
Fallback_Dispatch_Result disp_result =
fallback_command_dispatch(app, mapping, map, in);
if (disp_result.code == FallbackDispatch_DelayedUICall){
call_after_ctx_shutdown(app, view, disp_result.func);
result = true;
}
if (disp_result.code == FallbackDispatch_Unhandled){
leave_current_input_unhandled(app);
}
return(result);
}
////////////////////////////////
static void

View File

@ -54,9 +54,16 @@ struct ID_Pos_Jump_Location_Array{
////////////////////////////////
struct Named_Mapping{
String_Const_u8 name;
Custom_Command_Function *remap_command;
typedef i32 Fallback_Dispatch_Result_Code;
enum{
FallbackDispatch_Unhandled,
FallbackDispatch_DidCall,
FallbackDispatch_DelayedUICall,
};
struct Fallback_Dispatch_Result{
Fallback_Dispatch_Result_Code code;
Custom_Command_Function *func;
};
////////////////////////////////

View File

@ -649,30 +649,8 @@ lister_run(Application_Links *app, View_ID view, Lister *lister){
// TODO(allen): dedup this stuff.
Mapping *mapping = lister->mapping;
Command_Map *map = lister->map;
if (mapping != 0 && map != 0){
Command_Binding binding =
map_get_binding_recursive(mapping, map, &in.event);
if (binding.custom != 0){
Command_Metadata *metadata = get_command_metadata(binding.custom);
if (metadata != 0){
if (metadata->is_ui){
call_after_ui_shutdown(app, view, binding.custom);
break;
}
else{
binding.custom(app);
}
}
else{
binding.custom(app);
}
}
else{
leave_current_input_unhandled(app);
}
}
else{
leave_current_input_unhandled(app);
if (ui_fallback_command_dispatch(app, view, mapping, map, &in)){
break;
}
}
}

View File

@ -1009,6 +1009,7 @@ CUSTOM_DOC("Parses *log* and displays the 'log graph' UI")
break;
}
b32 handled = true;
switch (in.event.kind){
case InputEventKind_KeyStroke:
{
@ -1022,6 +1023,11 @@ CUSTOM_DOC("Parses *log* and displays the 'log graph' UI")
{
log_graph.y_scroll += get_page_jump(app, log_view);
}break;
default:
{
handled = false;
}break;
}
}break;
@ -1038,6 +1044,11 @@ CUSTOM_DOC("Parses *log* and displays the 'log graph' UI")
{
log_graph__click_select_event(app, m_p);
}break;
default:
{
handled = false;
}break;
}
}break;
@ -1046,6 +1057,20 @@ CUSTOM_DOC("Parses *log* and displays the 'log graph' UI")
f32 value = in.event.mouse_wheel.value;
log_graph.y_scroll += f32_round32(value);
}break;
default:
{
handled = false;
}break;
}
if (!handled){
// TODO(allen): get mapping and map from a more flexible source.
Mapping *mapping = &framework_mapping;
Command_Map *map = mapping_get_map(mapping, mapid_global);
if (ui_fallback_command_dispatch(app, view, mapping, map, &in)){
break;
}
}
}

View File

@ -667,9 +667,6 @@ parse_text(Arena *arena, Meta_Command_Entry_Arrays *entry_arrays, u8 *source_nam
}
}
}
else if (string_match(lexeme, string_u8_litexpr("CUSTOM_UI_COMMAND"))){
}
}
if (token.kind == TokenBaseKind_EOF){

View File

@ -374,7 +374,7 @@ profile_render(Application_Links *app, Frame_Info frame_info, View_ID view){
draw_set_clip(app, prev_clip);
}
CUSTOM_COMMAND_SIG(profile_inspect)
CUSTOM_UI_COMMAND_SIG(profile_inspect)
CUSTOM_DOC("Inspect all currently collected profiling information in 4coder's self profiler.")
{
if (HasFlag(global_prof_list.disable_bits, ProfileEnable_InspectBit)){
@ -426,27 +426,11 @@ CUSTOM_DOC("Inspect all currently collected profiling information in 4coder's se
}
if (!handled){
// TODO(allen): dedup this stuff.
// TODO(allen): get mapping and map from a more flexible source.
Mapping *mapping = &framework_mapping;
Command_Map *map = mapping_get_map(mapping, mapid_global);
if (mapping != 0 && map != 0){
Command_Binding binding =
map_get_binding_recursive(mapping, map, &in.event);
if (binding.custom != 0){
i64 old_num = get_current_input_sequence_number(app);
binding.custom(app);
i64 num = get_current_input_sequence_number(app);
if (old_num < num){
break;
}
}
else{
leave_current_input_unhandled(app);
}
}
else{
leave_current_input_unhandled(app);
if (ui_fallback_command_dispatch(app, view, mapping, map, &in)){
break;
}
}
}

View File

@ -454,8 +454,8 @@ STRUCT Record_Info{
TYPEDEF void Custom_Command_Function(struct Application_Links *app);
#if defined(CUSTOM_COMMAND_SIG) || defined(CUSTOM_UI_COMMAND) || defined(CUSTOM_DOC) || defined(CUSTOM_COMMAND)
#error Please do not define CUSTOM_COMMAND_SIG, CUSTOM_DOC, or CUSTOM_UI_COMMAND
#if defined(CUSTOM_COMMAND_SIG) || defined(CUSTOM_UI_COMMAND_SIG) || defined(CUSTOM_DOC) || defined(CUSTOM_COMMAND)
#error Please do not define CUSTOM_COMMAND_SIG, CUSTOM_DOC, CUSTOM_UI_COMMAND_SIG, or CUSTOM_COMMAND
#endif
#if !defined(META_PASS)

View File

@ -243,19 +243,19 @@ static Command_Metadata fcoder_metacmd_table[211] = {
{ PROC_LINKS(seek_end_of_line, 0), false, "seek_end_of_line", 16, "Seeks the cursor to the end of the visual line.", 47, "w:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2124 },
{ PROC_LINKS(goto_beginning_of_file, 0), false, "goto_beginning_of_file", 22, "Sets the cursor to the beginning of the file.", 45, "w:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2130 },
{ PROC_LINKS(goto_end_of_file, 0), false, "goto_end_of_file", 16, "Sets the cursor to the end of the file.", 39, "w:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2138 },
{ PROC_LINKS(change_active_panel, 0), false, "change_active_panel", 19, "Change the currently active panel, moving to the panel with the next highest view_id.", 85, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 213 },
{ PROC_LINKS(change_active_panel_backwards, 0), false, "change_active_panel_backwards", 29, "Change the currently active panel, moving to the panel with the next lowest view_id.", 84, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 223 },
{ PROC_LINKS(open_panel_vsplit, 0), false, "open_panel_vsplit", 17, "Create a new panel by vertically splitting the active panel.", 60, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 233 },
{ PROC_LINKS(open_panel_hsplit, 0), false, "open_panel_hsplit", 17, "Create a new panel by horizontally splitting the active panel.", 62, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 243 },
{ PROC_LINKS(suppress_mouse, 0), false, "suppress_mouse", 14, "Hides the mouse and causes all mosue input (clicks, position, wheel) to be ignored.", 83, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 308 },
{ PROC_LINKS(allow_mouse, 0), false, "allow_mouse", 11, "Shows the mouse and causes all mouse input to be processed normally.", 68, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 314 },
{ PROC_LINKS(toggle_mouse, 0), false, "toggle_mouse", 12, "Toggles the mouse suppression mode, see suppress_mouse and allow_mouse.", 71, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 320 },
{ PROC_LINKS(set_mode_to_original, 0), false, "set_mode_to_original", 20, "Sets the edit mode to 4coder original.", 38, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 326 },
{ PROC_LINKS(set_mode_to_notepad_like, 0), false, "set_mode_to_notepad_like", 24, "Sets the edit mode to Notepad like.", 35, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 332 },
{ PROC_LINKS(toggle_highlight_line_at_cursor, 0), false, "toggle_highlight_line_at_cursor", 31, "Toggles the line highlight at the cursor.", 41, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 338 },
{ PROC_LINKS(toggle_highlight_enclosing_scopes, 0), false, "toggle_highlight_enclosing_scopes", 33, "In code files scopes surrounding the cursor are highlighted with distinguishing colors.", 87, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 344 },
{ PROC_LINKS(toggle_paren_matching_helper, 0), false, "toggle_paren_matching_helper", 28, "In code files matching parentheses pairs are colored with distinguishing colors.", 80, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 350 },
{ PROC_LINKS(toggle_fullscreen, 0), false, "toggle_fullscreen", 17, "Toggle fullscreen mode on or off. The change(s) do not take effect until the next frame.", 89, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 356 },
{ PROC_LINKS(change_active_panel, 0), false, "change_active_panel", 19, "Change the currently active panel, moving to the panel with the next highest view_id.", 85, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 256 },
{ PROC_LINKS(change_active_panel_backwards, 0), false, "change_active_panel_backwards", 29, "Change the currently active panel, moving to the panel with the next lowest view_id.", 84, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 266 },
{ PROC_LINKS(open_panel_vsplit, 0), false, "open_panel_vsplit", 17, "Create a new panel by vertically splitting the active panel.", 60, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 276 },
{ PROC_LINKS(open_panel_hsplit, 0), false, "open_panel_hsplit", 17, "Create a new panel by horizontally splitting the active panel.", 62, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 286 },
{ PROC_LINKS(suppress_mouse, 0), false, "suppress_mouse", 14, "Hides the mouse and causes all mosue input (clicks, position, wheel) to be ignored.", 83, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 351 },
{ PROC_LINKS(allow_mouse, 0), false, "allow_mouse", 11, "Shows the mouse and causes all mouse input to be processed normally.", 68, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 357 },
{ PROC_LINKS(toggle_mouse, 0), false, "toggle_mouse", 12, "Toggles the mouse suppression mode, see suppress_mouse and allow_mouse.", 71, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 363 },
{ PROC_LINKS(set_mode_to_original, 0), false, "set_mode_to_original", 20, "Sets the edit mode to 4coder original.", 38, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 369 },
{ PROC_LINKS(set_mode_to_notepad_like, 0), false, "set_mode_to_notepad_like", 24, "Sets the edit mode to Notepad like.", 35, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 375 },
{ PROC_LINKS(toggle_highlight_line_at_cursor, 0), false, "toggle_highlight_line_at_cursor", 31, "Toggles the line highlight at the cursor.", 41, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 381 },
{ PROC_LINKS(toggle_highlight_enclosing_scopes, 0), false, "toggle_highlight_enclosing_scopes", 33, "In code files scopes surrounding the cursor are highlighted with distinguishing colors.", 87, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 387 },
{ PROC_LINKS(toggle_paren_matching_helper, 0), false, "toggle_paren_matching_helper", 28, "In code files matching parentheses pairs are colored with distinguishing colors.", 80, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 393 },
{ PROC_LINKS(toggle_fullscreen, 0), false, "toggle_fullscreen", 17, "Toggle fullscreen mode on or off. The change(s) do not take effect until the next frame.", 89, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 399 },
{ PROC_LINKS(write_text_input, 0), false, "write_text_input", 16, "Inserts whatever character was used to trigger this command.", 60, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 58 },
{ PROC_LINKS(write_space, 0), false, "write_space", 11, "Inserts an underscore.", 22, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 66 },
{ PROC_LINKS(write_underscore, 0), false, "write_underscore", 16, "Inserts an underscore.", 22, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 72 },
@ -441,7 +441,7 @@ static Command_Metadata fcoder_metacmd_table[211] = {
{ PROC_LINKS(miblo_decrement_time_stamp, 0), false, "miblo_decrement_time_stamp", 26, "Decrement a time stamp under the cursor by one second. (format [m]m:ss or h:mm:ss", 81, "w:\\4ed\\code\\custom\\4coder_miblo_numbers.cpp", 43, 237 },
{ PROC_LINKS(miblo_increment_time_stamp_minute, 0), false, "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, "w:\\4ed\\code\\custom\\4coder_miblo_numbers.cpp", 43, 243 },
{ PROC_LINKS(miblo_decrement_time_stamp_minute, 0), false, "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, "w:\\4ed\\code\\custom\\4coder_miblo_numbers.cpp", 43, 249 },
{ PROC_LINKS(profile_inspect, 0), false, "profile_inspect", 15, "Inspect all currently collected profiling information in 4coder's self profiler.", 80, "w:\\4ed\\code\\custom\\4coder_profile_inspect.cpp", 45, 377 },
{ PROC_LINKS(profile_inspect, 0), true, "profile_inspect", 15, "Inspect all currently collected profiling information in 4coder's self profiler.", 80, "w:\\4ed\\code\\custom\\4coder_profile_inspect.cpp", 45, 377 },
{ 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, 21 },
};