[Xfce4-commits] <thunar:jannis/new-shortcuts-pane> Continue reordering via DND. It sort of works but is unfinished.

Jannis Pohlmann noreply at xfce.org
Sun Dec 25 03:02:01 CET 2011


Updating branch refs/heads/jannis/new-shortcuts-pane
         to 5d320f84075019e4a61e8abf79ca0705f74bc399 (commit)
       from 7695d02ce8ab279163c23fb24e5d3d46493fae4e (commit)

commit 5d320f84075019e4a61e8abf79ca0705f74bc399
Author: Jannis Pohlmann <jannis.pohlmann at codethink.co.uk>
Date:   Sun Dec 25 02:55:13 2011 +0100

    Continue reordering via DND. It sort of works but is unfinished.
    
    We should probably drop the GtkVBox for the shortcuts in a
    ThunarShortcutGroup and just implement the layout mechanism inside the
    group. That would allow us to fake the empty spot indicator instead of
    using a real GtkImage widget. The empty spot indicator is cool as it
    delivers a feeling of direct manipulation. However, using a real widget
    causes a mix of ThunarShortcut and GtkImage widgets inside the vertical
    box of the group, which is kind of ugly. We should just render the
    indicator but not use a real widget.
    
    Other than that, reordering via DND works now. Shortcuts only
    temporarily remain in their new positions until the ThunarShortcutsView
    is destroyed. Windows are out of sync.

 thunar/thunar-enum-types.c     |    5 +-
 thunar/thunar-enum-types.h     |    1 +
 thunar/thunar-shortcut-group.c |  416 ++++++++++++++++++++++++++++++----------
 thunar/thunar-shortcut-group.h |    5 -
 thunar/thunar-shortcut.c       |   43 +++--
 thunar/thunar-shortcut.h       |  109 ++++++-----
 6 files changed, 394 insertions(+), 185 deletions(-)

diff --git a/thunar/thunar-enum-types.c b/thunar/thunar-enum-types.c
index 4ede8f2..355af7f 100644
--- a/thunar/thunar-enum-types.c
+++ b/thunar/thunar-enum-types.c
@@ -371,8 +371,9 @@ thunar_dnd_target_get_type (void)
     {
       static const GEnumValue values[] =
       {
-        { THUNAR_DND_TARGET_SHORTCUT, "THUNAR_DND_TARGET_SHORTCUT", "shortcut", },
-        { 0,                          NULL,                         NULL,       },
+        { THUNAR_DND_TARGET_SHORTCUT,      "THUNAR_DND_TARGET_SHORTCUT",      "shortcut",     },
+        { THUNAR_DND_TARGET_TEXT_URI_LIST, "THUNAR_DND_TARGET_TEXT_URI_LIST", "text/uri-list" },
+        { 0,                               NULL,                              NULL,           },
       };
 
       type = g_enum_register_static (I_("ThunarDNDTarget"), values);
diff --git a/thunar/thunar-enum-types.h b/thunar/thunar-enum-types.h
index b25014b..944573e 100644
--- a/thunar/thunar-enum-types.h
+++ b/thunar/thunar-enum-types.h
@@ -325,6 +325,7 @@ GType thunar_shortcut_type_get_type (void) G_GNUC_CONST;
 typedef enum
 {
   THUNAR_DND_TARGET_SHORTCUT,
+  THUNAR_DND_TARGET_TEXT_URI_LIST,
 } ThunarDNDTarget;
 
 GType thunar_dnd_target_get_type (void) G_GNUC_CONST;
diff --git a/thunar/thunar-shortcut-group.c b/thunar/thunar-shortcut-group.c
index 159a047..114fb85 100644
--- a/thunar/thunar-shortcut-group.c
+++ b/thunar/thunar-shortcut-group.c
@@ -48,32 +48,49 @@ enum
 
 
 
-static void     thunar_shortcut_group_constructed       (GObject                *object);
-static void     thunar_shortcut_group_dispose           (GObject                *object);
-static void     thunar_shortcut_group_finalize          (GObject                *object);
-static void     thunar_shortcut_group_get_property      (GObject                *object,
-                                                         guint                   prop_id,
-                                                         GValue                 *value,
-                                                         GParamSpec             *pspec);
-static void     thunar_shortcut_group_set_property      (GObject                *object,
-                                                         guint                   prop_id,
-                                                         const GValue           *value,
-                                                         GParamSpec             *pspec);
-static void     thunar_shortcut_group_drag_leave        (GtkWidget              *widget,
-                                                         GdkDragContext         *context,
-                                                         guint                   timestamp);
-static gboolean thunar_shortcut_group_drag_motion       (GtkWidget              *widget,
-                                                         GdkDragContext         *context,
-                                                         gint                    x,
-                                                         gint                    y,
-                                                         guint                   timestamp);
-static void     thunar_shortcut_group_attract_attention (ThunarShortcutGroup    *group);
-static gboolean thunar_shortcut_group_flash_expander    (gpointer                user_data);
-static void     thunar_shortcut_group_expand_style_set  (ThunarShortcutGroup    *group,
-                                                         GtkStyle               *style,
-                                                         GtkWidget              *expander);
-static void     thunar_shortcut_group_apply_indentation (ThunarShortcutGroup    *group,
-                                                         ThunarShortcut         *shortcut);
+static void     thunar_shortcut_group_constructed          (GObject                *object);
+static void     thunar_shortcut_group_dispose              (GObject                *object);
+static void     thunar_shortcut_group_finalize             (GObject                *object);
+static void     thunar_shortcut_group_get_property         (GObject                *object,
+                                                            guint                   prop_id,
+                                                            GValue                 *value,
+                                                            GParamSpec             *pspec);
+static void     thunar_shortcut_group_set_property         (GObject                *object,
+                                                            guint                   prop_id,
+                                                            const GValue           *value,
+                                                            GParamSpec             *pspec);
+static void     thunar_shortcut_group_drag_data_received   (GtkWidget              *widget,
+                                                            GdkDragContext         *context,
+                                                            gint                    x,
+                                                            gint                    y,
+                                                            GtkSelectionData       *data,
+                                                            guint                   info,
+                                                            guint                   timestamp);
+static gboolean thunar_shortcut_group_drag_drop            (GtkWidget              *widget,
+                                                            GdkDragContext         *context,
+                                                            gint                    x,
+                                                            gint                    y,
+                                                            guint                   timestamp);
+static void     thunar_shortcut_group_drag_leave           (GtkWidget              *widget,
+                                                            GdkDragContext         *context,
+                                                            guint                   timestamp);
+static gboolean thunar_shortcut_group_drag_motion          (GtkWidget              *widget,
+                                                            GdkDragContext         *context,
+                                                            gint                    x,
+                                                            gint                    y,
+                                                            guint                   timestamp);
+static void     thunar_shortcut_group_attract_attention    (ThunarShortcutGroup    *group);
+static gboolean thunar_shortcut_group_flash_expander       (gpointer                user_data);
+static void     thunar_shortcut_group_expand_style_set     (ThunarShortcutGroup    *group,
+                                                            GtkStyle               *style,
+                                                            GtkWidget              *expander);
+static void     thunar_shortcut_group_apply_indentation    (ThunarShortcutGroup    *group,
+                                                            ThunarShortcut         *shortcut);
+static gboolean thunar_shortcut_group_find_child_by_coords (ThunarShortcutGroup    *group,
+                                                            gint                    x,
+                                                            gint                    y,
+                                                            GtkWidget             **child,
+                                                            gint                   *child_index);
 
 
 
@@ -94,6 +111,10 @@ struct _ThunarShortcutGroup
 
   guint              flash_idle_id;
   guint              flash_count;
+
+  guint              drop_data_ready : 1;
+  guint              drop_occurred : 1;
+  ThunarShortcut    *drop_shortcut;
 };
 
 
