added new file hook; fixed up linux save-to-name bug; fixed up packaging bug

master
Allen Webster 2017-02-26 15:13:06 -05:00
parent a778d6c8fc
commit 18d19fb9fa
11 changed files with 88 additions and 201 deletions

View File

@ -117,6 +117,12 @@ OPEN_FILE_HOOK_SIG(default_file_settings){
return(0);
}
OPEN_FILE_HOOK_SIG(default_new_file){
Buffer_Summary buffer = get_buffer(app, buffer_id, AccessOpen);
char str[] = "/*\nNew File\n*/\n\n\n";
buffer_replace_range(app, &buffer, 0, 0, str, sizeof(str)-1);
}
OPEN_FILE_HOOK_SIG(default_file_save){
uint32_t access = AccessAll;
Buffer_Summary buffer = get_buffer(app, buffer_id, access);
@ -242,6 +248,7 @@ set_all_default_hooks(Bind_Helper *context){
set_hook(context, hook_view_size_change, default_view_adjust);
set_open_file_hook(context, default_file_settings);
set_new_file_hook(context, default_new_file);
set_save_file_hook(context, default_file_save);
set_command_caller(context, default_command_caller);
set_input_filter(context, default_suppress_mouse_filter);

50
4ed.cpp
View File

@ -284,13 +284,12 @@ COMMAND_DECL(null){
AllowLocal(command);
}
// TODO(allen): FIX THIS SHIT!
COMMAND_DECL(undo){
USE_MODELS(models);
REQ_OPEN_VIEW(view);
REQ_FILE_HISTORY(file, view);
view_undo(system, models, view);
view_undo_redo(system, models, view, &file->state.undo.undo, ED_UNDO);
Assert(file->state.undo.undo.size >= 0);
}
@ -300,7 +299,7 @@ COMMAND_DECL(redo){
REQ_OPEN_VIEW(view);
REQ_FILE_HISTORY(file, view);
view_redo(system, models, view);
view_undo_redo(system, models, view, &file->state.undo.redo, ED_REDO);
Assert(file->state.undo.undo.size >= 0);
}
@ -308,17 +307,13 @@ COMMAND_DECL(redo){
COMMAND_DECL(interactive_new){
USE_VIEW(view);
view_show_interactive(system, view,
IAct_New, IInt_Sys_File_List,
make_lit_string("New: "));
view_show_interactive(system, view, IAct_New, IInt_Sys_File_List, make_lit_string("New: "));
}
COMMAND_DECL(interactive_open){
USE_VIEW(view);
view_show_interactive(system, view,
IAct_Open, IInt_Sys_File_List,
make_lit_string("Open: "));
view_show_interactive(system, view, IAct_Open, IInt_Sys_File_List,make_lit_string("Open: "));
}
// TODO(allen): Improvements to reopen
@ -1282,6 +1277,8 @@ App_Init_Sig(app_init){
models->hook_open_file = 0;
models->hook_new_file = 0;
models->hook_save_file = 0;
models->command_caller = 0;
models->input_filter = 0;
setup_command_table();
@ -1419,28 +1416,34 @@ App_Init_Sig(app_init){
else{
switch (hook_id){
case special_hook_open_file:
models->hook_open_file = (Open_File_Hook_Function*)unit->hook.func;
break;
{
models->hook_open_file = (Open_File_Hook_Function*)unit->hook.func;
}break;
case special_hook_new_file:
models->hook_new_file = (Open_File_Hook_Function*)unit->hook.func;
break;
{
models->hook_new_file = (Open_File_Hook_Function*)unit->hook.func;
}break;
case special_hook_save_file:
models->hook_save_file = (Open_File_Hook_Function*)unit->hook.func;
break;
{
models->hook_save_file = (Open_File_Hook_Function*)unit->hook.func;
}break;
case special_hook_command_caller:
models->command_caller = (Command_Caller_Hook_Function*)unit->hook.func;
break;
{
models->command_caller = (Command_Caller_Hook_Function*)unit->hook.func;
}break;
case special_hook_scroll_rule:
models->scroll_rule = (Scroll_Rule_Function*)unit->hook.func;
break;
{
models->scroll_rule = (Scroll_Rule_Function*)unit->hook.func;
}break;
case special_hook_input_filter:
models->input_filter = (Input_Filter_Function*)unit->hook.func;
break;
{
models->input_filter = (Input_Filter_Function*)unit->hook.func;
}break;
}
}
}
@ -1673,7 +1676,7 @@ App_Step_Sig(app_step){
{
b32 mem_too_small = 0;
i32 size = 0;
i32 buffer_size = (32 << 10);
i32 buffer_size = KB(32);
Partition *part = &models->mem.part;
Temp_Memory temp = begin_temp_memory(part);
@ -1690,6 +1693,8 @@ App_Step_Sig(app_step){
if (get_canon_name(system, &canon, make_string(buffer, size))){
Editing_File *file = working_set_canon_contains(working_set, canon.name);
if (file){
Application_Links *app = &models->app_links;
if (file->state.ignore_behind_os == 0){
file_mark_behind_os(file);
}
@ -2402,6 +2407,7 @@ App_Step_Sig(app_step){
"Newest features:\n"
"-New support for extended ascii input.\n"
"-Extended ascii encoded in buffers as utf8.\n"
"-The custom layer now has a 'markers' API for tracking buffer positions across changes.\n"
"\n"
"New in alpha 4.0.16:\n"
"-<alt 2> If the current file is a C++ code file, this opens the matching header.\n"" If the current file is a C++ header, this opens the matching code file.\n"

View File

@ -790,7 +790,7 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file,
if (!using_actual_filename && file->canon.name.str != 0){
char space[512];
u32 length = str_size(filename);
system->get_canonical(filename, length, space, sizeof(space));
u32 canon_length = system->get_canonical(filename, length, space, sizeof(space));
char *source_path = file->canon.name.str;
if (match(space, source_path)){
@ -3458,9 +3458,7 @@ apply_history_edit(System_Functions *system, Models *models, Editing_File *file,
view->edit_pos->mark = view->edit_pos->cursor.pos;
Style *style = main_style(models);
view_post_paste_effect(view, 0.333f,
step.edit.start, step.edit.len,
style->main.undo_color);
view_post_paste_effect(view, 0.333f, step.edit.start, step.edit.len, style->main.undo_color);
}
}
else{
@ -3469,9 +3467,7 @@ apply_history_edit(System_Functions *system, Models *models, Editing_File *file,
}
internal void
view_undo_redo(System_Functions *system,
Models *models, View *view,
Edit_Stack *stack, Edit_Type expected_type){
view_undo_redo(System_Functions *system, Models *models, View *view, Edit_Stack *stack, Edit_Type expected_type){
Editing_File *file = view->file_data.file;
Assert(file);
@ -3479,89 +3475,11 @@ view_undo_redo(System_Functions *system,
if (stack->edit_count > 0){
Edit_Step step = stack->edits[stack->edit_count-1];
Assert(step.type == expected_type);
apply_history_edit(system, models,
file, view,
stack, step, hist_normal);
apply_history_edit(system, models, file, view, stack, step, hist_normal);
}
}
inline void
view_undo(System_Functions *system, Models *models, View *view){
view_undo_redo(system, models, view, &view->file_data.file->state.undo.undo, ED_UNDO);
}
inline void
view_redo(System_Functions *system, Models *models, View *view){
view_undo_redo(system, models, view, &view->file_data.file->state.undo.redo, ED_REDO);
}
inline u8*
write_data(u8 *ptr, void *x, i32 size){
memcpy(ptr, x, size);
return (ptr + size);
}
#define UseFileHistoryDump 0
#if UseFileHistoryDump
internal void
file_dump_history(System_Functions *system, Mem_Options *mem, Editing_File *file, char *filename){
if (!file->state.undo.undo.edits) return;
i32 size = 0;
size += sizeof(i32);
size += file->state.undo.undo.edit_count*sizeof(Edit_Step);
size += sizeof(i32);
size += file->state.undo.redo.edit_count*sizeof(Edit_Step);
size += sizeof(i32);
size += file->state.undo.history.edit_count*sizeof(Edit_Step);
size += sizeof(i32);
size += file->state.undo.children.edit_count*sizeof(Buffer_Edit);
size += sizeof(i32);
size += file->state.undo.undo.size;
size += sizeof(i32);
size += file->state.undo.redo.size;
size += sizeof(i32);
size += file->state.undo.history.size;
size += sizeof(i32);
size += file->state.undo.children.size;
Partition *part = &mem->part;
i32 remaining = partition_remaining(part);
if (size < remaining){
u8 *data, *curs;
data = (u8*)part->base + part->pos;
curs = data;
curs = write_data(curs, &file->state.undo.undo.edit_count, 4);
curs = write_data(curs, &file->state.undo.redo.edit_count, 4);
curs = write_data(curs, &file->state.undo.history.edit_count, 4);
curs = write_data(curs, &file->state.undo.children.edit_count, 4);
curs = write_data(curs, &file->state.undo.undo.size, 4);
curs = write_data(curs, &file->state.undo.redo.size, 4);
curs = write_data(curs, &file->state.undo.history.size, 4);
curs = write_data(curs, &file->state.undo.children.size, 4);
curs = write_data(curs, file->state.undo.undo.edits, sizeof(Edit_Step)*file->state.undo.undo.edit_count);
curs = write_data(curs, file->state.undo.redo.edits, sizeof(Edit_Step)*file->state.undo.redo.edit_count);
curs = write_data(curs, file->state.undo.history.edits, sizeof(Edit_Step)*file->state.undo.history.edit_count);
curs = write_data(curs, file->state.undo.children.edits, sizeof(Buffer_Edit)*file->state.undo.children.edit_count);
curs = write_data(curs, file->state.undo.undo.strings, file->state.undo.undo.size);
curs = write_data(curs, file->state.undo.redo.strings, file->state.undo.redo.size);
curs = write_data(curs, file->state.undo.history.strings, file->state.undo.history.size);
curs = write_data(curs, file->state.undo.children.strings, file->state.undo.children.size);
Assert((i32)(curs - data) == size);
system->save_file(filename, data, size);
}
}
#endif
internal void
view_history_step(System_Functions *system, Models *models, View *view, History_Mode history_mode){
Assert(history_mode != hist_normal);
@ -3780,10 +3698,7 @@ view_show_GUI(View *view, View_UI ui){
}
inline void
view_show_interactive(System_Functions *system, View *view,
Interactive_Action action,
Interactive_Interaction interaction,
String query){
view_show_interactive(System_Functions *system, View *view, Interactive_Action action, Interactive_Interaction interaction, String query){
Models *models = view->persistent.models;
@ -3992,7 +3907,7 @@ kill_file_by_name(System_Functions *system, Models *models, String name){
internal void
save_file_by_name(System_Functions *system, Models *models, String name){
Editing_File *file = working_set_name_contains(&models->working_set, name);
if (file){
if (file != 0){
save_file(system, models, file);
}
}
@ -4069,8 +3984,11 @@ interactive_view_complete(System_Functions *system, View *view, String dest, i32
if (dest.size > 0 && !char_is_slash(dest.str[dest.size-1])){
view_interactive_new_file(system, models, view, dest);
view_show_file(view);
}
break;
if (models->hook_new_file != 0){
Editing_File *file = view->file_data.file;
models->hook_new_file(&models->app_links, file->id.id);
}
}break;
case IAct_Switch:
{
@ -4079,14 +3997,12 @@ interactive_view_complete(System_Functions *system, View *view, String dest, i32
view_set_file(view, file, models);
}
view_show_file(view);
}
break;
}break;
case IAct_Kill:
if (!interactive_try_kill_file_by_name(system, models, view, dest)){
view_show_file(view);
}
break;
}break;
case IAct_Sure_To_Close:
switch (user_action){

View File

@ -10,8 +10,6 @@ SET FirstError=0
SET BUILD_MODE=%1
if "%BUILD_MODE%" == "" (SET BUILD_MODE="/DDEV_BUILD")
REM if "%BUILD_MODE%" == "/DDEV_BUILD_X86" (call "SETUP_CLX86")
pushd ..\build
cl %OPTS% ..\code\meta\build.cpp /Zi /Febuild %BUILD_MODE%
if %ERRORLEVEL% neq 0 (set FirstError=1)
@ -23,6 +21,4 @@ if %ERRORLEVEL% neq 0 (set FirstError=1)
:END
REM if "%BUILD_MODE%" == "/DDEV_BUILD" (call "SETUP_CLX64")
call "ctime" -end 4ed_data.ctm %FirstError%

View File

@ -1,7 +1,12 @@
#!/bin/bash
BUILD_MODE="$1"
if [ -z "$BUILD_MODE" ]; then
BUILD_MODE="-DDEV_BUILD"
fi
WARNINGS="-Wno-write-strings"
FLAGS="-D_GNU_SOURCE -fPIC -fpermissive -DDEV_BUILD"
FLAGS="-D_GNU_SOURCE -fPIC -fpermissive $BUILD_MODE"
g++ $WARNINGS $FLAGS meta/build.cpp -g -o ../build/build
../build/build

View File

@ -443,6 +443,12 @@ Sys_Get_Canonical_Sig(system_get_canonical){
return 0;
}
if (max == 0){
return 0;
}
max -= 1;
while(read_p < filename + len){
if(read_p == filename || read_p[0] == '/'){
if(read_p[1] == '/'){
@ -477,7 +483,9 @@ Sys_Get_Canonical_Sig(system_get_canonical){
}
#endif
return write_p - path;
u32 length = (i32)(write_p - path);
buffer[length] = 0;
return(length);
}
internal

View File

@ -426,6 +426,7 @@ copy_all(char *source, char *tag, char *folder){
static void
zip(char *parent, char *folder, char *file){
Temp_Dir temp = pushdir(parent);
printf("PARENT DIR: %s\n", parent);
systemf("zip -r %s %s", file, folder);
popdir(temp);
}

View File

@ -239,6 +239,10 @@ build_cl(u32 flags, char *code_path, char *code_file, char *out_path, char *out_
"-Wno-write-strings -D_GNU_SOURCE -fPIC " \
"-fno-threadsafe-statics -pthread"
#define GCC_X86 "-m32"
#define GCC_X64 "-m64"
#define GCC_INCLUDES "-I../foreign -I../code"
#define GCC_SITE_INCLUDES "-I../../foreign -I../../code"
@ -252,6 +256,13 @@ build_gcc(u32 flags, char *code_path, char *code_file, char *out_path, char *out
Build_Line line;
init_build_line(&line);
if (flags & X86){
build_ap(line, GCC_X86);
}
else{
build_ap(line, GCC_X64);
}
if (flags & OPTS){
build_ap(line, GCC_OPTS);
}
@ -510,7 +521,7 @@ get_4coder_dist_name(String *zip_file, i32 OS_specific, char *tier, char *ext){
#if defined(IS_WINDOWS)
append_sc(zip_file, "win-");
#elif defined(IS_LINUX) && defined(IS_64BIT)
append_sc(zip_file, "linux-64-");
append_sc(zip_file, "linux-");
#else
#error No OS string for zips on this OS
#endif
@ -571,8 +582,8 @@ package(char *cdir){
};
char *dest_par_dirs[] = {
pack_alpha_dir,
pack_alpha_x86_dir,
pack_alpha_par_dir,
pack_alpha_x86_par_dir,
};
char *zip_dirs[] = {
@ -629,8 +640,8 @@ package(char *cdir){
};
char *dest_par_dirs[] = {
pack_super_dir,
pack_super_x86_dir,
pack_super_par_dir,
pack_super_x86_par_dir,
};
char *zip_dirs[] = {

View File

@ -1375,6 +1375,7 @@ get_bindings(void *data, int32_t size){
set_hook(context, hook_view_size_change, default_view_adjust);
set_open_file_hook(context, default_file_settings);
set_new_file_hook(context, default_new_file);
set_save_file_hook(context, default_file_save);
set_input_filter(context, default_suppress_mouse_filter);
set_command_caller(context, default_command_caller);

View File

@ -1,5 +1,5 @@
extensions=".c.cpp.h.hpp.bat.sh";
open_recursively=false;
extensions=".c.cpp.h.hpp.bat.sh.4coder";
open_recursively=true;
fkey_command_win[1] = {"echo build: x64 & build.bat", "*compilation*", true , true };
fkey_command_win[2] = {"site\\build.bat", "*compilation*", true , true };
@ -8,7 +8,8 @@ fkey_command_win[4] = {"echo build: x86 & build.bat /DDEV_BUILD_X86", "*compila
fkey_command_win[5] = {"..\\misc\\run.bat", "*run*", false, false };
fkey_command_win[12] = {"package.bat", "*package*", false, true };
fkey_command_linux[1] = {"./build.sh", "*compilation*", true , true };
fkey_command_linux[1] = {"echo build: x64 & ./build.sh", "*compilation*", true , true };
fkey_command_linux[2] = {"site/build.sh", "*compilation*", true , true };
fkey_command_linux[5] = {"../build/4ed", "*run*", false, false};
fkey_command_linux[12] = {"./package.sh", "*package*", false, true };
fkey_command_linux[4] = {"echo build: x86 & ./build.sh -DDEV_BUILD_X86", "*compilation*", true, true };
fkey_command_linux[5] = {"../build/4ed", "*run*", false, false};
fkey_command_linux[12] = {"./package.sh", "*package*", false, true };

View File

@ -932,74 +932,9 @@ win32_canonical_ascii_name(char *src, u32 len, char *dst, u32 max){
return(result);
}
#if 0
internal u32
win32_canonical_ascii_name(char *src, u32 len, char *dst, u32 max){
char *wrt = dst;
char *wrt_stop = dst + max;
char *src_stop = src + len;
char c = 0;
if (len >= 2 && max > 0){
c = src[0];
if (c >= 'a' && c <= 'z'){
c -= 'a' - 'A';
}
if (c >= 'A' && c <= 'Z' && src[1] == ':'){
*(wrt++) = c;
if (wrt == wrt_stop) goto fail;
*(wrt++) = ':';
if (wrt == wrt_stop) goto fail;
src += 2;
for (; src < src_stop; ++src){
c = src[0];
if (c >= 'A' && c <= 'Z'){
c += 'a' - 'A';
}
if (c == '/' || c == '\\'){
c = '\\';
if (wrt > dst && wrt[-1] == '\\'){
continue;
}
else if (src[1] == '.'){
if (src[2] == '\\' || src[2] == '/'){
src += 1;
}
else if (src[2] == '.' && (src[3] == '\\' || src[3] == '/')){
src += 2;
while (wrt > dst && wrt[0] != '\\'){
--wrt;
}
if (wrt == dst) goto fail;
}
}
}
*wrt = c;
++wrt;
if (wrt == wrt_stop) goto fail;
}
}
}
if (0){
fail:;
wrt = dst;
}
u32 result = (u32)(wrt - dst);
return(result);
}
#endif
internal
Sys_Get_Canonical_Sig(system_get_canonical){
i32 result = win32_canonical_ascii_name(filename, len, buffer, max);
u32 result = win32_canonical_ascii_name(filename, len, buffer, max);
return(result);
}