[gimp] app: Introduce gimp_dialog_factory_set_put_in_dockables()



commit deb07e812dd8eddf84a1cd7e636e8588a7368bef
Author: Martin Nordholts <martinn src gnome org>
Date:   Sat Jan 16 17:54:56 2010 +0100

    app: Introduce gimp_dialog_factory_set_put_in_dockables()
    
    Change gimp_dialog_factory_set_constructor() to
    gimp_dialog_factory_set_put_in_dockables() order to narrow the
    interface a bit. We can make both
    gimp_dialog_factory_set_put_in_dockables() and the
    GimpDialogConstructor typedef internal this way.
    
    The main reason we do this is because we want to get rid of a
    dependency on factory->p->new_dock_func. Eventually we want to
    construct docks just like we construct other widgets in the factory,
    so new_dock_func will be removed.
    
    Also improve readability of code such as making it explicit that
    gimp_dialog_factory_put_in_dockable_constructor() is just an extended
    version of gimp_dialog_factory_default_constructor().

 app/dialogs/dialogs-constructors.c |   29 ------------
 app/dialogs/dialogs-constructors.h |    5 --
 app/dialogs/dialogs.c              |    6 +--
 app/widgets/gimpdialogfactory.c    |   83 +++++++++++++++++++++++++++++------
 app/widgets/gimpdialogfactory.h    |    8 +---
 5 files changed, 72 insertions(+), 59 deletions(-)
