[geary] Fix composers not dismissed when started hidden and main window closed.



commit 6a43bb3fb1edb5c4af96163ec5022238c1bab193
Author: Michael James Gratton <mike vee net>
Date:   Sat Dec 17 14:35:36 2016 +1100

    Fix composers not dismissed when started hidden and main window closed.
    
    Fixes Bug 770037.
    
    * src/client/application/geary-controller.vala
      (GearyController::close_composition_windows): Set from private to
      internal so MainWindow can call it, add an arg to determine if all
      composers should be closed, or only the one in the main window.
    
    * src/client/components/main-window.vala (MainWindow::on_delete_event):
      Close any main window composers before letting the window close.
    
    * src/client/composer/composer-widget.vala (ComposerWidget::state): Don't
      allow ny old code to set the composer's state.

 src/client/application/geary-controller.vala |   45 +++++++++++++++-----------
 src/client/components/main-window.vala       |   14 ++++---
 src/client/composer/composer-widget.vala     |    2 +-
 3 files changed, 35 insertions(+), 26 deletions(-)
---
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index 588f1e0..2d39231 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -2185,30 +2185,37 @@ public class GearyController : Geary.BaseObject {
         
         return ret;
     }
-    
-    private bool close_composition_windows() {
+
+    internal bool close_composition_windows(bool main_window_only = false) {
         Gee.List<ComposerWidget> composers_to_destroy = new Gee.ArrayList<ComposerWidget>();
         bool quit_cancelled = false;
-        
-        // If there's composer windows open, give the user a chance to save or cancel.
+
+        // If there's composer windows open, give the user a chance to
+        // save or cancel.
         foreach(ComposerWidget cw in composer_widgets) {
-            // Check if we should close the window immediately, or if we need to wait.
-            ComposerWidget.CloseStatus status = cw.should_close();
-            if (status == ComposerWidget.CloseStatus.PENDING_CLOSE) {
-                // Window is currently busy saving.
-                waiting_to_close.add(cw);
-            } else if (status == ComposerWidget.CloseStatus.CANCEL_CLOSE) {
-                // User cancelled operation.
-                quit_cancelled = true;
-                break;
-            } else if (status == ComposerWidget.CloseStatus.DO_CLOSE) {
-                // Hide any existing composer windows for the moment; actually deleting the windows
-                // will result in their removal from composer_windows, which could crash this loop.
-                composers_to_destroy.add(cw);
-                ((ComposerContainer) cw.parent).vanish();
+            if (!main_window_only ||
+                cw.state != ComposerWidget.ComposerState.DETACHED) {
+                // Check if we should close the window immediately, or
+                // if we need to wait.
+                ComposerWidget.CloseStatus status = cw.should_close();
+                if (status == ComposerWidget.CloseStatus.PENDING_CLOSE) {
+                    // Window is currently busy saving.
+                    waiting_to_close.add(cw);
+                } else if (status == ComposerWidget.CloseStatus.CANCEL_CLOSE) {
+                    // User cancelled operation.
+                    quit_cancelled = true;
+                    break;
+                } else if (status == ComposerWidget.CloseStatus.DO_CLOSE) {
+                    // Hide any existing composer windows for the
+                    // moment; actually deleting the windows will
+                    // result in their removal from composer_windows,
+                    // which could crash this loop.
+                    composers_to_destroy.add(cw);
+                    ((ComposerContainer) cw.parent).vanish();
+                }
             }
         }
-        
+
         // Safely destroy windows.
         foreach(ComposerWidget cw in composers_to_destroy)
             ((ComposerContainer) cw.parent).close_container();
diff --git a/src/client/components/main-window.vala b/src/client/components/main-window.vala
index 9cf92b7..8e22550 100644
--- a/src/client/components/main-window.vala
+++ b/src/client/components/main-window.vala
@@ -375,11 +375,13 @@ public class MainWindow : Gtk.ApplicationWindow {
 
     [GtkCallback]
     private bool on_delete_event() {
-        if (this.application.is_background_service)
-            return hide_on_delete();
-
-        this.application.exit();
-
-        return true;
+        if (this.application.is_background_service) {
+            if (this.application.controller.close_composition_windows(true)) {
+                hide();
+            }
+        } else {
+            this.application.exit();
+        }
+        return Gdk.EVENT_STOP;
     }
 }
diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala
index 0388c1c..3efab3d 100644
--- a/src/client/composer/composer-widget.vala
+++ b/src/client/composer/composer-widget.vala
@@ -249,7 +249,7 @@ public class ComposerWidget : Gtk.EventBox {
         }
     }
 
-    public ComposerState state { get; set; }
+    public ComposerState state { get; internal set; }
 
     public ComposeType compose_type { get; private set; default = ComposeType.NEW_MESSAGE; }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]