Browse Source

Keep track of default project path across sessions.

tags/non-daw-v1.1.0
Jonathan Moore Liles 17 years ago
parent
commit
a36f515f65
3 changed files with 62 additions and 6 deletions
  1. +18
    -6
      Timeline/TLE.fl
  2. +42
    -0
      util/file.C
  3. +2
    -0
      util/file.h

+ 18
- 6
Timeline/TLE.fl View File

@@ -234,9 +234,15 @@ main_window->redraw();}
} }
MenuItem {} { MenuItem {} {
label {&Open} 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} xywh {10 10 40 25}
} }
MenuItem {} { MenuItem {} {
@@ -647,8 +653,7 @@ else
} }


m->redraw(); 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} 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 Function {New_Project_Dialog()} {open
} { } {
code {make_window();} {} code {make_window();} {}
@@ -877,9 +883,15 @@ while ( _window->shown() )
{ {
fl_alert( "Must be a directory" ); fl_alert( "Must be a directory" );
o->value( "" ); o->value( "" );
}}
return;
}

write_line( user_config_dir, "default_path", o->value() );}
xywh {75 100 375 35} xywh {75 100 375 35}
code0 {\#include <FL/filename.H>} code0 {\#include <FL/filename.H>}
code1 {char *v;}
code2 {read_line( user_config_dir, "default_path", &v );}
code3 {o->value( v );}
} }
Fl_Box {} { Fl_Box {} {
label {New Project} label {New Project}


+ 42
- 0
util/file.C View File

@@ -22,6 +22,8 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <stdlib.h>


unsigned long unsigned long
mtime ( const char *file ) mtime ( const char *file )
@@ -136,3 +138,43 @@ touch ( int fd )


fchmod( fd, st.st_mode ); 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 );
}

+ 2
- 0
util/file.h View File

@@ -28,3 +28,5 @@ void release_lock ( int *lockfd, const char *filename );
int backwards_fgetc ( FILE *fp ); int backwards_fgetc ( FILE *fp );
char * backwards_fgets ( char *s, int size, FILE *fp ); char * backwards_fgets ( char *s, int size, FILE *fp );
void touch ( int fd ); 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 );

Loading…
Cancel
Save