Removal of the old commands system
parent
fcc3d4e64f
commit
d0eb652ab1
|
@ -56,18 +56,6 @@ ENUM(uint32_t, Key_Modifier_Flag){
|
|||
MDFR_SHIFT = 0x8,
|
||||
};
|
||||
|
||||
/* DOC(A Command_ID is used as a name for commands implemented internally in 4coder.) */
|
||||
ENUM(uint64_t, Command_ID){
|
||||
/* DOC(cmdid_null is set aside to always be zero and is not associated with any command.) */
|
||||
cmdid_null,
|
||||
/* DOC(cmdid_undo performs a standard undo behavior.) */
|
||||
cmdid_undo,
|
||||
/* DOC(cmdid_redo reperforms an edit that was undone.) */
|
||||
cmdid_redo,
|
||||
// count
|
||||
cmdid_count
|
||||
};
|
||||
|
||||
/* DOC(Flags for describing the memory protection status of pages that come back from memory allocate. Some combinations may not be available on some platforms, but you are gauranteed to get back a page with at least the permissions you requested. For example if you request just write permission, you may get back a page with read and write permission, but you will never get back a page that doesn't have write permission.) */
|
||||
ENUM(uint32_t, Memory_Protect_Flags){
|
||||
/* DOC(Allows the page to be read.) */
|
||||
|
@ -1029,10 +1017,7 @@ TYPEDEF void Custom_Command_Function(struct Application_Links *app);
|
|||
|
||||
/* DOC(Generic_Command acts as a name for a command, and can name an internal command or a custom command.) */
|
||||
UNION Generic_Command{
|
||||
/* DOC(If this Generic_Command represents an internal command the cmdid field will have a value less than cmdid_count, and this field is the command id for the command.) */
|
||||
Command_ID cmdid;
|
||||
/* DOC(If this Generic_Command does not represent an internal command the command
|
||||
field is the pointer to the custom command..) */
|
||||
/* DOC(If this Generic_Command does not represent an internal command the command field is the pointer to the custom command..) */
|
||||
Custom_Command_Function *command;
|
||||
};
|
||||
|
||||
|
@ -1159,7 +1144,6 @@ DOC_SEE(Binding_Unit)
|
|||
ENUM(int32_t, Binding_Unit_Type){
|
||||
unit_header,
|
||||
unit_map_begin,
|
||||
unit_binding,
|
||||
unit_callback,
|
||||
unit_inherit,
|
||||
unit_hook
|
||||
|
@ -1185,7 +1169,6 @@ STRUCT Binding_Unit{
|
|||
STRUCT{ int32_t total_size; int32_t user_map_count; int32_t error; } header;
|
||||
STRUCT{ int32_t mapid; int32_t replace; int32_t bind_count; } map_begin;
|
||||
STRUCT{ int32_t mapid; } map_inherit;
|
||||
STRUCT{ Key_Code code; uint8_t modifiers; Command_ID command_id; } binding;
|
||||
STRUCT{ Key_Code code; uint8_t modifiers; Custom_Command_Function *func; } callback;
|
||||
STRUCT{ int32_t hook_id; void *func; } hook;
|
||||
};
|
||||
|
|
|
@ -1582,13 +1582,23 @@ CUSTOM_DOC("Reopen the current buffer from the hard drive.")
|
|||
CUSTOM_COMMAND_SIG(undo)
|
||||
CUSTOM_DOC("Advances backwards through the undo history.")
|
||||
{
|
||||
exec_command(app, cmdid_undo);
|
||||
// TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen):
|
||||
// TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen):
|
||||
// TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen):
|
||||
// TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen):
|
||||
// TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen):
|
||||
// re-implement undo
|
||||
}
|
||||
|
||||
CUSTOM_COMMAND_SIG(redo)
|
||||
CUSTOM_DOC("Advances forewards through the undo history.")
|
||||
{
|
||||
exec_command(app, cmdid_redo);
|
||||
// TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen):
|
||||
// TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen):
|
||||
// TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen):
|
||||
// TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen):
|
||||
// TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen):
|
||||
// re-implement redo
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
struct Application_Links;
|
||||
#define GLOBAL_SET_SETTING_SIG(n) bool32 n(Application_Links *app, Global_Setting_ID setting, int32_t value)
|
||||
#define GLOBAL_SET_MAPPING_SIG(n) bool32 n(Application_Links *app, void *data, int32_t size)
|
||||
#define EXEC_COMMAND_SIG(n) bool32 n(Application_Links *app, Command_ID command_id)
|
||||
#define EXEC_SYSTEM_COMMAND_SIG(n) bool32 n(Application_Links *app, View_Summary *view, Buffer_Identifier buffer_id, char *path, int32_t path_len, char *command, int32_t command_len, Command_Line_Interface_Flag flags)
|
||||
#define CLIPBOARD_POST_SIG(n) void n(Application_Links *app, int32_t clipboard_id, char *str, int32_t len)
|
||||
#define CLIPBOARD_COUNT_SIG(n) int32_t n(Application_Links *app, int32_t clipboard_id)
|
||||
|
@ -129,7 +128,6 @@ struct Application_Links;
|
|||
#define GET_DEFAULT_FONT_FOR_VIEW_SIG(n) Face_ID n(Application_Links *app, View_ID view_id)
|
||||
typedef GLOBAL_SET_SETTING_SIG(Global_Set_Setting_Function);
|
||||
typedef GLOBAL_SET_MAPPING_SIG(Global_Set_Mapping_Function);
|
||||
typedef EXEC_COMMAND_SIG(Exec_Command_Function);
|
||||
typedef EXEC_SYSTEM_COMMAND_SIG(Exec_System_Command_Function);
|
||||
typedef CLIPBOARD_POST_SIG(Clipboard_Post_Function);
|
||||
typedef CLIPBOARD_COUNT_SIG(Clipboard_Count_Function);
|
||||
|
@ -259,7 +257,6 @@ struct Application_Links{
|
|||
#if defined(ALLOW_DEP_4CODER)
|
||||
Global_Set_Setting_Function *global_set_setting;
|
||||
Global_Set_Mapping_Function *global_set_mapping;
|
||||
Exec_Command_Function *exec_command;
|
||||
Exec_System_Command_Function *exec_system_command;
|
||||
Clipboard_Post_Function *clipboard_post;
|
||||
Clipboard_Count_Function *clipboard_count;
|
||||
|
@ -388,7 +385,6 @@ Get_Default_Font_For_View_Function *get_default_font_for_view;
|
|||
#else
|
||||
Global_Set_Setting_Function *global_set_setting_;
|
||||
Global_Set_Mapping_Function *global_set_mapping_;
|
||||
Exec_Command_Function *exec_command_;
|
||||
Exec_System_Command_Function *exec_system_command_;
|
||||
Clipboard_Post_Function *clipboard_post_;
|
||||
Clipboard_Count_Function *clipboard_count_;
|
||||
|
@ -525,7 +521,6 @@ int32_t type_coroutine;
|
|||
#define FillAppLinksAPI(app_links) do{\
|
||||
app_links->global_set_setting_ = Global_Set_Setting;\
|
||||
app_links->global_set_mapping_ = Global_Set_Mapping;\
|
||||
app_links->exec_command_ = Exec_Command;\
|
||||
app_links->exec_system_command_ = Exec_System_Command;\
|
||||
app_links->clipboard_post_ = Clipboard_Post;\
|
||||
app_links->clipboard_count_ = Clipboard_Count;\
|
||||
|
@ -654,7 +649,6 @@ app_links->get_default_font_for_view_ = Get_Default_Font_For_View;} while(false)
|
|||
#if defined(ALLOW_DEP_4CODER)
|
||||
static bool32 global_set_setting(Application_Links *app, Global_Setting_ID setting, int32_t value){return(app->global_set_setting(app, setting, value));}
|
||||
static bool32 global_set_mapping(Application_Links *app, void *data, int32_t size){return(app->global_set_mapping(app, data, size));}
|
||||
static bool32 exec_command(Application_Links *app, Command_ID command_id){return(app->exec_command(app, command_id));}
|
||||
static bool32 exec_system_command(Application_Links *app, View_Summary *view, Buffer_Identifier buffer_id, char *path, int32_t path_len, char *command, int32_t command_len, Command_Line_Interface_Flag flags){return(app->exec_system_command(app, view, buffer_id, path, path_len, command, command_len, flags));}
|
||||
static void clipboard_post(Application_Links *app, int32_t clipboard_id, char *str, int32_t len){(app->clipboard_post(app, clipboard_id, str, len));}
|
||||
static int32_t clipboard_count(Application_Links *app, int32_t clipboard_id){return(app->clipboard_count(app, clipboard_id));}
|
||||
|
@ -783,7 +777,6 @@ static Face_ID get_default_font_for_view(Application_Links *app, View_ID view_id
|
|||
#else
|
||||
static bool32 global_set_setting(Application_Links *app, Global_Setting_ID setting, int32_t value){return(app->global_set_setting_(app, setting, value));}
|
||||
static bool32 global_set_mapping(Application_Links *app, void *data, int32_t size){return(app->global_set_mapping_(app, data, size));}
|
||||
static bool32 exec_command(Application_Links *app, Command_ID command_id){return(app->exec_command_(app, command_id));}
|
||||
static bool32 exec_system_command(Application_Links *app, View_Summary *view, Buffer_Identifier buffer_id, char *path, int32_t path_len, char *command, int32_t command_len, Command_Line_Interface_Flag flags){return(app->exec_system_command_(app, view, buffer_id, path, path_len, command, command_len, flags));}
|
||||
static void clipboard_post(Application_Links *app, int32_t clipboard_id, char *str, int32_t len){(app->clipboard_post_(app, clipboard_id, str, len));}
|
||||
static int32_t clipboard_count(Application_Links *app, int32_t clipboard_id){return(app->clipboard_count_(app, clipboard_id));}
|
||||
|
|
|
@ -364,7 +364,7 @@ static Command_Metadata fcoder_metacmd_table[220] = {
|
|||
{ PROC_LINKS(open_all_code_recursive, 0), "open_all_code_recursive", 23, "Works as open_all_code but also runs in all subdirectories.", 59, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 1074 },
|
||||
{ PROC_LINKS(open_color_tweaker, 0), "open_color_tweaker", 18, "Opens the 4coder theme selector list.", 37, "w:\\4ed\\code\\4coder_lists.cpp", 28, 938 },
|
||||
{ PROC_LINKS(open_file_in_quotes, 0), "open_file_in_quotes", 19, "Reads a filename from surrounding '\"' characters and attempts to open the corresponding file.", 94, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1464 },
|
||||
{ PROC_LINKS(open_in_other, 0), "open_in_other", 13, "Interactively opens a file in the other panel.", 46, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1619 },
|
||||
{ PROC_LINKS(open_in_other, 0), "open_in_other", 13, "Interactively opens a file in the other panel.", 46, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1629 },
|
||||
{ PROC_LINKS(open_long_braces, 0), "open_long_braces", 16, "At the cursor, insert a '{' and '}' separated by a blank line.", 62, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 55 },
|
||||
{ PROC_LINKS(open_long_braces_break, 0), "open_long_braces_break", 22, "At the cursor, insert a '{' and '}break;' separated by a blank line.", 68, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 71 },
|
||||
{ PROC_LINKS(open_long_braces_semicolon, 0), "open_long_braces_semicolon", 26, "At the cursor, insert a '{' and '};' separated by a blank line.", 63, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 63 },
|
||||
|
@ -384,8 +384,8 @@ static Command_Metadata fcoder_metacmd_table[220] = {
|
|||
{ PROC_LINKS(query_replace, 0), "query_replace", 13, "Queries the user for two strings, and incrementally replaces every occurence of the first string with the second string.", 120, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1019 },
|
||||
{ PROC_LINKS(query_replace_identifier, 0), "query_replace_identifier", 24, "Queries the user for a string, and incrementally replace every occurence of the word or token found at the cursor with the specified string.", 140, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1043 },
|
||||
{ PROC_LINKS(query_replace_selection, 0), "query_replace_selection", 23, "Queries the user for a string, and incrementally replace every occurence of the string found in the selected range with the specified string.", 141, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1061 },
|
||||
{ PROC_LINKS(redo, 0), "redo", 4, "Advances forewards through the undo history.", 44, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1588 },
|
||||
{ PROC_LINKS(reload_themes, 0), "reload_themes", 13, "Loads all the theme files in the theme folder, replacing duplicates with the new theme data.", 92, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1596 },
|
||||
{ PROC_LINKS(redo, 0), "redo", 4, "Advances forewards through the undo history.", 44, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1593 },
|
||||
{ PROC_LINKS(reload_themes, 0), "reload_themes", 13, "Loads all the theme files in the theme folder, replacing duplicates with the new theme data.", 92, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1606 },
|
||||
{ PROC_LINKS(remap_interactive, 0), "remap_interactive", 17, "Switch to a named key binding map.", 34, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 290 },
|
||||
{ PROC_LINKS(rename_file_query, 0), "rename_file_query", 17, "Queries the user for a new name and renames the file of the current buffer, altering the buffer's name too.", 107, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1201 },
|
||||
{ PROC_LINKS(reopen, 0), "reopen", 6, "Reopen the current buffer from the hard drive.", 46, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1572 },
|
||||
|
|
|
@ -64,24 +64,6 @@ end_map(Bind_Helper *helper){
|
|||
helper->group = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
bind(Bind_Helper *helper, Key_Code code, uint8_t modifiers, Command_ID cmdid){
|
||||
if (helper->group == 0 && helper->error == 0){
|
||||
helper->error = BH_ERR_MISSING_BEGIN;
|
||||
}
|
||||
if (!helper->error){
|
||||
++helper->group->map_begin.bind_count;
|
||||
}
|
||||
|
||||
Binding_Unit unit;
|
||||
unit.type = unit_binding;
|
||||
unit.binding.command_id = cmdid;
|
||||
unit.binding.code = code;
|
||||
unit.binding.modifiers = modifiers;
|
||||
|
||||
write_unit(helper, unit);
|
||||
}
|
||||
|
||||
static void
|
||||
bind(Bind_Helper *helper, Key_Code code, uint8_t modifiers, Custom_Command_Function *func){
|
||||
if (helper->group == 0 && helper->error == 0){
|
||||
|
@ -102,17 +84,7 @@ bind(Bind_Helper *helper, Key_Code code, uint8_t modifiers, Custom_Command_Funct
|
|||
|
||||
static void
|
||||
bind(Bind_Helper *helper, Key_Code code, uint8_t modifiers, Generic_Command cmd){
|
||||
if (cmd.cmdid < cmdid_count){
|
||||
bind(helper, code, modifiers, cmd.cmdid);
|
||||
}
|
||||
else{
|
||||
bind(helper, code, modifiers, cmd.command);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
bind_vanilla_keys(Bind_Helper *helper, int32_t cmdid){
|
||||
bind(helper, 0, 0, cmdid);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -120,11 +92,6 @@ bind_vanilla_keys(Bind_Helper *helper, Custom_Command_Function *func){
|
|||
bind(helper, 0, 0, func);
|
||||
}
|
||||
|
||||
static void
|
||||
bind_vanilla_keys(Bind_Helper *helper, unsigned char modifiers, int32_t cmdid){
|
||||
bind(helper, 0, modifiers, cmdid);
|
||||
}
|
||||
|
||||
static void
|
||||
bind_vanilla_keys(Bind_Helper *helper, unsigned char modifiers, Custom_Command_Function *func){
|
||||
bind(helper, 0, modifiers, func);
|
||||
|
@ -301,12 +268,7 @@ exec_command(Application_Links *app, Custom_Command_Function *func){
|
|||
|
||||
static void
|
||||
exec_command(Application_Links *app, Generic_Command cmd){
|
||||
if (cmd.cmdid < cmdid_count){
|
||||
exec_command(app, cmd.cmdid);
|
||||
}
|
||||
else{
|
||||
exec_command(app, cmd.command);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t
|
||||
|
|
118
4ed.cpp
118
4ed.cpp
|
@ -100,58 +100,6 @@ file_cursor_to_end(System_Functions *system, Models *models, Editing_File *file)
|
|||
#define REQ_FILE(n,v) Editing_File *n = (v)->transient.file_data.file; if (n == 0) return
|
||||
#define REQ_FILE_HISTORY(n,v) Editing_File *n = (v)->transient.file_data.file; if (n == 0 || n->state.undo.undo.edits == 0) return
|
||||
|
||||
#define COMMAND_DECL(n) internal void command_##n(System_Functions *system, Models *models, Command_Binding binding)
|
||||
|
||||
COMMAND_DECL(null){}
|
||||
|
||||
internal void
|
||||
view_undo_redo(System_Functions *system, Models *models, View *view, Edit_Stack *stack, Edit_Type expected_type){
|
||||
Editing_File *file = view->transient.file_data.file;
|
||||
Assert(file != 0);
|
||||
if (stack->edit_count > 0){
|
||||
Edit_Step step = stack->edits[stack->edit_count - 1];
|
||||
Assert(step.type == expected_type);
|
||||
edit_historical(system, models, file, view, stack,
|
||||
step, hist_normal);
|
||||
}
|
||||
}
|
||||
|
||||
COMMAND_DECL(undo){
|
||||
Panel *active_panel = layout_get_active_panel(&models->layout);
|
||||
View *view = active_panel->view;
|
||||
if (view_lock_flags(view) != 0){
|
||||
return;
|
||||
}
|
||||
Editing_File *file = view->transient.file_data.file;
|
||||
if (file->state.undo.undo.edits == 0){
|
||||
return;
|
||||
}
|
||||
view_undo_redo(system, models, view, &file->state.undo.undo, ED_UNDO);
|
||||
Assert(file->state.undo.undo.size >= 0);
|
||||
}
|
||||
|
||||
COMMAND_DECL(redo){
|
||||
Panel *active_panel = layout_get_active_panel(&models->layout);
|
||||
View *view = active_panel->view;
|
||||
if (view_lock_flags(view) != 0){
|
||||
return;
|
||||
}
|
||||
Editing_File *file = view->transient.file_data.file;
|
||||
if (file->state.undo.undo.edits == 0){
|
||||
return;
|
||||
}
|
||||
view_undo_redo(system, models, view, &file->state.undo.redo, ED_REDO);
|
||||
Assert(file->state.undo.undo.size >= 0);
|
||||
}
|
||||
|
||||
COMMAND_DECL(user_callback){
|
||||
if (binding.custom != 0){
|
||||
binding.custom(&models->app_links);
|
||||
}
|
||||
}
|
||||
|
||||
global Command_Function *command_table[cmdid_count];
|
||||
|
||||
SCROLL_RULE_SIG(fallback_scroll_rule){
|
||||
b32 result = false;
|
||||
if (target_x != *scroll_x){
|
||||
|
@ -171,16 +119,15 @@ SCROLL_RULE_SIG(fallback_scroll_rule){
|
|||
internal void
|
||||
setup_ui_commands(Command_Map *commands, Partition *part, i32 parent){
|
||||
map_init(commands, part, DEFAULT_UI_MAP_SIZE, parent);
|
||||
|
||||
// TODO(allen): do(fix the weird built-in-ness of the ui map)
|
||||
u8 mdfr_array[] = {MDFR_NONE, MDFR_SHIFT, MDFR_CTRL, MDFR_SHIFT | MDFR_CTRL};
|
||||
for (i32 i = 0; i < 4; ++i){
|
||||
u8 mdfr = mdfr_array[i];
|
||||
map_add(commands, key_left , mdfr, command_null, (Custom_Command_Function*)0);
|
||||
map_add(commands, key_right, mdfr, command_null, (Custom_Command_Function*)0);
|
||||
map_add(commands, key_up , mdfr, command_null, (Custom_Command_Function*)0);
|
||||
map_add(commands, key_down , mdfr, command_null, (Custom_Command_Function*)0);
|
||||
map_add(commands, key_back , mdfr, command_null, (Custom_Command_Function*)0);
|
||||
map_add(commands, key_left , mdfr, (Custom_Command_Function*)0);
|
||||
map_add(commands, key_right, mdfr, (Custom_Command_Function*)0);
|
||||
map_add(commands, key_up , mdfr, (Custom_Command_Function*)0);
|
||||
map_add(commands, key_down , mdfr, (Custom_Command_Function*)0);
|
||||
map_add(commands, key_back , mdfr, (Custom_Command_Function*)0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -367,44 +314,18 @@ interpret_binding_buffer(Models *models, void *buffer, i32 size){
|
|||
}
|
||||
}break;
|
||||
|
||||
case unit_binding:
|
||||
{
|
||||
if (map_ptr != 0){
|
||||
Command_Function *func = 0;
|
||||
if (unit->binding.command_id < cmdid_count){
|
||||
func = command_table[unit->binding.command_id];
|
||||
}
|
||||
if (func != 0){
|
||||
if (unit->binding.code == 0){
|
||||
u32 index = 0;
|
||||
if (map_get_modifiers_hash(unit->binding.modifiers, &index)){
|
||||
map_ptr->vanilla_keyboard_default[index].function = func;
|
||||
map_ptr->vanilla_keyboard_default[index].custom_id = unit->binding.command_id;
|
||||
}
|
||||
}
|
||||
else{
|
||||
map_add(map_ptr, unit->binding.code, unit->binding.modifiers, func, unit->binding.command_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}break;
|
||||
|
||||
case unit_callback:
|
||||
{
|
||||
if (map_ptr != 0){
|
||||
Command_Function *func = command_user_callback;
|
||||
Custom_Command_Function *custom = unit->callback.func;
|
||||
if (func != 0){
|
||||
if (unit->callback.code == 0){
|
||||
u32 index = 0;
|
||||
if (map_get_modifiers_hash(unit->binding.modifiers, &index)){
|
||||
map_ptr->vanilla_keyboard_default[index].function = func;
|
||||
if (map_get_modifiers_hash(unit->callback.modifiers, &index)){
|
||||
map_ptr->vanilla_keyboard_default[index].custom = custom;
|
||||
}
|
||||
}
|
||||
else{
|
||||
map_add(map_ptr, unit->callback.code, unit->callback.modifiers, func, custom);
|
||||
}
|
||||
map_add(map_ptr, unit->callback.code, unit->callback.modifiers, custom);
|
||||
}
|
||||
}
|
||||
}break;
|
||||
|
@ -510,18 +431,13 @@ internal void
|
|||
command_caller(Coroutine_Head *coroutine){
|
||||
Command_In *cmd_in = (Command_In*)coroutine->in;
|
||||
Models *models = cmd_in->models;
|
||||
if (models->command_caller){
|
||||
Generic_Command generic;
|
||||
if (cmd_in->bind.function == command_user_callback){
|
||||
if (models->command_caller != 0){
|
||||
Generic_Command generic = {};
|
||||
generic.command = cmd_in->bind.custom;
|
||||
}
|
||||
else{
|
||||
generic.cmdid = (Command_ID)cmd_in->bind.custom_id;
|
||||
}
|
||||
models->command_caller(&models->app_links, generic);
|
||||
}
|
||||
else{
|
||||
cmd_in->bind.function(models->system, models, cmd_in->bind);
|
||||
cmd_in->bind.custom(&models->app_links);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -534,15 +450,6 @@ app_links_init(System_Functions *system, Application_Links *app_links, void *dat
|
|||
app_links->system_links = system;
|
||||
}
|
||||
|
||||
internal void
|
||||
setup_command_table(void){
|
||||
#define SET(n) command_table[cmdid_##n] = command_##n
|
||||
SET(null);
|
||||
SET(undo);
|
||||
SET(redo);
|
||||
#undef SET
|
||||
}
|
||||
|
||||
// App Functions
|
||||
|
||||
internal void
|
||||
|
@ -831,12 +738,12 @@ launch_command_via_event(System_Functions *system, Application_Step_Result *app_
|
|||
i32 map = view_get_map(view);
|
||||
Command_Binding cmd_bind = map_extract_recursive(&models->mapping, map, event);
|
||||
|
||||
if (cmd_bind.function != 0){
|
||||
if (cmd_bind.custom != 0){
|
||||
Assert(models->command_coroutine == 0);
|
||||
Coroutine_Head *command_coroutine = system->create_coroutine(command_caller);
|
||||
models->command_coroutine = command_coroutine;
|
||||
|
||||
Command_In cmd_in;
|
||||
Command_In cmd_in = {};
|
||||
cmd_in.models = models;
|
||||
cmd_in.bind = cmd_bind;
|
||||
|
||||
|
@ -912,7 +819,6 @@ App_Init_Sig(app_init){
|
|||
}
|
||||
|
||||
{
|
||||
setup_command_table();
|
||||
Assert(models->config_api.get_bindings != 0);
|
||||
i32 wanted_size = models->config_api.get_bindings(models->app_links.memory, models->app_links.memory_size);
|
||||
Assert(wanted_size <= models->app_links.memory_size);
|
||||
|
|
|
@ -190,34 +190,6 @@ DOC(Dumps away the previous mappings and instantiates the mappings described in
|
|||
return(result);
|
||||
}
|
||||
|
||||
API_EXPORT bool32
|
||||
Exec_Command(Application_Links *app, Command_ID command_id)
|
||||
/*
|
||||
DOC_PARAM(command_id, The command_id parameter specifies which internal command to execute.)
|
||||
DOC_RETURN(This call returns non-zero if command_id named a valid internal command.)
|
||||
DOC(A call to exec_command executes an internal command. If command_id is invalid a warning is posted to *messages*.)
|
||||
DOC_SEE(Command_ID)
|
||||
*/{
|
||||
bool32 result = false;
|
||||
|
||||
if (command_id < cmdid_count){
|
||||
Models *models = (Models*)app->cmd_context;
|
||||
Command_Function *function = command_table[command_id];
|
||||
Command_Binding binding = {};
|
||||
binding.function = function;
|
||||
if (function != 0){
|
||||
function(models->system, models, binding);
|
||||
}
|
||||
|
||||
result = true;
|
||||
}
|
||||
else{
|
||||
print_message(app, literal("WARNING: An invalid Command_ID was passed to exec_command."));
|
||||
}
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
API_EXPORT bool32
|
||||
Exec_System_Command(Application_Links *app, View_Summary *view, Buffer_Identifier buffer_id, char *path, int32_t path_len, char *command, int32_t command_len, Command_Line_Interface_Flag flags)
|
||||
/*
|
||||
|
|
|
@ -88,7 +88,7 @@ map_hash(Key_Code event_code, u8 modifiers){
|
|||
}
|
||||
|
||||
internal b32
|
||||
map_add(Command_Map *map, Key_Code event_code, u8 modifiers, Command_Function *function, Custom_Command_Function *custom){
|
||||
map_add(Command_Map *map, Key_Code event_code, u8 modifiers, Custom_Command_Function *custom){
|
||||
b32 result = false;
|
||||
Assert(map->count * 8 < map->max * 7);
|
||||
u64 hash = map_hash(event_code, modifiers);
|
||||
|
@ -96,7 +96,7 @@ map_add(Command_Map *map, Key_Code event_code, u8 modifiers, Command_Function *f
|
|||
u32 max = map->max;
|
||||
u32 index = hash % max;
|
||||
Command_Binding entry = map->commands[index];
|
||||
for (; entry.function != 0 && entry.hash != COMMAND_HASH_ERASED;){
|
||||
for (; entry.custom != 0 && entry.hash != COMMAND_HASH_ERASED;){
|
||||
if (entry.hash == hash){
|
||||
result = true;
|
||||
break;
|
||||
|
@ -106,7 +106,6 @@ map_add(Command_Map *map, Key_Code event_code, u8 modifiers, Command_Function *f
|
|||
}
|
||||
|
||||
Command_Binding bind = {};
|
||||
bind.function = function;
|
||||
bind.custom = custom;
|
||||
bind.hash = hash;
|
||||
map->commands[index] = bind;
|
||||
|
@ -117,11 +116,6 @@ map_add(Command_Map *map, Key_Code event_code, u8 modifiers, Command_Function *f
|
|||
return(result);
|
||||
}
|
||||
|
||||
internal b32
|
||||
map_add(Command_Map *map, Key_Code event_code, u8 modifiers, Command_Function *function, u64 custom_id){
|
||||
return(map_add(map, event_code, modifiers, function, (Custom_Command_Function*)custom_id));
|
||||
}
|
||||
|
||||
internal b32
|
||||
map_find_entry(Command_Map *map, Key_Code event_code, u8 modifiers, u32 *index_out){
|
||||
u64 hash = map_hash(event_code, modifiers);
|
||||
|
@ -129,7 +123,7 @@ map_find_entry(Command_Map *map, Key_Code event_code, u8 modifiers, u32 *index_o
|
|||
u32 index = hash % max;
|
||||
b32 result = false;
|
||||
Command_Binding entry = map->commands[index];
|
||||
for (; entry.function != 0;){
|
||||
for (; entry.custom != 0;){
|
||||
if (entry.hash == hash){
|
||||
*index_out = index;
|
||||
result = true;
|
||||
|
@ -156,7 +150,7 @@ map_drop(Command_Map *map, Key_Code event_code, u8 modifiers){
|
|||
u32 index = 0;
|
||||
b32 result = map_find_entry(map, event_code, modifiers, &index);
|
||||
if (result){
|
||||
map->commands[index].function = 0;
|
||||
map->commands[index].custom = 0;
|
||||
map->commands[index].hash = COMMAND_HASH_ERASED;
|
||||
}
|
||||
return(result);
|
||||
|
@ -228,7 +222,7 @@ map_extract(Command_Map *map, Key_Event_Data key){
|
|||
mod_flags &= ~(MDFR_SHIFT);
|
||||
}
|
||||
map_find(map, code, mod_flags, &bind);
|
||||
if (bind.function == 0){
|
||||
if (bind.custom == 0){
|
||||
map_get_vanilla_keyboard_default(map, mod_flags, &bind);
|
||||
}
|
||||
}
|
||||
|
@ -249,7 +243,7 @@ map_extract_recursive(Mapping *mapping, i32 map_id, Key_Event_Data key){
|
|||
Command_Binding cmd_bind = {};
|
||||
for (; map != 0; ){
|
||||
cmd_bind = map_extract(map, key);
|
||||
if (cmd_bind.function == 0){
|
||||
if (cmd_bind.custom == 0){
|
||||
if (visited_top < ArrayCount(visited_maps)){
|
||||
visited_maps[visited_top++] = map;
|
||||
map = get_map(mapping, map->parent);
|
||||
|
|
|
@ -12,17 +12,8 @@
|
|||
#if !defined(FRED_COMMAND_H)
|
||||
#define FRED_COMMAND_H
|
||||
|
||||
#define Command_Function_Sig(name) \
|
||||
void (name)(System_Functions *system, struct Models *models, struct Command_Binding binding)
|
||||
|
||||
typedef Command_Function_Sig(Command_Function);
|
||||
|
||||
struct Command_Binding{
|
||||
Command_Function *function;
|
||||
union{
|
||||
Custom_Command_Function *custom;
|
||||
u64 custom_id;
|
||||
};
|
||||
u64 hash;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue