Improve single-threaded operation. It's now safe(r?) to close a canvas while it...
[synfig.git] / synfig-studio / trunk / src / gtkmm / canvasview.cpp
index 9f4860e..14419be 100644 (file)
@@ -3526,10 +3526,12 @@ static bool _close_instance(etl::handle<Instance> instance)
 }
 
 bool
-CanvasView::on_delete_event(GdkEventAny* event)
+CanvasView::close_instance_when_safe()
 {
+       if (get_work_area()->get_updating())
+               return true;
+
        if(get_instance()->get_visible_canvases()==1)
-       {
                // Schedule a close to occur in a few moments
                Glib::signal_timeout().connect(
                        sigc::bind(
@@ -3538,8 +3540,24 @@ CanvasView::on_delete_event(GdkEventAny* event)
                        )
                        ,250
                );
+
+       return false;
+}
+
+bool
+CanvasView::on_delete_event(GdkEventAny* event)
+{
+       if (get_work_area()->get_updating())
+       {
+               get_work_area()->stop_updating(true); // stop and mark as cancelled
+
+               // give the workarea chances to stop updating
+               Glib::signal_timeout().connect(sigc::mem_fun(*this, &CanvasView::close_instance_when_safe) ,250);
+               return true;
        }
 
+       close_instance_when_safe();
+
        //! \todo This causes the window to be deleted straight away - but what if we prompt 'save?' and the user cancels?
        //                Is there ever any need to pass on the delete event to the window here?
        // if(event) return Gtk::Window::on_delete_event(event);