Add signals for song dirty state. Make file menu entries context sensitive.

This commit is contained in:
Jonathan Moore Liles 2008-02-12 00:06:08 -06:00
parent e3a3d71404
commit fe8fab22df
4 changed files with 53 additions and 33 deletions

View File

@ -84,7 +84,8 @@ void
Canvas::handle_event_change ( void ) Canvas::handle_event_change ( void )
{ {
/* mark the song as dirty and pass the signal on */ /* mark the song as dirty and pass the signal on */
song.dirty = true; song.dirty( true );
signal_draw(); signal_draw();
} }

View File

@ -72,6 +72,17 @@ if ( transport.rolling != oldstate )
{ {
ui->play_button->label( transport.rolling ? "@square" : "@>" ); ui->play_button->label( transport.rolling ? "@square" : "@>" );
oldstate = transport.rolling; oldstate = transport.rolling;
if ( transport.rolling )
{
ui->menu_new->deactivate();
ui->menu_open->deactivate();
}
else
{
ui->menu_new->activate();
ui->menu_open->activate();
}
} }
// JUST A TEST // JUST A TEST
@ -137,30 +148,20 @@ delete main_window;} {}
if ( Fl::event() == FL_SHORTCUT && Fl::event_key() == FL_Escape ) if ( Fl::event() == FL_SHORTCUT && Fl::event_key() == FL_Escape )
return; return;
if ( maybe_save_song() ) if ( maybe_save_song() )
quit();} open quit();} open
xywh {694 168 869 801} type Single box PLASTIC_UP_BOX color 37 resizable xclass non size_range {869 801 0 0} visible xywh {694 168 869 801} type Single box PLASTIC_UP_BOX color 37 resizable xclass non size_range {869 801 0 0} visible
} { } {
Fl_Menu_Bar {} {open Fl_Menu_Bar menu_bar {open
xywh {0 0 869 30} color 37 xywh {0 0 869 30} color 37
} { } {
Submenu {} { Submenu {} {
label {&File} open label {&File} open
xywh {0 0 100 20} color 37 xywh {0 0 100 20} color 37
} { } {
MenuItem {} { MenuItem menu_new {
label {&New} label {&New}
callback {if ( transport.rolling ) callback {if ( maybe_save_song() )
{
fl_alert( "Can't make new file while the transport is running." );
return;
}
// FIXME: check for dirtiness and ask to save.
if ( maybe_save_song() )
{ {
init_song(); init_song();
@ -171,15 +172,9 @@ if ( maybe_save_song() )
}} }}
xywh {0 0 40 25} xywh {0 0 40 25}
} }
MenuItem {} { MenuItem menu_open {
label {&Open} label {&Open}
callback {if ( transport.rolling ) callback {char *name = fl_file_chooser( "Open File", "Non Files (*.non)", NULL, 0 );
{
fl_alert( "Can't open file while transport is rolling." );
return;
}
char *name = fl_file_chooser( "Open File", "Non Files (*.non)", NULL, 0 );
if ( name ) if ( name )
{ {
@ -195,10 +190,12 @@ if ( name )
}} }}
xywh {0 0 40 25} shortcut 0x4006f color 37 xywh {0 0 40 25} shortcut 0x4006f color 37
} }
MenuItem {} { MenuItem menu_save {
label {&Save} label {&Save}
callback {save_dialog( song.filename );} callback {save_dialog( song.filename );} selected
xywh {0 0 40 25} shortcut 0x40073 color 37 xywh {0 0 40 25} shortcut 0x40073 color 37 deactivate
code0 {song.signal_dirty.connect( sigc::mem_fun( o, &Fl_Menu_Item::activate ) );}
code1 {song.signal_clean.connect( sigc::mem_fun( o, &Fl_Menu_Item::deactivate ) );}
} }
MenuItem {} { MenuItem {} {
label {Save &As} label {Save &As}
@ -304,7 +301,7 @@ if ( tabs->value() == pattern_tab )
} { } {
MenuItem {} { MenuItem {} {
label {&Events} label {&Events}
callback {event_editor( pattern_c->grid() );} selected callback {event_editor( pattern_c->grid() );}
xywh {0 0 40 25} xywh {0 0 40 25}
} }
MenuItem {} { MenuItem {} {
@ -368,13 +365,12 @@ about_popup->show();}
Fl_Tabs tabs { Fl_Tabs tabs {
callback {((Fl_Group*)o->value())->child( 0 )->take_focus(); callback {((Fl_Group*)o->value())->child( 0 )->take_focus();
if ( o->value() != pattern_tab ) if ( o->value() != pattern_tab )
edit_menu->deactivate(); edit_menu->deactivate();
else else
edit_menu->activate(); edit_menu->activate();
DEBUG( "tabs callback:" );} open menu_bar->redraw();} open
xywh {0 76 868 701} color 37 labeltype SHADOW_LABEL labelsize 19 when 1 xywh {0 76 868 701} color 37 labeltype SHADOW_LABEL labelsize 19 when 1
code0 {canvas_background_color = fl_rgb_color( 18, 18, 18 );} code0 {canvas_background_color = fl_rgb_color( 18, 18, 18 );}
} { } {
@ -1228,7 +1224,7 @@ help->show();
} }
Function {maybe_save_song()} {return_type bool Function {maybe_save_song()} {return_type bool
} { } {
code {if ( song.dirty ) code {if ( song.dirty() )
{ {
int c = fl_choice( "Song has been modified since last save. What shall I do?", "Cancel", "Save", "Discard" ); int c = fl_choice( "Song has been modified since last save. What shall I do?", "Cancel", "Save", "Discard" );

4
main.C
View File

@ -72,7 +72,7 @@ void
init_song ( void ) init_song ( void )
{ {
song.filename = NULL; song.filename = NULL;
song.dirty = false; song.dirty( false );
pattern_c->grid( NULL ); pattern_c->grid( NULL );
phrase_c->grid( NULL ); phrase_c->grid( NULL );
@ -124,7 +124,7 @@ save_song ( const char *name )
playlist->save( name ); playlist->save( name );
song.filename = strdup( name ); song.filename = strdup( name );
song.dirty = false; song.dirty( false );
return true; return true;
} }

25
non.H
View File

@ -85,7 +85,30 @@ struct song_settings
enum play_mode_e play_mode; enum play_mode_e play_mode;
char *filename; char *filename;
bool dirty;
signal <void> signal_dirty; /* emitted when first dirtied */
signal <void> signal_clean; /* emitted when first cleaned */
bool _dirty;
bool dirty ( void )
{
return _dirty;
}
void
dirty( bool b )
{
if ( _dirty != b )
{
_dirty = b;
if ( b )
signal_dirty();
else
signal_clean();
}
}
struct { struct {
int feel; int feel;