[geary/wip/trash-714212: 2/4] Clean up toolbar handling



commit 3ef76ed00df2e19163d352a13000b4b17aaba2d4
Author: Charles Lindsay <chaz yorba org>
Date:   Wed Dec 18 15:49:32 2013 -0800

    Clean up toolbar handling

 src/client/application/geary-controller.vala |   53 +++++++++++++++++++------
 src/client/components/main-toolbar.vala      |   24 ++++++++++--
 2 files changed, 60 insertions(+), 17 deletions(-)
---
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index 9a28f7e..2570bbd 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -405,6 +405,8 @@ public class GearyController : Geary.BaseObject {
             ACTION_REPLY_TO_MESSAGE,
             ACTION_REPLY_ALL_MESSAGE,
             ACTION_FORWARD_MESSAGE,
+            ACTION_ARCHIVE_MESSAGE,
+            ACTION_TRASH_MESSAGE,
             ACTION_DELETE_MESSAGE,
         };
         const string[] exported_actions = {
@@ -1862,6 +1864,23 @@ public class GearyController : Geary.BaseObject {
             on_archive_or_delete_selection_finished);
     }
     
+    private Geary.FolderSupport.Move? current_folder_supports_trash(out Geary.FolderPath? trash_path) {
+        try {
+            // TODO: current_folder is not a trash folder or a local-only folder
+            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) {
+                trash_path = trash_folder.path;
+                return supports_move;
+            }
+        } catch (Error e) {
+            debug("Error finding trash folder: %s", e.message);
+        }
+        
+        trash_path = null;
+        return null;
+    }
+    
     private async void archive_or_delete_selection_async(bool archive, bool trash,
         Cancellable? cancellable) throws Error {
         if (main_window.conversation_viewer.current_conversation != null
@@ -1891,13 +1910,14 @@ public class GearyController : Geary.BaseObject {
         if (trash) {
             debug("Trashing selected messages");
             
-            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)
+            Geary.FolderPath? trash_path;
+            Geary.FolderSupport.Move? supports_move = current_folder_supports_trash(out trash_path);
+            // TODO: prompt instead for deleting outright when not supported.
+            if (supports_move != null)
                 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
-                yield supports_move.move_email_async(ids, trash_folder.path, cancellable);
+                yield supports_move.move_email_async(ids, trash_path, cancellable);
             return;
         }
         
@@ -1958,8 +1978,12 @@ public class GearyController : Geary.BaseObject {
         // Mutliple message buttons.
         GearyApplication.instance.actions.get_action(ACTION_MOVE_MENU).sensitive =
             (current_folder is Geary.FolderSupport.Move);
+        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);
         GearyApplication.instance.actions.get_action(ACTION_DELETE_MESSAGE).sensitive =
-            (current_folder is Geary.FolderSupport.Remove) || (current_folder is 
Geary.FolderSupport.Archive);
+            (current_folder is Geary.FolderSupport.Remove);
         
         cancel_context_dependent_buttons();
         enable_context_dependent_buttons_async.begin(true, cancellable_context_dependent_buttons);
@@ -1979,8 +2003,12 @@ public class GearyController : Geary.BaseObject {
         GearyApplication.instance.actions.get_action(ACTION_FORWARD_MESSAGE).sensitive = respond_sensitive;
         GearyApplication.instance.actions.get_action(ACTION_MOVE_MENU).sensitive =
             sensitive && (current_folder is Geary.FolderSupport.Move);
+        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);
         GearyApplication.instance.actions.get_action(ACTION_DELETE_MESSAGE).sensitive = sensitive
-            && ((current_folder is Geary.FolderSupport.Remove) || (current_folder is 
Geary.FolderSupport.Archive));
+            && (current_folder is Geary.FolderSupport.Remove);
         
         cancel_context_dependent_buttons();
         enable_context_dependent_buttons_async.begin(sensitive, cancellable_context_dependent_buttons);
@@ -2026,13 +2054,12 @@ public class GearyController : Geary.BaseObject {
         GearyApplication.instance.actions.get_action(ACTION_MOVE_MENU).tooltip = single ?
             MOVE_MESSAGE_TOOLTIP_SINGLE : MOVE_MESSAGE_TOOLTIP_MULTIPLE;
         
-        if (current_folder is Geary.FolderSupport.Archive) {
-            GearyApplication.instance.actions.get_action(ACTION_DELETE_MESSAGE).tooltip = single ?
-                ARCHIVE_MESSAGE_TOOLTIP_SINGLE : ARCHIVE_MESSAGE_TOOLTIP_MULTIPLE;
-        } else {
-            GearyApplication.instance.actions.get_action(ACTION_DELETE_MESSAGE).tooltip = single ?
-                DELETE_MESSAGE_TOOLTIP_SINGLE : DELETE_MESSAGE_TOOLTIP_MULTIPLE;
-        }
+        GearyApplication.instance.actions.get_action(ACTION_ARCHIVE_MESSAGE).tooltip = single ?
+            ARCHIVE_MESSAGE_TOOLTIP_SINGLE : ARCHIVE_MESSAGE_TOOLTIP_MULTIPLE;
+        GearyApplication.instance.actions.get_action(ACTION_TRASH_MESSAGE).tooltip = single ?
+            TRASH_MESSAGE_TOOLTIP_SINGLE : TRASH_MESSAGE_TOOLTIP_MULTIPLE;
+        GearyApplication.instance.actions.get_action(ACTION_DELETE_MESSAGE).tooltip = single ?
+            DELETE_MESSAGE_TOOLTIP_SINGLE : DELETE_MESSAGE_TOOLTIP_MULTIPLE;
     }
     
     public void compose_mailto(string mailto) {
diff --git a/src/client/components/main-toolbar.vala b/src/client/components/main-toolbar.vala
index 0a8feee..8ad6910 100644
--- a/src/client/components/main-toolbar.vala
+++ b/src/client/components/main-toolbar.vala
@@ -14,6 +14,8 @@ public class MainToolbar : PillToolbar {
     public FolderMenu move_folder_menu { get; private set; default = new FolderMenu(); }
     public string search_text { get { return search_entry.text; } }
     
+    private Gtk.Button archive_button;
+    private Gtk.Button trash_button;
     private Gtk.ToolItem search_container = new Gtk.ToolItem();
     private Gtk.Entry search_entry = new Gtk.Entry();
     private Geary.ProgressMonitor? search_upgrade_progress_monitor = null;
@@ -61,11 +63,9 @@ public class MainToolbar : PillToolbar {
         insert.add(create_menu_button("folder-symbolic", move_folder_menu, 
GearyController.ACTION_MOVE_MENU));
         add(create_pill_buttons(insert));
         
-        // Archive/delete button.
-        // For this button, the controller sets the tooltip and icon depending on the context.
         insert.clear();
-        insert.add(create_toolbar_button("", GearyController.ACTION_ARCHIVE_MESSAGE, true));
-        insert.add(create_toolbar_button("", GearyController.ACTION_TRASH_MESSAGE, true));
+        insert.add(archive_button = create_toolbar_button("", GearyController.ACTION_ARCHIVE_MESSAGE, true));
+        insert.add(trash_button = create_toolbar_button("", GearyController.ACTION_TRASH_MESSAGE, true));
         add(create_pill_buttons(insert));
         
         // Spacer.
@@ -107,6 +107,22 @@ public class MainToolbar : PillToolbar {
         set_search_placeholder_text(DEFAULT_SEARCH_TEXT);
     }
     
+    public void show_archive_button(bool show) {
+        if (show)
+            archive_button.show();
+        else
+            archive_button.hide();
+    }
+    
+    public void replace_trash_with_delete(bool replace) {
+        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);
+    }
+    
     public void set_search_text(string text) {
         search_entry.text = text;
     }


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