[geary/wip/trash-714212: 4/4] Conditional archive button, clean up



commit 2dbbbdaa9ff49fd21caa3b2115af2d43e14a8c62
Author: Charles Lindsay <chaz yorba org>
Date:   Wed Dec 18 17:34:49 2013 -0800

    Conditional archive button, clean up

 src/client/application/geary-controller.vala       |   30 ++++++++-----------
 src/client/components/main-toolbar.vala            |    9 ++---
 src/engine/abstract/geary-abstract-account.vala    |    2 +
 src/engine/api/geary-account.vala                  |    8 +++++
 .../gmail/imap-engine-gmail-account.vala           |    4 ++
 .../imap-engine/imap-engine-generic-account.vala   |    4 ++
 6 files changed, 35 insertions(+), 22 deletions(-)
---
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index 6623031..9dda4cc 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -928,16 +928,9 @@ public class GearyController : Geary.BaseObject {
     // by other utility methods
     private void update_ui() {
         update_tooltips();
-        Gtk.Action delete_message = GearyApplication.instance.actions.get_action(ACTION_DELETE_MESSAGE);
-        if (current_folder is Geary.FolderSupport.Archive) {
-            delete_message.label = ARCHIVE_MESSAGE_LABEL;
-            delete_message.icon_name = ARCHIVE_MESSAGE_ICON_NAME;
-        } else {
-            // even if not Geary.FolderSupportsrRemove, use delete icons and label, although they
-            // may be insensitive the entire time
-            delete_message.label = DELETE_MESSAGE_LABEL;
-            delete_message.icon_name = DELETE_MESSAGE_ICON_NAME;
-        }
+        main_window.main_toolbar.show_archive_button(current_account.can_support_archive());
+        // TODO: also replace it with delete when shift is held down
+        main_window.main_toolbar.replace_trash_with_delete(!current_folder_supports_trash());
     }
     
     private void on_folder_selected(Geary.Folder? folder) {
@@ -1864,23 +1857,26 @@ public class GearyController : Geary.BaseObject {
             on_archive_or_delete_selection_finished);
     }
     
-    private Geary.FolderSupport.Move? current_folder_supports_trash(out Geary.FolderPath? trash_path) {
+    private bool current_folder_supports_trash(out Geary.FolderSupport.Move? move = null,
+        out Geary.FolderPath? trash_path = null) {
         try {
             if (current_folder != null && current_folder.special_folder_type != Geary.SpecialFolderType.TRASH
                 && current_account != null && !current_account.folder_is_local_only(current_folder.path)) {
                 Geary.FolderSupport.Move? supports_move = current_folder as Geary.FolderSupport.Move;
                 Geary.Folder? trash_folder = 
current_account.get_special_folder(Geary.SpecialFolderType.TRASH);
                 if (supports_move != null && trash_folder != null) {
+                    move = supports_move;
                     trash_path = trash_folder.path;
-                    return supports_move;
+                    return true;
                 }
             }
         } catch (Error e) {
             debug("Error finding trash folder: %s", e.message);
         }
         
+        move = null;
         trash_path = null;
-        return null;
+        return false;
     }
     
     private async void archive_or_delete_selection_async(bool archive, bool trash,
@@ -1913,9 +1909,9 @@ public class GearyController : Geary.BaseObject {
             debug("Trashing selected messages");
             
             Geary.FolderPath? trash_path;
-            Geary.FolderSupport.Move? supports_move = current_folder_supports_trash(out trash_path);
+            Geary.FolderSupport.Move? supports_move;
             // TODO: prompt instead for deleting outright when not supported.
-            if (supports_move != null)
+            if (current_folder_supports_trash(out supports_move, out trash_path))
                 debug("Folder %s doesn't support move or account %s doesn't have a trash folder",
                     current_folder.to_string(), current_account.to_string());
             else
@@ -1983,7 +1979,7 @@ public class GearyController : Geary.BaseObject {
         GearyApplication.instance.actions.get_action(ACTION_ARCHIVE_MESSAGE).sensitive =
             (current_folder is Geary.FolderSupport.Archive);
         GearyApplication.instance.actions.get_action(ACTION_TRASH_MESSAGE).sensitive =
-            (current_folder_supports_trash(null) != null);
+            current_folder_supports_trash();
         GearyApplication.instance.actions.get_action(ACTION_DELETE_MESSAGE).sensitive =
             (current_folder is Geary.FolderSupport.Remove);
         
@@ -2008,7 +2004,7 @@ public class GearyController : Geary.BaseObject {
         GearyApplication.instance.actions.get_action(ACTION_ARCHIVE_MESSAGE).sensitive = sensitive
             && (current_folder is Geary.FolderSupport.Archive);
         GearyApplication.instance.actions.get_action(ACTION_TRASH_MESSAGE).sensitive = sensitive
-            && (current_folder_supports_trash(null) != null);
+            && current_folder_supports_trash();
         GearyApplication.instance.actions.get_action(ACTION_DELETE_MESSAGE).sensitive = sensitive
             && (current_folder is Geary.FolderSupport.Remove);
         
diff --git a/src/client/components/main-toolbar.vala b/src/client/components/main-toolbar.vala
index 8ad6910..aef1474 100644
--- a/src/client/components/main-toolbar.vala
+++ b/src/client/components/main-toolbar.vala
@@ -64,8 +64,8 @@ public class MainToolbar : PillToolbar {
         add(create_pill_buttons(insert));
         
         insert.clear();
-        insert.add(archive_button = create_toolbar_button("", GearyController.ACTION_ARCHIVE_MESSAGE, true));
-        insert.add(trash_button = create_toolbar_button("", GearyController.ACTION_TRASH_MESSAGE, true));
+        insert.add(archive_button = create_toolbar_button(null, GearyController.ACTION_ARCHIVE_MESSAGE, 
true));
+        insert.add(trash_button = create_toolbar_button(null, GearyController.ACTION_TRASH_MESSAGE, true));
         add(create_pill_buttons(insert));
         
         // Spacer.
@@ -118,9 +118,8 @@ public class MainToolbar : PillToolbar {
         string action_name = (replace ? GearyController.ACTION_DELETE_MESSAGE : 
GearyController.ACTION_TRASH_MESSAGE);
         Gtk.Action action = GearyApplication.instance.get_action(action_name);
         trash_button.related_action = action;
-        // TODO: necessary?
-        //trash_button.tooltip_text = action.tooltip;
-        //trash_button.image = new Gtk.Image.from_icon_name(action.icon_name, Gtk.IconSize.MENU);
+        trash_button.tooltip_text = action.tooltip;
+        trash_button.image = new Gtk.Image.from_icon_name(action.icon_name, Gtk.IconSize.MENU);
     }
     
     public void set_search_text(string text) {
diff --git a/src/engine/abstract/geary-abstract-account.vala b/src/engine/abstract/geary-abstract-account.vala
index 11f7eaf..4d3dff1 100644
--- a/src/engine/abstract/geary-abstract-account.vala
+++ b/src/engine/abstract/geary-abstract-account.vala
@@ -81,6 +81,8 @@ public abstract class Geary.AbstractAccount : BaseObject, Geary.Account {
     
     public abstract bool is_open();
     
+    public abstract bool can_support_archive();
+    
     public abstract async void rebuild_async(Cancellable? cancellable = null) throws Error;
     
     public abstract Gee.Collection<Geary.Folder> list_matching_folders(
diff --git a/src/engine/api/geary-account.vala b/src/engine/api/geary-account.vala
index 06a1089..1c9232e 100644
--- a/src/engine/api/geary-account.vala
+++ b/src/engine/api/geary-account.vala
@@ -205,6 +205,14 @@ public interface Geary.Account : BaseObject {
     public abstract bool is_open();
     
     /**
+     * HACK: for now, only certain account types support folders with
+     * FolderSupport.Archive.  It's useful to know whether an account supports
+     * archive because the button is hidden for accounts that will never
+     * support it.
+     */
+    public abstract bool can_support_archive();
+    
+    /**
      * Rebuild the local data stores for this { link Account}.
      *
      * This should only be used if { link open_async} throws { link EngineError.CORRUPTION},
diff --git a/src/engine/imap-engine/gmail/imap-engine-gmail-account.vala 
b/src/engine/imap-engine/gmail/imap-engine-gmail-account.vala
index 93a7bce..5324507 100644
--- a/src/engine/imap-engine/gmail/imap-engine-gmail-account.vala
+++ b/src/engine/imap-engine/gmail/imap-engine-gmail-account.vala
@@ -71,6 +71,10 @@ private class Geary.ImapEngine.GmailAccount : Geary.ImapEngine.GenericAccount {
         }
     }
     
+    protected override bool can_support_archive() {
+        return true;
+    }
+    
     protected override GenericFolder new_folder(Geary.FolderPath path, Imap.Account remote_account,
         ImapDB.Account local_account, ImapDB.Folder local_folder) {
         // although Gmail supports XLIST, this will be called on startup if the XLIST properties
diff --git a/src/engine/imap-engine/imap-engine-generic-account.vala 
b/src/engine/imap-engine/imap-engine-generic-account.vala
index e67f96e..80a7838 100644
--- a/src/engine/imap-engine/imap-engine-generic-account.vala
+++ b/src/engine/imap-engine/imap-engine-generic-account.vala
@@ -169,6 +169,10 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.AbstractAccount {
         return open;
     }
     
+    public override bool can_support_archive() {
+        return false;
+    }
+    
     public override async void rebuild_async(Cancellable? cancellable = null) throws Error {
         if (open)
             throw new EngineError.ALREADY_OPEN("Account cannot be open during rebuild");


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