command maps can now be reopened and extended
This commit is contained in:
parent
6145408548
commit
95f33accb3
|
@ -604,7 +604,7 @@ struct Binding_Unit{
|
||||||
union{
|
union{
|
||||||
struct{ int total_size; int user_map_count; int error; } header;
|
struct{ int total_size; int user_map_count; int error; } header;
|
||||||
|
|
||||||
struct{ int mapid; int bind_count; } map_begin;
|
struct{ int mapid; int replace; int bind_count; } map_begin;
|
||||||
struct{ int mapid; } map_inherit;
|
struct{ int mapid; } map_inherit;
|
||||||
struct{
|
struct{
|
||||||
short code;
|
short code;
|
||||||
|
|
|
@ -75,17 +75,28 @@ begin_bind_helper(void *data, int size){
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
begin_map(Bind_Helper *helper, int mapid){
|
begin_map_(Bind_Helper *helper, int mapid, int replace){
|
||||||
if (helper->group != 0 && helper->error == 0) helper->error = BH_ERR_MISSING_END;
|
if (helper->group != 0 && helper->error == 0) helper->error = BH_ERR_MISSING_END;
|
||||||
if (!helper->error && mapid < mapid_global) ++helper->header->header.user_map_count;
|
if (!helper->error && mapid < mapid_global) ++helper->header->header.user_map_count;
|
||||||
|
|
||||||
Binding_Unit unit;
|
Binding_Unit unit;
|
||||||
unit.type = unit_map_begin;
|
unit.type = unit_map_begin;
|
||||||
unit.map_begin.mapid = mapid;
|
unit.map_begin.mapid = mapid;
|
||||||
|
unit.map_begin.replace = replace;
|
||||||
helper->group = write_unit(helper, unit);
|
helper->group = write_unit(helper, unit);
|
||||||
helper->group->map_begin.bind_count = 0;
|
helper->group->map_begin.bind_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void
|
||||||
|
begin_map(Bind_Helper *helper, int mapid){
|
||||||
|
begin_map_(helper, mapid, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void
|
||||||
|
restart_map(Bind_Helper *helper, int mapid){
|
||||||
|
begin_map_(helper, mapid, 1);
|
||||||
|
}
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
end_map(Bind_Helper *helper){
|
end_map(Bind_Helper *helper){
|
||||||
if (helper->group == 0 && helper->error == 0) helper->error = BH_ERR_MISSING_BEGIN;
|
if (helper->group == 0 && helper->error == 0) helper->error = BH_ERR_MISSING_BEGIN;
|
||||||
|
|
77
4ed.cpp
77
4ed.cpp
|
@ -118,17 +118,59 @@ app_get_map_index(Models *models, i32 mapid){
|
||||||
}
|
}
|
||||||
|
|
||||||
internal Command_Map*
|
internal Command_Map*
|
||||||
app_get_map(Models *models, i32 mapid){
|
app_get_map_base(Models *models, i32 mapid, b32 add){
|
||||||
Command_Map *map = 0;
|
Command_Map *map = 0;
|
||||||
if (mapid < mapid_global){
|
if (mapid < mapid_global){
|
||||||
mapid = app_get_map_index(models, mapid);
|
if (add){
|
||||||
|
mapid = app_get_or_add_map_index(models, mapid);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
mapid = app_get_map_index(models, mapid);
|
||||||
|
}
|
||||||
if (mapid < models->user_map_count){
|
if (mapid < models->user_map_count){
|
||||||
map = models->user_maps + mapid;
|
map = models->user_maps + mapid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (mapid == mapid_global) map = &models->map_top;
|
else if (mapid == mapid_global) map = &models->map_top;
|
||||||
else if (mapid == mapid_file) map = &models->map_file;
|
else if (mapid == mapid_file) map = &models->map_file;
|
||||||
return map;
|
return(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal Command_Map*
|
||||||
|
app_get_or_add_map(Models *models, i32 mapid){
|
||||||
|
Command_Map *map = app_get_map_base(models, mapid, 1);
|
||||||
|
return(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal Command_Map*
|
||||||
|
app_get_map(Models *models, i32 mapid){
|
||||||
|
Command_Map *map = app_get_map_base(models, mapid, 0);
|
||||||
|
return(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void
|
||||||
|
app_map_set_count(Models *models, i32 mapid, i32 count){
|
||||||
|
Command_Map *map = app_get_or_add_map(models, mapid);
|
||||||
|
Assert(map->commands == 0);
|
||||||
|
map->count = count;
|
||||||
|
if (map->max < count){
|
||||||
|
map->max = count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal i32
|
||||||
|
app_map_get_count(Models *models, i32 mapid){
|
||||||
|
Command_Map *map = app_get_or_add_map(models, mapid);
|
||||||
|
i32 count = map->count;
|
||||||
|
Assert(map->commands == 0);
|
||||||
|
return(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal i32
|
||||||
|
app_map_get_max_count(Models *models, i32 mapid){
|
||||||
|
Command_Map *map = app_get_or_add_map(models, mapid);
|
||||||
|
i32 count = map->max;
|
||||||
|
return(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
|
@ -2614,8 +2656,9 @@ setup_ui_commands(Command_Map *commands, Partition *part, Command_Map *parent){
|
||||||
|
|
||||||
commands->vanilla_keyboard_default.function = command_null;
|
commands->vanilla_keyboard_default.function = command_null;
|
||||||
|
|
||||||
// TODO(allen): This is hacky, when the new UI stuff happens, let's fix it, and by that
|
// TODO(allen): This is hacky, when the new UI stuff happens, let's fix it,
|
||||||
// I mean actually fix it, don't just say you fixed it with something stupid again.
|
// and by that I mean actually fix it, don't just say you fixed it with
|
||||||
|
// something stupid again.
|
||||||
u8 mdfr;
|
u8 mdfr;
|
||||||
u8 mdfr_array[] = {MDFR_NONE, MDFR_SHIFT, MDFR_CTRL, MDFR_SHIFT | MDFR_CTRL};
|
u8 mdfr_array[] = {MDFR_NONE, MDFR_SHIFT, MDFR_CTRL, MDFR_SHIFT | MDFR_CTRL};
|
||||||
for (i32 i = 0; i < 4; ++i){
|
for (i32 i = 0; i < 4; ++i){
|
||||||
|
@ -3240,8 +3283,26 @@ App_Init_Sig(app_init){
|
||||||
switch (unit->type){
|
switch (unit->type){
|
||||||
case unit_map_begin:
|
case unit_map_begin:
|
||||||
{
|
{
|
||||||
int table_max = unit->map_begin.bind_count * 3 / 2;
|
|
||||||
int mapid = unit->map_begin.mapid;
|
int mapid = unit->map_begin.mapid;
|
||||||
|
int count = app_map_get_count(models, mapid);
|
||||||
|
if (unit->map_begin.replace){
|
||||||
|
app_map_set_count(models, mapid, unit->map_begin.bind_count);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
app_map_set_count(models, mapid, unit->map_begin.bind_count + count);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unit = (Binding_Unit*)models->app_links.memory;
|
||||||
|
for (++unit; unit < end; ++unit){
|
||||||
|
switch (unit->type){
|
||||||
|
case unit_map_begin:
|
||||||
|
{
|
||||||
|
int mapid = unit->map_begin.mapid;
|
||||||
|
int count = app_map_get_max_count(models, mapid);
|
||||||
|
int table_max = count * 3 / 2;
|
||||||
if (mapid == mapid_global){
|
if (mapid == mapid_global){
|
||||||
map_ptr = &models->map_top;
|
map_ptr = &models->map_top;
|
||||||
map_init(map_ptr, &models->mem.part, table_max, global);
|
map_init(map_ptr, &models->mem.part, table_max, global);
|
||||||
|
@ -3259,6 +3320,10 @@ App_Init_Sig(app_init){
|
||||||
map_init(map_ptr, &models->mem.part, table_max, global);
|
map_init(map_ptr, &models->mem.part, table_max, global);
|
||||||
}
|
}
|
||||||
else map_ptr = 0;
|
else map_ptr = 0;
|
||||||
|
|
||||||
|
if (map_ptr && unit->map_begin.replace){
|
||||||
|
map_clear(map_ptr);
|
||||||
|
}
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case unit_inherit:
|
case unit_inherit:
|
||||||
|
|
|
@ -117,16 +117,25 @@ command_binding_zero(){
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
map_init(Command_Map *commands, Partition *part, i32 max, Command_Map *parent){
|
map_clear(Command_Map *commands){
|
||||||
max = ((max < 6)?(6):(max));
|
i32 max = commands->max;
|
||||||
commands->parent = parent;
|
|
||||||
commands->commands = push_array(part, Command_Binding, max);
|
|
||||||
memset(commands->commands, 0, max*sizeof(*commands->commands));
|
memset(commands->commands, 0, max*sizeof(*commands->commands));
|
||||||
commands->vanilla_keyboard_default = command_binding_zero();
|
commands->vanilla_keyboard_default = command_binding_zero();
|
||||||
commands->max = max;
|
|
||||||
commands->count = 0;
|
commands->count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void
|
||||||
|
map_init(Command_Map *commands, Partition *part, i32 max, Command_Map *parent){
|
||||||
|
if (commands->commands == 0){
|
||||||
|
max = ((max < 6)?(6):(max));
|
||||||
|
commands->parent = parent;
|
||||||
|
commands->commands = push_array(part, Command_Binding, max);
|
||||||
|
commands->max = max;
|
||||||
|
|
||||||
|
map_clear(commands);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
map_get_vanilla_keyboard_default(Command_Map *map, u8 command,
|
map_get_vanilla_keyboard_default(Command_Map *map, u8 command,
|
||||||
Command_Binding *bind_out){
|
Command_Binding *bind_out){
|
||||||
|
|
|
@ -1274,11 +1274,6 @@ gui_standard_list(GUI_Target *target, GUI_id id, GUI_Scroll_Vars scroll,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (update->has_index_position){
|
if (update->has_index_position){
|
||||||
// TODO(allen): THOUGHT:
|
|
||||||
// Could we better abstract this idea of having something that
|
|
||||||
// wants to stay in view so that users don't have to manage this
|
|
||||||
// nasty view back and forth directly if they don't want?
|
|
||||||
|
|
||||||
GUI_View_Jump jump =
|
GUI_View_Jump jump =
|
||||||
gui_compute_view_jump(scroll, update->index_position);
|
gui_compute_view_jump(scroll, update->index_position);
|
||||||
jump.view_min += 45.f;
|
jump.view_min += 45.f;
|
||||||
|
|
|
@ -305,11 +305,13 @@ CUSTOM_COMMAND_SIG(save_theme_settings){
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
void experiment_extension(Bind_Helper *context){
|
void experiment_extension(Bind_Helper *context){
|
||||||
bind(context, 'k', MDFR_ALT, kill_rect);
|
bind(context, 'k', MDFR_ALT, kill_rect);
|
||||||
bind(context, '/', MDFR_ALT, mark_matching_brace);
|
bind(context, '/', MDFR_ALT, mark_matching_brace);
|
||||||
bind(context, '\'', MDFR_ALT, cursor_to_surrounding_scope);
|
bind(context, '\'', MDFR_ALT, cursor_to_surrounding_scope);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
@ -354,7 +356,16 @@ int get_bindings(void *data, int size){
|
||||||
|
|
||||||
set_scroll_rule(context, smooth_scroll_rule);
|
set_scroll_rule(context, smooth_scroll_rule);
|
||||||
|
|
||||||
default_keys(context, experiment_extension);
|
default_keys(context, 0);
|
||||||
|
|
||||||
|
begin_map(context, mapid_file);
|
||||||
|
bind(context, 'k', MDFR_ALT, kill_rect);
|
||||||
|
end_map(context);
|
||||||
|
|
||||||
|
begin_map(context, my_code_map);
|
||||||
|
bind(context, '/', MDFR_ALT, mark_matching_brace);
|
||||||
|
bind(context, '\'', MDFR_ALT, cursor_to_surrounding_scope);
|
||||||
|
end_map(context);
|
||||||
|
|
||||||
int result = end_bind_helper(context);
|
int result = end_bind_helper(context);
|
||||||
return(result);
|
return(result);
|
||||||
|
|
Loading…
Reference in New Issue