API tweaks

This commit is contained in:
Allen Webster 2016-02-25 07:12:09 -05:00
parent 3a03c6dbb0
commit 9c6fdde85d
8 changed files with 662 additions and 730 deletions

View File

@ -12,6 +12,15 @@
#ifndef FRED_BUFFER_TYPES_H #ifndef FRED_BUFFER_TYPES_H
#define FRED_BUFFER_TYPES_H #define FRED_BUFFER_TYPES_H
typedef union Range{
struct{
int min, max;
};
struct{
int start, end;
};
} Range;
typedef struct Full_Cursor{ typedef struct Full_Cursor{
int pos; int pos;
int line, character; int line, character;
@ -66,12 +75,10 @@ seek_unwrapped_xy(float x, float y, int round_down){
static Buffer_Seek static Buffer_Seek
seek_xy(float x, float y, int round_down, int unwrapped){ seek_xy(float x, float y, int round_down, int unwrapped){
Buffer_Seek result; Buffer_Seek result;
if (unwrapped){ result.type = unwrapped?buffer_seek_unwrapped_xy:buffer_seek_wrapped_xy;
result = seek_unwrapped_xy(x,y,round_down); result.x = x;
} result.y = y;
else{ result.round_down = round_down;
result = seek_wrapped_xy(x,y,round_down);
}
return(result); return(result);
} }

File diff suppressed because it is too large Load Diff

View File

@ -215,6 +215,21 @@ push_directory(Application_Links *app, void *cmd_context){
#define expand_string(d) ((d).str), ((d).size) #define expand_string(d) ((d).str), ((d).size)
inline Range
get_range(File_View_Summary *view){
Range range;
if (view->cursor.pos < view->mark.pos){
range.min = view->cursor.pos;
range.max = view->mark.pos;
}
else{
range.max = view->cursor.pos;
range.min = view->mark.pos;
}
return(range);
}
#if DisableMacroTranslations == 0 #if DisableMacroTranslations == 0
inline void inline void

View File

@ -273,6 +273,9 @@ tailstr(String str){
#ifdef FCPP_STRING_IMPLEMENTATION #ifdef FCPP_STRING_IMPLEMENTATION
#ifndef FCPP_DID_STRING_IMPLEMENTATION
#define FCPP_DID_STRING_IMPLEMENTATION
FCPP_LINK int FCPP_LINK int
str_size(char *str){ str_size(char *str){
int i = 0; int i = 0;
@ -1171,6 +1174,8 @@ wildcard_match(Absolutes *absolutes, String x, int case_sensitive){
return wildcard_match(absolutes, x.str, case_sensitive); return wildcard_match(absolutes, x.str, case_sensitive);
} }
#endif // #ifndef FCPP_DID_STRING_IMPLEMENTATION
#undef FCPP_STRING_IMPLEMENTATION #undef FCPP_STRING_IMPLEMENTATION
#endif // #ifdef FCPP_STRING_IMPLEMENTATION #endif // #ifdef FCPP_STRING_IMPLEMENTATION

254
4ed.cpp
View File

@ -1086,13 +1086,6 @@ COMMAND_DECL(save){
USE_PANEL(panel); USE_PANEL(panel);
delayed_action(delay, DACT_SAVE, file->name.source_path, panel); delayed_action(delay, DACT_SAVE, file->name.source_path, panel);
#if 0
String *file_path = &file->name.source_path;
if (file_path->size > 0){
i32 sys_id = file_save(system, exchange, mem, file, file_path->str);
app_push_file_binding(vars, sys_id, get_file_id(working_set, file));
}
#endif
} }
COMMAND_DECL(interactive_save_as){ COMMAND_DECL(interactive_save_as){
@ -2533,92 +2526,12 @@ setup_ui_commands(Command_Map *commands, Partition *part, Key_Codes *codes, Comm
internal void internal void
setup_file_commands(Command_Map *commands, Partition *part, Key_Codes *codes, Command_Map *parent){ setup_file_commands(Command_Map *commands, Partition *part, Key_Codes *codes, Command_Map *parent){
map_init(commands, part, 101, parent); map_init(commands, part, 10, parent);
commands->vanilla_keyboard_default.function = command_write_character;
map_add(commands, codes->left, MDFR_NONE, command_move_left);
map_add(commands, codes->right, MDFR_NONE, command_move_right);
map_add(commands, codes->del, MDFR_NONE, command_delete);
map_add(commands, codes->back, MDFR_NONE, command_backspace);
map_add(commands, codes->up, MDFR_NONE, command_move_up);
map_add(commands, codes->down, MDFR_NONE, command_move_down);
map_add(commands, codes->end, MDFR_NONE, command_seek_end_of_line);
map_add(commands, codes->home, MDFR_NONE, command_seek_beginning_of_line);
map_add(commands, codes->page_up, MDFR_NONE, command_page_up);
map_add(commands, codes->page_down, MDFR_NONE, command_page_down);
map_add(commands, codes->right, MDFR_CTRL, command_seek_alphanumeric_or_camel_right);
map_add(commands, codes->left, MDFR_CTRL, command_seek_alphanumeric_or_camel_left);
map_add(commands, codes->up, MDFR_CTRL, command_seek_whitespace_up);
map_add(commands, codes->down, MDFR_CTRL, command_seek_whitespace_down);
map_add(commands, ' ', MDFR_CTRL, command_set_mark);
map_add(commands, 'm', MDFR_CTRL, command_cursor_mark_swap);
map_add(commands, 'c', MDFR_CTRL, command_copy);
map_add(commands, 'x', MDFR_CTRL, command_cut);
map_add(commands, 'v', MDFR_CTRL, command_paste);
map_add(commands, 'V', MDFR_CTRL, command_paste_next);
map_add(commands, 'z', MDFR_CTRL, command_undo);
map_add(commands, 'y', MDFR_CTRL, command_redo);
map_add(commands, 'Z', MDFR_CTRL, command_timeline_scrub);
map_add(commands, codes->left, MDFR_ALT, command_increase_rewind_speed);
map_add(commands, codes->right, MDFR_ALT, command_increase_fastforward_speed);
map_add(commands, codes->down, MDFR_ALT, command_stop_rewind_fastforward);
map_add(commands, 'h', MDFR_CTRL, command_history_backward);
map_add(commands, 'H', MDFR_CTRL, command_history_forward);
map_add(commands, 'd', MDFR_CTRL, command_delete_range);
map_add(commands, 'l', MDFR_CTRL, command_toggle_line_wrap);
map_add(commands, '?', MDFR_CTRL, command_toggle_show_whitespace);
map_add(commands, '|', MDFR_CTRL, command_toggle_tokens);
map_add(commands, 'u', MDFR_CTRL, command_to_uppercase);
map_add(commands, 'j', MDFR_CTRL, command_to_lowercase);
map_add(commands, '~', MDFR_CTRL, command_clean_all_lines);
map_add(commands, 'f', MDFR_CTRL, command_search);
map_add(commands, 'r', MDFR_CTRL, command_reverse_search);
map_add(commands, 'g', MDFR_CTRL, command_goto_line);
map_add(commands, '\n', MDFR_NONE, compose_write_auto_tab_line);
map_add(commands, '}', MDFR_NONE, compose_write_auto_tab_line);
map_add(commands, ')', MDFR_NONE, compose_write_auto_tab_line);
map_add(commands, ']', MDFR_NONE, compose_write_auto_tab_line);
map_add(commands, ';', MDFR_NONE, compose_write_auto_tab_line);
map_add(commands, '#', MDFR_NONE, compose_write_auto_tab_line);
map_add(commands, '\t', MDFR_NONE, command_word_complete);
map_add(commands, '\t', MDFR_CTRL, command_auto_tab_range);
map_add(commands, '\t', MDFR_SHIFT, command_auto_tab_line_at_cursor);
map_add(commands, 'K', MDFR_CTRL, command_kill_buffer);
map_add(commands, 'O', MDFR_CTRL, command_reopen);
map_add(commands, 's', MDFR_CTRL, command_save);
map_add(commands, 'w', MDFR_CTRL, command_interactive_save_as);
#if UseFileHistoryDump
map_add(commands, 'h', MDFR_ALT, command_save_history);
#endif
} }
internal void internal void
setup_top_commands(Command_Map *commands, Partition *part, Key_Codes *codes, Command_Map *parent){ setup_top_commands(Command_Map *commands, Partition *part, Key_Codes *codes, Command_Map *parent){
map_init(commands, part, 51, parent); map_init(commands, part, 5, parent);
#if FRED_INTERNAL
map_add(commands, 'd', MDFR_ALT, command_open_debug_view);
#endif
map_add(commands, 'p', MDFR_CTRL, command_open_panel_vsplit);
map_add(commands, '-', MDFR_CTRL, command_open_panel_hsplit);
map_add(commands, 'P', MDFR_CTRL, command_close_panel);
map_add(commands, 'n', MDFR_CTRL, command_interactive_new);
map_add(commands, 'o', MDFR_CTRL, command_interactive_open);
map_add(commands, ',', MDFR_CTRL, command_change_active_panel);
map_add(commands, 'k', MDFR_CTRL, command_interactive_kill_buffer);
map_add(commands, 'i', MDFR_CTRL, command_interactive_switch_buffer);
map_add(commands, 'c', MDFR_ALT, command_open_color_tweaker);
map_add(commands, 'x', MDFR_ALT, command_open_menu);
map_add(commands, 'm', MDFR_ALT, command_build_here);
} }
internal void internal void
@ -3091,9 +3004,16 @@ app_setup_memory(Application_Memory *memory){
internal i32 internal i32
execute_special_tool(void *memory, i32 size, Command_Line_Parameters clparams){ execute_special_tool(void *memory, i32 size, Command_Line_Parameters clparams){
char message[] = "Hell World!"; i32 result;
i32 result = sizeof(message) - 1; char message[] = "tool was not specified or is invalid";
result = sizeof(message) - 1;
memcpy(memory, message, result); memcpy(memory, message, result);
if (clparams.argc > 2){
if (match(clparams.argv[2], "version")){
result = sizeof(VERSION) - 1;
memcpy(memory, VERSION, result);
}
}
return(result); return(result);
} }
@ -3179,37 +3099,38 @@ App_Init_Sig(app_init){
setup_command_table(); setup_command_table();
Command_Map *global = &vars->map_top; Command_Map *global = &vars->map_top;
if (vars->config_api.get_bindings){ Assert(vars->config_api.get_bindings != 0);
i32 size = partition_remaining(partition);
void *data = partition_current(partition); i32 size = partition_remaining(partition);
void *data = partition_current(partition);
// TODO(allen): Use a giant bubble of general memory for this.
// TODO(allen): Use a giant bubble of general memory for this.
// So that it doesn't interfere with the command maps as they allocate // So that it doesn't interfere with the command maps as they allocate
// their own memory. // their own memory.
i32 wanted_size = vars->config_api.get_bindings(data, size, codes); i32 wanted_size = vars->config_api.get_bindings(data, size, codes);
b32 did_top = 0;
b32 did_file = 0;
if (wanted_size <= size){
partition_allocate(partition, wanted_size);
Binding_Unit *unit = (Binding_Unit*)data;
if (unit->type == unit_header && unit->header.error == 0){
Binding_Unit *end = unit + unit->header.total_size;
i32 user_map_count = unit->header.user_map_count;
vars->map_id_table =
push_array(&vars->mem.part, i32, user_map_count);
vars->user_maps =
push_array(&vars->mem.part, Command_Map, user_map_count);
vars->user_map_count = user_map_count; b32 did_top = 0;
b32 did_file = 0;
Command_Map *mapptr = 0; if (wanted_size <= size){
for (++unit; unit < end; ++unit){ partition_allocate(partition, wanted_size);
switch (unit->type){
Binding_Unit *unit = (Binding_Unit*)data;
if (unit->type == unit_header && unit->header.error == 0){
Binding_Unit *end = unit + unit->header.total_size;
i32 user_map_count = unit->header.user_map_count;
vars->map_id_table =
push_array(&vars->mem.part, i32, user_map_count);
vars->user_maps =
push_array(&vars->mem.part, Command_Map, user_map_count);
vars->user_map_count = user_map_count;
Command_Map *mapptr = 0;
for (++unit; unit < end; ++unit){
switch (unit->type){
case unit_map_begin: case unit_map_begin:
{ {
int table_max = unit->map_begin.bind_count * 3 / 2; int table_max = unit->map_begin.bind_count * 3 / 2;
@ -3232,53 +3153,53 @@ App_Init_Sig(app_init){
} }
else mapptr = 0; else mapptr = 0;
}break; }break;
case unit_inherit: case unit_inherit:
if (mapptr){ if (mapptr){
Command_Map *parent = 0; Command_Map *parent = 0;
int mapid = unit->map_inherit.mapid; int mapid = unit->map_inherit.mapid;
if (mapid == mapid_global) parent = &vars->map_top; if (mapid == mapid_global) parent = &vars->map_top;
else if (mapid == mapid_file) parent = &vars->map_file; else if (mapid == mapid_file) parent = &vars->map_file;
else if (mapid < mapid_global){ else if (mapid < mapid_global){
i32 index = app_get_or_add_map_index(vars, mapid); i32 index = app_get_or_add_map_index(vars, mapid);
if (index < user_map_count) parent = vars->user_maps + index; if (index < user_map_count) parent = vars->user_maps + index;
else parent = 0; else parent = 0;
} }
mapptr->parent = parent; mapptr->parent = parent;
}break; }break;
case unit_binding: case unit_binding:
if (mapptr){ if (mapptr){
Command_Function func = 0; Command_Function func = 0;
if (unit->binding.command_id >= 0 && unit->binding.command_id < cmdid_count) if (unit->binding.command_id >= 0 && unit->binding.command_id < cmdid_count)
func = command_table [unit->binding.command_id]; func = command_table [unit->binding.command_id];
if (func){ if (func){
if (unit->binding.code == 0 && unit->binding.modifiers == 0){ if (unit->binding.code == 0 && unit->binding.modifiers == 0){
mapptr->vanilla_keyboard_default.function = func; mapptr->vanilla_keyboard_default.function = func;
} }
else{ else{
map_add(mapptr, unit->binding.code, unit->binding.modifiers, func); map_add(mapptr, unit->binding.code, unit->binding.modifiers, func);
}
} }
} }
break; }
break;
case unit_callback: case unit_callback:
if (mapptr){ if (mapptr){
Command_Function func = command_user_callback; Command_Function func = command_user_callback;
Custom_Command_Function *custom = unit->callback.func; Custom_Command_Function *custom = unit->callback.func;
if (func){ if (func){
if (unit->callback.code == 0 && unit->callback.modifiers == 0){ if (unit->callback.code == 0 && unit->callback.modifiers == 0){
mapptr->vanilla_keyboard_default.function = func; mapptr->vanilla_keyboard_default.function = func;
mapptr->vanilla_keyboard_default.custom = custom; mapptr->vanilla_keyboard_default.custom = custom;
} }
else{ else{
map_add(mapptr, unit->callback.code, unit->callback.modifiers, func, custom); map_add(mapptr, unit->callback.code, unit->callback.modifiers, func, custom);
}
} }
} }
break; }
break;
case unit_hook: case unit_hook:
{ {
int hook_id = unit->hook.hook_id; int hook_id = unit->hook.hook_id;
@ -3286,19 +3207,18 @@ App_Init_Sig(app_init){
vars->hooks[hook_id] = unit->hook.func; vars->hooks[hook_id] = unit->hook.func;
} }
}break; }break;
}
} }
} }
} }
if (!did_top) setup_top_commands(&vars->map_top, &vars->mem.part, codes, global);
if (!did_file) setup_file_commands(&vars->map_file, &vars->mem.part, codes, global);
}
else{
setup_top_commands(&vars->map_top, &vars->mem.part, codes, global);
setup_file_commands(&vars->map_file, &vars->mem.part, codes, global);
} }
if (!did_top) setup_top_commands(&vars->map_top, &vars->mem.part, codes, global);
if (!did_file) setup_file_commands(&vars->map_file, &vars->mem.part, codes, global);
#if !defined(FRED_SUPER)
vars->hooks[hook_start] = 0;
#endif
setup_ui_commands(&vars->map_ui, &vars->mem.part, codes, global); setup_ui_commands(&vars->map_ui, &vars->mem.part, codes, global);
#if FRED_INTERNAL #if FRED_INTERNAL
setup_debug_commands(&vars->map_debug, &vars->mem.part, codes, global); setup_debug_commands(&vars->map_debug, &vars->mem.part, codes, global);

View File

@ -9,6 +9,16 @@
// TOP // TOP
#define VERSION_NUMBER "alpha 3.4.3"
#ifdef FRED_SUPER
#define VERSION_TYPE " super!"
#else
#define VERSION_TYPE ""
#endif
#define VERSION VERSION_NUMBER VERSION_TYPE
#include "4ed_config.h" #include "4ed_config.h"
#define BUFFER_EXPERIMENT_SCALPEL 0 #define BUFFER_EXPERIMENT_SCALPEL 0

View File

@ -9,10 +9,6 @@
// TOP // TOP
struct Range{
i32 start, end;
};
struct File_View_Mode{ struct File_View_Mode{
b8 rewrite; b8 rewrite;
}; };

View File

@ -24,7 +24,12 @@
#include "4ed_dll_reader.h" #include "4ed_dll_reader.h"
#include "4coder_custom.h" #include "4coder_custom.cpp"
#undef exec_command
#undef exec_command_keep_stack
#undef clear_parameters
#include "4ed_system.h" #include "4ed_system.h"
#include "4ed_rendering.h" #include "4ed_rendering.h"
#include "4ed.h" #include "4ed.h"
@ -1601,6 +1606,10 @@ main(int argc, char **argv){
GetProcAddress(win32vars.custom, "get_bindings"); GetProcAddress(win32vars.custom, "get_bindings");
} }
#endif #endif
if (win32vars.custom_api.get_bindings == 0){
win32vars.custom_api.get_bindings = (Get_Binding_Data_Function*)get_bindings;
}
Thread_Context background[4]; Thread_Context background[4];
memset(background, 0, sizeof(background)); memset(background, 0, sizeof(background));