fixed casey's 'panel lock up' bug

This commit is contained in:
Allen Webster 2016-05-19 21:12:41 -04:00
parent c8c62dca58
commit 134e166099
4 changed files with 129 additions and 134 deletions

137
4ed.cpp
View File

@ -87,92 +87,6 @@ struct App_Vars{
Command_Data command_data; Command_Data command_data;
}; };
internal i32
app_get_or_add_map_index(Models *models, i32 mapid){
i32 result;
i32 user_map_count = models->user_map_count;
i32 *map_id_table = models->map_id_table;
for (result = 0; result < user_map_count; ++result){
if (map_id_table[result] == mapid) break;
if (map_id_table[result] == -1){
map_id_table[result] = mapid;
break;
}
}
return result;
}
internal i32
app_get_map_index(Models *models, i32 mapid){
i32 result;
i32 user_map_count = models->user_map_count;
i32 *map_id_table = models->map_id_table;
for (result = 0; result < user_map_count; ++result){
if (map_id_table[result] == mapid) break;
if (map_id_table[result] == 0){
result = user_map_count;
break;
}
}
return result;
}
internal Command_Map*
app_get_map_base(Models *models, i32 mapid, b32 add){
Command_Map *map = 0;
if (mapid < mapid_global){
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){
map = models->user_maps + mapid;
}
}
else if (mapid == mapid_global) map = &models->map_top;
else if (mapid == mapid_file) map = &models->map_file;
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
output_file_append(System_Functions *system, Models *models, Editing_File *file, String value, b32 cursor_at_end){ output_file_append(System_Functions *system, Models *models, Editing_File *file, String value, b32 cursor_at_end){
i32 end = buffer_size(&file->state.buffer); i32 end = buffer_size(&file->state.buffer);
@ -267,7 +181,7 @@ panel_make_empty(System_Functions *system, Exchange *exchange, App_Vars *vars, P
Assert(panel->view == 0); Assert(panel->view == 0);
new_view = live_set_alloc_view(&vars->live_set, panel, models); new_view = live_set_alloc_view(&vars->live_set, panel, models);
view_set_file(new_view.view, 0, models); view_set_file(new_view.view, 0, models);
new_view.view->map = app_get_map(models, mapid_global); new_view.view->map = get_map(models, mapid_global);
return(new_view.view); return(new_view.view);
} }
@ -925,13 +839,13 @@ view_file_in_panel(Command_Data *cmd, Panel *panel, Editing_File *file){
View *view = panel->view; View *view = panel->view;
view_set_file(view, file, models); view_set_file(view, file, models);
view_show_file(view, 0); view_show_file(view);
cmd->part = old_part; cmd->part = old_part;
end_temp_memory(temp); end_temp_memory(temp);
cmd->view = old_view; cmd->view = old_view;
panel->view->map = app_get_map(models, file->settings.base_map_id); panel->view->map = get_map(models, file->settings.base_map_id);
} }
// TODO(allen): Improvements to reopen // TODO(allen): Improvements to reopen
@ -956,7 +870,7 @@ COMMAND_DECL(reopen){
app_push_file_binding(vars, file_id, index); app_push_file_binding(vars, file_id, index);
view_set_file(view, file, models); view_set_file(view, file, models);
view_show_file(view, 0); view_show_file(view);
} }
else{ else{
do_feedback_message(system, models, make_lit_string("ERROR: no file load slot available\n")); do_feedback_message(system, models, make_lit_string("ERROR: no file load slot available\n"));
@ -1550,13 +1464,7 @@ COMMAND_DECL(open_menu){
COMMAND_DECL(close_minor_view){ COMMAND_DECL(close_minor_view){
USE_VIEW(view); USE_VIEW(view);
USE_MODELS(models); view_show_file(view);
Command_Map *map = &models->map_top;
if (view->file_data.file){
map = app_get_map(models, view->file_data.file->settings.base_map_id);
}
view_show_file(view, map);
} }
COMMAND_DECL(cursor_mark_swap){ COMMAND_DECL(cursor_mark_swap){
@ -1631,7 +1539,7 @@ COMMAND_DECL(set_settings){
if (v == mapid_global) file->settings.base_map_id = mapid_global; if (v == mapid_global) file->settings.base_map_id = mapid_global;
else if (v == mapid_file) file->settings.base_map_id = mapid_file; else if (v == mapid_file) file->settings.base_map_id = mapid_file;
else if (v < mapid_global){ else if (v < mapid_global){
new_mapid = app_get_map_index(models, v); new_mapid = get_map_index(models, v);
if (new_mapid < models->user_map_count) file->settings.base_map_id = v; if (new_mapid < models->user_map_count) file->settings.base_map_id = v;
else file->settings.base_map_id = mapid_file; else file->settings.base_map_id = mapid_file;
} }
@ -1644,7 +1552,7 @@ COMMAND_DECL(set_settings){
for (View_Iter iter = file_view_iter_init(&models->layout, file, 0); for (View_Iter iter = file_view_iter_init(&models->layout, file, 0);
file_view_iter_good(iter); file_view_iter_good(iter);
iter = file_view_iter_next(iter)){ iter = file_view_iter_next(iter)){
iter.view->map = app_get_map(models, file->settings.base_map_id); iter.view->map = get_map(models, file->settings.base_map_id);
} }
} }
} }
@ -2476,7 +2384,7 @@ extern "C"{
result = 1; result = 1;
if (file != vptr->file_data.file){ if (file != vptr->file_data.file){
view_set_file(vptr, file, models); view_set_file(vptr, file, models);
view_show_file(vptr, 0); view_show_file(vptr);
} }
} }
@ -2818,20 +2726,19 @@ app_hardcode_styles(Models *models){
style->main.mark_color = 0xFF808080; style->main.mark_color = 0xFF808080;
style->main.highlight_color = 0xFF703419; style->main.highlight_color = 0xFF703419;
style->main.at_highlight_color = 0xFFCDAA7D; style->main.at_highlight_color = 0xFFCDAA7D;
style->main.default_color = 0xFFCDAA7D; style->main.default_color = 0xFFA08563;
style->main.comment_color = 0xFF7F7F7F; style->main.comment_color = 0xFF7D7D7D;
style->main.keyword_color = 0xFFCD950C; style->main.keyword_color = 0xFFCD950C;
style->main.str_constant_color = 0xFF6B8E23; style->main.str_constant_color = 0xFF6B8E23;
style->main.char_constant_color = style->main.str_constant_color; style->main.char_constant_color = style->main.str_constant_color;
style->main.int_constant_color = style->main.str_constant_color; style->main.int_constant_color = style->main.str_constant_color;
style->main.float_constant_color = style->main.str_constant_color; style->main.float_constant_color = style->main.str_constant_color;
style->main.bool_constant_color = style->main.str_constant_color; style->main.bool_constant_color = style->main.str_constant_color;
style->main.include_color = style->main.str_constant_color; style->main.include_color = 0xFF6B8E23;
style->main.preproc_color = style->main.default_color; style->main.preproc_color = 0xFFDAB98F;
style->main.special_character_color = 0xFFFF0000; style->main.special_character_color = 0xFFFF0000;
style->main.paste_color = 0xFFFFBB00; style->main.paste_color = 0xFFFFBB00;
style->main.undo_color = 0xFFFF00BB;
style->main.undo_color = 0xFF80005D; style->main.undo_color = 0xFF80005D;
style->main.highlight_junk_color = 0xFF3A0000; style->main.highlight_junk_color = 0xFF3A0000;
@ -3296,12 +3203,12 @@ App_Init_Sig(app_init){
case unit_map_begin: case unit_map_begin:
{ {
int mapid = unit->map_begin.mapid; int mapid = unit->map_begin.mapid;
int count = app_map_get_count(models, mapid); int count = map_get_count(models, mapid);
if (unit->map_begin.replace){ if (unit->map_begin.replace){
app_map_set_count(models, mapid, unit->map_begin.bind_count); map_set_count(models, mapid, unit->map_begin.bind_count);
} }
else{ else{
app_map_set_count(models, mapid, unit->map_begin.bind_count + count); map_set_count(models, mapid, unit->map_begin.bind_count + count);
} }
}; };
} }
@ -3313,7 +3220,7 @@ App_Init_Sig(app_init){
case unit_map_begin: case unit_map_begin:
{ {
int mapid = unit->map_begin.mapid; int mapid = unit->map_begin.mapid;
int count = app_map_get_max_count(models, mapid); int count = map_get_max_count(models, mapid);
int table_max = count * 3 / 2; int table_max = count * 3 / 2;
if (mapid == mapid_global){ if (mapid == mapid_global){
map_ptr = &models->map_top; map_ptr = &models->map_top;
@ -3326,7 +3233,7 @@ App_Init_Sig(app_init){
did_file = 1; did_file = 1;
} }
else if (mapid < mapid_global){ else if (mapid < mapid_global){
i32 index = app_get_or_add_map_index(models, mapid); i32 index = get_or_add_map_index(models, mapid);
Assert(index < user_map_count); Assert(index < user_map_count);
map_ptr = models->user_maps + index; map_ptr = models->user_maps + index;
map_init(map_ptr, &models->mem.part, table_max, global); map_init(map_ptr, &models->mem.part, table_max, global);
@ -3345,7 +3252,7 @@ App_Init_Sig(app_init){
if (mapid == mapid_global) parent = &models->map_top; if (mapid == mapid_global) parent = &models->map_top;
else if (mapid == mapid_file) parent = &models->map_file; else if (mapid == mapid_file) parent = &models->map_file;
else if (mapid < mapid_global){ else if (mapid < mapid_global){
i32 index = app_get_or_add_map_index(models, mapid); i32 index = get_or_add_map_index(models, mapid);
if (index < user_map_count) parent = models->user_maps + index; if (index < user_map_count) parent = models->user_maps + index;
else parent = 0; else parent = 0;
} }
@ -4474,8 +4381,8 @@ App_Step_Sig(app_step){
View *view = panel->view; View *view = panel->view;
view_set_file(view, file, models); view_set_file(view, file, models);
view_show_file(view, 0); view_show_file(view);
view->map = app_get_map(models, file->settings.base_map_id); view->map = get_map(models, file->settings.base_map_id);
Hook_Function *new_file_fnc = models->hooks[hook_new_file]; Hook_Function *new_file_fnc = models->hooks[hook_new_file];
if (new_file_fnc){ if (new_file_fnc){
@ -4504,8 +4411,8 @@ App_Step_Sig(app_step){
View *view = panel->view; View *view = panel->view;
view_set_file(view, file, models); view_set_file(view, file, models);
view_show_file(view, 0); view_show_file(view);
view->map = app_get_map(models, file->settings.base_map_id); view->map = get_map(models, file->settings.base_map_id);
} }
}break; }break;

View File

@ -9,6 +9,92 @@
// TOP // TOP
internal i32
get_or_add_map_index(Models *models, i32 mapid){
i32 result;
i32 user_map_count = models->user_map_count;
i32 *map_id_table = models->map_id_table;
for (result = 0; result < user_map_count; ++result){
if (map_id_table[result] == mapid) break;
if (map_id_table[result] == -1){
map_id_table[result] = mapid;
break;
}
}
return result;
}
internal i32
get_map_index(Models *models, i32 mapid){
i32 result;
i32 user_map_count = models->user_map_count;
i32 *map_id_table = models->map_id_table;
for (result = 0; result < user_map_count; ++result){
if (map_id_table[result] == mapid) break;
if (map_id_table[result] == 0){
result = user_map_count;
break;
}
}
return result;
}
internal Command_Map*
get_map_base(Models *models, i32 mapid, b32 add){
Command_Map *map = 0;
if (mapid < mapid_global){
if (add){
mapid = get_or_add_map_index(models, mapid);
}
else{
mapid = get_map_index(models, mapid);
}
if (mapid < models->user_map_count){
map = models->user_maps + mapid;
}
}
else if (mapid == mapid_global) map = &models->map_top;
else if (mapid == mapid_file) map = &models->map_file;
return(map);
}
internal Command_Map*
get_or_add_map(Models *models, i32 mapid){
Command_Map *map = get_map_base(models, mapid, 1);
return(map);
}
internal Command_Map*
get_map(Models *models, i32 mapid){
Command_Map *map = get_map_base(models, mapid, 0);
return(map);
}
internal void
map_set_count(Models *models, i32 mapid, i32 count){
Command_Map *map = get_or_add_map(models, mapid);
Assert(map->commands == 0);
map->count = count;
if (map->max < count){
map->max = count;
}
}
internal i32
map_get_count(Models *models, i32 mapid){
Command_Map *map = get_or_add_map(models, mapid);
i32 count = map->count;
Assert(map->commands == 0);
return(count);
}
internal i32
map_get_max_count(Models *models, i32 mapid){
Command_Map *map = get_or_add_map(models, mapid);
i32 count = map->max;
return(count);
}
enum Interactive_Action{ enum Interactive_Action{
IAct_Open, IAct_Open,
IAct_Save_As, IAct_Save_As,
@ -105,7 +191,6 @@ struct View{
Panel *panel; Panel *panel;
Command_Map *map; Command_Map *map;
Command_Map *map_for_file;
File_Viewing_Data file_data; File_Viewing_Data file_data;
@ -2750,7 +2835,6 @@ remeasure_file_view(System_Functions *system, View *view){
inline void inline void
view_show_menu(View *view, Command_Map *gui_map){ view_show_menu(View *view, Command_Map *gui_map){
view->map_for_file = view->map;
view->map = gui_map; view->map = gui_map;
view->showing_ui = VUI_Menu; view->showing_ui = VUI_Menu;
view->current_scroll = &view->gui_scroll; view->current_scroll = &view->gui_scroll;
@ -2758,7 +2842,6 @@ view_show_menu(View *view, Command_Map *gui_map){
inline void inline void
view_show_config(View *view, Command_Map *gui_map){ view_show_config(View *view, Command_Map *gui_map){
view->map_for_file = view->map;
view->map = gui_map; view->map = gui_map;
view->showing_ui = VUI_Config; view->showing_ui = VUI_Config;
view->current_scroll = &view->gui_scroll; view->current_scroll = &view->gui_scroll;
@ -2778,7 +2861,6 @@ view_show_interactive(System_Functions *system, View *view,
view->list_i = 0; view->list_i = 0;
view->current_scroll = &view->gui_scroll; view->current_scroll = &view->gui_scroll;
view->map_for_file = view->map;
view->map = gui_map; view->map = gui_map;
hot_directory_clean_end(&models->hot_directory); hot_directory_clean_end(&models->hot_directory);
@ -2787,7 +2869,6 @@ view_show_interactive(System_Functions *system, View *view,
inline void inline void
view_show_theme(View *view, Command_Map *gui_map){ view_show_theme(View *view, Command_Map *gui_map){
view->map_for_file = view->map;
view->map = gui_map; view->map = gui_map;
view->showing_ui = VUI_Theme; view->showing_ui = VUI_Theme;
view->color_mode = CV_Mode_Library; view->color_mode = CV_Mode_Library;
@ -2797,12 +2878,13 @@ view_show_theme(View *view, Command_Map *gui_map){
} }
inline void inline void
view_show_file(View *view, Command_Map *file_map){ view_show_file(View *view){
if (file_map){ Editing_File *file = view->file_data.file;
view->map = file_map; if (file){
view->map = get_map(view->models, file->settings.base_map_id);
} }
else{ else{
view->map = view->map_for_file; view->map = get_map(view->models, mapid_global);
} }
view->showing_ui = VUI_None; view->showing_ui = VUI_None;
view->current_scroll = &view->recent->scroll; view->current_scroll = &view->recent->scroll;
@ -2881,7 +2963,7 @@ interactive_view_complete(View *view, String dest, i32 user_action){
} }
break; break;
} }
view_show_file(view, 0); view_show_file(view);
// TODO(allen): This is here to prevent the key press from being passed to the // TODO(allen): This is here to prevent the key press from being passed to the
// underlying file which is a giant pain. But I want a better system. // underlying file which is a giant pain. But I want a better system.
@ -4256,7 +4338,7 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
} }
if (did_esc && view->showing_ui != VUI_None){ if (did_esc && view->showing_ui != VUI_None){
view_show_file(view, 0); view_show_file(view);
} }
} }

View File

@ -22,8 +22,8 @@ popd
pushd ..\build pushd ..\build
REM call "..\code\buildsuper.bat" ..\code\4coder_default_bindings.cpp REM call "..\code\buildsuper.bat" ..\code\4coder_default_bindings.cpp
call "..\code\buildsuper.bat" ..\code\power\4coder_experiments.cpp REM call "..\code\buildsuper.bat" ..\code\power\4coder_experiments.cpp
REM call "..\code\buildsuper.bat" ..\code\power\4coder_casey.cpp call "..\code\buildsuper.bat" ..\code\power\4coder_casey.cpp
if %ERRORLEVEL% neq 0 (set FirstError=1) if %ERRORLEVEL% neq 0 (set FirstError=1)
set EXPORTS=/EXPORT:app_get_functions set EXPORTS=/EXPORT:app_get_functions

View File

@ -23,8 +23,6 @@
- Multi-line comments should default to indenting to the indentation of the line prior? - Multi-line comments should default to indenting to the indentation of the line prior?
- Would like the option to indent to hanging parentheses, equals signs, etc. instead of - Would like the option to indent to hanging parentheses, equals signs, etc. instead of
always just "one tab in from the previous line". always just "one tab in from the previous line".
- Actually, maybe just expose the dirty state, so that the user can decide whether to
save or not? Not sure...
- Replace: - Replace:
- Needs to be case-insensitive, or at least have the option to be - Needs to be case-insensitive, or at least have the option to be
- Needs to replace using the case of the thing being replaced, or at least have the option to do so - Needs to replace using the case of the thing being replaced, or at least have the option to do so
@ -107,7 +105,7 @@
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
#include "..\4coder_default_include.cpp" #include "../4coder_default_include.cpp"
enum maps{ enum maps{
my_code_map my_code_map
@ -1266,9 +1264,10 @@ HOOK_SIG(casey_file_settings)
treat_as_project = match(ext, make_lit_string("prj")); treat_as_project = match(ext, make_lit_string("prj"));
} }
push_parameter(app, par_buffer_id, buffer.buffer_id);
push_parameter(app, par_lex_as_cpp_file, treat_as_code); push_parameter(app, par_lex_as_cpp_file, treat_as_code);
push_parameter(app, par_wrap_lines, !treat_as_code); push_parameter(app, par_wrap_lines, !treat_as_code);
push_parameter(app, par_key_mapid, (treat_as_code)?((int)my_code_map):((int)mapid_file)); push_parameter(app, par_key_mapid, mapid_file);
exec_command(app, cmdid_set_settings); exec_command(app, cmdid_set_settings);
if(treat_as_project) if(treat_as_project)
@ -1420,7 +1419,15 @@ win32_toggle_fullscreen(void)
HOOK_SIG(casey_start) HOOK_SIG(casey_start)
{ {
// NOTE(allen): I added some stuff here based on wishes expressed on stream:
// - Two calls to cmdid_hide_scrollbar to hide the scrollbar GUI elements
// - One call to cmdid_change_active_panel so that 4coder starts on the right panel
exec_command(app, cmdid_hide_scrollbar);
exec_command(app, cmdid_open_panel_vsplit); exec_command(app, cmdid_open_panel_vsplit);
exec_command(app, cmdid_hide_scrollbar);
exec_command(app, cmdid_change_active_panel);
app->change_theme(app, literal("Handmade Hero")); app->change_theme(app, literal("Handmade Hero"));
app->change_font(app, literal("liberation mono")); app->change_font(app, literal("liberation mono"));
@ -1589,4 +1596,3 @@ extern "C" GET_BINDING_DATA(get_bindings)
end_bind_helper(context); end_bind_helper(context);
return context->write_total; return context->write_total;
} }