@@ -104,6 +125,7 @@ G_DEFINE_TYPE (ThunarShortcutGroup, thunar_shortcut_group, GTK_TYPE_EXPANDER)
 
 static const GtkTargetEntry drop_targets[] =
 {
+  { "text/uri-list", 0, THUNAR_DND_TARGET_TEXT_URI_LIST },
   { "THUNAR_DND_TARGET_SHORTCUT", GTK_TARGET_SAME_APP, THUNAR_DND_TARGET_SHORTCUT },
 };
 
@@ -126,6 +148,8 @@ thunar_shortcut_group_class_init (ThunarShortcutGroupClass *klass)
   gobject_class->set_property = thunar_shortcut_group_set_property;
 
   gtkwidget_class = GTK_WIDGET_CLASS (klass);
+  gtkwidget_class->drag_data_received = thunar_shortcut_group_drag_data_received;
+  gtkwidget_class->drag_drop = thunar_shortcut_group_drag_drop;
   gtkwidget_class->drag_leave = thunar_shortcut_group_drag_leave;
   gtkwidget_class->drag_motion = thunar_shortcut_group_drag_motion;
 
@@ -188,8 +212,7 @@ thunar_shortcut_group_constructed (GObject *object)
 
   /* create an empty label to indicate an empty spot when re-ordering 
    * shortcuts via DND */
-  group->empty_spot = gtk_frame_new (NULL);
-  gtk_frame_set_shadow_type (GTK_FRAME (group->empty_spot), GTK_SHADOW_IN);
+  group->empty_spot = gtk_image_new ();
   g_object_ref (group->empty_spot);
 }
 
