[geary/wip/uidplus-drafts-726665: 3/3] Properly handle delayed opens



commit 6e13b2e834246263184f5a849ecffb8bd87afd75
Author: Charles Lindsay <chaz yorba org>
Date:   Wed Mar 19 17:15:57 2014 -0700

    Properly handle delayed opens

 src/client/composer/composer-window.vala |   19 ++++++++++++-------
 1 files changed, 12 insertions(+), 7 deletions(-)
---
diff --git a/src/client/composer/composer-window.vala b/src/client/composer/composer-window.vala
index 222d0a9..8092f6f 100644
--- a/src/client/composer/composer-window.vala
+++ b/src/client/composer/composer-window.vala
@@ -668,11 +668,8 @@ public class ComposerWindow : Gtk.Window {
     }
     
     private bool can_save() {
-        if (!editor.can_undo())
-            return false;
-        if (drafts_folder != null && drafts_folder.properties.create_never_returns_id)
-            return false;
-        return true;
+        return (drafts_folder != null && drafts_folder.get_open_state() == Geary.Folder.OpenState.BOTH
+            && !drafts_folder.properties.create_never_returns_id && editor.can_undo());
     }
 
     public bool should_close() {
@@ -806,6 +803,11 @@ public class ComposerWindow : Gtk.Window {
         destroy(); // Only close window after draft is deleted; this closes the drafts folder.
     }
     
+    private void on_drafts_opened(Geary.Folder.OpenState open_state, int count) {
+        if (open_state == Geary.Folder.OpenState.BOTH)
+            reset_draft_timer();
+    }
+    
     // Returns the drafts folder for the current From account.
     private async void open_drafts_folder_async(Cancellable cancellable) throws Error {
         yield close_drafts_folder_async(cancellable);
@@ -816,9 +818,11 @@ public class ComposerWindow : Gtk.Window {
         if (folder == null)
             return; // No drafts folder.
         
-        yield folder.open_async(Geary.Folder.OpenFlags.FAST_OPEN, cancellable);
+        yield folder.open_async(Geary.Folder.OpenFlags.FAST_OPEN | Geary.Folder.OpenFlags.NO_DELAY,
+            cancellable);
         
         drafts_folder = folder;
+        drafts_folder.opened.connect(on_drafts_opened);
     }
     
     private async void close_drafts_folder_async(Cancellable? cancellable = null) throws Error {
@@ -826,6 +830,7 @@ public class ComposerWindow : Gtk.Window {
             return;
         
         // Close existing folder.
+        drafts_folder.opened.disconnect(on_drafts_opened);
         yield drafts_folder.close_async(cancellable);
         drafts_folder = null;
     }
@@ -843,7 +848,7 @@ public class ComposerWindow : Gtk.Window {
     }
     
     private async void save_async(Cancellable? cancellable) {
-        if (drafts_folder == null)
+        if (drafts_folder == null || !can_save())
             return;
         
         draft_save_label.label = DRAFT_SAVING_TEXT;


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