[Xfce4-commits] <thunar:jannis/new-shortcuts-pane> Add ThunarDNDTarget enum. Try implement shortcut reorder DND.

Jannis Pohlmann noreply at xfce.org
Sat Dec 24 03:36:01 CET 2011


Updating branch refs/heads/jannis/new-shortcuts-pane
         to 37fefbcce950246d7277d82c0df8d91ebb15e326 (commit)
       from ffe9390edb86f1a448b4080f523d3ab6979df363 (commit)

commit 37fefbcce950246d7277d82c0df8d91ebb15e326
Author: Jannis Pohlmann <jannis.pohlmann at codethink.co.uk>
Date:   Sat Dec 24 03:34:16 2011 +0100

    Add ThunarDNDTarget enum. Try implement shortcut reorder DND.
    
    This is not working but I'm uploading what I have so that others can
    have a look.

 thunar/thunar-enum-types.c     |   21 +++++++++++
 thunar/thunar-enum-types.h     |   15 ++++++++
 thunar/thunar-shortcut-group.c |   44 +++++++++++++++++++++++-
 thunar/thunar-shortcut.c       |   74 +++++++++++++++++++++++++++++++++++++++-
 4 files changed, 152 insertions(+), 2 deletions(-)

diff --git a/thunar/thunar-enum-types.c b/thunar/thunar-enum-types.c
index 374d25c..4ede8f2 100644
--- a/thunar/thunar-enum-types.c
+++ b/thunar/thunar-enum-types.c
@@ -359,3 +359,24 @@ thunar_shortcut_type_get_type (void)
 
   return type;
 }
+
+
+
+GType
+thunar_dnd_target_get_type (void)
+{
+  static GType type = G_TYPE_INVALID;
+
+  if (G_UNLIKELY (type == G_TYPE_INVALID))
+    {
+      static const GEnumValue values[] =
+      {
+        { THUNAR_DND_TARGET_SHORTCUT, "THUNAR_DND_TARGET_SHORTCUT", "shortcut", },
+        { 0,                          NULL,                         NULL,       },
+      };
+
+      type = g_enum_register_static (I_("ThunarDNDTarget"), values);
+    }
+
+  return type;
+}
diff --git a/thunar/thunar-enum-types.h b/thunar/thunar-enum-types.h
index 68b1f5c..b25014b 100644
--- a/thunar/thunar-enum-types.h
+++ b/thunar/thunar-enum-types.h
@@ -314,6 +314,21 @@ typedef enum
 
 GType thunar_shortcut_type_get_type (void) G_GNUC_CONST;
 
+
+#define THUNAR_TYPE_DND_TARGET (thunar_dnd_target_get_type ())
+
+/**
+ * ThunarDNDTarget:
+ *
+ * Enum for thunar-internal drag-and-drop targets.
+ **/
+typedef enum
+{
+  THUNAR_DND_TARGET_SHORTCUT,
+} ThunarDNDTarget;
+
+GType thunar_dnd_target_get_type (void) G_GNUC_CONST;
+
 G_END_DECLS
 
 #endif /* !__THUNAR_ENUM_TYPES_H__ */
diff --git a/thunar/thunar-shortcut-group.c b/thunar/thunar-shortcut-group.c
index 258877a..4c16439 100644
--- a/thunar/thunar-shortcut-group.c
+++ b/thunar/thunar-shortcut-group.c
@@ -59,6 +59,11 @@ static void     thunar_shortcut_group_set_property      (GObject
                                                          guint                   prop_id,
                                                          const GValue           *value,
                                                          GParamSpec             *pspec);
+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,
@@ -93,10 +98,18 @@ G_DEFINE_TYPE (ThunarShortcutGroup, thunar_shortcut_group, GTK_TYPE_EVENT_BOX)
 
 
 
