Hot directory setting API; project file open/close timing fix

This commit is contained in:
Allen Webster 2017-06-20 16:37:45 -04:00
parent 2964d13377
commit 752356b8b0
7 changed files with 229 additions and 188 deletions

View File

@ -62,6 +62,7 @@ struct Application_Links;
#define SET_THEME_COLORS_SIG(n) void n(Application_Links *app, Theme_Color *colors, int32_t count)
#define GET_THEME_COLORS_SIG(n) void n(Application_Links *app, Theme_Color *colors, int32_t count)
#define DIRECTORY_GET_HOT_SIG(n) int32_t n(Application_Links *app, char *out, int32_t capacity)
#define DIRECTORY_SET_HOT_SIG(n) bool32 n(Application_Links *app, char *str, int32_t len)
#define GET_FILE_LIST_SIG(n) File_List n(Application_Links *app, char *dir, int32_t len)
#define FREE_FILE_LIST_SIG(n) void n(Application_Links *app, File_List list)
#define SET_GUI_UP_DOWN_KEYS_SIG(n) void n(Application_Links *app, Key_Code up_key, Key_Modifier up_key_modifier, Key_Code down_key, Key_Modifier down_key_modifier)
@ -138,6 +139,7 @@ typedef BUFFER_GET_FONT_SIG(Buffer_Get_Font_Function);
typedef SET_THEME_COLORS_SIG(Set_Theme_Colors_Function);
typedef GET_THEME_COLORS_SIG(Get_Theme_Colors_Function);
typedef DIRECTORY_GET_HOT_SIG(Directory_Get_Hot_Function);
typedef DIRECTORY_SET_HOT_SIG(Directory_Set_Hot_Function);
typedef GET_FILE_LIST_SIG(Get_File_List_Function);
typedef FREE_FILE_LIST_SIG(Free_File_List_Function);
typedef SET_GUI_UP_DOWN_KEYS_SIG(Set_GUI_Up_Down_Keys_Function);
@ -216,6 +218,7 @@ Buffer_Get_Font_Function *buffer_get_font;
Set_Theme_Colors_Function *set_theme_colors;
Get_Theme_Colors_Function *get_theme_colors;
Directory_Get_Hot_Function *directory_get_hot;
Directory_Set_Hot_Function *directory_set_hot;
Get_File_List_Function *get_file_list;
Free_File_List_Function *free_file_list;
Set_GUI_Up_Down_Keys_Function *set_gui_up_down_keys;
@ -293,6 +296,7 @@ Buffer_Get_Font_Function *buffer_get_font_;
Set_Theme_Colors_Function *set_theme_colors_;
Get_Theme_Colors_Function *get_theme_colors_;
Directory_Get_Hot_Function *directory_get_hot_;
Directory_Set_Hot_Function *directory_set_hot_;
Get_File_List_Function *get_file_list_;
Free_File_List_Function *free_file_list_;
Set_GUI_Up_Down_Keys_Function *set_gui_up_down_keys_;
@ -378,6 +382,7 @@ app_links->buffer_get_font_ = Buffer_Get_Font;\
app_links->set_theme_colors_ = Set_Theme_Colors;\
app_links->get_theme_colors_ = Get_Theme_Colors;\
app_links->directory_get_hot_ = Directory_Get_Hot;\
app_links->directory_set_hot_ = Directory_Set_Hot;\
app_links->get_file_list_ = Get_File_List;\
app_links->free_file_list_ = Free_File_List;\
app_links->set_gui_up_down_keys_ = Set_GUI_Up_Down_Keys;\
@ -455,6 +460,7 @@ static inline bool32 buffer_get_font(Application_Links *app, Buffer_Summary *buf
static inline void set_theme_colors(Application_Links *app, Theme_Color *colors, int32_t count){(app->set_theme_colors(app, colors, count));}
static inline void get_theme_colors(Application_Links *app, Theme_Color *colors, int32_t count){(app->get_theme_colors(app, colors, count));}
static inline int32_t directory_get_hot(Application_Links *app, char *out, int32_t capacity){return(app->directory_get_hot(app, out, capacity));}
static inline bool32 directory_set_hot(Application_Links *app, char *str, int32_t len){return(app->directory_set_hot(app, str, len));}
static inline File_List get_file_list(Application_Links *app, char *dir, int32_t len){return(app->get_file_list(app, dir, len));}
static inline void free_file_list(Application_Links *app, File_List list){(app->free_file_list(app, list));}
static inline void set_gui_up_down_keys(Application_Links *app, Key_Code up_key, Key_Modifier up_key_modifier, Key_Code down_key, Key_Modifier down_key_modifier){(app->set_gui_up_down_keys(app, up_key, up_key_modifier, down_key, down_key_modifier));}
@ -532,6 +538,7 @@ static inline bool32 buffer_get_font(Application_Links *app, Buffer_Summary *buf
static inline void set_theme_colors(Application_Links *app, Theme_Color *colors, int32_t count){(app->set_theme_colors_(app, colors, count));}
static inline void get_theme_colors(Application_Links *app, Theme_Color *colors, int32_t count){(app->get_theme_colors_(app, colors, count));}
static inline int32_t directory_get_hot(Application_Links *app, char *out, int32_t capacity){return(app->directory_get_hot_(app, out, capacity));}
static inline bool32 directory_set_hot(Application_Links *app, char *str, int32_t len){return(app->directory_set_hot_(app, str, len));}
static inline File_List get_file_list(Application_Links *app, char *dir, int32_t len){return(app->get_file_list_(app, dir, len));}
static inline void free_file_list(Application_Links *app, File_List list){(app->free_file_list_(app, list));}
static inline void set_gui_up_down_keys(Application_Links *app, Key_Code up_key, Key_Modifier up_key_modifier, Key_Code down_key, Key_Modifier down_key_modifier){(app->set_gui_up_down_keys_(app, up_key, up_key_modifier, down_key, down_key_modifier));}

View File

@ -27,6 +27,7 @@ default_keys(Bind_Helper *context){
bind(context, 'k', MDFR_CTRL, interactive_kill_buffer);
bind(context, 'i', MDFR_CTRL, interactive_switch_buffer);
bind(context, 'w', MDFR_CTRL, save_as);
bind(context, 'h', MDFR_CTRL, project_go_to_root_directory);
bind(context, 'c', MDFR_ALT, open_color_tweaker);
bind(context, 'd', MDFR_ALT, open_debug);
@ -132,7 +133,7 @@ default_keys(Bind_Helper *context){
bind(context, key_mouse_right, MDFR_NONE, click_set_mark);
// NOTE(allen|a4.0.11): You can now bind left and right mouse
// button releases. Modifiers do work so control+click shift+click
// button releases. Modifiers do work so control+release shift+release
// etc can now have special meanings.
bind(context, key_mouse_left_release, MDFR_NONE, click_set_mark);

View File

@ -294,6 +294,8 @@ struct Project{
bool32 close_all_files_when_project_opens;
bool32 open_recursively;
bool32 loaded;
};
static Project null_project = {0};

View File

@ -187,17 +187,16 @@ CUSTOM_COMMAND_SIG(close_all_code){
}
static void
load_project_from_file(Application_Links *app, Partition *part, FILE *file, String project_dir){
load_project_from_config_data(Application_Links *app, Partition *part, char *config_data, int32_t config_data_size, String project_dir){
Temp_Memory temp = begin_temp_memory(part);
char *mem = 0;
int32_t size = 0;
bool32 file_read_success = file_handle_dump(part, file, &mem, &size);
if (file_read_success){
char *mem = config_data;
int32_t size = config_data_size;
Cpp_Token_Array array;
array.count = 0;
array.max_count = (1 << 20)/sizeof(Cpp_Token);
array.tokens = push_array(&global_part, Cpp_Token, array.max_count);
array.tokens = push_array(part, Cpp_Token, array.max_count);
Cpp_Keyword_Table kw_table = {0};
Cpp_Keyword_Table pp_table = {0};
@ -212,6 +211,7 @@ load_project_from_file(Application_Links *app, Partition *part, FILE *file, Stri
exec_command(app, close_all_code);
}
current_project = null_project;
current_project.loaded = true;
// Set new project directory
{
@ -363,7 +363,7 @@ load_project_from_file(Application_Links *app, Partition *part, FILE *file, Stri
}
if (current_project.close_all_files_when_project_opens){
close_all_files_with_extension(app, &global_part, 0, 0);
close_all_files_with_extension(app, part, 0, 0);
}
// Open all project files
@ -374,7 +374,6 @@ load_project_from_file(Application_Links *app, Partition *part, FILE *file, Stri
open_all_code(app, project_dir);
}
}
}
end_temp_memory(temp);
}
@ -382,6 +381,8 @@ load_project_from_file(Application_Links *app, Partition *part, FILE *file, Stri
CUSTOM_COMMAND_SIG(load_project){
Partition *part = &global_part;
Temp_Memory temp = begin_temp_memory(part);
char project_file_space[512];
String project_name = make_fixed_width_string(project_file_space);
project_name.size = directory_get_hot(app, project_name.str, project_name.memory_size);
@ -390,7 +391,6 @@ CUSTOM_COMMAND_SIG(load_project){
}
if (project_name.size != 0){
bool32 load_failed = false;
for(;;){
int32_t original_size = project_name.size;
@ -401,8 +401,15 @@ CUSTOM_COMMAND_SIG(load_project){
if (file){
project_name.size = original_size;
terminate_with_null(&project_name);
load_project_from_file(app, part, file, project_name);
char *mem = 0;
int32_t size = 0;
bool32 file_read_success = file_handle_dump(part, file, &mem, &size);
fclose(file);
if (file_read_success){
load_project_from_config_data(app, part, mem, size, project_name);
}
break;
}
else{
@ -434,6 +441,8 @@ CUSTOM_COMMAND_SIG(load_project){
else{
print_message(app, literal("Failed trying to get project file name"));
}
end_temp_memory(temp);
}
static void
@ -514,6 +523,12 @@ CUSTOM_COMMAND_SIG(project_fkey_command){
}
}
CUSTOM_COMMAND_SIG(project_go_to_root_directory){
if (current_project.loaded){
directory_set_hot(app, current_project.dir, current_project.dir_len);
}
}
#endif
// BOTTOM

View File

@ -2364,13 +2364,8 @@ Directory_Get_Hot(Application_Links *app, char *out, int32_t capacity)
DOC_PARAM(out, This parameter provides a character buffer that receives the 4coder 'hot directory'.)
DOC_PARAM(capacity, This parameter specifies the maximum size to be output to the out buffer.)
DOC_RETURN(This call returns the size of the string written into the buffer.)
DOC(
4coder has a concept of a 'hot directory' which is the directory most recently
accessed in the GUI. Whenever the GUI is opened it shows the hot directory.
In the future this will be deprecated and eliminated in favor of more flexible
directories controlled on the custom side.
)
DOC(4coder has a concept of a 'hot directory' which is the directory most recently accessed in the GUI. Whenever the GUI is opened it shows the hot directory. In the future this will be deprecated and eliminated in favor of more flexible directories controlled on the custom side.)
DOC_SEE(directory_set_hot)
*/{
Command_Data *cmd = (Command_Data*)app->cmd_context;
Hot_Directory *hot = &cmd->models->hot_directory;
@ -2384,6 +2379,25 @@ directories controlled on the custom side.
return(hot->string.size);
}
API_EXPORT bool32
Directory_Set_Hot(Application_Links *app, char *str, int32_t len)
/*
DOC_PARAM(str, The new value of the hot directory. This does not need to be a null terminated string.)
DOC_PARAM(len, The length of str in bytes.)
DOC_RETURN(Returns non-zero on success.)
DOC(4coder has a concept of a 'hot directory' which is the directory most recently accessed in the GUI. Whenever the GUI is opened it shows the hot directory. In the future this will be deprecated and eliminated in favor of more flexible directories controlled on the custom side.)
DOC_SEE(directory_get_hot)
*/{
Command_Data *cmd = (Command_Data*)app->cmd_context;
Hot_Directory *hot = &cmd->models->hot_directory;
b32 success = false;
if (len < hot->string.memory_size){
hot_directory_set(cmd->system, hot, make_string(str, len));
success = true;
}
return(success);
}
API_EXPORT File_List
Get_File_List(Application_Links *app, char *dir, int32_t len)
/*

View File

@ -19,6 +19,8 @@ The following bindings apply in all situations.
\BEGIN_ITEM \BEGIN_STYLE{code} <alt o> \END_STYLE Open file dialogue in other panel \END_ITEM
\BEGIN_ITEM \BEGIN_STYLE{code} <ctrl k> \END_STYLE Kill buffer dialogue \END_ITEM
\BEGIN_ITEM \BEGIN_STYLE{code} <ctrl i> \END_STYLE Switch open buffer dialogue \END_ITEM
\BEGIN_ITEM \BEGIN_STYLE{code} <ctrl w> \END_STYLE 'Save As' - save file into new name \END_ITEM
\BEGIN_ITEM \BEGIN_STYLE{code} <ctrl h> \END_STYLE Set hot directory to projet root directory \END_ITEM
\BEGIN_ITEM \BEGIN_STYLE{code} <alt c> \END_STYLE Open color and font selection GUI \END_ITEM
\BEGIN_ITEM \BEGIN_STYLE{code} <alt d> \END_STYLE Open a debug information GUI \END_ITEM

View File

@ -1792,7 +1792,7 @@ Win32Callback(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
memcpy(data[*count].modifiers, control_keys, control_keys_size);
++(*count);
win32vars.got_useful_event = 1;
win32vars.got_useful_event = true;
}
}
}break;
@ -1838,7 +1838,7 @@ Win32Callback(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
memcpy(data[*count].modifiers, control_keys, control_keys_size);
++(*count);
win32vars.got_useful_event = 1;
win32vars.got_useful_event = true;
}break;
case WM_MOUSEMOVE:
@ -1850,13 +1850,13 @@ Win32Callback(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
win32vars.input_chunk.pers.mouse_x = new_x;
win32vars.input_chunk.pers.mouse_y = new_y;
win32vars.got_useful_event = 1;
win32vars.got_useful_event = true;
}
}break;
case WM_MOUSEWHEEL:
{
win32vars.got_useful_event = 1;
win32vars.got_useful_event = true;
i32 rotation = GET_WHEEL_DELTA_WPARAM(wParam);
if (rotation > 0){
win32vars.input_chunk.trans.mouse_wheel = 1;
@ -1868,28 +1868,28 @@ Win32Callback(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
case WM_LBUTTONDOWN:
{
win32vars.got_useful_event = 1;
win32vars.got_useful_event = true;
win32vars.input_chunk.trans.mouse_l_press = 1;
win32vars.input_chunk.pers.mouse_l = 1;
}break;
case WM_RBUTTONDOWN:
{
win32vars.got_useful_event = 1;
win32vars.got_useful_event = true;
win32vars.input_chunk.trans.mouse_r_press = 1;
win32vars.input_chunk.pers.mouse_r = 1;
}break;
case WM_LBUTTONUP:
{
win32vars.got_useful_event = 1;
win32vars.got_useful_event = true;
win32vars.input_chunk.trans.mouse_l_release = 1;
win32vars.input_chunk.pers.mouse_l = 0;
}break;
case WM_RBUTTONUP:
{
win32vars.got_useful_event = 1;
win32vars.got_useful_event = true;
win32vars.input_chunk.trans.mouse_r_release = 1;
win32vars.input_chunk.pers.mouse_r = 0;
}break;
@ -1897,7 +1897,7 @@ Win32Callback(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
case WM_KILLFOCUS:
case WM_SETFOCUS:
{
win32vars.got_useful_event = 1;
win32vars.got_useful_event = true;
win32vars.input_chunk.pers.mouse_l = 0;
win32vars.input_chunk.pers.mouse_r = 0;
@ -1909,7 +1909,7 @@ Win32Callback(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
case WM_SIZE:
{
win32vars.got_useful_event = 1;
win32vars.got_useful_event = true;
i32 new_width = LOWORD(lParam);
i32 new_height = HIWORD(lParam);
@ -1918,7 +1918,7 @@ Win32Callback(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
case WM_DISPLAYCHANGE:
{
win32vars.got_useful_event = 1;
win32vars.got_useful_event = true;
LONG_PTR style = GetWindowLongPtr(hwnd, GWL_STYLE);
if (!(style & WS_OVERLAPPEDWINDOW)){
@ -1936,7 +1936,7 @@ Win32Callback(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
case WM_PAINT:
{
win32vars.got_useful_event = 1;
win32vars.got_useful_event = true;
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
Win32RedrawScreen(hdc);
@ -1946,13 +1946,13 @@ Win32Callback(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
case WM_CLOSE:
case WM_DESTROY:
{
win32vars.got_useful_event = 1;
win32vars.got_useful_event = true;
win32vars.input_chunk.trans.trying_to_kill = 1;
}break;
case WM_4coder_ANIMATE:
{
win32vars.got_useful_event = 1;
win32vars.got_useful_event = true;
}break;
case WM_CANCELMODE: