- 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:
parent
b3999f2803
commit
76b33d4269
|
@ -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(),
|
||||
_("<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)
|
||||
{
|
||||
// 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(),
|
||||
_("<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)
|
||||
{
|
||||
// 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(),
|
||||
_("<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)
|
||||
{
|
||||
// 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()),
|
||||
|
|
|
@ -87,6 +87,7 @@ namespace sgpem
|
|||
SimulationWidget* _simulation_widget;
|
||||
bool _show_threads;
|
||||
|
||||
void set_filename(const std::string& filename = "");
|
||||
void ask_save();
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue