Sending commands to views working; open in other working

master
Allen Webster 2019-11-06 17:36:30 -08:00
parent d76385fde3
commit 2834583b98
14 changed files with 160 additions and 67 deletions

54
4ed.cpp
View File

@ -9,32 +9,6 @@
// TOP
internal void
output_file_append(Thread_Context *tctx, Models *models, Editing_File *file, String_Const_u8 value){
i64 end = buffer_size(&file->state.buffer);
Edit_Behaviors behaviors = {};
edit_single(tctx, models, file, Ii64(end), value, behaviors);
}
internal void
file_cursor_to_end(Thread_Context *tctx, Models *models, Editing_File *file){
Assert(file != 0);
i64 pos = buffer_size(&file->state.buffer);
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){
continue;
}
view_set_cursor(tctx, models, view, pos);
view->mark = pos;
}
}
#include "4ed_api_implementation.cpp"
internal void
fill_hardcode_default_style(Color_Table color_table){
color_table.vals[Stag_Back] = 0xFF0C0C0C;
@ -616,11 +590,31 @@ App_Step_Sig(app_step){
}
// NOTE(allen): consume event stream
for (Input_Event_Node *node = input_list.first;
node != 0;
node = node->next){
Input_Event_Node *input_node = input_list.first;
Input_Event_Node *input_node_next = 0;
for (;; input_node = input_node_next){
// NOTE(allen): first handle any events coming from the view command
// function queue
Model_View_Command_Function cmd_func = models_pop_view_command_function(models);
if (cmd_func.custom_func != 0){
View *view = imp_get_view(models, cmd_func.view_id);
if (view != 0){
input_node_next = input_node;
Input_Event cmd_func_event = {};
cmd_func_event.kind = InputEventKind_CustomFunction;
cmd_func_event.custom_func = cmd_func.custom_func;
co_send_event(tctx, models, view, &cmd_func_event);
continue;
}
}
if (input_node == 0){
break;
}
input_node_next = input_node->next;
b32 event_was_handled = false;
Input_Event *event = &node->event;
Input_Event *event = &input_node->event;
if (event->kind == InputEventKind_TextInsert && event->text.blocked){
continue;

View File

@ -9,6 +9,59 @@
// TOP
internal void
output_file_append(Thread_Context *tctx, Models *models, Editing_File *file, String_Const_u8 value){
i64 end = buffer_size(&file->state.buffer);
Edit_Behaviors behaviors = {};
edit_single(tctx, models, file, Ii64(end), value, behaviors);
}
internal void
file_cursor_to_end(Thread_Context *tctx, Models *models, Editing_File *file){
Assert(file != 0);
i64 pos = buffer_size(&file->state.buffer);
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){
continue;
}
view_set_cursor(tctx, models, view, pos);
view->mark = pos;
}
}
function void
models_push_view_command_function(Models *models, View_ID view_id, Custom_Command_Function *custom_func){
Model_View_Command_Function *node = models->free_view_cmd_funcs;
if (node == 0){
node = push_array(models->arena, Model_View_Command_Function, 1);
}
else{
sll_stack_pop(models->free_view_cmd_funcs);
}
sll_queue_push(models->first_view_cmd_func, models->last_view_cmd_func, node);
node->view_id = view_id;
node->custom_func = custom_func;
}
function Model_View_Command_Function
models_pop_view_command_function(Models *models){
Model_View_Command_Function result = {};
if (models->first_view_cmd_func != 0){
Model_View_Command_Function *node = models->first_view_cmd_func;
result.custom_func = node->custom_func;
result.view_id = node->view_id;
sll_queue_pop(models->first_view_cmd_func, models->last_view_cmd_func);
sll_stack_push(models->free_view_cmd_funcs, node);
}
return(result);
}
////////////////////////////////
function b32
access_test(Access_Flag object_flags, Access_Flag access_flags){
return((object_flags & access_flags) == access_flags);
@ -1420,6 +1473,19 @@ view_set_active(Application_Links *app, View_ID view_id)
return(result);
}
api(custom) function b32
view_enqueue_command_function(Application_Links *app, View_ID view_id, Custom_Command_Function *custom_func)
{
Models *models = (Models*)app->cmd_context;
View *view = imp_get_view(models, view_id);
b32 result = false;
if (api_check_view(view)){
models_push_view_command_function(models, view_id, custom_func);
result = true;
}
return(result);
}
api(custom) function b32
view_get_setting(Application_Links *app, View_ID view_id, View_Setting_ID setting, i64 *value_out)
{

View File

@ -34,6 +34,12 @@ enum App_State{
APP_STATE_COUNT
};
struct Model_View_Command_Function{
Model_View_Command_Function *next;
Custom_Command_Function *custom_func;
View_ID view_id;
};
struct Models{
Arena arena_;
Arena *arena;
@ -68,6 +74,10 @@ struct Models{
Color_Table fallback_color_table;
Color_Table color_table;
Model_View_Command_Function *free_view_cmd_funcs;
Model_View_Command_Function *first_view_cmd_func;
Model_View_Command_Function *last_view_cmd_func;
Layout layout;
Working_Set working_set;
Live_Views view_set;

View File

@ -103,6 +103,7 @@
#include "4ed_view.cpp"
#include "4ed_edit.cpp"
#include "4ed_text_layout.cpp"
#include "4ed_api_implementation.cpp"
#include "4ed.cpp"
// BOTTOM

View File

@ -178,7 +178,10 @@ function Command_Binding
map_get_binding_non_recursive(Command_Map *map, Input_Event *event){
Command_Binding result = {};
if (map != 0){
if (event->kind == InputEventKind_CustomFunction){
result.custom = event->custom_func;
}
else if (map != 0){
b32 do_table_lookup = false;
Input_Modifier_Set *mods = 0;
u64 key = 0;

View File

@ -269,17 +269,20 @@ view_buffer_set(Application_Links *app, Buffer_ID *buffers, i32 *positions, i32
function void
change_active_panel_send_command(Application_Links *app, Custom_Command_Function *custom_func){
NotImplemented;
}
CUSTOM_COMMAND_SIG(change_active_panel)
CUSTOM_DOC("Change the currently active panel, moving to the panel with the next highest view_id.")
{
View_ID view = get_active_view(app, Access_Always);
view = get_next_view_looped_primary_panels(app, view, Access_Always);
if (view != 0){
view_set_active(app, view);
}
if (custom_func != 0){
view_enqueue_command_function(app, view, custom_func);
}
}
CUSTOM_COMMAND_SIG(change_active_panel)
CUSTOM_DOC("Change the currently active panel, moving to the panel with the next highest view_id.")
{
change_active_panel_send_command(app, 0);
}
CUSTOM_COMMAND_SIG(change_active_panel_backwards)

View File

@ -98,8 +98,7 @@ CUSTOM_DOC("Input consumption loop for default view behavior")
}
Command_Map_ID map_id = *map_id_ptr;
Command_Binding binding =
map_get_binding_recursive(&framework_mapping, map_id, &input.event);
Command_Binding binding = map_get_binding_recursive(&framework_mapping, map_id, &input.event);
Managed_Scope scope = view_get_managed_scope(app, view);
Custom_Command_Function** next_call = 0;

View File

@ -240,6 +240,11 @@ get_event_properties(Input_Event *event){
}break;
}
}break;
case InputEventKind_CustomFunction:
{
flags |= EventProperty_CustomFunction;
}break;
}
return(flags);

View File

@ -7,6 +7,8 @@
#if !defined(FCODER_EVENTS_H)
#define FCODER_EVENTS_H
typedef void Custom_Command_Function(struct Application_Links *app);
typedef u32 Key_Code;
typedef u32 Mouse_Code;
typedef u32 Core_Code;
@ -22,6 +24,7 @@ enum{
InputEventKind_MouseWheel,
InputEventKind_MouseMove,
InputEventKind_Core,
InputEventKind_CustomFunction,
};
global_const i32 Input_MaxModifierCount = 8;
@ -78,6 +81,7 @@ struct Input_Event{
};
};
} core;
Custom_Command_Function *custom_func;
};
};
@ -94,20 +98,21 @@ struct Input_List{
typedef u32 Event_Property;
enum{
EventProperty_AnyKey = 0x1,
EventProperty_Escape = 0x2,
EventProperty_AnyKeyRelease = 0x4,
EventProperty_MouseButton = 0x8,
EventProperty_MouseRelease = 0x10,
EventProperty_MouseWheel = 0x20,
EventProperty_MouseMove = 0x40,
EventProperty_Animate = 0x80,
EventProperty_ViewActivation = 0x100,
EventProperty_TextInsert = 0x200,
EventProperty_AnyFile = 0x400,
EventProperty_Startup = 0x800,
EventProperty_AnyKey = 0x0001,
EventProperty_Escape = 0x0002,
EventProperty_AnyKeyRelease = 0x0004,
EventProperty_MouseButton = 0x0008,
EventProperty_MouseRelease = 0x0010,
EventProperty_MouseWheel = 0x0020,
EventProperty_MouseMove = 0x0040,
EventProperty_Animate = 0x0080,
EventProperty_ViewActivation = 0x0100,
EventProperty_TextInsert = 0x0200,
EventProperty_AnyFile = 0x0400,
EventProperty_Startup = 0x0800,
EventProperty_Exit = 0x1000,
EventProperty_Clipboard = 0x2000,
EventProperty_CustomFunction = 0x4000,
};
enum{
EventPropertyGroup_AnyKeyboardEvent =
@ -130,7 +135,8 @@ enum{
EventProperty_AnyFile|
EventProperty_Startup|
EventProperty_Exit|
EventProperty_Clipboard,
EventProperty_Clipboard|
EventProperty_CustomFunction,
};
#endif

View File

@ -531,8 +531,6 @@ struct Record_Info{
};
};
typedef void Custom_Command_Function(struct Application_Links *app);
#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

View File

@ -246,19 +246,19 @@ static Command_Metadata fcoder_metacmd_table[214] = {
{ 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, 2175 },
{ 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, 2181 },
{ 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, 2189 },
{ 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, 275 },
{ 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, 285 },
{ 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, 295 },
{ 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, 305 },
{ 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, 370 },
{ 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, 376 },
{ 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, 382 },
{ 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, 388 },
{ 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, 394 },
{ 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, 400 },
{ 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, 406 },
{ 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, 412 },
{ 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, 418 },
{ 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, 282 },
{ 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, 288 },
{ 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, 298 },
{ 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, 308 },
{ 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, 373 },
{ 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, 379 },
{ 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, 385 },
{ 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, 391 },
{ 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, 397 },
{ 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, 403 },
{ 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, 409 },
{ 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, 415 },
{ 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, 421 },
{ 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, 59 },
{ 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_underscore, 0), false, "write_underscore", 16, "Inserts an underscore.", 22, "w:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 73 },

View File

@ -82,6 +82,7 @@ vtable->view_close = view_close;
vtable->view_get_buffer_region = view_get_buffer_region;
vtable->view_get_buffer_scroll = view_get_buffer_scroll;
vtable->view_set_active = view_set_active;
vtable->view_enqueue_command_function = view_enqueue_command_function;
vtable->view_get_setting = view_get_setting;
vtable->view_set_setting = view_set_setting;
vtable->view_get_managed_scope = view_get_managed_scope;
@ -262,6 +263,7 @@ view_close = vtable->view_close;
view_get_buffer_region = vtable->view_get_buffer_region;
view_get_buffer_scroll = vtable->view_get_buffer_scroll;
view_set_active = vtable->view_set_active;
view_enqueue_command_function = vtable->view_enqueue_command_function;
view_get_setting = vtable->view_get_setting;
view_set_setting = vtable->view_set_setting;
view_get_managed_scope = vtable->view_get_managed_scope;

View File

@ -80,6 +80,7 @@
#define custom_view_get_buffer_region_sig() Rect_f32 custom_view_get_buffer_region(Application_Links* app, View_ID view_id)
#define custom_view_get_buffer_scroll_sig() Buffer_Scroll custom_view_get_buffer_scroll(Application_Links* app, View_ID view_id)
#define custom_view_set_active_sig() b32 custom_view_set_active(Application_Links* app, View_ID view_id)
#define custom_view_enqueue_command_function_sig() b32 custom_view_enqueue_command_function(Application_Links* app, View_ID view_id, Custom_Command_Function* custom_func)
#define custom_view_get_setting_sig() b32 custom_view_get_setting(Application_Links* app, View_ID view_id, View_Setting_ID setting, i64* value_out)
#define custom_view_set_setting_sig() b32 custom_view_set_setting(Application_Links* app, View_ID view_id, View_Setting_ID setting, i64 value)
#define custom_view_get_managed_scope_sig() Managed_Scope custom_view_get_managed_scope(Application_Links* app, View_ID view_id)
@ -256,6 +257,7 @@ typedef b32 custom_view_close_type(Application_Links* app, View_ID view_id);
typedef Rect_f32 custom_view_get_buffer_region_type(Application_Links* app, View_ID view_id);
typedef Buffer_Scroll custom_view_get_buffer_scroll_type(Application_Links* app, View_ID view_id);
typedef b32 custom_view_set_active_type(Application_Links* app, View_ID view_id);
typedef b32 custom_view_enqueue_command_function_type(Application_Links* app, View_ID view_id, Custom_Command_Function* custom_func);
typedef b32 custom_view_get_setting_type(Application_Links* app, View_ID view_id, View_Setting_ID setting, i64* value_out);
typedef b32 custom_view_set_setting_type(Application_Links* app, View_ID view_id, View_Setting_ID setting, i64 value);
typedef Managed_Scope custom_view_get_managed_scope_type(Application_Links* app, View_ID view_id);
@ -433,6 +435,7 @@ custom_view_close_type *view_close;
custom_view_get_buffer_region_type *view_get_buffer_region;
custom_view_get_buffer_scroll_type *view_get_buffer_scroll;
custom_view_set_active_type *view_set_active;
custom_view_enqueue_command_function_type *view_enqueue_command_function;
custom_view_get_setting_type *view_get_setting;
custom_view_set_setting_type *view_set_setting;
custom_view_get_managed_scope_type *view_get_managed_scope;
@ -611,6 +614,7 @@ internal b32 view_close(Application_Links* app, View_ID view_id);
internal Rect_f32 view_get_buffer_region(Application_Links* app, View_ID view_id);
internal Buffer_Scroll view_get_buffer_scroll(Application_Links* app, View_ID view_id);
internal b32 view_set_active(Application_Links* app, View_ID view_id);
internal b32 view_enqueue_command_function(Application_Links* app, View_ID view_id, Custom_Command_Function* custom_func);
internal b32 view_get_setting(Application_Links* app, View_ID view_id, View_Setting_ID setting, i64* value_out);
internal b32 view_set_setting(Application_Links* app, View_ID view_id, View_Setting_ID setting, i64 value);
internal Managed_Scope view_get_managed_scope(Application_Links* app, View_ID view_id);
@ -789,6 +793,7 @@ global custom_view_close_type *view_close = 0;
global custom_view_get_buffer_region_type *view_get_buffer_region = 0;
global custom_view_get_buffer_scroll_type *view_get_buffer_scroll = 0;
global custom_view_set_active_type *view_set_active = 0;
global custom_view_enqueue_command_function_type *view_enqueue_command_function = 0;
global custom_view_get_setting_type *view_get_setting = 0;
global custom_view_set_setting_type *view_set_setting = 0;
global custom_view_get_managed_scope_type *view_get_managed_scope = 0;

View File

@ -80,6 +80,7 @@ api(custom) function b32 view_close(Application_Links* app, View_ID view_id);
api(custom) function Rect_f32 view_get_buffer_region(Application_Links* app, View_ID view_id);
api(custom) function Buffer_Scroll view_get_buffer_scroll(Application_Links* app, View_ID view_id);
api(custom) function b32 view_set_active(Application_Links* app, View_ID view_id);
api(custom) function b32 view_enqueue_command_function(Application_Links* app, View_ID view_id, Custom_Command_Function* custom_func);
api(custom) function b32 view_get_setting(Application_Links* app, View_ID view_id, View_Setting_ID setting, i64* value_out);
api(custom) function b32 view_set_setting(Application_Links* app, View_ID view_id, View_Setting_ID setting, i64 value);
api(custom) function Managed_Scope view_get_managed_scope(Application_Links* app, View_ID view_id);