From ce86e3aa50786c82eae11d5fea58fc4139151a2e Mon Sep 17 00:00:00 2001 From: Michael Gratton Date: Wed, 30 Oct 2019 14:26:05 +1100 Subject: [PATCH] Move policy decision for folders supporting trash to controller This allows classes other than the main window to make the determination for other folders. --- .../application/application-controller.vala | 11 +++++++++ src/client/components/main-window.vala | 23 +++++++++---------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/client/application/application-controller.vala b/src/client/application/application-controller.vala index bcfda6a8..3b24f65d 100644 --- a/src/client/application/application-controller.vala +++ b/src/client/application/application-controller.vala @@ -21,6 +21,17 @@ public class Application.Controller : Geary.BaseObject { private const uint MAX_AUTH_ATTEMPTS = 3; + /** Determines if conversations can be trashed from the given folder. */ + public static bool does_folder_support_trash(Geary.Folder? target) { + return ( + target != null && + target.special_folder_type != TRASH && + !target.properties.is_local_only && + (target as Geary.FolderSupport.Move) != null + ); + } + + /** * Collects objects and state related to a single open account. */ diff --git a/src/client/components/main-window.vala b/src/client/components/main-window.vala index 4ca33df0..bdf43fbf 100644 --- a/src/client/components/main-window.vala +++ b/src/client/components/main-window.vala @@ -174,6 +174,15 @@ public class MainWindow : Gtk.ApplicationWindow, Geary.BaseInterface { /** The attachment manager for this window. */ public Application.AttachmentManager attachments { get; private set; } + /** Determines if conversations in the selected folder can be trashed. */ + public bool selected_folder_supports_trash { + get { + return Application.Controller.does_folder_support_trash( + this.selected_folder + ); + } + } + /** Determines if a composer is currently open in this window. */ public bool has_composer { get { @@ -692,7 +701,7 @@ public class MainWindow : Gtk.ApplicationWindow, Geary.BaseInterface { update_conversation_actions(NONE); this.conversation_viewer.show_loading(); this.main_toolbar.update_trash_button( - !this.is_shift_down && selected_folder_supports_trash() + !this.is_shift_down && this.selected_folder_supports_trash ); if (folder != null) { @@ -1178,7 +1187,7 @@ public class MainWindow : Gtk.ApplicationWindow, Geary.BaseInterface { sensitive && (selected_folder is Geary.FolderSupport.Archive) ); get_action(ACTION_TRASH_CONVERSATION).set_enabled( - sensitive && selected_folder_supports_trash() + sensitive && this.selected_folder_supports_trash ); get_action(ACTION_DELETE_CONVERSATION).set_enabled( sensitive && (selected_folder is Geary.FolderSupport.Remove) @@ -1260,16 +1269,6 @@ public class MainWindow : Gtk.ApplicationWindow, Geary.BaseInterface { return (SimpleAction) lookup_action(name); } - private bool selected_folder_supports_trash() { - Geary.Folder? current = this.selected_folder; - return ( - current != null && - current.special_folder_type != TRASH && - !selected_folder.properties.is_local_only && - (selected_folder as Geary.FolderSupport.Move) != null - ); - } - private void on_scan_completed(Geary.App.ConversationMonitor monitor) { // Done scanning. Check if we have enough messages to fill // the conversation list; if not, trigger a load_more();