13
0

handle main window delete events sensibly

This commit is contained in:
Paul Davis 2015-07-27 10:50:35 -04:00
parent 58757ebd38
commit 1be30e0401
3 changed files with 44 additions and 1 deletions

View File

@ -839,6 +839,8 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
bool key_press_focus_accelerator_handler (Gtk::Window& window, GdkEventKey* ev, Gtkmm2ext::Bindings*);
bool try_gtk_accel_binding (GtkWindow* win, GdkEventKey* ev, bool translate, GdkModifierType modifier);
bool main_window_delete_event (GdkEventAny*);
bool idle_ask_about_quit ();
};
#endif /* __ardour_gui_h__ */

View File

@ -184,9 +184,11 @@ ARDOUR_UI::setup_windows ()
build_menu_bar ();
setup_tooltips ();
_main_window.signal_delete_event().connect (sigc::mem_fun (*this, &ARDOUR_UI::main_window_delete_event));
/* pack the main vpacker into the main window and show everything
*/
_main_window.add (main_vpacker);
transport_frame.show_all ();
@ -905,3 +907,4 @@ ARDOUR_UI::update_title ()
}
}

View File

@ -155,3 +155,41 @@ ARDOUR_UI::tab_window_root_drop (GtkNotebook* src,
return 0; /* what was that? */
}
bool
ARDOUR_UI::idle_ask_about_quit ()
{
if (_session && _session->dirty()) {
finish ();
} else {
/* no session or session not dirty, but still ask anyway */
Gtk::MessageDialog msg (string_compose ("Quit %1?", PROGRAM_NAME),
false, /* no markup */
Gtk::MESSAGE_INFO,
Gtk::BUTTONS_YES_NO,
true); /* modal */
msg.set_default_response (Gtk::RESPONSE_YES);
if (msg.run() == Gtk::RESPONSE_YES) {
finish ();
}
}
/* not reached but keep the compiler happy */
return false;
}
bool
ARDOUR_UI::main_window_delete_event (GdkEventAny* ev)
{
/* quit the application as soon as we go idle. If we call this here,
* the window manager/desktop can think we're taking too longer to
* handle the "delete" event
*/
Glib::signal_idle().connect (sigc::mem_fun (*this, &ARDOUR_UI::idle_ask_about_quit));
return true;
}