- Connect signals for saving and loading from file in the GUI
- Implement GuiBuilder::on_file_save_activate() - TODO: manage more than one serializer - TODO: append standard extension to filename if it isn't there git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@998 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
77c91ebfec
commit
40ab20a87a
|
@ -85,11 +85,14 @@ GuiBuilder::on_file_open_activate()
|
|||
// will need to be changed when multiple serializers will
|
||||
// be made available
|
||||
Serializer& serializer = *serializers.at(0);
|
||||
History& history = Simulation::get_instance().get_history();
|
||||
|
||||
Simulation& sim = Simulation::get_instance();
|
||||
|
||||
// open file dialog...
|
||||
Gtk::FileChooserDialog dialog("Please choose a file", Gtk::FILE_CHOOSER_ACTION_OPEN);
|
||||
dialog.set_transient_for(get_initial_window());
|
||||
if(!_filename.empty()) // Please test the following line extensively:
|
||||
dialog.set_current_folder(Glib::path_get_dirname(_filename));
|
||||
|
||||
//Add response buttons the the dialog:
|
||||
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
||||
|
@ -114,18 +117,22 @@ GuiBuilder::on_file_open_activate()
|
|||
int result = dialog.run();
|
||||
if(result==Gtk::RESPONSE_OK)
|
||||
{
|
||||
Glib::ustring filename = dialog.get_filename();
|
||||
serializer.restore_snapshot(filename, history);
|
||||
msg = "File: " + filename + " loaded.";
|
||||
_filename = dialog.get_filename();
|
||||
sim.stop(); // It would work anyhow, but it'd look strange
|
||||
History& history = sim.get_history();
|
||||
serializer.restore_snapshot(_filename, history);
|
||||
msg = "File: " + _filename + " loaded.";
|
||||
} // end - if(result==Gtk::RESPONSE_OK)
|
||||
|
||||
}
|
||||
catch (std::out_of_range e)
|
||||
{
|
||||
// FIXME: this should be an error dialog
|
||||
msg = _("ERROR: No registered serializer available");
|
||||
}
|
||||
catch (SerializerError e)
|
||||
{
|
||||
// FIXME: this should be an error dialog
|
||||
msg = _("ERROR: ") + Glib::ustring(e.what());
|
||||
}
|
||||
if(!msg.empty())
|
||||
|
@ -138,9 +145,48 @@ GuiBuilder::on_file_open_activate()
|
|||
void
|
||||
GuiBuilder::on_file_save_activate()
|
||||
{
|
||||
// _simulation_widget->change_scaling_mode();
|
||||
if(_filename.empty())
|
||||
{
|
||||
on_file_saveas_activate();
|
||||
return;
|
||||
}
|
||||
|
||||
// else:
|
||||
|
||||
Glib::ustring msg;
|
||||
try
|
||||
{
|
||||
std::vector<Serializer*> serializers =
|
||||
SerializersGatekeeper::get_instance().get_registered();
|
||||
|
||||
// FIXME using the first serializer available, this
|
||||
// will need to be changed when multiple serializers will
|
||||
// be made available
|
||||
Serializer& serializer = *serializers.at(0);
|
||||
History& history = Simulation::get_instance().get_history();
|
||||
|
||||
serializer.save_snapshot(_filename, history);
|
||||
msg = "File: " + _filename + " saved.";
|
||||
}
|
||||
catch (std::out_of_range e)
|
||||
{
|
||||
// FIXME: this should be an error dialog
|
||||
msg = _("ERROR: No registered serializer available");
|
||||
}
|
||||
catch (SerializerError e)
|
||||
{
|
||||
// FIXME: this should be an error dialog
|
||||
msg = _("ERROR: ") + Glib::ustring(e.what());
|
||||
}
|
||||
|
||||
if(!msg.empty())
|
||||
{
|
||||
Gtk::Statusbar* sbar = _refXml->get_widget("MainStatusBar", sbar);
|
||||
sbar->push(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GuiBuilder::on_file_saveas_activate()
|
||||
{
|
||||
|
@ -180,16 +226,19 @@ GuiBuilder::on_file_saveas_activate()
|
|||
if(result==Gtk::RESPONSE_OK)
|
||||
{
|
||||
serializer.save_snapshot(dialog.get_filename(), history);
|
||||
msg = "File: " + dialog.get_filename() + " saved.";
|
||||
_filename = dialog.get_filename();
|
||||
msg = "File: " + _filename + " saved.";
|
||||
} // end - if(result==Gtk::RESPONSE_OK)
|
||||
|
||||
}
|
||||
catch (std::out_of_range e)
|
||||
{
|
||||
// FIXME: This should be an error dialog:
|
||||
msg = _("ERROR: No registered serializer available");
|
||||
}
|
||||
catch (SerializerError e)
|
||||
{
|
||||
// FIXME: This should be an error dialog:
|
||||
msg = _("ERROR: ") + Glib::ustring(e.what());
|
||||
}
|
||||
|
||||
|
@ -417,6 +466,17 @@ GuiBuilder::GuiBuilder(const std::string& gladefile)
|
|||
|
||||
// Note: the Play, Pause and Stop buttons are already managed by sgpem::SimulationController.
|
||||
|
||||
// Open file
|
||||
ToolButton* toolb_open;
|
||||
_refXml->get_widget("ToolBar.Open", toolb_open);
|
||||
toolb_open->signal_clicked().connect(sigc::mem_fun(*this, &GuiBuilder::on_file_open_activate));
|
||||
|
||||
// Save file
|
||||
ToolButton* toolb_save;
|
||||
_refXml->get_widget("ToolBar.Save", toolb_save);
|
||||
toolb_save->signal_clicked().connect(sigc::mem_fun(*this, &GuiBuilder::on_file_save_activate));
|
||||
|
||||
|
||||
// Configure CPU Policy
|
||||
MenuToolButton* cpu_policies_tb_menu;
|
||||
_refXml->get_widget("ToolBar.PolicySelector", cpu_policies_tb_menu);
|
||||
|
|
|
@ -66,6 +66,9 @@ namespace sgpem
|
|||
Glib::RefPtr<Gnome::Glade::Xml> _refXml;
|
||||
SimulationWidget* _simulation_widget;
|
||||
SimulationController _controller;
|
||||
|
||||
// Used to store the loaded snapshot filename, when !empty
|
||||
std::string _filename;
|
||||
};
|
||||
|
||||
} //~ namespace sgpem
|
||||
|
|
Loading…
Reference in New Issue