FL/New_Project_Dialog: Don't crash if aborted.

This commit is contained in:
Jonathan Moore Liles 2013-05-13 17:21:50 -07:00
parent d4c15e6fa7
commit 89f2633463
3 changed files with 62 additions and 95 deletions

View File

@ -54,17 +54,17 @@ while ( _window->shown() )
Function {make_window()} {open
} {
Fl_Window _window {
label {New Project} open
xywh {762 252 550 195} type Double hide modal
label {New Project} open selected
xywh {743 696 550 105} type Double modal visible
} {
Fl_File_Input _name {
label {Named:}
xywh {75 140 375 35}
xywh {75 55 375 35}
}
Fl_Button {} {
label Browse
callback {_directory->value( fl_dir_chooser( "Directory for new project", NULL, 0 ) );}
xywh {455 100 80 35}
xywh {455 15 80 35}
}
Fl_Return_Button {} {
label Create
@ -83,7 +83,7 @@ while ( _window->shown() )
_window->hide();
}}
xywh {455 140 80 35}
xywh {455 55 80 35}
}
Fl_File_Input _directory {
label {Where:}
@ -95,36 +95,18 @@ while ( _window->shown() )
}
// write_line( user_config_dir, "default_path", o->value() );}
xywh {75 100 375 35}
xywh {75 15 375 35}
code0 {\#include <FL/filename.H>}
code1 {char *v = NULL;}
code2 {// read_line( user_config_dir, "default_path", &v );}
code3 {o->value( v );}
}
Fl_Box {} {
label {New Project}
xywh {15 8 520 33} box RSHADOW_BOX color 133 labelsize 20 labelcolor 32
}
Fl_Choice _template {
label {Template:} open
private xywh {310 60 225 25} down_box BORDER_BOX
} {
MenuItem {} {
label Default selected
xywh {0 0 40 25}
}
}
}
}
decl {char *path;} {public local
}
decl {char *_default_path} {private local
}
Function {templates( const char **templates )} {open return_type void
} {
code {for ( const char **s = templates; *s; ++s )
_template->add( *s );} {}
}
Function {default_path( char *s )} {open return_type void
} {
code {_default_path = s;} {}
@ -133,23 +115,18 @@ while ( _window->shown() )
} {
code {return _default_path;} {}
}
Function {selected_template()} {open return_type {const char *}
} {
code {return _template->text( _template->value() );} {}
}
}
Function {new_project_chooser( const char **templates, char **default_path, char **selected_template )} {open C return_type {char*}
Function {new_project_chooser( char **default_path)} {open C return_type {char*}
} {
code {New_Project_Dialog nsd;
nsd.templates( templates );
nsd.default_path( *default_path );
nsd.run();
*default_path = strdup( nsd.default_path() );
*selected_template = strdup( nsd.selected_template() );
if ( nsd.default_path() )
*default_path = strdup( nsd.default_path() );
return nsd.path;} {}
}

View File

@ -186,21 +186,18 @@ void Mixer::cb_menu(Fl_Widget* o) {
if (! strcmp( picked, "&Project/&New") )
{
DMESSAGE( "New project" );
const char *templates[] = { "Default", NULL };
char *default_path;
char *selected_template;
read_line( user_config_dir, "default_path", &default_path );
char *path = new_project_chooser( templates, &default_path, &selected_template );
char *path = new_project_chooser( &default_path );
if ( path )
{
if ( ! Project::create( path, selected_template ) )
if ( ! Project::create( path, NULL ) )
fl_alert( "Error creating project!" );
free( path );
free( selected_template );
}
update_menu();

View File

@ -261,7 +261,7 @@ Loggable::progress_callback( &TLE::progress_cb, this );} {}
label {Non Timeline}
callback {if ( Fl::event_key() != FL_Escape )
timeline->command_quit();} open
xywh {202 266 1025 770} type Double resizable
xywh {204 266 1025 770} type Double resizable
code0 {o->xclass( APP_NAME );}
class TLE_Window size_range {900 300 0 0} visible
} {
@ -330,21 +330,18 @@ pi.run();}
label {&New}
callback {save_timeline_settings();
const char *templates[] = { "Default", NULL };
char *default_path;
char *selected_template;
read_line( user_config_dir, "default_path", &default_path );
char *path = new_project_chooser( templates, &default_path, &selected_template );
char *path = new_project_chooser( &default_path );
if ( path )
{
if ( ! Project::create( path, selected_template ) )
if ( ! Project::create( path, NULL ) )
fl_alert( "Error creating project!" );
free( path );
free( selected_template );
}
if ( default_path )
@ -422,7 +419,7 @@ while ( 0 == waitpid( pid, &status, WNOHANG ) )
Project::open(path);
free(path);} selected
free(path);}
xywh {20 20 40 25}
}
}
@ -1055,16 +1052,19 @@ if ( logo_box->image() )
((Fl_Shared_Image*)logo_box->image())->release();
logo_box->image( NULL );
}} open
private xywh {1193 174 520 775} type Double hide modal
private xywh {1195 197 520 710} type Double modal visible
} {
Fl_Group {} {open
xywh {25 30 470 75}
} {
Fl_Value_Output {} {
label {Sample Rate}
xywh {40 80 90 25} labeltype SHADOW_LABEL align 1
xywh {35 30 90 25} labeltype SHADOW_LABEL align 1
code0 {o->value( timeline->sample_rate() );}
}
Fl_Output {} {
label {Size of Journal}
xywh {180 80 100 25} box UP_BOX labeltype SHADOW_LABEL align 1
xywh {175 30 100 25} box UP_BOX labeltype SHADOW_LABEL align 1
code0 {static char pat[40];}
code1 {snprintf( pat, sizeof( pat ), "%.1fK", size( "history" ) / (float)1024 );}
code2 {o->value( pat );}
@ -1072,30 +1072,39 @@ if ( logo_box->image() )
}
Fl_Output {} {
label {Created On}
xywh {320 80 180 25} box UP_BOX labeltype SHADOW_LABEL align 1 textfont 11 textsize 12
xywh {315 30 180 25} box UP_BOX labeltype SHADOW_LABEL align 1 textfont 11 textsize 12
code0 {o->value( Project::created_on() );}
}
Fl_Output {} {
label Length
xywh {30 130 115 25} box BORDER_BOX color 47 align 1 textcolor 71
xywh {25 80 115 25} box BORDER_BOX color 47 align 1 textcolor 71
code0 {char pat[40];}
code1 {Clock::frame_to_HMS( pat, sizeof( pat ), timeline->length() );}
code2 {o->value( pat );}
}
Fl_Value_Output {} {
label Tracks
xywh {200 130 55 25} align 1
xywh {195 80 55 25} align 1
code0 {o->value( timeline->ntracks() );}
}
Fl_Output {} {
label {Last Modified On}
xywh {315 80 180 25} box UP_BOX labeltype SHADOW_LABEL align 1 textfont 11 textsize 12
code0 {time_t t = modification_time( "history" );}
code1 {static char s[40];}
code2 {ctime_r( &t, s ); s[ strlen( s ) - 1 ] = 0;}
code3 {o->value( s );}
}
}
Fl_Box logo_box {
label {<LOGO>}
private xywh {20 173 485 268} color 53 labelfont 1 labelsize 18 align 16
private xywh {18 117 485 268} color 53 labelfont 1 labelsize 18 align 16
code0 {o->image( Fl_Shared_Image::get( PIXMAP_PATH "/non-timeline/icon-256x256.png" ) );}
code1 {o->label( NULL );}
}
Fl_Text_Editor notes_field {
label {Notes:}
private xywh {20 475 480 245} color 47 selection_color 31 textsize 18 textcolor 92
label {Notes:} selected
private xywh {20 420 480 245} color 47 selection_color 31 textsize 18 textcolor 92
code0 {o->buffer( new Fl_Text_Buffer() );}
code1 {o->buffer()->loadfile( "notes" );}
}
@ -1104,28 +1113,12 @@ if ( logo_box->image() )
callback {notes_field->buffer()->savefile( "notes" );
window->do_callback();}
xywh {420 735 74 25}
}
Fl_Box {} {
label {Project Info}
xywh {40 18 405 27} box RSHADOW_BOX color 95 labeltype SHADOW_LABEL labelsize 18
}
Fl_Box {} {
label {Project Info}
xywh {25 18 470 33} box RSHADOW_BOX color 0 labelsize 20 labelcolor 32
xywh {422 676 74 25}
}
Fl_Button {} {
label {&Discard}
callback {window->do_callback();}
xywh {330 735 74 25}
}
Fl_Output {} {
label {Last Modified On}
xywh {320 130 180 25} box UP_BOX labeltype SHADOW_LABEL align 1 textfont 11 textsize 12
code0 {time_t t = modification_time( "history" );}
code1 {static char s[40];}
code2 {ctime_r( &t, s ); s[ strlen( s ) - 1 ] = 0;}
code3 {o->value( s );}
xywh {332 676 74 25}
}
}
}