@@ -284,6 +307,99 @@ thunar_shortcut_group_set_property (GObject      *object,
 
 
 static void
+thunar_shortcut_group_drag_data_received (GtkWidget        *widget,
+                                          GdkDragContext   *context,
+                                          gint              x,
+                                          gint              y,
+                                          GtkSelectionData *data,
+                                          guint             info,
+                                          guint             timestamp)
+{
+  ThunarShortcutGroup *group = THUNAR_SHORTCUT_GROUP (widget);
+  GtkWidget           *shortcut;
+  GList               *children;
+  GList               *iter;
+  gint                 empty_spot_index;
+
+  _thunar_return_if_fail (THUNAR_IS_SHORTCUT_GROUP (widget));
+  _thunar_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
+
+  if (info == THUNAR_DND_TARGET_SHORTCUT)
+    {
+      /* only read data if we don't have it yet */
+      if (!group->drop_data_ready)
+        {
+          group->drop_shortcut = THUNAR_SHORTCUT (gtk_drag_get_source_widget (context));
+          group->drop_data_ready = TRUE;
+        }
+
+      if (group->drop_occurred)
+        {
+          group->drop_occurred = FALSE;
+
+          children = gtk_container_get_children (GTK_CONTAINER (group->shortcuts));
+          iter = g_list_find (children, group->empty_spot);
+          empty_spot_index = g_list_position (children, iter);
+          g_list_free (children);
+
+          shortcut = gtk_drag_get_source_widget (context);
+          gtk_box_reorder_child (GTK_BOX (group->shortcuts), shortcut, empty_spot_index);
+
+          thunar_shortcut_group_drag_leave (widget, context, timestamp);
+
+          gtk_drag_finish (context, TRUE, FALSE, timestamp);
+        }
+    }
+  else if (info == THUNAR_DND_TARGET_TEXT_URI_LIST)
+    {
+      /* only read data if we don't have it yet */
+      if (!group->drop_data_ready)
+        {
+        }
+
+      if (group->drop_occurred)
+        {
+          group->drop_occurred = FALSE;
+        }
+    }
+}
+
+
+
+static gboolean
+thunar_shortcut_group_drag_drop (GtkWidget      *widget,
+                                 GdkDragContext *context,
+                                 gint            x,
+                                 gint            y,
+                                 guint           timestamp)
+{
+  ThunarShortcutGroup *group = THUNAR_SHORTCUT_GROUP (widget);
+  GdkAtom              target;
+
+  _thunar_return_val_if_fail (THUNAR_IS_SHORTCUT_GROUP (widget), FALSE);
+  _thunar_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), FALSE);
+
+  target = gtk_drag_dest_find_target (widget, context, NULL);
+  if (target == gdk_atom_intern_static_string ("THUNAR_DND_TARGET_SHORTCUT"))
+    {
+      /* set the state so that drag_data_received knows that it needs to drop now */
+      group->drop_occurred = TRUE;
+
+      /* request the drag data from the source and perform the drop */
+      gtk_drag_get_data (widget, context, target, timestamp);
+
+      return TRUE;
+    }
+  else
+    {
+      /* we cannot handle the drop */
+      return FALSE;
+    }
+}
+
+
+
+static void
 thunar_shortcut_group_drag_leave (GtkWidget      *widget,
                                   GdkDragContext *context,
                                   guint           timestamp)
@@ -293,9 +409,16 @@ thunar_shortcut_group_drag_leave (GtkWidget      *widget,
   _thunar_return_if_fail (THUNAR_IS_SHORTCUT_GROUP (widget));
   _thunar_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
 
-  /* TODO immediately make the drag source visible again */
+  /* reset DND state information */
+  if (group->drop_data_ready)
+    {
+      group->drop_data_ready = FALSE;
+      group->drop_occurred = FALSE;
+      group->drop_shortcut = NULL;
+    }
 
-  gtk_container_remove (GTK_CONTAINER (group->shortcuts), group->empty_spot);
+  /* hide the empty spot indicator */
+  gtk_widget_hide (group->empty_spot);
 
   /* call the parent's drag_leave() handler */
   if (GTK_WIDGET_CLASS (thunar_shortcut_group_parent_class)->drag_leave != NULL)
@@ -312,10 +435,12 @@ thunar_shortcut_group_drag_motion (GtkWidget      *widget,
                                    guint           timestamp)
 {
   ThunarShortcutGroup *group = THUNAR_SHORTCUT_GROUP (widget);
-  ThunarShortcut      *shortcut;
   GtkAllocation        allocation;
+  GdkDragAction        actions = 0;
+  GdkPixmap           *pixmap;
+  GtkWidget           *child = NULL;
   GdkAtom              target;
-  gint                 shortcut_index;
+  gint                 child_index;
 
   _thunar_return_val_if_fail (THUNAR_IS_SHORTCUT_GROUP (widget), FALSE);
   _thunar_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), FALSE);
