diff --git a/Timeline/TLE.fl b/Timeline/TLE.fl index bf293ee..0b9acc1 100644 --- a/Timeline/TLE.fl +++ b/Timeline/TLE.fl @@ -234,9 +234,15 @@ main_window->redraw();} } MenuItem {} { label {&Open} - callback {const char *name = fl_dir_chooser( "Open Project", NULL, NULL ); + callback {char *path; -open( name );} +read_line( user_config_dir, "default_path", &path ); + +const char *name = fl_dir_chooser( "Open Project", path, NULL ); + +free( path ); + +open( name );} selected xywh {10 10 40 25} } MenuItem {} { @@ -647,8 +653,7 @@ else } m->redraw(); -project_name->redraw();} {selected - } +project_name->redraw();} {} } Function {update_progress( Fl_Progress *p, char *s, float v )} {open private return_type {static void} } { @@ -829,7 +834,8 @@ if ( r < 0 ) } } -class New_Project_Dialog {} { +class New_Project_Dialog {open +} { Function {New_Project_Dialog()} {open } { code {make_window();} {} @@ -877,9 +883,15 @@ while ( _window->shown() ) { fl_alert( "Must be a directory" ); o->value( "" ); -}} + return; +} + +write_line( user_config_dir, "default_path", o->value() );} xywh {75 100 375 35} code0 {\#include } + code1 {char *v;} + code2 {read_line( user_config_dir, "default_path", &v );} + code3 {o->value( v );} } Fl_Box {} { label {New Project} diff --git a/util/file.C b/util/file.C index b7a6195..f35f3a8 100644 --- a/util/file.C +++ b/util/file.C @@ -22,6 +22,8 @@ #include #include #include +#include +#include unsigned long mtime ( const char *file ) @@ -136,3 +138,43 @@ touch ( int fd ) fchmod( fd, st.st_mode ); } + +/** write a single string to a file */ +void +write_line ( const char *dir, const char *name, const char *value ) +{ + char path[512]; + + snprintf( path, sizeof( path ), "%s/%s", dir, name ); + + FILE *fp = fopen( path, "w" ); + + if ( ! fp ) + return; + + fputs( value, fp ); + + fclose( fp ); +} + +/** write a single string to a file */ +void +read_line ( const char *dir, const char *name, char **value ) +{ + char path[512]; + + *value = 0; + + snprintf( path, sizeof( path ), "%s/%s", dir, name ); + + FILE *fp = fopen( path, "r" ); + + if ( ! fp ) + return; + + *value = (char*)malloc( 512 ); + + fgets( *value, 512, fp ); + + fclose( fp ); +} diff --git a/util/file.h b/util/file.h index 12210e3..9c02b7c 100644 --- a/util/file.h +++ b/util/file.h @@ -28,3 +28,5 @@ void release_lock ( int *lockfd, const char *filename ); int backwards_fgetc ( FILE *fp ); char * backwards_fgets ( char *s, int size, FILE *fp ); void touch ( int fd ); +void write_line ( const char *dir, const char *name, const char *value ); +void read_line ( const char *dir, const char *name, char **value );