---
diff --git a/app/dialogs/dialogs-constructors.c b/app/dialogs/dialogs-constructors.c
index fc85926..2305fc1 100644
--- a/app/dialogs/dialogs-constructors.c
+++ b/app/dialogs/dialogs-constructors.c
@@ -266,35 +266,6 @@ dialogs_dock_window_new (GimpDialogFactory *factory,
 /*  dockables  */
 /***************/
 
-/*****  the dockable constructor  *****/
-
-GtkWidget *
-dialogs_dockable_constructor (GimpDialogFactory      *factory,
-                              GimpDialogFactoryEntry *entry,
-                              GimpContext            *context,
-                              gint                    view_size)
-{
-  GtkWidget *dockable = NULL;
-  GtkWidget *widget;
-
-  widget = entry->new_func (factory, context, view_size);
-
-  if (widget)
-    {
-      dockable = gimp_dockable_new (entry->name, entry->blurb,
-                                    entry->stock_id, entry->help_id);
-      gtk_container_add (GTK_CONTAINER (dockable), widget);
-      gtk_widget_show (widget);
-
-      /* EEK */
-      g_object_set_data (G_OBJECT (dockable), "gimp-dialog-identifier",
-                         entry->identifier);
-    }
-
-  return dockable;
-}
-
-
 /*****  singleton dialogs  *****/
 
 GtkWidget *
diff --git a/app/dialogs/dialogs-constructors.h b/app/dialogs/dialogs-constructors.h
index e9d0c9d..1b757a1 100644
--- a/app/dialogs/dialogs-constructors.h
+++ b/app/dialogs/dialogs-constructors.h
@@ -84,11 +84,6 @@ GtkWidget * dialogs_dock_window_new        (GimpDialogFactory *factory,
 
 /*  dockables  */
 
-GtkWidget * dialogs_dockable_constructor   (GimpDialogFactory      *factory,
-                                            GimpDialogFactoryEntry *entry,
-                                            GimpContext            *context,
-                                            gint                    view_size);
-
 GtkWidget * dialogs_tool_options_new       (GimpDialogFactory *factory,
                                             GimpContext       *context,
                                             gint               view_size);
diff --git a/app/dialogs/dialogs.c b/app/dialogs/dialogs.c
index c7125c7..490a09a 100644
--- a/app/dialogs/dialogs.c
+++ b/app/dialogs/dialogs.c
@@ -328,8 +328,7 @@ dialogs_init (Gimp            *gimp,
                                                     menu_factory,
                                                     dialogs_toolbox_new,
                                                     TRUE);
-  gimp_dialog_factory_set_constructor (global_toolbox_factory,
-                                       dialogs_dockable_constructor);
+  gimp_dialog_factory_set_put_in_dockables (global_toolbox_factory, TRUE);
   gimp_dialog_factory_set_dock_window_func (global_toolbox_factory,
                                             dialogs_toolbox_dock_window_new);
 
@@ -339,8 +338,7 @@ dialogs_init (Gimp            *gimp,
                                                         menu_factory,
                                                         dialogs_dock_new,
                                                         TRUE);
-  gimp_dialog_factory_set_constructor (global_dock_window_factory,
-                                       dialogs_dockable_constructor);
+  gimp_dialog_factory_set_put_in_dockables (global_dock_window_factory, TRUE);
   gimp_dialog_factory_set_dock_window_func (global_dock_window_factory,
                                             dialogs_dock_window_new);
 
diff --git a/app/widgets/gimpdialogfactory.c b/app/widgets/gimpdialogfactory.c
index a8a00da..3d4ac1d 100644
--- a/app/widgets/gimpdialogfactory.c
+++ b/app/widgets/gimpdialogfactory.c
@@ -59,6 +59,10 @@ enum
   LAST_SIGNAL
 };
 
+typedef GtkWidget * (* GimpDialogConstructor) (GimpDialogFactory      *factory,
+                                               GimpDialogFactoryEntry *entry,
+                                               GimpContext            *context,
+                                               gint                    view_size);
 
 struct _GimpDialogFactoryPrivate
 {
@@ -84,6 +88,11 @@ static GtkWidget * gimp_dialog_factory_default_constructor  (GimpDialogFactory
                                                              GimpDialogFactoryEntry *entry,
                                                              GimpContext            *context,
                                                              gint                    view_size);
+static GtkWidget * gimp_dialog_factory_put_in_dockable_constructor
+                                                            (GimpDialogFactory      *factory,
+                                                             GimpDialogFactoryEntry *entry,
+                                                             GimpContext            *context,
+                                                             gint                    view_size);
 static void        gimp_dialog_factory_set_widget_data      (GtkWidget              *dialog,
                                                              GimpDialogFactory      *factory,
                                                              GimpDialogFactoryEntry *entry);
@@ -319,15 +328,14 @@ gimp_dialog_factory_from_name (const gchar *name)
 }
 
 void
-gimp_dialog_factory_set_constructor (GimpDialogFactory     *factory,
-                                     GimpDialogConstructor  constructor)
+gimp_dialog_factory_set_put_in_dockables (GimpDialogFactory *factory,
+                                          gboolean           put_in_dockables)
 {
   g_return_if_fail (GIMP_IS_DIALOG_FACTORY (factory));
 
-  if (! constructor)
-    constructor = gimp_dialog_factory_default_constructor;
-
-  factory->p->constructor = constructor;
+  factory->p->constructor = (put_in_dockables ?
+                             gimp_dialog_factory_put_in_dockable_constructor :
+                             gimp_dialog_factory_default_constructor);
 }
 
 void
@@ -502,18 +510,23 @@ gimp_dialog_factory_dialog_new_internal (GimpDialogFactory *factory,
   /*  create the dialog if it was not found  */
   if (! dialog)
     {
-      GtkWidget *dock = NULL;
-
-      /*  If the dialog will be a dockable (factory->p->new_dock_func) and
-       *  we are called from gimp_dialog_factory_dialog_raise() (! context),
-       *  create a new dock _before_ creating the dialog.
-       *  We do this because the new dockable needs to be created in it's
-       *  dock's context.
-       */
-      if (factory->p->new_dock_func && ! context)
+      GtkWidget *dock                    = NULL;
+      gboolean   dialog_will_be_dockable = FALSE;
+      gboolean   called_from_raise       = FALSE;
+
+      dialog_will_be_dockable = (factory->p->constructor ==
+                                 gimp_dialog_factory_put_in_dockable_constructor);
+      called_from_raise       = (context == NULL);
+                                 
+      if (dialog_will_be_dockable && called_from_raise)
         {
           GtkWidget *dockbook;
 
+          /*  It doesn't make sense to have a dockable without a dock
+           *  so create one. Create a new dock _before_ creating the
+           *  dialog. We do this because the new dockable needs to be
+           *  created in its dock's context.
+           */
           dock     = gimp_dialog_factory_dock_with_window_new (factory, screen);
           dockbook = gimp_dockbook_new (factory->p->menu_factory);
 
@@ -1391,6 +1404,46 @@ gimp_dialog_factory_default_constructor (GimpDialogFactory      *factory,
   return entry->new_func (factory, context, view_size);
 }
 
+/**
+ * gimp_dialog_factory_put_in_dockable_constructor:
+ * @factory:
+ * @entry:
+ * @context:
+ * @view_size:
+ *
+ * Put the created widget inside a #GimpDockable.
+ *
+ * Returns:
+ **/
+static GtkWidget *
+gimp_dialog_factory_put_in_dockable_constructor (GimpDialogFactory      *factory,
+                                                 GimpDialogFactoryEntry *entry,
+                                                 GimpContext            *context,
+                                                 gint                    view_size)
+{
+  GtkWidget *dockable = NULL;
+  GtkWidget *widget;
+
+  widget = gimp_dialog_factory_default_constructor (factory,
+                                                    entry,
+                                                    context,
+                                                    view_size);
+
+  if (widget)
+    {
+      dockable = gimp_dockable_new (entry->name, entry->blurb,
+                                    entry->stock_id, entry->help_id);
+      gtk_container_add (GTK_CONTAINER (dockable), widget);
+      gtk_widget_show (widget);
+
+      /* EEK */
+      g_object_set_data (G_OBJECT (dockable), "gimp-dialog-identifier",
+                         entry->identifier);
+    }
+
+  return dockable;
+}
+
 static void
 gimp_dialog_factory_set_widget_data (GtkWidget               *dialog,
                                      GimpDialogFactory       *factory,
diff --git a/app/widgets/gimpdialogfactory.h b/app/widgets/gimpdialogfactory.h
index 4af49fc..bc3f65d 100644
--- a/app/widgets/gimpdialogfactory.h
+++ b/app/widgets/gimpdialogfactory.h
@@ -40,10 +40,6 @@ typedef GtkWidget * (* GimpDialogNewFunc)     (GimpDialogFactory      *factory,
 typedef GtkWidget * (* GimpDialogNewDockFunc) (GimpDialogFactory      *factory,
                                                GimpContext            *context,
                                                GimpUIManager          *ui_manager);
-typedef GtkWidget * (* GimpDialogConstructor) (GimpDialogFactory      *factory,
-                                               GimpDialogFactoryEntry *entry,
-                                               GimpContext            *context,
-                                               gint                    view_size);
 
 
 struct _GimpDialogFactoryEntry
@@ -114,8 +110,8 @@ GimpDialogFactory * gimp_dialog_factory_new                  (const gchar
                                                               GimpDialogNewDockFunc    new_dock_func,
                                                               gboolean                 toggle_visibility);
 GimpDialogFactory * gimp_dialog_factory_from_name            (const gchar             *name);
-void                gimp_dialog_factory_set_constructor      (GimpDialogFactory       *factory,
-                                                              GimpDialogConstructor    constructor);
+void                gimp_dialog_factory_set_put_in_dockables (GimpDialogFactory       *factory,
+                                                              gboolean                 put_in_dockables);
 void                gimp_dialog_factory_set_dock_window_func (GimpDialogFactory       *factory,
                                                               GimpDialogNewFunc        new_dock_window_func);
 void                gimp_dialog_factory_register_entry       (GimpDialogFactory       *factory,



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