@@ -329,41 +454,95 @@ thunar_shortcut_group_drag_motion (GtkWidget      *widget,
 
   if (target == gdk_atom_intern_static_string ("THUNAR_DND_TARGET_SHORTCUT"))
     {
-      gtk_widget_get_allocation (widget, &allocation);
-      y = y + allocation.y;
-
-      if (!thunar_shortcut_group_find_shortcut_by_coords (group, x, y,
-                                                          &shortcut,
-                                                          &shortcut_index))
+      /* request the drop data on demand */
+      if (!group->drop_data_ready)
         {
-          gdk_drag_status (context, 0, timestamp);
+          /* request the drop data from the source */
+          gtk_drag_get_data (widget, context, target, timestamp);
+          if (!gtk_widget_is_ancestor (GTK_WIDGET (group->drop_shortcut), widget))
+            return FALSE;
           return TRUE;
         }
-
-      if (gtk_widget_get_parent (group->empty_spot) == NULL)
+      else
         {
-          gtk_box_pack_start (GTK_BOX (group->shortcuts),
-                              group->empty_spot,
-                              FALSE, TRUE, 0);
-        }
+          if (!gtk_widget_is_ancestor (GTK_WIDGET (group->drop_shortcut), widget))
+            return FALSE;
 
-      gtk_box_reorder_child (GTK_BOX (group->shortcuts),
-                             group->empty_spot,
-                             shortcut_index);
-      gtk_widget_show (group->empty_spot);
-          
-      gdk_drag_status (context, 0, timestamp);
-      return TRUE;
+          /* translate the y coordinate so that it is relative to the parent */
+          gtk_widget_get_allocation (widget, &allocation);
+          y = y + allocation.y;
+
+          /* find the shortcut we are currently hovering */
+          if (!thunar_shortcut_group_find_child_by_coords (group, x, y,
+                                                           &child,
+                                                           &child_index))
+            {
+              gdk_drag_status (context, 0, timestamp);
+              return TRUE;
+            }
+
+          /* if the hovered shortcut is mutable, show an empty spot indicator */
+          if (THUNAR_IS_SHORTCUT (child))
+            {
+              if (thunar_shortcut_get_mutable (THUNAR_SHORTCUT (child)))
+                {
+                  /* add the empty spot indicator to the shortcuts container */
+                  if (gtk_widget_get_parent (group->empty_spot) == NULL)
+                    {
+                      gtk_box_pack_start (GTK_BOX (group->shortcuts),
+                                          group->empty_spot,
+                                          FALSE, TRUE, 0);
+                    }
+
+                  /* show the empty spot indicator before/after the hovered shortcut,
+                   * depending on where exactly the drag motion happened */
+                  gtk_widget_get_allocation (child, &allocation);
+                  if (y > allocation.y + allocation.height / 2)
+                    child_index += 1;
+                  gtk_box_reorder_child (GTK_BOX (group->shortcuts),
+                                         group->empty_spot,
+                                         child_index);
+
+                  /* display a snapshot of the dragged shortcut in the empty spot */
+                  pixmap = thunar_shortcut_get_pre_drag_snapshot (group->drop_shortcut);
+                  gtk_image_set_from_pixmap (GTK_IMAGE (group->empty_spot),
+                                             pixmap,
+                                             NULL);
+
+                  /* hide the dragged shortcut as we are now dragging it */
+                  gtk_widget_hide (GTK_WIDGET (group->drop_shortcut));
+
+                  /* make sure to show the empty spot indicator */
+                  gtk_widget_show (group->empty_spot);
+                }
+            }
+
+          /* allow reordering */
+          actions = GDK_ACTION_MOVE;
+        }
     }
   else if (target == gdk_atom_intern_static_string ("text/uri-list"))
     {
-      gdk_drag_status (context, 0, timestamp);
-      return TRUE;
+      /* request the drop data on demand */
+      if (!group->drop_data_ready)
+        {
+          /* request the drop data from the source */
+          gtk_drag_get_data (widget, context, target, timestamp);
+        }
+      else
+        {
+        }
     }
   else
     {
+      /* unsupported target */
       return FALSE;
     }
+
+  /* tell Gdk whether we can drop here */
+  gdk_drag_status (context, actions, timestamp);
+
+  return TRUE;
 }
 
 
@@ -454,7 +633,10 @@ thunar_shortcut_group_expand_style_set (ThunarShortcutGroup *group,
   children = gtk_container_get_children (GTK_CONTAINER (group->shortcuts));
 
   for (iter = children; iter != NULL; iter = iter->next)
-    thunar_shortcut_group_apply_indentation (group, THUNAR_SHORTCUT (iter->data));
+    {
+      if (THUNAR_IS_SHORTCUT (iter->data))
+        thunar_shortcut_group_apply_indentation (group, THUNAR_SHORTCUT (iter->data));
+    }
 
   g_list_free (children);
 }
