[geary] Don't allow copy/move message to save folder: Bug #731879



commit 2a35b7750c10903e8e33951d715d83d5cc285c59
Author: Jim Nelson <jim yorba org>
Date:   Wed Jun 18 13:12:59 2014 -0700

    Don't allow copy/move message to save folder: Bug #731879
    
    The Folder implementation returns with no error if attempted and the
    folder menu item is disabled in the drop-down copy/move menus.

 src/client/application/geary-controller.vala       |   13 +++++++++++++
 src/client/components/folder-menu.vala             |    8 +++++++-
 src/engine/api/geary-folder-supports-copy.vala     |    3 +++
 src/engine/api/geary-folder-supports-move.vala     |    3 +++
 .../imap-engine/imap-engine-minimal-folder.vala    |    8 ++++++++
 5 files changed, 34 insertions(+), 1 deletions(-)
---
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index 944f89d..aa9c01c 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -1028,7 +1028,14 @@ public class GearyController : Geary.BaseObject {
             yield current_folder.close_async();
         }
         
+        // re-enable copy/move to the last selected folder
+        if (current_folder != null) {
+            main_window.main_toolbar.copy_folder_menu.enable_disable_folder(current_folder, true);
+            main_window.main_toolbar.move_folder_menu.enable_disable_folder(current_folder, true);
+        }
+        
         current_folder = folder;
+        
         if (current_account != folder.account) {
             current_account = folder.account;
             account_selected(current_account);
@@ -1057,6 +1064,12 @@ public class GearyController : Geary.BaseObject {
             main_window.main_toolbar.move_folder_menu.add_folder(f);
         }
         
+        // disable copy/move to the new folder
+        if (current_folder != null) {
+            main_window.main_toolbar.copy_folder_menu.enable_disable_folder(current_folder, false);
+            main_window.main_toolbar.move_folder_menu.enable_disable_folder(current_folder, false);
+        }
+        
         update_ui();
         
         current_conversations = new Geary.App.ConversationMonitor(current_folder, 
Geary.Folder.OpenFlags.NO_DELAY,
diff --git a/src/client/components/folder-menu.vala b/src/client/components/folder-menu.vala
index da1110c..c4b3d9f 100644
--- a/src/client/components/folder-menu.vala
+++ b/src/client/components/folder-menu.vala
@@ -35,7 +35,13 @@ public class FolderMenu : Gtk.Menu {
         
         show_all();
     }
-
+    
+    public void enable_disable_folder(Geary.Folder folder, bool sensitive) {
+        int index = folder_list.index_of(folder);
+        if (index >= 0)
+            get_children().nth_data(index).sensitive = sensitive;
+    }
+    
     public void remove_folder(Geary.Folder folder) {
         int index = folder_list.index_of(folder);
         folder_list.remove(folder);
diff --git a/src/engine/api/geary-folder-supports-copy.vala b/src/engine/api/geary-folder-supports-copy.vala
index 84b20a8..351a16a 100644
--- a/src/engine/api/geary-folder-supports-copy.vala
+++ b/src/engine/api/geary-folder-supports-copy.vala
@@ -16,6 +16,9 @@ public interface Geary.FolderSupport.Copy : Geary.Folder {
     /**
      * Copies messages into another folder.
      *
+     * If the destination is this { link Folder}, the operation will not make a copy of the message
+     * but will return success.
+     *
      * The Folder must be opened prior to attempting this operation.
      */
     public abstract async void copy_email_async(Gee.List<Geary.EmailIdentifier> to_copy,
diff --git a/src/engine/api/geary-folder-supports-move.vala b/src/engine/api/geary-folder-supports-move.vala
index b1bd821..58ededf 100644
--- a/src/engine/api/geary-folder-supports-move.vala
+++ b/src/engine/api/geary-folder-supports-move.vala
@@ -15,6 +15,9 @@ public interface Geary.FolderSupport.Move : Geary.Folder {
     /**
      * Moves messages to another folder.
      *
+     * If the destination is this { link Folder}, the operation will not move the message in any
+     * way but will return success.
+     *
      * The { link Geary.Folder} must be opened prior to attempting this operation.
      */
     public abstract async void move_email_async(Gee.List<Geary.EmailIdentifier> to_move,
diff --git a/src/engine/imap-engine/imap-engine-minimal-folder.vala 
b/src/engine/imap-engine/imap-engine-minimal-folder.vala
index 34e9088..30e1093 100644
--- a/src/engine/imap-engine/imap-engine-minimal-folder.vala
+++ b/src/engine/imap-engine/imap-engine-minimal-folder.vala
@@ -1296,6 +1296,10 @@ private class Geary.ImapEngine.MinimalFolder : Geary.AbstractFolder, Geary.Folde
         check_open("copy_email_async");
         check_ids("copy_email_async", to_copy);
         
+        // watch for copying to this folder, which is treated as a no-op
+        if (destination.equal_to(path))
+            return;
+        
         CopyEmail copy = new CopyEmail(this, (Gee.List<ImapDB.EmailIdentifier>) to_copy, destination);
         replay_queue.schedule(copy);
         yield copy.wait_for_ready_async(cancellable);
@@ -1306,6 +1310,10 @@ private class Geary.ImapEngine.MinimalFolder : Geary.AbstractFolder, Geary.Folde
         check_open("move_email_async");
         check_ids("move_email_async", to_move);
         
+        // watch for moving to this folder, which is treated as a no-op
+        if (destination.equal_to(path))
+            return;
+        
         MoveEmail move = new MoveEmail(this, (Gee.List<ImapDB.EmailIdentifier>) to_move, destination);
         replay_queue.schedule(move);
         yield move.wait_for_ready_async(cancellable);


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