[geary/wip/730682-refine-convo-list: 11/11] Re-enable drag and drop for conversation list.



commit e86079704cc6fbe0e844d17608b103c00ad35b1b
Author: Michael James Gratton <mike vee net>
Date:   Fri Jan 5 15:18:53 2018 +1100

    Re-enable drag and drop for conversation list.
    
    Also fixes Bug 743667.
    
    * src/client/conversation-list/conversation-list.vala (ConversationList):
      Call Gtk.drag_source_set to enable drag from the list.
    
    * src/client/folder-list/folder-list-folder-entry.vala
      (internal_drop_received): Simply activate the move or drag action
      directly, without going via the folder list and controller. Determine
      move or copy action from DragContext directly rather than via the
      Gdk.Device, which was causing a crash.
    
    * src/client/folder-list/folder-list-tree.vala (Tree): Remove
      now-redundant copy and move signals.
    
    * src/client/application/geary-controller.vala (GearyController): Remove
      use of folder list signals, and remove last vestiges of now-unused
      controller-based conversation moving/copying code.

 src/client/application/geary-controller.vala       |   62 +-------------------
 .../conversation-list/conversation-list.vala       |   10 +++-
 .../folder-list/folder-list-folder-entry.vala      |   22 ++++---
 src/client/folder-list/folder-list-tree.vala       |    8 +--
 4 files changed, 25 insertions(+), 77 deletions(-)
