From 76b33d42695010ae08bc68a388cd1f752ab27d11 Mon Sep 17 00:00:00 2001 From: tchernobog Date: Sun, 17 Sep 2006 13:03:07 +0000 Subject: [PATCH] - 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 --- src/gui_builder.cc | 56 +++++++++++++++++++++++++++++++++++----------- src/gui_builder.hh | 1 + 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/src/gui_builder.cc b/src/gui_builder.cc index d2c9d35..4fe2f57 100644 --- a/src/gui_builder.cc +++ b/src/gui_builder.cc @@ -73,6 +73,7 @@ using namespace sgpem; using Gnome::Glade::Xml; + void GuiBuilder::on_edit_preferences_activate() { @@ -149,7 +150,7 @@ GuiBuilder::on_file_new_activate() sim.stop(); history.clear(); - _filename = ""; + set_filename(); } @@ -201,7 +202,7 @@ GuiBuilder::on_file_open_activate() int result = dialog.run(); 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 History& history = sim.get_history(); serializer.restore_snapshot(_filename, history); @@ -211,13 +212,18 @@ GuiBuilder::on_file_open_activate() } catch (std::out_of_range e) { - // FIXME: this should be an error dialog - msg = _("ERROR: No registered serializer available"); + Gtk::MessageDialog error(get_initial_window(), + _("No serializer available.\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) { - // 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()); + set_filename(); } if(!msg.empty()) { @@ -254,13 +260,17 @@ GuiBuilder::on_file_save_activate() } catch (std::out_of_range e) { - // FIXME: this should be an error dialog + Gtk::MessageDialog error(get_initial_window(), + _("No serializer available.\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) { - // FIXME: this should be an error dialog - msg = _("ERROR: ") + Glib::ustring(e.what()); + Gtk::MessageDialog error(get_initial_window(), e.what(), true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); + error.run(); + msg = _("ERROR: ") + Glib::ustring(e.what()); } if(!msg.empty()) @@ -309,12 +319,14 @@ GuiBuilder::on_file_saveas_activate() int result = dialog.run(); 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 std::string ext = std::string(".") + serializer.get_filename_extension(); - if(_filename.size() < ext.size() || _filename.substr(_filename.size() - ext.size()) != ext) - _filename += ext; + if(filename.size() < ext.size() || filename.substr(filename.size() - ext.size()) != ext) + filename += ext; + + set_filename(filename); serializer.save_snapshot(_filename, history); @@ -324,13 +336,18 @@ GuiBuilder::on_file_saveas_activate() } catch (std::out_of_range e) { - // FIXME: This should be an error dialog: + Gtk::MessageDialog error(get_initial_window(), + _("No serializer available.\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) { - // 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()); + set_filename(); } 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) : _refXml(Xml::create(gladefile)), _controller(Simulation::get_instance(), _refXml), _holt_container(Simulation::get_instance()), diff --git a/src/gui_builder.hh b/src/gui_builder.hh index 6bfc282..d235515 100644 --- a/src/gui_builder.hh +++ b/src/gui_builder.hh @@ -87,6 +87,7 @@ namespace sgpem SimulationWidget* _simulation_widget; bool _show_threads; + void set_filename(const std::string& filename = ""); void ask_save(); };