Usage code for the new lister API

master
Allen Webster 2018-06-22 22:14:51 -07:00
parent c835f46570
commit ad26a76060
6 changed files with 175 additions and 3 deletions

View File

@ -652,7 +652,8 @@ GLOBAL_VAR f32_Rect null_f32_rect = {0};
/* DOC(View_Summary acts as a handle to a view and describes the state of the view.)
DOC_SEE(Access_Flag)
DOC_SEE(Full_Cursor) */
DOC_SEE(Full_Cursor)
DOC_SEE(GUI_Scroll_Vars) */
STRUCT View_Summary{
/* DOC(This field indicates whether the View_Summary describes a view that is open in 4coder. When this field is false the summary is referred to as a "null summary". ) */
bool32 exists;

View File

@ -1497,6 +1497,130 @@ CUSTOM_DOC("Opens the 4coder colors and fonts selector menu.")
////////////////////////////////
#if 0
CUSTOM_COMMAND_SIG(interactive_switch_buffer_DUMMY_API_EXPLORATION)
CUSTOM_DOC("Interactively switch to an open buffer.")
{
Partition *scratch = &global_part;
View_Summary view = get_active_view(app, AccessAll);
view_start_list_mode(app, &view);
int32_t x0 = 0;
int32_t x1 = view.view_region.x1 - view.view_region.x0;
int32_t line_height = view.line_height;
int32_t block_height = line_height*2;
Temp_Memory temp = begin_temp_memory(scratch);
String text_field = push_string(scratch, 256);
Temp_Memory list_restore_point = begin_temp_memory(scratch);
for(;;){
end_temp_memory(list_restore_point);
int32_t y_pos = line_height;
List_Control list = {0};
List_Item *highlighted_item = 0;
for (Buffer_Summary buffer = get_buffer_first(app, AccessAll);
buffer.exists;
get_buffer_next(app, &buffer, AccessAll)){
String buffer_name = make_string(buffer.buffer_name, buffer.buffer_name_len);
if (has_substr(buffer_name, text_field)){
i32_Rect item_rect = {0};
item_rect.x0 = x0;
item_rect.y0 = y_pos;
item_rect.x1 = x1;
item_rect.y1 = y_pos + block_height;
y_pos = item_rect.y1;
List_Item *item = push_array(scratch, List_Item, 1);
memset(item, 0, sizeof(*item));
item->type = ListItemType_Option;
item->string = push_string_copy(scratch, buffer_name);
char *status = "";
switch (buffer.dirty){
case DirtyState_UnsavedChanges: status = " *"; break;
case DirtyState_UnloadedChanges: status = " !"; break;
}
item->status = push_string_copy(scratch, status);
item->user_data = (void*)buffer.buffer_id;
item->highlighted = false;
item->rectangle = item_rect;
list_control_add_item(&list, item);
if (highlighted_item == 0){
highlighted_item = item;
}
}
}
{
i32_Rect item_rect = {0};
item_rect.x0 = x0;
item_rect.y0 = 0;
item_rect.x1 = x1;
item_rect.y1 = line_height;
y_pos = item_rect.y1;
List_Item *item = push_array(scratch, List_Item, 1);
memset(item, 0, sizeof(*item));
item->type = ListItemType_TextField;
item->query = push_string_copy(scratch, "Switch: ");
item->string = text_field;
item->user_data = 0;
item->rectangle = item_rect;
}
view_set_list(app, &view, &list);
User_Input in = get_user_input(app, EventAll, EventOnEsc);
if (in.abort){
goto done;
}
List_Item *activated_item = 0;
switch (in.type){
case UserInputKey:
{
if (in.key.keycode == '\n' || in.key.keycode == '\t'){
activated_item = highlighted_item;
}
else if (in.key.keycode == key_back){
backspace_utf8(&text_field);
}
else{
uint8_t character[4];
uint32_t length = to_writable_character(in, character);
if (length > 0){
append(&text_field, make_string(character, length));
}
}
}break;
case UserInputMouse:
{
if (in.mouse.press_l){
int32_t mx = in.mouse.x - view.view_region.x0;
int32_t my = in.mouse.y - view.view_region.y0;
activated_item = list_control_get_mouse_hit(&list, mx, my);
}
}break;
}
if (activated_item != 0){
int32_t buffer_id = (int32_t)activated_item->user_data;
view_set_buffer(app, &view, buffer_id, 0);
goto done;
}
}
done:;
view_end_list_mode(app, &view);
end_temp_memory(temp);
}
#endif
////////////////////////////////
CUSTOM_COMMAND_SIG(open_in_other)
CUSTOM_DOC("Interactively opens a file in the other panel.")
{

View File

@ -305,7 +305,7 @@ static Command_Metadata fcoder_metacmd_table[184] = {
{ 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", 42, 1062 },
{ PROC_LINKS(open_color_tweaker, 0), "open_color_tweaker", 18, "Opens the 4coder colors and fonts selector menu.", 48, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 1492 },
{ 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", 39, 1339 },
{ 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", 39, 1500 },
{ 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", 39, 1624 },
{ 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", 49, 58 },
{ 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", 49, 74 },
{ 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", 49, 66 },

View File

@ -1290,5 +1290,15 @@ push_string_copy(Partition *arena, String str){
return(result);
}
static String
push_string_copy(Partition *arena, char *str, int32_t size){
return(push_string_copy(arena, make_string(str, size)));
}
static String
push_string_copy(Partition *arena, char *str){
return(push_string_copy(arena, make_string_slowly(str)));
}
// BOTTOM

View File

@ -976,7 +976,6 @@ compare_ss(String a, String b){
// Finding Characters and Substrings
//
#if defined(FSTRING_IMPLEMENTATION)
FSTRING_LINK i32_4tech
find_c_char(char *str, i32_4tech start, char character){

View File

@ -0,0 +1,38 @@
name = "midnight";
Back = 0xFF202020;
Margin = 0xFF383838;
Margin_Hover = 0xFF404040;
Margin_Active = 0xFF484848;
List_Item = Margin;
List_Item_Hover = Margin_Hover;
List_Item_Active = Margin_Active;
Cursor = 0xFFDDDDDD;
At_Cursor = Back;
Mark = 0xFF808080;
Highlight = 0xFF006080;
At_Highlight = Back;
Default = 0xFFDDDDDD;
Comment = 0xFF6AC000;
Keyword = 0xFFFFDDAA;
Str_Constant = Keyword;
Char_Constant = Str_Constant;
Int_Constant = Str_Constant;
Float_Constant = Str_Constant;
Bool_Constant = Str_Constant;
Include = Str_Constant;
Preproc = 0xFFFFFFFF;
Special_Character = 0xFFFF0000;
Ghost_Character = 0xFF6D6D6D;
Paste = 0xFF00FFFF;
Undo = 0xFFFF00FF;
Highlight_Junk = 0xFF482020;
Highlight_White = 0xFF383838;
Bar = 0xFF606060;
Bar_Active = 0xFF3E3E3E;
Base = 0xFF000000;
Pop1 = 0xFF00B0D0;
Pop2 = 0xFFFF3A00;