- Ask if you want to save also when closing main window, or

opening another file


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1213 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-09-16 22:27:34 +00:00
parent 927f912e07
commit 2935d9fcfd
3 changed files with 28 additions and 12 deletions

View File

@ -84,7 +84,6 @@ libpyloader_la_LIBADD = \
libpyloader_la_LDFLAGS = \ libpyloader_la_LDFLAGS = \
$(PYTHON_LDFLAGS) \ $(PYTHON_LDFLAGS) \
$(PYTHON_EXTRA_LDFLAGS) \ $(PYTHON_EXTRA_LDFLAGS) \
$(LT_LDFLAGS) \
-version-info 0:0:0 \ -version-info 0:0:0 \
-module -module

View File

@ -144,16 +144,8 @@ GuiBuilder::on_file_new_activate()
{ {
Simulation& sim = Simulation::get_instance(); Simulation& sim = Simulation::get_instance();
History& history = sim.get_history(); History& history = sim.get_history();
const Environment& env = history.get_environment_at(0);
if(!(_filename.empty() && env.get_processes().empty() && env.get_resources().empty())) ask_save();
{
Gtk::MessageDialog want_to_save(get_initial_window(),
_("<b>Want to save?</b>\nYou'll lose your changes if you don't."),
true, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_YES_NO, true);
if(want_to_save.run() == Gtk::RESPONSE_YES)
on_file_save_activate();
}
sim.stop(); sim.stop();
history.clear(); history.clear();
@ -165,6 +157,8 @@ GuiBuilder::on_file_new_activate()
void void
GuiBuilder::on_file_open_activate() GuiBuilder::on_file_open_activate()
{ {
ask_save();
Glib::ustring msg; Glib::ustring msg;
try try
{ {
@ -531,6 +525,24 @@ GuiBuilder::on_toggle_simulation_mode()
} }
void
GuiBuilder::ask_save()
{
History& history = Simulation::get_instance().get_history();
const Environment& env = history.get_environment_at(0);
if(!(_filename.empty() && env.get_processes().empty() && env.get_resources().empty()))
{
Gtk::MessageDialog want_to_save(get_initial_window(),
_("<b>Want to save?</b>\nYou'll lose your changes if you don't."),
true, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_YES_NO, true);
want_to_save.set_default_response(Gtk::RESPONSE_YES);
if(want_to_save.run() == Gtk::RESPONSE_YES)
on_file_save_activate();
}
}
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()),
@ -538,6 +550,9 @@ GuiBuilder::GuiBuilder(const std::string& gladefile)
{ {
using namespace Gtk; using namespace Gtk;
Window& main_window = get_initial_window();
main_window.signal_delete_event().connect(sigc::bind_return(sigc::hide(sigc::mem_fun(*this, &GuiBuilder::ask_save)), false));
// ---------------- Menu items ------------------ // ---------------- Menu items ------------------
// Note: the Play, Pause and Stop menu items are already managed by sgpem::SimulationController. // Note: the Play, Pause and Stop menu items are already managed by sgpem::SimulationController.
@ -564,6 +579,7 @@ GuiBuilder::GuiBuilder(const std::string& gladefile)
MenuItem* file_quit = NULL; MenuItem* file_quit = NULL;
_refXml->get_widget("MenuItem.File.Quit", file_quit); _refXml->get_widget("MenuItem.File.Quit", file_quit);
file_quit->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::ask_save));
file_quit->signal_activate().connect(sigc::ptr_fun(&Main::quit)); file_quit->signal_activate().connect(sigc::ptr_fun(&Main::quit));
// preferences dialog // preferences dialog
@ -670,7 +686,6 @@ GuiBuilder::GuiBuilder(const std::string& gladefile)
simulation_jump_to->signal_clicked().connect(sigc::mem_fun(*this, &GuiBuilder::on_simulation_jump_to_clicked)); simulation_jump_to->signal_clicked().connect(sigc::mem_fun(*this, &GuiBuilder::on_simulation_jump_to_clicked));
Window& main_window = get_initial_window();
// HoltGraph container window // HoltGraph container window
_holt_container.set_transient_for(main_window); _holt_container.set_transient_for(main_window);
_holt_container.get_holt_widget().set_show_threads(_show_threads); _holt_container.get_holt_widget().set_show_threads(_show_threads);

View File

@ -86,6 +86,8 @@ namespace sgpem
StatisticsContainerWindow _statistics_container; StatisticsContainerWindow _statistics_container;
SimulationWidget* _simulation_widget; SimulationWidget* _simulation_widget;
bool _show_threads; bool _show_threads;
void ask_save();
}; };
} //~ namespace sgpem } //~ namespace sgpem