- Set window title with current filename

- Add error dialogs for serializer-related exceptions


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1225 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-09-17 13:03:07 +00:00
parent b3999f2803
commit 76b33d4269
2 changed files with 44 additions and 13 deletions

View File

@ -73,6 +73,7 @@
using namespace sgpem; using namespace sgpem;
using Gnome::Glade::Xml; using Gnome::Glade::Xml;
void void
GuiBuilder::on_edit_preferences_activate() GuiBuilder::on_edit_preferences_activate()
{ {
@ -149,7 +150,7 @@ GuiBuilder::on_file_new_activate()
sim.stop(); sim.stop();
history.clear(); history.clear();
_filename = ""; set_filename();
} }
@ -201,7 +202,7 @@ GuiBuilder::on_file_open_activate()
int result = dialog.run(); int result = dialog.run();
if(result==Gtk::RESPONSE_OK) if(result==Gtk::RESPONSE_OK)
{ {
_filename = dialog.get_filename(); set_filename(dialog.get_filename());
sim.stop(); // It would work anyhow, but it'd look strange sim.stop(); // It would work anyhow, but it'd look strange
History& history = sim.get_history(); History& history = sim.get_history();
serializer.restore_snapshot(_filename, history); serializer.restore_snapshot(_filename, history);
@ -211,13 +212,18 @@ GuiBuilder::on_file_open_activate()
} }
catch (std::out_of_range e) catch (std::out_of_range e)
{ {
// FIXME: this should be an error dialog Gtk::MessageDialog error(get_initial_window(),
msg = _("ERROR: No registered serializer available"); _("<b>No serializer available.</b>\nThere's no registered serializer. Please check the loaded plugins."),
true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
error.run();
msg = _("ERROR: No registered serializer available");
} }
catch (SerializerError e) catch (SerializerError e)
{ {
// FIXME: this should be an error dialog Gtk::MessageDialog error(get_initial_window(), e.what(), true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
error.run();
msg = _("ERROR: ") + Glib::ustring(e.what()); msg = _("ERROR: ") + Glib::ustring(e.what());
set_filename();
} }
if(!msg.empty()) if(!msg.empty())
{ {
@ -254,13 +260,17 @@ GuiBuilder::on_file_save_activate()
} }
catch (std::out_of_range e) catch (std::out_of_range e)
{ {
// FIXME: this should be an error dialog Gtk::MessageDialog error(get_initial_window(),
_("<b>No serializer available.</b>\nThere's no registered serializer. Please check the loaded plugins."),
true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
error.run();
msg = _("ERROR: No registered serializer available"); msg = _("ERROR: No registered serializer available");
} }
catch (SerializerError e) catch (SerializerError e)
{ {
// FIXME: this should be an error dialog Gtk::MessageDialog error(get_initial_window(), e.what(), true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
msg = _("ERROR: ") + Glib::ustring(e.what()); error.run();
msg = _("ERROR: ") + Glib::ustring(e.what());
} }
if(!msg.empty()) if(!msg.empty())
@ -309,12 +319,14 @@ GuiBuilder::on_file_saveas_activate()
int result = dialog.run(); int result = dialog.run();
if(result==Gtk::RESPONSE_OK) if(result==Gtk::RESPONSE_OK)
{ {
_filename = dialog.get_filename(); std::string filename = dialog.get_filename();
// Append standard extension if none (or a different one) is provided // Append standard extension if none (or a different one) is provided
std::string ext = std::string(".") + serializer.get_filename_extension(); std::string ext = std::string(".") + serializer.get_filename_extension();
if(_filename.size() < ext.size() || _filename.substr(_filename.size() - ext.size()) != ext) if(filename.size() < ext.size() || filename.substr(filename.size() - ext.size()) != ext)
_filename += ext; filename += ext;
set_filename(filename);
serializer.save_snapshot(_filename, history); serializer.save_snapshot(_filename, history);
@ -324,13 +336,18 @@ GuiBuilder::on_file_saveas_activate()
} }
catch (std::out_of_range e) catch (std::out_of_range e)
{ {
// FIXME: This should be an error dialog: Gtk::MessageDialog error(get_initial_window(),
_("<b>No serializer available.</b>\nThere's no registered serializer. Please check the loaded plugins."),
true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
error.run();
msg = _("ERROR: No registered serializer available"); msg = _("ERROR: No registered serializer available");
} }
catch (SerializerError e) catch (SerializerError e)
{ {
// FIXME: This should be an error dialog: Gtk::MessageDialog error(get_initial_window(), e.what(), true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
error.run();
msg = _("ERROR: ") + Glib::ustring(e.what()); msg = _("ERROR: ") + Glib::ustring(e.what());
set_filename();
} }
if(!msg.empty()) if(!msg.empty())
@ -543,6 +560,19 @@ GuiBuilder::ask_save()
} }
void
GuiBuilder::set_filename(const std::string& filename)
{
static const Glib::ustring default_title = get_initial_window().get_title();
Glib::ustring title;
_filename = filename;
if(!_filename.empty())
title = Glib::path_get_basename(_filename) + " - ";
title += default_title;
get_initial_window().set_title(title);
}
GuiBuilder::GuiBuilder(const std::string& gladefile) GuiBuilder::GuiBuilder(const std::string& gladefile)
: _refXml(Xml::create(gladefile)), _controller(Simulation::get_instance(), _refXml), : _refXml(Xml::create(gladefile)), _controller(Simulation::get_instance(), _refXml),
_holt_container(Simulation::get_instance()), _holt_container(Simulation::get_instance()),

View File

@ -87,6 +87,7 @@ namespace sgpem
SimulationWidget* _simulation_widget; SimulationWidget* _simulation_widget;
bool _show_threads; bool _show_threads;
void set_filename(const std::string& filename = "");
void ask_save(); void ask_save();
}; };