[libdazzle] tree: implement drag_delete for DnD



commit 4d134dc3873b7cf2768a2d1f4cb46d6f7c4aacf3
Author: Christian Hergert <chergert redhat com>
Date:   Tue Dec 5 02:38:20 2017 -0800

    tree: implement drag_delete for DnD
    
    This allows us to cleanup the node that was moved when doing
    a MOVE action with DzlTree{,Node,Builder}.

 src/tree/dzl-tree-builder.c |   25 ++++++++++++++++++++++++-
 src/tree/dzl-tree-builder.h |    2 ++
 src/tree/dzl-tree-private.h |    2 ++
 src/tree/dzl-tree-store.c   |   28 ++++++++++++++++++++++++++--
 4 files changed, 54 insertions(+), 3 deletions(-)
---
diff --git a/src/tree/dzl-tree-builder.c b/src/tree/dzl-tree-builder.c
index b9e360c..4c7c6f7 100644
--- a/src/tree/dzl-tree-builder.c
+++ b/src/tree/dzl-tree-builder.c
@@ -43,13 +43,14 @@ enum {
   ADDED,
   REMOVED,
   BUILD_NODE,
+  DRAG_DATA_GET,
   DRAG_DATA_RECEIVED,
   DRAG_NODE_RECEIVED,
+  DRAG_NODE_DELETE,
   NODE_ACTIVATED,
   NODE_COLLAPSED,
   NODE_DRAGGABLE,
   NODE_DROPPABLE,
-  DRAG_DATA_GET,
   NODE_EXPANDED,
   NODE_POPUP,
   NODE_SELECTED,
@@ -208,6 +209,20 @@ _dzl_tree_builder_node_droppable (DzlTreeBuilder   *builder,
 }
 
 gboolean
+_dzl_tree_builder_drag_node_delete (DzlTreeBuilder *builder,
+                                    DzlTreeNode    *node)
+{
+  gboolean ret = FALSE;
+
+  g_return_val_if_fail (DZL_IS_TREE_BUILDER (builder), FALSE);
+  g_return_val_if_fail (DZL_IS_TREE_NODE (node), FALSE);
+
+  g_signal_emit (builder, signals [DRAG_NODE_DELETE], 0, node, &ret);
+
+  return ret;
+}
+
+gboolean
 _dzl_tree_builder_drag_data_get (DzlTreeBuilder   *builder,
                                  DzlTreeNode      *node,
                                  GtkSelectionData *data)
@@ -363,6 +378,14 @@ dzl_tree_builder_class_init (DzlTreeBuilderClass *klass)
                   DZL_TYPE_TREE_DROP_POSITION,
                   GTK_TYPE_SELECTION_DATA);
 
+  signals [DRAG_NODE_DELETE] =
+    g_signal_new ("drag-node-delete",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  G_STRUCT_OFFSET (DzlTreeBuilderClass, drag_node_delete),
+                  NULL, NULL, NULL,
+                  G_TYPE_BOOLEAN, 1, DZL_TYPE_TREE_NODE);
+
   signals [NODE_ACTIVATED] =
     g_signal_new ("node-activated",
                   G_TYPE_FROM_CLASS (klass),
diff --git a/src/tree/dzl-tree-builder.h b/src/tree/dzl-tree-builder.h
index ba2c47d..24e4d59 100644
--- a/src/tree/dzl-tree-builder.h
+++ b/src/tree/dzl-tree-builder.h
@@ -69,6 +69,8 @@ struct _DzlTreeBuilderClass
                                        DzlTreeNode         *drop_node,
                                        DzlTreeDropPosition  position,
                                        GtkSelectionData    *data);
+  gboolean (*drag_node_delete)        (DzlTreeBuilder      *builder,
+                                       DzlTreeNode         *node);
 
   /*< private >*/
   gpointer _padding[12];
diff --git a/src/tree/dzl-tree-private.h b/src/tree/dzl-tree-private.h
index 35f2c29..5683fbd 100644
--- a/src/tree/dzl-tree-private.h
+++ b/src/tree/dzl-tree-private.h
@@ -80,6 +80,8 @@ gboolean      _dzl_tree_builder_drag_node_received      (DzlTreeBuilder
                                                          DzlTreeNode            *drop_node,
                                                          DzlTreeDropPosition     position,
                                                          GtkSelectionData       *data);
+gboolean      _dzl_tree_builder_drag_node_delete        (DzlTreeBuilder         *builder,
+                                                         DzlTreeNode            *node);
 gboolean      _dzl_tree_builder_node_activated          (DzlTreeBuilder         *builder,
                                                          DzlTreeNode            *node);
 void          _dzl_tree_builder_node_popup              (DzlTreeBuilder         *builder,
diff --git a/src/tree/dzl-tree-store.c b/src/tree/dzl-tree-store.c
index 602f6ee..4897c65 100644
--- a/src/tree/dzl-tree-store.c
+++ b/src/tree/dzl-tree-store.c
@@ -261,10 +261,34 @@ static gboolean
 dzl_tree_store_drag_data_delete (GtkTreeDragSource *source,
                                  GtkTreePath       *path)
 {
-  g_assert (GTK_IS_TREE_DRAG_SOURCE (source));
+  DzlTreeStore *self = (DzlTreeStore *)source;
+  GtkTreeIter iter;
+  GPtrArray *builders;
+
+  g_assert (GTK_IS_TREE_DRAG_SOURCE (self));
+  g_assert (self->tree != NULL);
   g_assert (path != NULL);
 
-  /* XXX: Handle drag data delete */
+  builders = _dzl_tree_get_builders (self->tree);
+  g_assert (builders != NULL);
+
+  if (gtk_tree_model_get_iter (GTK_TREE_MODEL (source), &iter, path))
+    {
+      g_autoptr(DzlTreeNode) node = NULL;
+
+      gtk_tree_model_get (GTK_TREE_MODEL (source), &iter, 0, &node, -1);
+      g_assert (DZL_IS_TREE_NODE (node));
+
+      for (guint i = 0; i < builders->len; i++)
+        {
+          DzlTreeBuilder *builder = g_ptr_array_index (builders, i);
+
+          g_assert (DZL_IS_TREE_BUILDER (builder));
+
+          if (_dzl_tree_builder_drag_node_delete (builder, node))
+            return TRUE;
+        }
+    }
 
   return FALSE;
 }


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