Cleanup open/new behavior.

This commit is contained in:
Jonathan Moore Liles 2008-05-16 23:18:00 -05:00
parent 251d7f9267
commit 4422c354f7
4 changed files with 57 additions and 25 deletions

View File

@ -47,7 +47,6 @@ Loggable::open ( const char *filename )
return false;
}
/* replay log */
{
char buf[BUFSIZ];

View File

@ -35,6 +35,8 @@ project state belongs to Timeline and other classes. */
#include "TLE.H" // all this just for load and save...
#include <FL/filename.H>
extern TLE *tle;
/* FIXME: wrong place for this */
@ -44,6 +46,7 @@ extern TLE *tle;
#include "debug.h"
char Project::_name[256];
char Project::_path[512];
bool Project::_is_open = false;
void
@ -78,6 +81,9 @@ exists ( const char *name )
bool
Project::close ( void )
{
if ( ! open() )
return true;
tle->save_timeline_settings();
Loggable::close();
@ -86,6 +92,8 @@ Project::close ( void )
_is_open = false;
*Project::_name = '\0';
return true;
}
@ -132,29 +140,54 @@ Project::read_info ( void )
return true;
}
/** ensure a project is valid before opening it... */
bool
Project::open ( const char *name )
Project::validate ( const char *name )
{
bool r = true;
char pwd[512];
fl_filename_absolute( pwd, sizeof( pwd ), "." );
if ( chdir( name ) )
{
WARNING( "Cannot change to project dir \"%s\"", name );
return false;
}
if ( ! exists( "history" ) ||
if ( ! exists( "info" ) ||
! exists( "history" ) ||
! exists( "sources" ) )
// ! exists( "options" ) )
{
WARNING( "Not a Non-DAW project: \"%s\"", name );
return false;
r = false;
}
chdir( pwd );
return r;
}
bool
Project::open ( const char *name )
{
if ( ! validate( name ) )
return false;
close();
chdir( name );
if ( ! Loggable::open( "history" ) )
FATAL( "error opening journal" );
set_name( name );
*_path = '\0';
fl_filename_absolute( _path, sizeof( _path ), "." );
read_info();
_is_open = true;
@ -167,14 +200,14 @@ Project::open ( const char *name )
bool
Project::create ( const char *name, const char *template_name )
{
close();
if ( exists( name ) )
{
WARNING( "Project already exists" );
return false;
}
close();
if ( mkdir( name, 0777 ) )
{
WARNING( "Cannot create project directory" );
@ -186,12 +219,15 @@ Project::create ( const char *name, const char *template_name )
mkdir( "sources", 0777 );
creat( "info", 0666 );
creat( "history", 0666 );
/* TODO: copy template */
if ( open( name ) )
{
write_info();
/* add the bare essentials */
timeline->beats_per_minute( 0, 120 );
timeline->time( 0, 4, 4 );

View File

@ -25,6 +25,7 @@ class Project
static bool _is_open;
static char _name[256];
static char _path[512];
public:
@ -33,6 +34,7 @@ public:
static const char *name ( void ) { return Project::_name; }
static void set_name ( const char *name );
static bool close ( void );
static bool validate ( const char *name );
static bool open ( const char *name );
static bool open ( void ) { return _is_open; }
static bool create ( const char *name, const char *template_name );

View File

@ -35,8 +35,7 @@ decl {\#include <FL/Fl_File_Chooser.H>} {}
decl {\#include <FL/Fl.H>} {}
decl {\#include <Fl/Fl_Shared_Image.H>} {selected
}
decl {\#include <Fl/Fl_Shared_Image.H>} {}
decl {extern char project_display_name[256];} {global
}
@ -170,9 +169,14 @@ main_window->redraw();}
label {&Open}
callback {const char *name = fl_dir_chooser( "Open Project", NULL, NULL );
Project::close();
if ( ! Project::open( name ) )
if ( ! name )
return;
if ( ! Project::validate( name ) )
{
fl_alert( "\\"%s\\" does not appear to be a valid Non-DAW project!", name );
}
else if ( ! Project::open( name ) )
{
fl_alert( "Could not open \\"%s\\" as a Non-DAW project!", name );
@ -768,20 +772,11 @@ while ( _window->shown() )
snprintf( pat, sizeof( pat ), "%s/%s", _directory->value(), _name->value() );
// if ( ! fl_filename_exists( pat ) )
{
if ( ! Project::create( pat, _template->text( _template->value() ) ) )
fl_alert( "Error creating project!" );
if ( ! Project::create( pat, _template->text( _template->value() ) ) )
fl_alert( "Error opening project!" );
_window->hide();
}
// else
// {
// fl_alert( "A file already exists at that location. Choose a differnt name." );
//
// }
}}
_window->hide();
}} selected
xywh {455 140 80 35}
}
Fl_File_Input _directory {