Revision: 6492
          http://playerstage.svn.sourceforge.net/playerstage/?rev=6492&view=rev
Author:   jeremy_asher
Date:     2008-06-09 11:36:48 -0700 (Mon, 09 Jun 2008)

Log Message:
-----------
Added Save As menu item

Modified Paths:
--------------
    code/stage/trunk/libstage/stage.hh
    code/stage/trunk/libstage/world.cc
    code/stage/trunk/libstage/worldfile.cc
    code/stage/trunk/libstage/worldgui.cc

Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh  2008-06-09 18:34:44 UTC (rev 6491)
+++ code/stage/trunk/libstage/stage.hh  2008-06-09 18:36:48 UTC (rev 6492)
@@ -1059,7 +1059,7 @@
   
     virtual void Load( const char* worldfile_path );
     virtual void Reload();
-    virtual void Save();
+    virtual bool Save( const char* filename );
     virtual bool Update(void);
     virtual void AddModel( StgModel* mod );
     virtual void RemoveModel( StgModel* mod );
@@ -1839,10 +1839,11 @@
   void Cycle();
   
   virtual void Load( const char* filename );
-  virtual void Save();
+  virtual bool Save( const char* filename );
   
   // static callback functions
   static void SaveCallback( Fl_Widget* wid, StgWorldGui* world );
+  static void SaveAsCallback( Fl_Widget* wid, StgWorldGui* world );
   
   virtual void PushColor( stg_color_t col )
   { canvas->PushColor( col ); } 

Modified: code/stage/trunk/libstage/world.cc
===================================================================
--- code/stage/trunk/libstage/world.cc  2008-06-09 18:34:44 UTC (rev 6491)
+++ code/stage/trunk/libstage/world.cc  2008-06-09 18:36:48 UTC (rev 6492)
@@ -654,14 +654,14 @@
   ((StgModel*)data)->Save();
 }
 
-void StgWorld::Save( void )
+bool StgWorld::Save( const char *filename )
 {
   // ask every model to save itself
   //g_hash_table_foreach( this->models_by_id, stg_model_save_cb, NULL );
   
   ForEachModel( _save_cb, NULL );
 
-  this->wf->Save(NULL);
+  return this->wf->Save( filename );
 }
 
 static void _reload_cb( gpointer key, gpointer data, gpointer user )

Modified: code/stage/trunk/libstage/worldfile.cc
===================================================================
--- code/stage/trunk/libstage/worldfile.cc      2008-06-09 18:34:44 UTC (rev 
6491)
+++ code/stage/trunk/libstage/worldfile.cc      2008-06-09 18:36:48 UTC (rev 
6492)
@@ -232,15 +232,15 @@
     filename = this->filename;
 
   // Open file
-  //FILE *file = fopen(filename, "w+");
-  FILE *file = FileOpen(filename, "w+");
+  FILE *file = fopen(filename, "w+");
+  //FILE *file = FileOpen(filename, "w+");
   if (!file)
   {
     PRINT_ERR2("unable to open world file %s : %s",
                filename, strerror(errno));
     return false;
   }
-
+  
   // TODO - make a backup before saving the file
 
   // Write the current set of tokens to the file

Modified: code/stage/trunk/libstage/worldgui.cc
===================================================================
--- code/stage/trunk/libstage/worldgui.cc       2008-06-09 18:34:44 UTC (rev 
6491)
+++ code/stage/trunk/libstage/worldgui.cc       2008-06-09 18:36:48 UTC (rev 
6492)
@@ -103,6 +103,7 @@
 #include <FL/Fl_PNG_Image.H>
 #include <FL/Fl_Output.H>
 #include <FL/Fl_Multiline_Output.H>
+#include <FL/Fl_File_Chooser.H>
 
 static const char* MITEM_VIEW_DATA =      "View/Data";
 static const char* MITEM_VIEW_BLOCKS =    "View/Blocks";
@@ -188,7 +189,7 @@
   
   mbar->add( "File", 0, 0, 0, FL_SUBMENU );
   mbar->add( "File/Save File", FL_CTRL + 's', (Fl_Callback *)SaveCallback, 
this );
-  //mbar->add( "File/Save File &As...", FL_CTRL + FL_SHIFT + 's', (Fl_Callback 
*)dummy_cb, 0, FL_MENU_DIVIDER );
+  mbar->add( "File/Save File &As...", FL_CTRL + FL_SHIFT + 's', (Fl_Callback 
*)SaveAsCallback, this, FL_MENU_DIVIDER );
   mbar->add( "File/Exit", FL_CTRL+'q', (Fl_Callback *)dummy_cb, 0 );
  
   mbar->add( "View", 0, 0, 0, FL_SUBMENU );
@@ -297,11 +298,42 @@
 
  void StgWorldGui::SaveCallback( Fl_Widget* wid, StgWorldGui* world )
  {
-   world->Save();
+   // save to current file
+   bool success =  world->Save( NULL ); 
+   if ( !success ) {
+     fl_alert( "Error saving world file." );
+   }
  }
 
-void StgWorldGui::Save( void )
+void StgWorldGui::SaveAsCallback( Fl_Widget* wid, StgWorldGui* world )
 {
+  const char* curFilename = world->wf->filename;
+  const char* newFilename;
+  bool success;
+  const char* pattern = "World Files (*.world)"; 
+  
+  Fl_File_Chooser fc( curFilename, pattern, Fl_File_Chooser::CREATE, "Save 
File As..." );
+  fc.ok_label( "Save" );
+
+  fc.show();
+  while (fc.shown())
+    Fl::wait();
+  
+  newFilename = fc.value();
+
+  if (newFilename != NULL) {
+    // todo: make sure file ends in .world
+    success = world->Save( newFilename );
+    if ( !success ) {
+      fl_alert( "Error saving world file." );
+    }
+  }
+
+  
+}
+
+bool StgWorldGui::Save( const char* filename )
+{
   PRINT_DEBUG1( "%s.Save()", token );
   
   wf->WriteTupleFloat( wf_section, "size", 0, w() );
@@ -326,7 +358,7 @@
   
   // TODO - per model visualizations save 
 
-  StgWorld::Save();
+  return StgWorld::Save( filename );
 }
 
 void StgWorld::UpdateCb( StgWorld* world  )


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to