@@ -487,6 +669,57 @@ thunar_shortcut_group_apply_indentation (ThunarShortcutGroup *group,
 
 
 
+static gboolean
+thunar_shortcut_group_find_child_by_coords (ThunarShortcutGroup *group,
+                                            gint                 x,
+                                            gint                 y,
+                                            GtkWidget          **child,
+                                            gint                *child_index)
+{
+  GtkAllocation allocation = { 0, 0, 0, 0 };
+  gboolean      child_found = FALSE;
+  GList        *children;
+  GList        *iter;
+  gint          idx = 0;
+
+  _thunar_return_val_if_fail (THUNAR_IS_SHORTCUT_GROUP (group), FALSE);
+
+  if (child != NULL)
+    *child = NULL;
+
+  if (child_index != NULL)
+    *child_index = -1;
+
+  children = gtk_container_get_children (GTK_CONTAINER (group->shortcuts));
+
+  for (iter = children; !child_found && iter != NULL; iter = iter->next)
+    {
+      if (gtk_widget_get_visible (iter->data))
+        {
+          gtk_widget_get_allocation (iter->data, &allocation);
+
+          if (y >= allocation.y && y <= allocation.y + allocation.height)
+            {
+              if (child != NULL)
+                *child = iter->data;
+
+              if (child_index != NULL)
+                *child_index = idx;
+
+              child_found = TRUE;
+            }
+        }
+
+      idx++;
+    }
+
+  g_list_free (children);
+
+  return child_found;
+}
+
+
+
 GtkWidget *
 thunar_shortcut_group_new (const gchar       *label,
                            ThunarShortcutType accepted_types)
@@ -550,6 +783,9 @@ thunar_shortcut_group_unselect_shortcuts (ThunarShortcutGroup *group,
 
   for (iter = children; iter != NULL; iter = iter->next)
     {
+      if (!THUNAR_IS_SHORTCUT (iter->data))
+        continue;
+
       shortcut = THUNAR_SHORTCUT (iter->data);
 
       if (shortcut != exception
@@ -557,6 +793,7 @@ thunar_shortcut_group_unselect_shortcuts (ThunarShortcutGroup *group,
         {
           gtk_widget_set_state (GTK_WIDGET (shortcut), GTK_STATE_NORMAL);
         }
+      
     }
 
   g_list_free (children);
@@ -579,6 +816,9 @@ thunar_shortcut_group_unprelight_shortcuts (ThunarShortcutGroup *group,
 
   for (iter = children; iter != NULL; iter = iter->next)
     {
+      if (!THUNAR_IS_SHORTCUT (iter->data))
+        continue;
+
       shortcut = THUNAR_SHORTCUT (iter->data);
 
       if (shortcut != exception
@@ -608,6 +848,9 @@ thunar_shortcut_group_cancel_activations (ThunarShortcutGroup *group,
 
   for (iter = children; iter != NULL; iter = iter->next)
     {
+      if (!THUNAR_IS_SHORTCUT (iter->data))
+        continue;
+
       shortcut = THUNAR_SHORTCUT (iter->data);
 
       if (shortcut != exception)
@@ -634,6 +877,9 @@ thunar_shortcut_group_update_selection (ThunarShortcutGroup *group,
 
   for (iter = children; iter != NULL; iter = iter->next)
     {
+      if (!THUNAR_IS_SHORTCUT (iter->data))
+        continue;
+
       shortcut = THUNAR_SHORTCUT (iter->data);
 
       if (thunar_shortcut_matches_file (shortcut, file))
@@ -663,6 +909,9 @@ thunar_shortcut_group_remove_volume_shortcut (ThunarShortcutGroup *group,
 
   for (iter = children; iter != NULL; iter = iter->next)
     {
+      if (!THUNAR_IS_SHORTCUT (iter->data))
+        continue;
+
       shortcut = THUNAR_SHORTCUT (iter->data);
       shortcut_volume = thunar_shortcut_get_volume (shortcut);
 
@@ -692,6 +941,9 @@ thunar_shortcut_group_remove_mount_shortcut (ThunarShortcutGroup *group,
 
   for (iter = children; iter != NULL; iter = iter->next)
     {
+      if (!THUNAR_IS_SHORTCUT (iter->data))
+        continue;
+
       shortcut = THUNAR_SHORTCUT (iter->data);
 
       if (!thunar_shortcut_get_persistent (shortcut))
@@ -742,6 +994,9 @@ thunar_shortcut_group_find_shortcut_by_location (ThunarShortcutGroup *group,
 
   for (iter = children; !has_shortcut && iter != NULL; iter = iter->next)
     {
+      if (!THUNAR_IS_SHORTCUT (iter->data))
+        continue;
+
       shortcut = THUNAR_SHORTCUT (iter->data);
 
       if (thunar_shortcut_matches_location (shortcut, location))
@@ -757,54 +1012,3 @@ thunar_shortcut_group_find_shortcut_by_location (ThunarShortcutGroup *group,
 
   return has_shortcut;
 }
-
-
-
-gboolean
-thunar_shortcut_group_find_shortcut_by_coords (ThunarShortcutGroup *group,
-                                               gint                 x,
-                                               gint                 y,
-                                               ThunarShortcut     **shortcut,
-                                               gint                *shortcut_index)
-{
-  GtkAllocation allocation = { 0, 0, 0, 0 };
-  gboolean      shortcut_found = FALSE;
-  GList        *children;
-  GList        *iter;
-  gint          idx = 0;
-
-  _thunar_return_val_if_fail (THUNAR_IS_SHORTCUT_GROUP (group), FALSE);
-
-  if (shortcut != NULL)
-    *shortcut = NULL;
-
-  if (shortcut_index != NULL)
-    *shortcut_index = -1;
-
-  children = gtk_container_get_children (GTK_CONTAINER (group->shortcuts));
-
-  for (iter = children; !shortcut_found && iter != NULL; iter = iter->next)
-    {
-      if (gtk_widget_get_visible (iter->data))
-        {
-          gtk_widget_get_allocation (iter->data, &allocation);
-
-          if (y >= allocation.y && y <= allocation.y + allocation.height)
-            {
-              if (shortcut != NULL)
-                *shortcut = iter->data;
-
-              if (shortcut_index != NULL)
-                *shortcut_index = idx;
-
-              shortcut_found = TRUE;
-            }
-        }
-
-      idx++;
-    }
-
-  g_list_free (children);
-
-  return shortcut_found;
-}
diff --git a/thunar/thunar-shortcut-group.h b/thunar/thunar-shortcut-group.h
index 4c95baf..b21bcc6 100644
--- a/thunar/thunar-shortcut-group.h
+++ b/thunar/thunar-shortcut-group.h
@@ -61,11 +61,6 @@ gboolean   thunar_shortcut_group_find_shortcut_by_file     (ThunarShortcutGroup
 gboolean   thunar_shortcut_group_find_shortcut_by_location (ThunarShortcutGroup *group,
                                                             GFile               *location,
                                                             ThunarShortcut     **result);
-gboolean   thunar_shortcut_group_find_shortcut_by_coords   (ThunarShortcutGroup *group,
-                                                            gint                 x,
-                                                            gint                 y,
-                                                            ThunarShortcut     **shortcut,
-                                                            gint                *shortcut_index);
 
 G_END_DECLS
 
diff --git a/thunar/thunar-shortcut.c b/thunar/thunar-shortcut.c
index cc93f37..1eeb1e6 100644
--- a/thunar/thunar-shortcut.c
+++ b/thunar/thunar-shortcut.c
@@ -75,12 +75,6 @@ enum
   LAST_SIGNAL,
 };
 
-/* identifiers for DnD target types */
-enum
-{
-  TARGET_TEXT_URI_LIST,
-};
-
 /* row states */
 typedef enum
 {
@@ -245,6 +239,8 @@ struct _ThunarShortcut
   guint               drop_data_ready : 1;
   GList              *drop_file_list;
 
+  GdkPixmap          *pre_drag_snapshot;
+
   gint                pressed_button;
 };
 
@@ -264,7 +260,7 @@ static const GtkTargetEntry drag_targets[] =
 
 static const GtkTargetEntry drop_targets[] =
 {
-  { "text/uri-list", 0, TARGET_TEXT_URI_LIST },
+  { "text/uri-list", 0, THUNAR_DND_TARGET_TEXT_URI_LIST },
 };
 
 
@@ -560,6 +556,10 @@ thunar_shortcut_finalize (GObject *object)
 {
   ThunarShortcut *shortcut = THUNAR_SHORTCUT (object);
 
+  /* release the pre-drag snapshot */
+  if (shortcut->pre_drag_snapshot != NULL)
+    g_object_unref (shortcut->pre_drag_snapshot);
+
   /* release the spinner and action image */
   g_object_unref (shortcut->spinner);
   g_object_unref (shortcut->action_image);
@@ -833,7 +833,6 @@ thunar_shortcut_drag_begin (GtkWidget      *widget,
                             GdkDragContext *context)
 {
   ThunarShortcut *shortcut = THUNAR_SHORTCUT (widget);
-  GdkPixmap      *pixmap;
 
   _thunar_return_if_fail (THUNAR_IS_SHORTCUT (widget));
   _thunar_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
@@ -841,14 +840,13 @@ thunar_shortcut_drag_begin (GtkWidget      *widget,
   /* reset the pressed button state */
   shortcut->pressed_button = -1;
 
-  /* take a snapshot of the shortcut and use it as the drag icon */
-  pixmap = gtk_widget_get_snapshot (widget, NULL);
-  gtk_drag_set_icon_pixmap (context, gtk_widget_get_colormap (widget),
-                            pixmap, NULL, 0, 0);
-  g_object_unref (pixmap);
-
-  /* hide the shortcut as we are now dragging it */
-  gtk_widget_hide (widget);
+  /* take a snapshot of the shortcut */
+  if (shortcut->pre_drag_snapshot != NULL)
+    {
+      g_object_unref (shortcut->pre_drag_snapshot);
+      shortcut->pre_drag_snapshot = NULL;
+    }
+  shortcut->pre_drag_snapshot = gtk_widget_get_snapshot (widget, NULL);
 
   /* call the parent's drag_begin() handler */
   if (GTK_WIDGET_CLASS (thunar_shortcut_parent_class)->drag_begin != NULL)
@@ -878,7 +876,7 @@ thunar_shortcut_drag_data_received (GtkWidget        *widget,
   if (!shortcut->drop_data_ready)
     {
       /* extract the URI list from the selection data (if valid) */
-      if (info == TARGET_TEXT_URI_LIST
+      if (info == THUNAR_DND_TARGET_TEXT_URI_LIST
           && selection_data->format == 8
           && selection_data->length > 0)
         {
@@ -897,7 +895,7 @@ thunar_shortcut_drag_data_received (GtkWidget        *widget,
       shortcut->drop_occurred = FALSE;
 
       /* make sure we only handle text/uri-list */
-      if (info == TARGET_TEXT_URI_LIST)
+      if (info == THUNAR_DND_TARGET_TEXT_URI_LIST)
         {
           if (shortcut->file != NULL)
             {
@@ -2845,3 +2843,12 @@ thunar_shortcut_matches_location (ThunarShortcut *shortcut,
 
   return matches;
 }
+
+
+
+GdkPixmap *
+thunar_shortcut_get_pre_drag_snapshot (ThunarShortcut *shortcut)
+{
+  _thunar_return_val_if_fail (THUNAR_IS_SHORTCUT (shortcut), NULL);
+  return shortcut->pre_drag_snapshot;
+}
diff --git a/thunar/thunar-shortcut.h b/thunar/thunar-shortcut.h
index c28b373..fb56f34 100644
--- a/thunar/thunar-shortcut.h
+++ b/thunar/thunar-shortcut.h
@@ -37,61 +37,62 @@ G_BEGIN_DECLS
 typedef struct _ThunarShortcutClass ThunarShortcutClass;
 typedef struct _ThunarShortcut      ThunarShortcut;
 
-GType              thunar_shortcut_get_type             (void) G_GNUC_CONST;
+GType              thunar_shortcut_get_type              (void) G_GNUC_CONST;
 
-GFile             *thunar_shortcut_get_location         (ThunarShortcut    *shortcut);
-void               thunar_shortcut_set_location         (ThunarShortcut    *shortcut,
-                                                         GFile             *location);
-ThunarFile        *thunar_shortcut_get_file             (ThunarShortcut    *shortcut);
-void               thunar_shortcut_set_file             (ThunarShortcut    *shortcut,
-                                                         ThunarFile        *file);
-GVolume           *thunar_shortcut_get_volume           (ThunarShortcut    *shortcut);
-void               thunar_shortcut_set_volume           (ThunarShortcut    *shortcut,
-                                                         GVolume           *volume);
-GMount            *thunar_shortcut_get_mount            (ThunarShortcut    *shortcut);
-void               thunar_shortcut_set_mount            (ThunarShortcut    *shortcut,
-                                                         GMount            *mount);
-GIcon             *thunar_shortcut_get_icon             (ThunarShortcut    *shortcut);
-void               thunar_shortcut_set_icon             (ThunarShortcut    *shortcut,
-                                                         GIcon             *icon);
-GIcon             *thunar_shortcut_get_custom_icon      (ThunarShortcut    *shortcut);
-void               thunar_shortcut_set_custom_icon      (ThunarShortcut    *shortcut,
-                                                         GIcon             *custom_icon);
-GIcon             *thunar_shortcut_get_eject_icon       (ThunarShortcut    *shortcut);
-void               thunar_shortcut_set_eject_icon       (ThunarShortcut    *shortcut,
-                                                         GIcon             *eject_icon);
-const gchar       *thunar_shortcut_get_name             (ThunarShortcut    *shortcut);
-void               thunar_shortcut_set_name             (ThunarShortcut    *shortcut,
-                                                         const gchar       *name);
-const gchar       *thunar_shortcut_get_custom_name      (ThunarShortcut    *shortcut);
-void               thunar_shortcut_set_custom_name      (ThunarShortcut    *shortcut,
-                                                         const gchar       *custom_name);
-ThunarShortcutType thunar_shortcut_get_shortcut_type    (ThunarShortcut    *shortcut);
-void               thunar_shortcut_set_shortcut_type    (ThunarShortcut    *shortcut,
-                                                         ThunarShortcutType shortcut_type);
-ThunarIconSize     thunar_shortcut_get_icon_size        (ThunarShortcut    *shortcut);
-void               thunar_shortcut_set_icon_size        (ThunarShortcut    *shortcut,
-                                                         ThunarIconSize     icon_size);
-gboolean           thunar_shortcut_get_hidden           (ThunarShortcut    *shortcut);
-void               thunar_shortcut_set_hidden           (ThunarShortcut    *shortcut,
-                                                         gboolean           hidden);
-gboolean           thunar_shortcut_get_mutable          (ThunarShortcut    *shortcut);
-void               thunar_shortcut_set_mutable          (ThunarShortcut    *shortcut,
-                                                         gboolean           mutable);
-gboolean           thunar_shortcut_get_persistent       (ThunarShortcut    *shortcut);
-void               thunar_shortcut_set_persistent       (ThunarShortcut    *shortcut,
-                                                         gboolean           persistent);
-GtkWidget         *thunar_shortcut_get_alignment        (ThunarShortcut    *shortcut);
-void               thunar_shortcut_resolve_and_activate (ThunarShortcut    *shortcut,
-                                                         gboolean           open_in_new_window);
-void               thunar_shortcut_cancel_activation    (ThunarShortcut    *shortcut);
-void               thunar_shortcut_mount                (ThunarShortcut    *shortcut);
-void               thunar_shortcut_unmount              (ThunarShortcut    *shortcut);
-void               thunar_shortcut_disconnect           (ThunarShortcut    *shortcut);
-gboolean           thunar_shortcut_matches_file         (ThunarShortcut    *shortcut,
-                                                         ThunarFile        *file);
-gboolean           thunar_shortcut_matches_location     (ThunarShortcut    *shortcut,
-                                                         GFile             *location);
+GFile             *thunar_shortcut_get_location          (ThunarShortcut    *shortcut);
+void               thunar_shortcut_set_location          (ThunarShortcut    *shortcut,
+                                                          GFile             *location);
+ThunarFile        *thunar_shortcut_get_file              (ThunarShortcut    *shortcut);
+void               thunar_shortcut_set_file              (ThunarShortcut    *shortcut,
+                                                          ThunarFile        *file);
+GVolume           *thunar_shortcut_get_volume            (ThunarShortcut    *shortcut);
+void               thunar_shortcut_set_volume            (ThunarShortcut    *shortcut,
+                                                          GVolume           *volume);
+GMount            *thunar_shortcut_get_mount             (ThunarShortcut    *shortcut);
+void               thunar_shortcut_set_mount             (ThunarShortcut    *shortcut,
+                                                          GMount            *mount);
+GIcon             *thunar_shortcut_get_icon              (ThunarShortcut    *shortcut);
+void               thunar_shortcut_set_icon              (ThunarShortcut    *shortcut,
+                                                          GIcon             *icon);
+GIcon             *thunar_shortcut_get_custom_icon       (ThunarShortcut    *shortcut);
+void               thunar_shortcut_set_custom_icon       (ThunarShortcut    *shortcut,
+                                                          GIcon             *custom_icon);
+GIcon             *thunar_shortcut_get_eject_icon        (ThunarShortcut    *shortcut);
+void               thunar_shortcut_set_eject_icon        (ThunarShortcut    *shortcut,
+                                                          GIcon             *eject_icon);
+const gchar       *thunar_shortcut_get_name              (ThunarShortcut    *shortcut);
+void               thunar_shortcut_set_name              (ThunarShortcut    *shortcut,
+                                                          const gchar       *name);
+const gchar       *thunar_shortcut_get_custom_name       (ThunarShortcut    *shortcut);
+void               thunar_shortcut_set_custom_name       (ThunarShortcut    *shortcut,
+                                                          const gchar       *custom_name);
+ThunarShortcutType thunar_shortcut_get_shortcut_type     (ThunarShortcut    *shortcut);
+void               thunar_shortcut_set_shortcut_type     (ThunarShortcut    *shortcut,
+                                                          ThunarShortcutType shortcut_type);
+ThunarIconSize     thunar_shortcut_get_icon_size         (ThunarShortcut    *shortcut);
+void               thunar_shortcut_set_icon_size         (ThunarShortcut    *shortcut,
+                                                          ThunarIconSize     icon_size);
+gboolean           thunar_shortcut_get_hidden            (ThunarShortcut    *shortcut);
+void               thunar_shortcut_set_hidden            (ThunarShortcut    *shortcut,
+                                                          gboolean           hidden);
+gboolean           thunar_shortcut_get_mutable           (ThunarShortcut    *shortcut);
+void               thunar_shortcut_set_mutable           (ThunarShortcut    *shortcut,
+                                                          gboolean           mutable);
+gboolean           thunar_shortcut_get_persistent        (ThunarShortcut    *shortcut);
+void               thunar_shortcut_set_persistent        (ThunarShortcut    *shortcut,
+                                                          gboolean           persistent);
+GtkWidget         *thunar_shortcut_get_alignment         (ThunarShortcut    *shortcut);
+void               thunar_shortcut_resolve_and_activate  (ThunarShortcut    *shortcut,
+                                                          gboolean           open_in_new_window);
+void               thunar_shortcut_cancel_activation     (ThunarShortcut    *shortcut);
+void               thunar_shortcut_mount                 (ThunarShortcut    *shortcut);
+void               thunar_shortcut_unmount               (ThunarShortcut    *shortcut);
+void               thunar_shortcut_disconnect            (ThunarShortcut    *shortcut);
+gboolean           thunar_shortcut_matches_file          (ThunarShortcut    *shortcut,
+                                                          ThunarFile        *file);
+gboolean           thunar_shortcut_matches_location      (ThunarShortcut    *shortcut,
+                                                          GFile             *location);
+GdkPixmap         *thunar_shortcut_get_pre_drag_snapshot (ThunarShortcut    *shortcut);
 
 G_END_DECLS
 


More information about the Xfce4-commits mailing list