Browse Source

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

tags/non-sequencer-v1.9.4
Jonathan Moore Liles 16 years ago
parent
commit
fe8fab22df
4 changed files with 53 additions and 33 deletions
  1. +2
    -1
      canvas.C
  2. +25
    -29
      gui/ui.fl
  3. +2
    -2
      main.C
  4. +24
    -1
      non.H

+ 2
- 1
canvas.C View File

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

signal_draw();
}



+ 25
- 29
gui/ui.fl View File

@@ -72,6 +72,17 @@ if ( transport.rolling != oldstate )
{
ui->play_button->label( transport.rolling ? "@square" : "@>" );
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
@@ -137,30 +148,20 @@ delete main_window;} {}
if ( Fl::event() == FL_SHORTCUT && Fl::event_key() == FL_Escape )
return;

if ( maybe_save_song() )
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
} {
Fl_Menu_Bar {} {open
Fl_Menu_Bar menu_bar {open
xywh {0 0 869 30} color 37
} {
Submenu {} {
label {&File} open
xywh {0 0 100 20} color 37
} {
MenuItem {} {
MenuItem menu_new {
label {&New}
callback {if ( transport.rolling )
{
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() )
callback {if ( maybe_save_song() )
{
init_song();

@@ -171,15 +172,9 @@ if ( maybe_save_song() )
}}
xywh {0 0 40 25}
}
MenuItem {} {
MenuItem menu_open {
label {&Open}
callback {if ( transport.rolling )
{
fl_alert( "Can't open file while transport is rolling." );
return;
}

char *name = fl_file_chooser( "Open File", "Non Files (*.non)", NULL, 0 );
callback {char *name = fl_file_chooser( "Open File", "Non Files (*.non)", NULL, 0 );

if ( name )
{
@@ -195,10 +190,12 @@ if ( name )
}}
xywh {0 0 40 25} shortcut 0x4006f color 37
}
MenuItem {} {
MenuItem menu_save {
label {&Save}
callback {save_dialog( song.filename );}
xywh {0 0 40 25} shortcut 0x40073 color 37
callback {save_dialog( song.filename );} selected
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 {} {
label {Save &As}
@@ -304,7 +301,7 @@ if ( tabs->value() == pattern_tab )
} {
MenuItem {} {
label {&Events}
callback {event_editor( pattern_c->grid() );} selected
callback {event_editor( pattern_c->grid() );}
xywh {0 0 40 25}
}
MenuItem {} {
@@ -368,13 +365,12 @@ about_popup->show();}
Fl_Tabs tabs {
callback {((Fl_Group*)o->value())->child( 0 )->take_focus();


if ( o->value() != pattern_tab )
edit_menu->deactivate();
else
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
code0 {canvas_background_color = fl_rgb_color( 18, 18, 18 );}
} {
@@ -1228,7 +1224,7 @@ help->show();
}
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" );



+ 2
- 2
main.C View File

@@ -72,7 +72,7 @@ void
init_song ( void )
{
song.filename = NULL;
song.dirty = false;
song.dirty( false );

pattern_c->grid( NULL );
phrase_c->grid( NULL );
@@ -124,7 +124,7 @@ save_song ( const char *name )
playlist->save( name );

song.filename = strdup( name );
song.dirty = false;
song.dirty( false );

return true;
}


+ 24
- 1
non.H View File

@@ -85,7 +85,30 @@ struct song_settings
enum play_mode_e play_mode;

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 {
int feel;


Loading…
Cancel
Save