Browse Source

Cleanup open/new behavior.

tags/non-daw-v1.1.0
Jonathan Moore Liles 17 years ago
parent
commit
4422c354f7
4 changed files with 57 additions and 25 deletions
  1. +0
    -1
      Timeline/Loggable.C
  2. +42
    -6
      Timeline/Project.C
  3. +2
    -0
      Timeline/Project.H
  4. +13
    -18
      Timeline/TLE.fl

+ 0
- 1
Timeline/Loggable.C View File

@@ -47,7 +47,6 @@ Loggable::open ( const char *filename )
return false; return false;
} }



/* replay log */ /* replay log */
{ {
char buf[BUFSIZ]; char buf[BUFSIZ];


+ 42
- 6
Timeline/Project.C 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 "TLE.H" // all this just for load and save...


#include <FL/filename.H>

extern TLE *tle; extern TLE *tle;


/* FIXME: wrong place for this */ /* FIXME: wrong place for this */
@@ -44,6 +46,7 @@ extern TLE *tle;


#include "debug.h" #include "debug.h"
char Project::_name[256]; char Project::_name[256];
char Project::_path[512];
bool Project::_is_open = false; bool Project::_is_open = false;


void void
@@ -78,6 +81,9 @@ exists ( const char *name )
bool bool
Project::close ( void ) Project::close ( void )
{ {
if ( ! open() )
return true;

tle->save_timeline_settings(); tle->save_timeline_settings();


Loggable::close(); Loggable::close();
@@ -86,6 +92,8 @@ Project::close ( void )


_is_open = false; _is_open = false;


*Project::_name = '\0';

return true; return true;
} }


@@ -132,29 +140,54 @@ Project::read_info ( void )
return true; return true;
} }


/** ensure a project is valid before opening it... */
bool 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 ) ) if ( chdir( name ) )
{ {
WARNING( "Cannot change to project dir \"%s\"", name ); WARNING( "Cannot change to project dir \"%s\"", name );
return false; return false;
} }


if ( ! exists( "history" ) ||
if ( ! exists( "info" ) ||
! exists( "history" ) ||
! exists( "sources" ) ) ! exists( "sources" ) )
// ! exists( "options" ) ) // ! exists( "options" ) )
{ {
WARNING( "Not a Non-DAW project: \"%s\"", name ); 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" ) ) if ( ! Loggable::open( "history" ) )
FATAL( "error opening journal" ); FATAL( "error opening journal" );


set_name( name ); set_name( name );


*_path = '\0';
fl_filename_absolute( _path, sizeof( _path ), "." );

read_info(); read_info();


_is_open = true; _is_open = true;
@@ -167,14 +200,14 @@ Project::open ( const char *name )
bool bool
Project::create ( const char *name, const char *template_name ) Project::create ( const char *name, const char *template_name )
{ {
close();

if ( exists( name ) ) if ( exists( name ) )
{ {
WARNING( "Project already exists" ); WARNING( "Project already exists" );
return false; return false;
} }


close();

if ( mkdir( name, 0777 ) ) if ( mkdir( name, 0777 ) )
{ {
WARNING( "Cannot create project directory" ); WARNING( "Cannot create project directory" );
@@ -186,12 +219,15 @@ Project::create ( const char *name, const char *template_name )


mkdir( "sources", 0777 ); mkdir( "sources", 0777 );


creat( "info", 0666 );
creat( "history", 0666 ); creat( "history", 0666 );


/* TODO: copy template */ /* TODO: copy template */


if ( open( name ) ) if ( open( name ) )
{ {
write_info();

/* add the bare essentials */ /* add the bare essentials */
timeline->beats_per_minute( 0, 120 ); timeline->beats_per_minute( 0, 120 );
timeline->time( 0, 4, 4 ); timeline->time( 0, 4, 4 );


+ 2
- 0
Timeline/Project.H View File

@@ -25,6 +25,7 @@ class Project


static bool _is_open; static bool _is_open;
static char _name[256]; static char _name[256];
static char _path[512];


public: public:


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


+ 13
- 18
Timeline/TLE.fl View File

@@ -35,8 +35,7 @@ decl {\#include <FL/Fl_File_Chooser.H>} {}


decl {\#include <FL/Fl.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 decl {extern char project_display_name[256];} {global
} }
@@ -170,9 +169,14 @@ main_window->redraw();}
label {&Open} label {&Open}
callback {const char *name = fl_dir_chooser( "Open Project", NULL, NULL ); 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 ); 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() ); 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} xywh {455 140 80 35}
} }
Fl_File_Input _directory { Fl_File_Input _directory {


Loading…
Cancel
Save