+static const GtkTargetEntry drop_targets[] =
+{
+  { "THUNAR_DND_TARGET_SHORTCUT", GTK_TARGET_SAME_APP, THUNAR_DND_TARGET_SHORTCUT },
+};
+
+
+
 static void
 thunar_shortcut_group_class_init (ThunarShortcutGroupClass *klass)
 {
-  GObjectClass *gobject_class;
+  GtkWidgetClass *gtkwidget_class;
+  GObjectClass   *gobject_class;
 
   /* Determine the parent type class */
   thunar_shortcut_group_parent_class = g_type_class_peek_parent (klass);
@@ -108,6 +121,9 @@ thunar_shortcut_group_class_init (ThunarShortcutGroupClass *klass)
   gobject_class->get_property = thunar_shortcut_group_get_property;
   gobject_class->set_property = thunar_shortcut_group_set_property;
 
+  gtkwidget_class = GTK_WIDGET_CLASS (klass);
+  gtkwidget_class->drag_motion = thunar_shortcut_group_drag_motion;
+
   g_object_class_install_property (gobject_class,
                                    PROP_LABEL,
                                    g_param_spec_string ("label",
@@ -151,6 +167,11 @@ thunar_shortcut_group_init (ThunarShortcutGroup *group)
   group->shortcuts = gtk_vbox_new (TRUE, 0);
   gtk_container_add (GTK_CONTAINER (group->expander), group->shortcuts);
   gtk_widget_show (group->shortcuts);
+
+  /* set the group up as a drop site to allow shortcuts to be re-ordered by DND */
+  gtk_drag_dest_set (GTK_WIDGET (group), 0,
+                     drop_targets, G_N_ELEMENTS (drop_targets),
+                     GDK_ACTION_MOVE);
 }
 
 
@@ -247,6 +268,27 @@ thunar_shortcut_group_set_property (GObject      *object,
 
 
 
+static gboolean
+thunar_shortcut_group_drag_motion (GtkWidget      *widget,
+                                   GdkDragContext *context,
+                                   gint            x,
+                                   gint            y,
+                                   guint           timestamp)
+{
+#if 0
+  ThunarShortcutGroup *group = THUNAR_SHORTCUT_GROUP (widget);
+#endif
+
+  _thunar_return_val_if_fail (THUNAR_IS_SHORTCUT_GROUP (widget), FALSE);
+  _thunar_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), FALSE);
+
+  g_debug ("shortcut group drag motion!");
+
+  return FALSE;
+}
+
+
+
 static void
 thunar_shortcut_group_attract_attention (ThunarShortcutGroup *group)
 {
diff --git a/thunar/thunar-shortcut.c b/thunar/thunar-shortcut.c
index a46e59b..ee1fee9 100644
--- a/thunar/thunar-shortcut.c
+++ b/thunar/thunar-shortcut.c
@@ -105,6 +105,8 @@ static gboolean      thunar_shortcut_button_press_event      (GtkWidget
                                                               GdkEventButton     *event);
 static gboolean      thunar_shortcut_button_release_event    (GtkWidget          *widget,
                                                               GdkEventButton     *event);
+static void          thunar_shortcut_drag_begin              (GtkWidget          *widget,
+                                                              GdkDragContext     *context);
 static void          thunar_shortcut_drag_data_received      (GtkWidget          *widget,
                                                               GdkDragContext     *context,
                                                               gint                x,
@@ -117,6 +119,8 @@ static gboolean      thunar_shortcut_drag_drop               (GtkWidget
                                                               gint                x,
                                                               gint                y,
                                                               guint               timestamp);
+static void          thunar_shortcut_drag_end                (GtkWidget          *widget,
+                                                              GdkDragContext     *context);
 static void          thunar_shortcut_drag_leave              (GtkWidget          *widget,
                                                               GdkDragContext     *context,
                                                               guint               timestamp);
@@ -253,9 +257,14 @@ G_DEFINE_TYPE_WITH_CODE (ThunarShortcut, thunar_shortcut, GTK_TYPE_EVENT_BOX,
 
 static guint shortcut_signals[LAST_SIGNAL];
 
+static const GtkTargetEntry drag_targets[] =
+{
+  { "THUNAR_DND_TARGET_SHORTCUT", GTK_TARGET_SAME_APP, THUNAR_DND_TARGET_SHORTCUT }
+};
+
 static const GtkTargetEntry drop_targets[] =
 {
-  { "text/uri-list", 0, TARGET_TEXT_URI_LIST }
+  { "text/uri-list", 0, TARGET_TEXT_URI_LIST },
 };
 
 
@@ -278,8 +287,10 @@ thunar_shortcut_class_init (ThunarShortcutClass *klass)
   gtkwidget_class = GTK_WIDGET_CLASS (klass);
   gtkwidget_class->button_press_event = thunar_shortcut_button_press_event;
   gtkwidget_class->button_release_event = thunar_shortcut_button_release_event;
+  gtkwidget_class->drag_begin = thunar_shortcut_drag_begin;
   gtkwidget_class->drag_data_received = thunar_shortcut_drag_data_received;
   gtkwidget_class->drag_drop = thunar_shortcut_drag_drop;
+  gtkwidget_class->drag_end = thunar_shortcut_drag_end;
   gtkwidget_class->drag_leave = thunar_shortcut_drag_leave;
   gtkwidget_class->drag_motion = thunar_shortcut_drag_motion;
   gtkwidget_class->key_press_event = thunar_shortcut_key_press_event;
@@ -532,6 +543,14 @@ thunar_shortcut_constructed (GObject *object)
 
   /* mark as constructed so now all properties can be changed as usual */
   shortcut->constructed = TRUE;
+
+  if (shortcut->mutable)
+    {
+      /* set up drag support for re-ordering shortcuts */
+      gtk_drag_source_set (GTK_WIDGET (shortcut), GDK_BUTTON1_MASK,
+                           drag_targets, G_N_ELEMENTS (drag_targets),
+                           GDK_ACTION_MOVE);
+    }
 }
 
 
@@ -810,6 +829,35 @@ thunar_shortcut_button_release_event (GtkWidget      *widget,
 
 
 static void
+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));
+
+  /* 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);
+
+  /* call the parent's drag_begin() handler */
+  if (GTK_WIDGET_CLASS (thunar_shortcut_parent_class)->drag_begin != NULL)
+    (*GTK_WIDGET_CLASS (thunar_shortcut_parent_class)->drag_begin) (widget, context);
+}
+
+
+
+static void
 thunar_shortcut_drag_data_received (GtkWidget        *widget,
                                     GdkDragContext   *context,
                                     gint              x,
@@ -933,6 +981,28 @@ thunar_shortcut_drag_drop (GtkWidget      *widget,
 
 
 static void
+thunar_shortcut_drag_end (GtkWidget      *widget,
+                          GdkDragContext *context)
+{
+  ThunarShortcut *shortcut = THUNAR_SHORTCUT (widget);
+
+  _thunar_return_if_fail (THUNAR_IS_SHORTCUT (widget));
+  _thunar_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
+
+  /* reset the pressed button state */
+  shortcut->pressed_button = -1;
+
+  /* show the shortcut again as we are finished dragging it */
+  gtk_widget_show (widget);
+
+  /* call the parent's drag_begin() handler */
+  if (GTK_WIDGET_CLASS (thunar_shortcut_parent_class)->drag_end != NULL)
+    (*GTK_WIDGET_CLASS (thunar_shortcut_parent_class)->drag_end) (widget, context);
+}
+
+
+
+static void
 thunar_shortcut_drag_leave (GtkWidget      *widget,
                             GdkDragContext *context,
                             guint           timestamp)
@@ -983,6 +1053,8 @@ thunar_shortcut_drag_motion (GtkWidget      *widget,
   /* abort if the target is unsupported */
   if (target != gdk_atom_intern_static_string ("text/uri-list"))
     {
+      g_debug ("shortcut drag motion: not a URI list");
+
       /* unsupported target, can't handle it, sorry */
       return FALSE;
     }


More information about the Xfce4-commits mailing list