[gimp] app: Add and use gimp_dockbook_drag_source_to_dockable()



commit d3bb3e7f9943e02d114e87cc250d665d139415c9
Author: Martin Nordholts <martinn src gnome org>
Date:   Sun Oct 25 23:02:05 2009 +0100

    app: Add and use gimp_dockbook_drag_source_to_dockable()

 app/widgets/gimpdock.c     |   10 +--------
 app/widgets/gimpdockbook.c |   48 ++++++++++++++++++++++++++-----------------
 app/widgets/gimpdockbook.h |   36 ++++++++++++++------------------
 3 files changed, 46 insertions(+), 48 deletions(-)
---
diff --git a/app/widgets/gimpdock.c b/app/widgets/gimpdock.c
index 05b8dee..5ec1f21 100644
--- a/app/widgets/gimpdock.c
+++ b/app/widgets/gimpdock.c
@@ -297,21 +297,13 @@ gimp_dock_dropped_cb (GimpDockSeparator *separator,
                       gpointer           data)
 {
   GimpDock     *dock     = GIMP_DOCK (data);
-  GimpDockable *dockable = NULL;
+  GimpDockable *dockable = gimp_dockbook_drag_source_to_dockable (source);
   GtkWidget    *dockbook = NULL;
   gint          index    = gimp_dock_separator_get_insert_pos (separator);
 
-  if (GIMP_IS_DOCKABLE (source))
-    dockable = GIMP_DOCKABLE (source);
-  else
-    dockable = g_object_get_data (G_OBJECT (source), "gimp-dockable");
-
   if (!dockable )
     return FALSE;
 
-  g_object_set_data (G_OBJECT (dockable),
-                     "gimp-dock-drag-widget", NULL);
-
   /*  if dropping to the same dock, take care that we don't try
    *  to reorder the *only* dockable in the dock
    */
diff --git a/app/widgets/gimpdockbook.c b/app/widgets/gimpdockbook.c
index 5a6df48..e38cd04 100644
--- a/app/widgets/gimpdockbook.c
+++ b/app/widgets/gimpdockbook.c
@@ -581,19 +581,11 @@ gimp_dockbook_drop_dockable (GimpDockbook *dockbook,
 
   if (drag_source)
     {
-      GimpDockable *dockable;
-
-      if (GIMP_IS_DOCKABLE (drag_source))
-        dockable = GIMP_DOCKABLE (drag_source);
-      else
-        dockable = (GimpDockable *) g_object_get_data (G_OBJECT (drag_source),
-                                                       "gimp-dockable");
+      GimpDockable *dockable =
+        gimp_dockbook_drag_source_to_dockable (drag_source);
 
       if (dockable)
         {
-          g_object_set_data (G_OBJECT (dockable),
-                             "gimp-dock-drag-widget", NULL);
-
           if (dockable->dockbook == dockbook)
             {
               gtk_notebook_reorder_child (GTK_NOTEBOOK (dockbook),
@@ -616,6 +608,31 @@ gimp_dockbook_drop_dockable (GimpDockbook *dockbook,
   return FALSE;
 }
 
+/**
+ * gimp_dockbook_drag_source_to_dockable:
+ * @drag_source: A drag-and-drop source widget
+ *
+ * Gets the dockable associated with a drag-and-drop source. If
+ * successfull, the function will also cleanup the dockable.
+ *
+ * Returns: The dockable
+ **/
+GimpDockable *
+gimp_dockbook_drag_source_to_dockable (GtkWidget *drag_source)
+{
+  GimpDockable *dockable = NULL;
+
+  if (GIMP_IS_DOCKABLE (drag_source))
+    dockable = GIMP_DOCKABLE (drag_source);
+  else
+    dockable = g_object_get_data (G_OBJECT (drag_source),
+                                  "gimp-dockable");
+  if (dockable)
+    g_object_set_data (G_OBJECT (dockable),
+                       "gimp-dock-drag-widget", NULL);
+
+  return dockable;
+}
 
 /*  tab DND source side  */
 
@@ -798,12 +815,8 @@ gimp_dockbook_tab_drag_drop (GtkWidget      *widget,
 
   if (dest_dockable && source)
     {
-      GimpDockable *src_dockable;
-
-      if (GIMP_IS_DOCKABLE (source))
-        src_dockable = GIMP_DOCKABLE (source);
-      else
-        src_dockable = g_object_get_data (G_OBJECT (source), "gimp-dockable");
+      GimpDockable *src_dockable =
+        gimp_dockbook_drag_source_to_dockable (source);
 
       if (src_dockable)
         {
@@ -813,9 +826,6 @@ gimp_dockbook_tab_drag_drop (GtkWidget      *widget,
             gtk_notebook_page_num (GTK_NOTEBOOK (dest_dockable->dockbook),
                                    GTK_WIDGET (dest_dockable));
 
-          g_object_set_data (G_OBJECT (src_dockable),
-                             "gimp-dock-drag-widget", NULL);
-
           if (src_dockable->dockbook != dest_dockable->dockbook)
             {
               g_object_ref (src_dockable);
diff --git a/app/widgets/gimpdockbook.h b/app/widgets/gimpdockbook.h
index f1ad96a..77cccdf 100644
--- a/app/widgets/gimpdockbook.h
+++ b/app/widgets/gimpdockbook.h
@@ -59,26 +59,22 @@ struct _GimpDockbookClass
 };
 
 
-GType       gimp_dockbook_get_type          (void) G_GNUC_CONST;
-
-GtkWidget * gimp_dockbook_new               (GimpMenuFactory  *menu_factory);
-
-GimpDock  * gimp_dockbook_get_dock          (GimpDockbook     *dockbook);
-void        gimp_dockbook_set_dock          (GimpDockbook     *dockbook,
-                                             GimpDock         *dock);
-GimpUIManager *
-            gimp_dockbook_get_ui_manager    (GimpDockbook     *dockbook);
-
-void        gimp_dockbook_add               (GimpDockbook     *dockbook,
-                                             GimpDockable     *dockable,
-                                             gint              position);
-void        gimp_dockbook_remove            (GimpDockbook     *dockbook,
-                                             GimpDockable     *dockable);
-
-GtkWidget * gimp_dockbook_create_tab_widget (GimpDockbook     *dockbook,
-                                             GimpDockable     *dockable);
-gboolean    gimp_dockbook_drop_dockable     (GimpDockbook     *dockbook,
-                                             GtkWidget        *drag_source);
+GType           gimp_dockbook_get_type                  (void) G_GNUC_CONST;
+GtkWidget     * gimp_dockbook_new                       (GimpMenuFactory *menu_factory);
+GimpDock      * gimp_dockbook_get_dock                  (GimpDockbook    *dockbook);
+void            gimp_dockbook_set_dock                  (GimpDockbook    *dockbook,
+                                                         GimpDock        *dock);
+GimpUIManager * gimp_dockbook_get_ui_manager            (GimpDockbook    *dockbook);
+void            gimp_dockbook_add                       (GimpDockbook    *dockbook,
+                                                         GimpDockable    *dockable,
+                                                         gint             position);
+void            gimp_dockbook_remove                    (GimpDockbook    *dockbook,
+                                                         GimpDockable    *dockable);
+GtkWidget    *  gimp_dockbook_create_tab_widget         (GimpDockbook    *dockbook,
+                                                         GimpDockable    *dockable);
+gboolean        gimp_dockbook_drop_dockable             (GimpDockbook    *dockbook,
+                                                         GtkWidget       *drag_source);
+GimpDockable *  gimp_dockbook_drag_source_to_dockable   (GtkWidget       *drag_source);
 
 
 #endif /* __GIMP_DOCKBOOK_H__ */



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