---
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index 026cafb..e1782fa 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -186,11 +186,9 @@ public class GearyController : Geary.BaseObject {
         Geary.Engine.instance.account_available.connect(on_account_available);
         Geary.Engine.instance.account_unavailable.connect(on_account_unavailable);
         Geary.Engine.instance.untrusted_host.connect(on_untrusted_host);
-        
+
         // Connect to various UI signals.
         main_window.folder_list.folder_selected.connect(on_folder_selected);
-        main_window.folder_list.copy_conversation.connect(on_copy_conversation);
-        main_window.folder_list.move_conversation.connect(on_move_conversation);
         main_window.search_bar.search_text_changed.connect((text) => { do_search(text); });
         main_window.conversation_viewer.conversation_added.connect(
             on_conversation_view_added
@@ -256,8 +254,6 @@ public class GearyController : Geary.BaseObject {
 
         // Disconnect from various UI signals.
         main_window.folder_list.folder_selected.disconnect(on_folder_selected);
-        main_window.folder_list.copy_conversation.disconnect(on_copy_conversation);
-        main_window.folder_list.move_conversation.disconnect(on_move_conversation);
         main_window.conversation_viewer.conversation_added.disconnect(
             on_conversation_view_added
         );
@@ -1583,26 +1579,6 @@ public class GearyController : Geary.BaseObject {
         clear_new_messages("on_has_toplevel_focus", null);
     }
 
-    // latest_sent_only uses Email's Date: field, which corresponds to how they're sorted in the
-    // ConversationViewer
-    private Gee.ArrayList<Geary.EmailIdentifier> get_selected_email_ids(bool latest_sent_only) {
-        Geary.App.Conversation? conversation =
-            this.main_window.conversation_list.selected;
-        Gee.ArrayList<Geary.EmailIdentifier> ids =
-            new Gee.ArrayList<Geary.EmailIdentifier>();
-        if (conversation != null) {
-            if (latest_sent_only) {
-                Geary.Email? latest = conversation.get_latest_sent_email(
-                    Geary.App.Conversation.Location.IN_FOLDER_OUT_OF_FOLDER);
-                if (latest != null)
-                    ids.add(latest.id);
-            } else {
-                ids.add_all(conversation.get_email_ids());
-            }
-        }
-        return ids;
-    }
-
     private bool should_notify_new_messages(Geary.Folder folder) {
         // A monitored folder must be selected to squelch notifications;
         // if conversation list is at top of display, don't display
@@ -1637,42 +1613,6 @@ public class GearyController : Geary.BaseObject {
         mark_email.begin(emails, flags_to_add, flags_to_remove);
     }
 
-    private void copy_email(Gee.Collection<Geary.EmailIdentifier> ids,
-        Geary.FolderPath destination) {
-        if (ids.size > 0) {
-            email_stores.get(current_folder.account).copy_email_async.begin(
-                ids, destination, cancellable_folder);
-        }
-    }
-    
-    private void on_copy_conversation(Geary.Folder destination) {
-        copy_email(get_selected_email_ids(false), destination.path);
-    }
-    
-    private void on_move_conversation(Geary.Folder destination) {
-        // Nothing to do if nothing selected.
-        Gee.List<Geary.EmailIdentifier> ids = get_selected_email_ids(false);
-        if (ids.size == 0)
-            return;
-
-        Geary.FolderSupport.Move? supports_move = current_folder as Geary.FolderSupport.Move;
-        if (supports_move != null)
-            move_conversation_async.begin(
-                supports_move, ids, destination.path, cancellable_folder
-            );
-    }
-
-    private async void move_conversation_async(Geary.FolderSupport.Move source_folder,
-        Gee.List<Geary.EmailIdentifier> ids, Geary.FolderPath destination, Cancellable? cancellable) {
-        try {
-            save_revokable(yield source_folder.move_email_async(ids, destination, cancellable),
-                _("Undo move (Ctrl+Z)"));
-        } catch (Error err) {
-            debug("%s: Unable to move %d emails: %s", source_folder.to_string(), ids.size,
-                err.message);
-        }
-    }
-
     private void on_attachments_activated(Gee.Collection<Geary.Attachment> attachments) {
         if (this.application.config.ask_open_attachment) {
             QuestionDialog ask_to_open = new QuestionDialog.with_checkbox(main_window,
diff --git a/src/client/conversation-list/conversation-list.vala 
b/src/client/conversation-list/conversation-list.vala
index d9178ab..27ee235 100644
--- a/src/client/conversation-list/conversation-list.vala
+++ b/src/client/conversation-list/conversation-list.vala
@@ -1,6 +1,6 @@
 /*
  * Copyright 2016 Software Freedom Conservancy Inc.
- * Copyright 2017 Michael Gratton <mike vee net>
+ * Copyright 2017-2018 Michael Gratton <mike vee net>
  *
  * This software is licensed under the GNU Lesser General Public License
  * (version 2.1 or later).  See the COPYING file in this distribution.
@@ -115,6 +115,14 @@ public class ConversationList : Gtk.ListBox {
             });
         this.show.connect(on_show);
 
+        Gtk.drag_source_set(
+            this,
+            Gdk.ModifierType.BUTTON1_MASK,
+            FolderList.Tree.TARGET_ENTRY_LIST,
+            Gdk.DragAction.COPY | Gdk.DragAction.MOVE
+        );
+        Gtk.drag_source_set_icon_name(this, "mail-unread-symbolic");
+
         Gtk.Builder builder = new Gtk.Builder.from_resource(
             "/org/gnome/Geary/conversation-list-menus.ui"
         );
diff --git a/src/client/folder-list/folder-list-folder-entry.vala 
b/src/client/folder-list/folder-list-folder-entry.vala
index 5a5396f..c64cd60 100644
--- a/src/client/folder-list/folder-list-folder-entry.vala
+++ b/src/client/folder-list/folder-list-folder-entry.vala
@@ -98,22 +98,24 @@ public class FolderList.FolderEntry : FolderList.AbstractFolderEntry, Sidebar.In
         this.has_new = has_new;
         is_emphasized_changed(has_new);
     }
-    
+
     public bool internal_drop_received(Gdk.DragContext context, Gtk.SelectionData data) {
-        // Copy or move?
-        Gdk.ModifierType mask;
-        double[] axes = new double[2];
-        context.get_device().get_state(context.get_dest_window(), axes, out mask);
         MainWindow main_window = GearyApplication.instance.controller.main_window;
-        if ((mask & Gdk.ModifierType.CONTROL_MASK) != 0) {
-            main_window.folder_list.copy_conversation(folder);
+        debug("drop on: %s", this.folder.to_string());
+        if (context.get_selected_action() == Gdk.DragAction.MOVE) {
+            main_window.activate_action(
+                MainWindow.ACTION_HIGHLIGHTED_MOVE,
+                this.folder.path.to_variant()
+            );
         } else {
-            main_window.folder_list.move_conversation(folder);
+            main_window.activate_action(
+                MainWindow.ACTION_HIGHLIGHTED_COPY,
+                this.folder.path.to_variant()
+            );
         }
-
         return true;
     }
-    
+
     private void on_counts_changed() {
         sidebar_count_changed(get_count());
         sidebar_tooltip_changed(get_sidebar_tooltip());
diff --git a/src/client/folder-list/folder-list-tree.vala b/src/client/folder-list/folder-list-tree.vala
index d4a3ebe..51c4016 100644
--- a/src/client/folder-list/folder-list-tree.vala
+++ b/src/client/folder-list/folder-list-tree.vala
@@ -11,11 +11,9 @@ public class FolderList.Tree : Sidebar.Tree {
     
     private const int INBOX_ORDINAL = -2; // First account branch is zero
     private const int SEARCH_ORDINAL = -1;
-    
+
     public signal void folder_selected(Geary.Folder? folder);
-    public signal void copy_conversation(Geary.Folder folder);
-    public signal void move_conversation(Geary.Folder folder);
-    
+
     private Gee.HashMap<Geary.Account, AccountBranch> account_branches
         = new Gee.HashMap<Geary.Account, AccountBranch>();
     private InboxesBranch inboxes_branch = new InboxesBranch();
@@ -210,7 +208,7 @@ public class FolderList.Tree : Sidebar.Tree {
         }
         return ret;
     }
-    
+
     private void on_ordinal_changed() {
         if (account_branches.size <= 1)
             return;


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