[geary/wip/713739-inline: 14/37] Make composers close properly



commit e5d3be7e8caac19fdeabeb516c3ac77328bb2f38
Author: Robert Schroll <rschroll gmail com>
Date:   Tue May 13 22:33:09 2014 -0700

    Make composers close properly
    
    For some reason, overriding the destroy handler causes reference errors
    and multiple destructions.  So don't do that -- connect to the destroy
    signal instead.

 src/client/application/geary-controller.vala       |    3 +-
 src/client/composer/composer-container.vala        |    2 +
 src/client/composer/composer-embed.vala            |   21 +++++++----------
 src/client/composer/composer-widget.vala           |   23 +++++++++----------
 src/client/composer/composer-window.vala           |    4 +++
 .../conversation-list/conversation-list-view.vala  |    4 +-
 .../conversation-viewer/conversation-viewer.vala   |    3 --
 7 files changed, 30 insertions(+), 30 deletions(-)
---
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index 534fcc1..0d5eaa9 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -1850,6 +1850,7 @@ public class GearyController : Geary.BaseObject {
         
         main_window.present();
         AlertDialog dialog;
+        // TODO: Clean up when closing (like delete_and_exit) / offer save option.
         if (new_composer != null)
             dialog = new AlertDialog(main_window, Gtk.MessageType.QUESTION,
                 _("Do you want to discard the existing composition?"), null, Gtk.Stock.DISCARD,
@@ -1860,7 +1861,7 @@ public class GearyController : Geary.BaseObject {
                 Gtk.Stock.CANCEL, _("Move Composition to New Window"), Gtk.ResponseType.YES);
         Gtk.ResponseType response = dialog.run();
         if (response == Gtk.ResponseType.OK) {
-            close();
+            inline_composer.close();
             return true;
         }
         if (new_composer != null) {
diff --git a/src/client/composer/composer-container.vala b/src/client/composer/composer-container.vala
index a2c890b..5e9cd0b 100644
--- a/src/client/composer/composer-container.vala
+++ b/src/client/composer/composer-container.vala
@@ -9,4 +9,6 @@ public interface ComposerContainer {
     
     public abstract void present();
     public abstract unowned Gtk.Widget get_focus();
+    public abstract void vanish();
+    public abstract void close();
 }
diff --git a/src/client/composer/composer-embed.vala b/src/client/composer/composer-embed.vala
index 7888c83..ff1b9f4 100644
--- a/src/client/composer/composer-embed.vala
+++ b/src/client/composer/composer-embed.vala
@@ -15,9 +15,6 @@ public class ComposerEmbed : Gtk.Box, ComposerContainer {
     public Gtk.Window top_window {
         get { return (Gtk.Window) get_toplevel(); }
     }
-    public bool is_active {
-        get { return composer != null; }
-    }
     
     public ComposerEmbed(ComposerWidget composer, ConversationViewer conversation_viewer,
         Geary.Email? referred) {
@@ -89,7 +86,6 @@ public class ComposerEmbed : Gtk.Box, ComposerContainer {
         ComposerWindow focus_win = focus.get_toplevel() as ComposerWindow;
         if (focus_win != null && focus_win == window)
             focus.grab_focus();
-        composer = null;
         close();
     }
     
@@ -123,16 +119,11 @@ public class ComposerEmbed : Gtk.Box, ComposerContainer {
         return top_window.get_focus();
     }
     
-    private void close() {
+    public void vanish() {
         GearyApplication.instance.controller.inline_composer = null;
         hide();
-        if (composer != null) {
-            composer.editor.focus_in_event.disconnect(on_focus_in);
-            composer.editor.focus_out_event.disconnect(on_focus_out);
-            remove(composer);
-            composer.destroy();
-            composer = null;
-        }
+        composer.editor.focus_in_event.disconnect(on_focus_in);
+        composer.editor.focus_out_event.disconnect(on_focus_out);
         
         WebKit.DOM.Element embed = 
conversation_viewer.web_view.get_dom_document().get_element_by_id(embed_id);
         try{
@@ -152,5 +143,11 @@ public class ComposerEmbed : Gtk.Box, ComposerContainer {
             prev_selection = null;
         }
     }
+    
+    public void close() {
+        if (GearyApplication.instance.controller.inline_composer == this)
+            vanish();
+        conversation_viewer.compose_overlay.remove(this);
+    }
 }
 
diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala
index 7dbbb80..bce362f 100644
--- a/src/client/composer/composer-widget.vala
+++ b/src/client/composer/composer-widget.vala
@@ -463,6 +463,8 @@ public class ComposerWidget : Gtk.EventBox {
         // the drafts folder will be opened by on_from_changed().
         if (!from_multiple.visible)
             open_drafts_folder_async.begin(cancellable_drafts);
+        
+        destroy.connect(() => { close_drafts_folder_async.begin(); });
     }
     
     public ComposerWidget.from_mailto(Geary.Account account, string mailto) {
@@ -708,13 +710,9 @@ public class ComposerWidget : Gtk.EventBox {
         }
     }
     
-    public override bool delete_event(Gdk.EventAny event) {
-        return !(should_close() == CloseStatus.DO_CLOSE);
-    }
-    
     private void on_close() {
         if (should_close() == CloseStatus.DO_CLOSE)
-            destroy();
+            ((ComposerContainer) parent).close();
     }
     
     private bool email_contains_attachment_keywords() {
@@ -796,7 +794,7 @@ public class ComposerWidget : Gtk.EventBox {
     private async void on_send_async() {
         cancellable_save_draft.cancel();
         
-        hide();
+        ((ComposerEmbed) parent).vanish();
         
         linkify_document(editor.get_dom_document());
         
@@ -808,7 +806,7 @@ public class ComposerWidget : Gtk.EventBox {
         }
         
         yield delete_draft_async();
-        destroy(); // Only close window after draft is deleted; this closes the drafts folder.
+        ((ComposerContainer) parent).close(); // Only close window after draft is deleted; this closes the 
drafts folder.
     }
     
     private void on_drafts_opened(Geary.Folder.OpenState open_state, int count) {
@@ -880,6 +878,10 @@ public class ComposerWidget : Gtk.EventBox {
     
     // Prevents user from editing anything.  Used while waiting for draft to save before exiting window.
     private void make_gui_insensitive() {
+        ((ComposerContainer) parent).vanish();
+        
+        // TODO: Is the rest of this necessary now?
+        
         // Halt draft timer.
         if (draft_save_timeout_id != 0)
             Source.remove(draft_save_timeout_id);
@@ -904,7 +906,7 @@ public class ComposerWidget : Gtk.EventBox {
         // Do the save.
         yield save_async(null);
         
-        destroy();
+        ((ComposerContainer) parent).close();
     }
     
     private async void delete_and_exit() {
@@ -913,7 +915,7 @@ public class ComposerWidget : Gtk.EventBox {
         // Do the delete.
         yield delete_draft_async();
         
-        destroy();
+        ((ComposerContainer) parent).close();
     }
     
     private async void delete_draft_async() {
@@ -1741,8 +1743,5 @@ public class ComposerWidget : Gtk.EventBox {
         bcc_entry.completion = new ContactEntryCompletion(contact_list_store);
     }
     
-    public override void destroy() {
-        close_drafts_folder_async.begin();
-    }
 }
 
diff --git a/src/client/composer/composer-window.vala b/src/client/composer/composer-window.vala
index 6f9a8c0..d6de090 100644
--- a/src/client/composer/composer-window.vala
+++ b/src/client/composer/composer-window.vala
@@ -36,5 +36,9 @@ public class ComposerWindow : Gtk.Window, ComposerContainer {
     public override bool delete_event(Gdk.EventAny event) {
         return !(((ComposerWidget) get_child()).should_close() == ComposerWidget.CloseStatus.DO_CLOSE);
     }
+    
+    public void vanish() {
+        hide();
+    }
 }
 
diff --git a/src/client/conversation-list/conversation-list-view.vala 
b/src/client/conversation-list/conversation-list-view.vala
index 56085a2..8382637 100644
--- a/src/client/conversation-list/conversation-list-view.vala
+++ b/src/client/conversation-list/conversation-list-view.vala
@@ -387,8 +387,8 @@ public class ConversationListView : Gtk.TreeView {
     
     // Selects the first conversation, if nothing has been selected yet and we're not composing.
     public void select_first_conversation() {
-        if (get_selected_path() == null && !((MainWindow) GearyApplication.instance.
-            controller.main_window).conversation_viewer.composer_embed.is_active) {
+        if (get_selected_path() == null &&
+            GearyApplication.instance.controller.inline_composer == null) {
             set_cursor(new Gtk.TreePath.from_indices(0, -1), null, false);
         }
     }
diff --git a/src/client/conversation-viewer/conversation-viewer.vala 
b/src/client/conversation-viewer/conversation-viewer.vala
index 3e6077e..1954c6c 100644
--- a/src/client/conversation-viewer/conversation-viewer.vala
+++ b/src/client/conversation-viewer/conversation-viewer.vala
@@ -117,9 +117,6 @@ public class ConversationViewer : Gtk.Box {
     // The HTML viewer to view the emails.
     public ConversationWebView web_view { get; private set; }
     
-    // The container to hold the inline composer.
-    public ComposerEmbed composer_embed { get; private set; }
-    
     // Current conversation, or null if none.
     public Geary.App.Conversation? current_conversation = null;
     


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