[gnome-builder] project-tree: implement copy and move



commit 1322130d6f34cd61b2719d6d78cda12b2b2cde6b
Author: Christian Hergert <chergert redhat com>
Date:   Tue Dec 5 17:51:29 2017 -0800

    project-tree: implement copy and move
    
    This allows dragging contents within the tree as well as from
    external programs that support text/uri-list (such as Nautilus).
    
    We rely on the change monitors to rebuild nodes instead of
    manually removing nodes from the tree when doing moves. It has
    the chance of breaking if the user has run out of inotify
    watches, but that's not something I really want to deal with
    protecting against here (instead we should get the sysctl bumped
    or something to that nature).

 src/plugins/project-tree/gb-project-tree-builder.c |   58 +++++++++++++-------
 1 files changed, 37 insertions(+), 21 deletions(-)
---
diff --git a/src/plugins/project-tree/gb-project-tree-builder.c 
b/src/plugins/project-tree/gb-project-tree-builder.c
index 4546e0b..308efa6 100644
--- a/src/plugins/project-tree/gb-project-tree-builder.c
+++ b/src/plugins/project-tree/gb-project-tree-builder.c
@@ -744,12 +744,36 @@ gb_project_tree_builder_drag_data_received (DzlTreeBuilder      *builder,
 
           if (uris != NULL && uris[0] != NULL)
             {
+              g_autoptr(DzlFileTransfer) transfer = dzl_file_transfer_new ();
               g_autofree gchar *joined = g_strjoinv (" ", uris);
               g_autofree gchar *dst_uri = g_file_get_uri (file);
 
-              g_debug ("Drop %s onto %s with position %d",
+              if (action == GDK_ACTION_MOVE)
+                dzl_file_transfer_set_flags (transfer, DZL_FILE_TRANSFER_FLAGS_MOVE);
+
+              g_debug ("%s uris %s onto %s with position %d",
+                       action == GDK_ACTION_MOVE ? "Move" : "Copy",
                        joined, dst_uri, position);
 
+              for (guint i = 0; uris[i] != NULL; i++)
+                {
+                  g_autoptr(GFile) drag_file = g_file_new_for_uri (uris[i]);
+                  g_autoptr(GFile) dst_file = NULL;
+                  g_autofree gchar *name = NULL;
+
+                  if (drag_file == NULL)
+                    continue;
+
+                  if (NULL == (name = g_file_get_basename (drag_file)))
+                    continue;
+
+                  dst_file = g_file_get_child (file, name);
+
+                  dzl_file_transfer_add (transfer, drag_file, dst_file);
+                }
+
+              dzl_file_transfer_execute_async (transfer, G_PRIORITY_DEFAULT, NULL, NULL, NULL);
+
               return TRUE;
             }
         }
@@ -805,8 +829,19 @@ gb_project_tree_builder_drag_node_received (DzlTreeBuilder      *builder,
         {
           g_autofree gchar *src_uri = g_file_get_uri (drag_file);
           g_autofree gchar *dst_uri = g_file_get_uri (drop_file);
+          g_autofree gchar *name = g_file_get_basename (drag_file);
+          g_autoptr(GFile) dst_file = g_file_get_child (drop_file, name);
+          g_autoptr(DzlFileTransfer) transfer = dzl_file_transfer_new ();
+
+          g_debug ("Need to %s %s into %s",
+                   (action & GDK_ACTION_MOVE) ? "move" : "copy",
+                   src_uri, dst_uri);
+
+          dzl_file_transfer_add (transfer, drag_file, dst_file);
+          if (action == GDK_ACTION_MOVE)
+            dzl_file_transfer_set_flags (transfer, DZL_FILE_TRANSFER_FLAGS_MOVE);
 
-          g_debug ("Need to copy %s into %s", src_uri, dst_uri);
+          dzl_file_transfer_execute_async (transfer, G_PRIORITY_DEFAULT, NULL, NULL, NULL);
 
           return TRUE;
         }
@@ -815,24 +850,6 @@ gb_project_tree_builder_drag_node_received (DzlTreeBuilder      *builder,
   return FALSE;
 }
 
-static gboolean
-gb_project_tree_builder_drag_node_delete (DzlTreeBuilder *builder,
-                                          DzlTreeNode    *node)
-{
-  GbProjectTreeBuilder *self = (GbProjectTreeBuilder *)builder;
-
-  g_assert (GB_IS_PROJECT_TREE_BUILDER (self));
-  g_assert (DZL_IS_TREE_NODE (node));
-
-  /*
-   * We must have done a GTK_ACTION_MOVE, which means that we need to
-   * cleanup whatever it is that we moved. In our case, that means
-   * removing the files.
-   */
-
-  return FALSE;
-}
-
 static void
 gb_project_tree_builder_dispose (GObject *object)
 {
@@ -856,7 +873,6 @@ gb_project_tree_builder_class_init (GbProjectTreeBuilderClass *klass)
   tree_builder_class->drag_data_get = gb_project_tree_builder_drag_data_get;
   tree_builder_class->drag_data_received = gb_project_tree_builder_drag_data_received;
   tree_builder_class->drag_node_received = gb_project_tree_builder_drag_node_received;
-  tree_builder_class->drag_node_delete = gb_project_tree_builder_drag_node_delete;
   tree_builder_class->node_activated = gb_project_tree_builder_node_activated;
   tree_builder_class->node_collapsed = gb_project_tree_builder_node_collapsed;
   tree_builder_class->node_expanded = gb_project_tree_builder_node_expanded;


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