[gimp] app: pull some GEGL operation logic from subclasses into GimpImageMapTool



commit 9bb4c3d4841b9704b68d158edf5995ef59cb620b
Author: Michael Natterer <mitch gimp org>
Date:   Tue Apr 16 22:06:48 2013 +0200

    app: pull some GEGL operation logic from subclasses into GimpImageMapTool
    
    - connect to the config object's notify generically and update the preview
    - allow to properly exchange the operation at runtime to remove major
      uglyness from GimpOperationTool
    - return undo_desc from GimpImageMapTool::get_operation() so we have
      proper strings in the undo history, not always "GEGL operation"
    - simplify all get_operation() implementations

 app/tools/gimpbrightnesscontrasttool.c |  24 +++-----
 app/tools/gimpcolorbalancetool.c       |  24 +++-----
 app/tools/gimpcolorizetool.c           |  24 +++-----
 app/tools/gimpcurvestool.c             |  24 +++-----
 app/tools/gimpdesaturatetool.c         |  24 +++-----
 app/tools/gimphuesaturationtool.c      |  24 +++-----
 app/tools/gimpimagemaptool.c           | 105 +++++++++++++++++++++++++--------
 app/tools/gimpimagemaptool.h           |  18 +++---
 app/tools/gimplevelstool.c             |  24 +++-----
 app/tools/gimpoperationtool.c          |  64 +++++++-------------
 app/tools/gimpposterizetool.c          |  24 +++-----
 app/tools/gimpthresholdtool.c          |  24 +++-----
 12 files changed, 190 insertions(+), 213 deletions(-)
---
diff --git a/app/tools/gimpbrightnesscontrasttool.c b/app/tools/gimpbrightnesscontrasttool.c
index ab4d7ee..55a6c11 100644
--- a/app/tools/gimpbrightnesscontrasttool.c
+++ b/app/tools/gimpbrightnesscontrasttool.c
@@ -72,7 +72,8 @@ static void   gimp_brightness_contrast_tool_motion         (GimpTool
 
 static GeglNode *
               gimp_brightness_contrast_tool_get_operation  (GimpImageMapTool      *image_map_tool,
-                                                            GObject              **config);
+                                                            GObject              **config,
+                                                            gchar                **undo_desc);
 static void   gimp_brightness_contrast_tool_dialog         (GimpImageMapTool      *image_map_tool);
 
 static void   brightness_contrast_config_notify            (GObject                    *object,
@@ -154,28 +155,23 @@ gimp_brightness_contrast_tool_initialize (GimpTool     *tool,
 
 static GeglNode *
 gimp_brightness_contrast_tool_get_operation (GimpImageMapTool  *im_tool,
-                                             GObject          **config)
+                                             GObject          **config,
+                                             gchar            **undo_desc)
 {
   GimpBrightnessContrastTool *bc_tool = GIMP_BRIGHTNESS_CONTRAST_TOOL (im_tool);
-  GeglNode                   *node;
-
-  node = g_object_new (GEGL_TYPE_NODE,
-                       "operation", "gimp:brightness-contrast",
-                       NULL);
 
   bc_tool->config = g_object_new (GIMP_TYPE_BRIGHTNESS_CONTRAST_CONFIG, NULL);
 
-  *config = G_OBJECT (bc_tool->config);
-
   g_signal_connect_object (bc_tool->config, "notify",
                            G_CALLBACK (brightness_contrast_config_notify),
                            G_OBJECT (bc_tool), 0);
 
-  gegl_node_set (node,
-                 "config", bc_tool->config,
-                 NULL);
+  *config = G_OBJECT (bc_tool->config);
 
-  return node;
+  return gegl_node_new_child (NULL,
+                              "operation", "gimp:brightness-contrast",
+                              "config",    bc_tool->config,
+                              NULL);
 }
 
 static void
@@ -322,8 +318,6 @@ brightness_contrast_config_notify (GObject                    *object,
       gtk_adjustment_set_value (bc_tool->contrast_data,
                                 config->contrast * 127.0);
     }
-
-  gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (bc_tool));
 }
 
 static void
diff --git a/app/tools/gimpcolorbalancetool.c b/app/tools/gimpcolorbalancetool.c
index a9668d0..7d97990 100644
--- a/app/tools/gimpcolorbalancetool.c
+++ b/app/tools/gimpcolorbalancetool.c
@@ -50,7 +50,8 @@ static gboolean   gimp_color_balance_tool_initialize    (GimpTool         *tool,
                                                          GError          **error);
 
 static GeglNode * gimp_color_balance_tool_get_operation (GimpImageMapTool *im_tool,
-                                                         GObject         **config);
+                                                         GObject         **config,
+                                                         gchar           **undo_desc);
 static void       gimp_color_balance_tool_dialog        (GimpImageMapTool *im_tool);
 static void       gimp_color_balance_tool_reset         (GimpImageMapTool *im_tool);
 
@@ -143,28 +144,23 @@ gimp_color_balance_tool_initialize (GimpTool     *tool,
 
 static GeglNode *
 gimp_color_balance_tool_get_operation (GimpImageMapTool  *im_tool,
-                                       GObject          **config)
+                                       GObject          **config,
+                                       gchar            **undo_desc)
 {
   GimpColorBalanceTool *cb_tool = GIMP_COLOR_BALANCE_TOOL (im_tool);
-  GeglNode             *node;
-
-  node = g_object_new (GEGL_TYPE_NODE,
-                       "operation", "gimp:color-balance",
-                       NULL);
 
   cb_tool->config = g_object_new (GIMP_TYPE_COLOR_BALANCE_CONFIG, NULL);
 
-  *config = G_OBJECT (cb_tool->config);
-
   g_signal_connect_object (cb_tool->config, "notify",
                            G_CALLBACK (color_balance_config_notify),
                            G_OBJECT (cb_tool), 0);
 
-  gegl_node_set (node,
-                 "config", cb_tool->config,
-                 NULL);
+  *config = G_OBJECT (cb_tool->config);
 
-  return node;
+  return gegl_node_new_child (NULL,
+                              "operation", "gimp:color-balance",
+                              "config",    cb_tool->config,
+                              NULL);
 }
 
 
@@ -365,8 +361,6 @@ color_balance_config_notify (GObject              *object,
       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cb_tool->preserve_toggle),
                                     config->preserve_luminosity);
     }
-
-  gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (cb_tool));
 }
 
 static void
diff --git a/app/tools/gimpcolorizetool.c b/app/tools/gimpcolorizetool.c
index 70e0a0f..d4b6d62 100644
--- a/app/tools/gimpcolorizetool.c
+++ b/app/tools/gimpcolorizetool.c
@@ -55,7 +55,8 @@ static gboolean   gimp_colorize_tool_initialize    (GimpTool         *tool,
                                                     GError          **error);
 
 static GeglNode * gimp_colorize_tool_get_operation (GimpImageMapTool *im_tool,
-                                                    GObject         **config);
+                                                    GObject         **config,
+                                                    gchar           **undo_desc);
 static void       gimp_colorize_tool_dialog        (GimpImageMapTool *im_tool);
 static void       gimp_colorize_tool_color_picked  (GimpImageMapTool *im_tool,
                                                     gpointer          identifier,
@@ -154,28 +155,23 @@ gimp_colorize_tool_initialize (GimpTool     *tool,
 
 static GeglNode *
 gimp_colorize_tool_get_operation (GimpImageMapTool  *im_tool,
-                                  GObject          **config)
+                                  GObject          **config,
+                                  gchar            **undo_desc)
 {
   GimpColorizeTool *col_tool = GIMP_COLORIZE_TOOL (im_tool);
-  GeglNode         *node;
-
-  node = g_object_new (GEGL_TYPE_NODE,
-                       "operation", "gimp:colorize",
-                       NULL);
 
   col_tool->config = g_object_new (GIMP_TYPE_COLORIZE_CONFIG, NULL);
 
-  *config = G_OBJECT (col_tool->config);
-
   g_signal_connect_object (col_tool->config, "notify",
                            G_CALLBACK (gimp_colorize_tool_config_notify),
                            G_OBJECT (col_tool), 0);
 
-  gegl_node_set (node,
-                 "config", col_tool->config,
-                 NULL);
+  *config = G_OBJECT (col_tool->config);
 
-  return node;
+  return gegl_node_new_child (NULL,
+                              "operation", "gimp:colorize",
+                              "config",    col_tool->config,
+                              NULL);
 }
 
 
@@ -323,8 +319,6 @@ gimp_colorize_tool_config_notify (GObject          *object,
   gimp_colorize_config_get_color (col_tool->config, &color);
   gimp_color_button_set_color (GIMP_COLOR_BUTTON (col_tool->color_button),
                                &color);
-
-  gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (col_tool));
 }
 
 static void
diff --git a/app/tools/gimpcurvestool.c b/app/tools/gimpcurvestool.c
index 90c1d1a..20aed9c 100644
--- a/app/tools/gimpcurvestool.c
+++ b/app/tools/gimpcurvestool.c
@@ -86,7 +86,8 @@ static void       gimp_curves_tool_color_picked   (GimpColorTool        *color_t
                                                    const GimpRGB        *color,
                                                    gint                  color_index);
 static GeglNode * gimp_curves_tool_get_operation  (GimpImageMapTool     *image_map_tool,
-                                                   GObject             **config);
+                                                   GObject             **config,
+                                                   gchar               **undo_desc);
 static void       gimp_curves_tool_dialog         (GimpImageMapTool     *image_map_tool);
 static void       gimp_curves_tool_reset          (GimpImageMapTool     *image_map_tool);
 static gboolean   gimp_curves_tool_settings_import(GimpImageMapTool     *image_map_tool,
@@ -351,28 +352,23 @@ gimp_curves_tool_color_picked (GimpColorTool      *color_tool,
 
 static GeglNode *
 gimp_curves_tool_get_operation (GimpImageMapTool  *image_map_tool,
-                                GObject          **config)
+                                GObject          **config,
+                                gchar            **undo_desc)
 {
   GimpCurvesTool *tool = GIMP_CURVES_TOOL (image_map_tool);
-  GeglNode       *node;
-
-  node = g_object_new (GEGL_TYPE_NODE,
-                       "operation", "gimp:curves",
-                       NULL);
 
   tool->config = g_object_new (GIMP_TYPE_CURVES_CONFIG, NULL);
 
-  *config = G_OBJECT (tool->config);
-
   g_signal_connect_object (tool->config, "notify",
                            G_CALLBACK (gimp_curves_tool_config_notify),
                            tool, 0);
 
-  gegl_node_set (node,
-                 "config", tool->config,
-                 NULL);
+  *config = G_OBJECT (tool->config);
 
-  return node;
+  return gegl_node_new_child (NULL,
+                              "operation", "gimp:curves",
+                              "config",    tool->config,
+                              NULL);
 }
 
 
@@ -773,8 +769,6 @@ gimp_curves_tool_config_notify (GObject        *object,
       gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (tool->curve_type),
                                      curve->curve_type);
     }
-
-  gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (tool));
 }
 
 static void
diff --git a/app/tools/gimpdesaturatetool.c b/app/tools/gimpdesaturatetool.c
index e574d5b..99bc83c 100644
--- a/app/tools/gimpdesaturatetool.c
+++ b/app/tools/gimpdesaturatetool.c
@@ -47,7 +47,8 @@ static gboolean   gimp_desaturate_tool_initialize    (GimpTool           *tool,
                                                       GError            **error);
 
 static GeglNode * gimp_desaturate_tool_get_operation (GimpImageMapTool   *im_tool,
-                                                      GObject           **config);
+                                                      GObject           **config,
+                                                      gchar             **undo_desc);
 static void       gimp_desaturate_tool_dialog        (GimpImageMapTool   *im_tool);
 
 static void       gimp_desaturate_tool_config_notify (GObject            *object,
@@ -134,28 +135,23 @@ gimp_desaturate_tool_initialize (GimpTool     *tool,
 
 static GeglNode *
 gimp_desaturate_tool_get_operation (GimpImageMapTool  *image_map_tool,
-                                    GObject          **config)
+                                    GObject          **config,
+                                    gchar            **undo_desc)
 {
   GimpDesaturateTool *desaturate_tool = GIMP_DESATURATE_TOOL (image_map_tool);
-  GeglNode           *node;
-
-  node = g_object_new (GEGL_TYPE_NODE,
-                       "operation", "gimp:desaturate",
-                       NULL);
 
   desaturate_tool->config = g_object_new (GIMP_TYPE_DESATURATE_CONFIG, NULL);
 
-  *config = G_OBJECT (desaturate_tool->config);
-
   g_signal_connect_object (desaturate_tool->config, "notify",
                            G_CALLBACK (gimp_desaturate_tool_config_notify),
                            G_OBJECT (desaturate_tool), 0);
 
-  gegl_node_set (node,
-                 "config", desaturate_tool->config,
-                 NULL);
+  *config = G_OBJECT (desaturate_tool->config);
 
-  return node;
+  return gegl_node_new_child (NULL,
+                              "operation", "gimp:desaturate",
+                              "config",    desaturate_tool->config,
+                              NULL);
 }
 
 
@@ -195,8 +191,6 @@ gimp_desaturate_tool_config_notify (GObject            *object,
 
   gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (desaturate_tool->button),
                                    config->mode);
-
-  gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (desaturate_tool));
 }
 
 static void
diff --git a/app/tools/gimphuesaturationtool.c b/app/tools/gimphuesaturationtool.c
index c3c5ae1..dd81c06 100644
--- a/app/tools/gimphuesaturationtool.c
+++ b/app/tools/gimphuesaturationtool.c
@@ -56,7 +56,8 @@ static gboolean   gimp_hue_saturation_tool_initialize    (GimpTool         *tool
                                                           GError          **error);
 
 static GeglNode * gimp_hue_saturation_tool_get_operation (GimpImageMapTool *im_tool,
-                                                          GObject         **config);
+                                                          GObject         **config,
+                                                          gchar           **undo_desc);
 static void       gimp_hue_saturation_tool_dialog        (GimpImageMapTool *im_tool);
 static void       gimp_hue_saturation_tool_reset         (GimpImageMapTool *im_tool);
 
@@ -151,28 +152,23 @@ gimp_hue_saturation_tool_initialize (GimpTool     *tool,
 
 static GeglNode *
 gimp_hue_saturation_tool_get_operation (GimpImageMapTool  *im_tool,
-                                        GObject          **config)
+                                        GObject          **config,
+                                        gchar            **undo_desc)
 {
   GimpHueSaturationTool *hs_tool = GIMP_HUE_SATURATION_TOOL (im_tool);
-  GeglNode              *node;
-
-  node = g_object_new (GEGL_TYPE_NODE,
-                       "operation", "gimp:hue-saturation",
-                       NULL);
 
   hs_tool->config = g_object_new (GIMP_TYPE_HUE_SATURATION_CONFIG, NULL);
 
-  *config = G_OBJECT (hs_tool->config);
-
   g_signal_connect_object (hs_tool->config, "notify",
                            G_CALLBACK (hue_saturation_config_notify),
                            G_OBJECT (hs_tool), 0);
 
-  gegl_node_set (node,
-                 "config", hs_tool->config,
-                 NULL);
+  *config = G_OBJECT (hs_tool->config);
 
-  return node;
+  return gegl_node_new_child (NULL,
+                              "operation", "gimp:hue-saturation",
+                              "config",    hs_tool->config,
+                              NULL);
 }
 
 
@@ -470,8 +466,6 @@ hue_saturation_config_notify (GObject               *object,
     }
 
   hue_saturation_update_color_areas (hs_tool);
-
-  gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (hs_tool));
 }
 
 static void
diff --git a/app/tools/gimpimagemaptool.c b/app/tools/gimpimagemaptool.c
index d368794..d47fd08 100644
--- a/app/tools/gimpimagemaptool.c
+++ b/app/tools/gimpimagemaptool.c
@@ -111,9 +111,13 @@ static void      gimp_image_map_tool_dialog         (GimpImageMapTool *im_tool);
 static void      gimp_image_map_tool_dialog_unmap   (GtkWidget        *dialog,
                                                      GimpImageMapTool *im_tool);
 static void      gimp_image_map_tool_reset          (GimpImageMapTool *im_tool);
+static void      gimp_image_map_tool_create_map     (GimpImageMapTool *im_tool);
 
 static void      gimp_image_map_tool_flush          (GimpImageMap     *image_map,
                                                      GimpImageMapTool *im_tool);
+static void      gimp_image_map_tool_config_notify  (GObject          *object,
+                                                     const GParamSpec *pspec,
+                                                     GimpImageMapTool *im_tool);
 
 static void      gimp_image_map_tool_response       (GtkWidget        *widget,
                                                      gint              response_id,
@@ -210,32 +214,16 @@ gimp_image_map_tool_init (GimpImageMapTool *image_map_tool)
                                      GIMP_DIRTY_DRAWABLE        |
                                      GIMP_DIRTY_SELECTION       |
                                      GIMP_DIRTY_ACTIVE_DRAWABLE);
-
-  image_map_tool->drawable       = NULL;
-  image_map_tool->operation      = NULL;
-  image_map_tool->config         = NULL;
-  image_map_tool->default_config = NULL;
-  image_map_tool->image_map      = NULL;
-
-  image_map_tool->dialog         = NULL;
-  image_map_tool->main_vbox      = NULL;
-  image_map_tool->settings_box   = NULL;
-  image_map_tool->label_group    = NULL;
 }
 
 static void
 gimp_image_map_tool_constructed (GObject *object)
 {
-  GimpImageMapTool      *image_map_tool = GIMP_IMAGE_MAP_TOOL (object);
-  GimpImageMapToolClass *klass;
+  GimpImageMapTool *image_map_tool = GIMP_IMAGE_MAP_TOOL (object);
 
   G_OBJECT_CLASS (parent_class)->constructed (object);
 
-  klass = GIMP_IMAGE_MAP_TOOL_GET_CLASS (image_map_tool);
-
-  if (klass->get_operation)
-    image_map_tool->operation = klass->get_operation (image_map_tool,
-                                                      &image_map_tool->config);
+  gimp_image_map_tool_get_operation (image_map_tool);
 }
 
 static void
@@ -261,6 +249,12 @@ gimp_image_map_tool_finalize (GObject *object)
       image_map_tool->default_config = NULL;
     }
 
+  if (image_map_tool->undo_desc)
+    {
+      g_free (image_map_tool->undo_desc);
+      image_map_tool->undo_desc = NULL;
+    }
+
   if (image_map_tool->dialog)
     gimp_image_map_tool_dialog_destroy (image_map_tool);
 
@@ -429,7 +423,7 @@ gimp_image_map_tool_initialize (GimpTool     *tool,
 
   image_map_tool->drawable = drawable;
 
-  gimp_image_map_tool_create_map (image_map_tool, NULL);
+  gimp_image_map_tool_create_map (image_map_tool);
 
   return TRUE;
 }
@@ -651,9 +645,8 @@ gimp_image_map_tool_reset (GimpImageMapTool *tool)
     }
 }
 
-void
-gimp_image_map_tool_create_map (GimpImageMapTool *tool,
-                                const gchar      *undo_desc)
+static void
+gimp_image_map_tool_create_map (GimpImageMapTool *tool)
 {
   GimpToolInfo *tool_info;
 
@@ -669,11 +662,8 @@ gimp_image_map_tool_create_map (GimpImageMapTool *tool,
 
   tool_info = GIMP_TOOL (tool)->tool_info;
 
-  if (! undo_desc)
-    undo_desc = tool_info->blurb;
-
   tool->image_map = gimp_image_map_new (tool->drawable,
-                                        undo_desc,
+                                        tool->undo_desc,
                                         tool->operation,
                                         gimp_viewable_get_stock_id (GIMP_VIEWABLE (tool_info)));
 
@@ -693,6 +683,14 @@ gimp_image_map_tool_flush (GimpImageMap     *image_map,
 }
 
 static void
+gimp_image_map_tool_config_notify (GObject          *object,
+                                   const GParamSpec *pspec,
+                                   GimpImageMapTool *image_map_tool)
+{
+  gimp_image_map_tool_preview (image_map_tool);
+}
+
+static void
 gimp_image_map_tool_response (GtkWidget        *widget,
                               gint              response_id,
                               GimpImageMapTool *image_map_tool)
@@ -780,6 +778,61 @@ gimp_image_map_tool_dialog_destroy (GimpImageMapTool *image_map_tool)
 }
 
 void
+gimp_image_map_tool_get_operation (GimpImageMapTool *image_map_tool)
+{
+  GimpImageMapToolClass *klass;
+
+  g_return_if_fail (GIMP_IS_IMAGE_MAP_TOOL (image_map_tool));
+
+  klass = GIMP_IMAGE_MAP_TOOL_GET_CLASS (image_map_tool);
+
+  if (image_map_tool->image_map)
+    {
+      gimp_image_map_abort (image_map_tool->image_map);
+      g_object_unref (image_map_tool->image_map);
+      image_map_tool->image_map = NULL;
+    }
+
+  if (image_map_tool->operation)
+    {
+      g_object_unref (image_map_tool->operation);
+      image_map_tool->operation = NULL;
+    }
+
+  if (image_map_tool->config)
+    {
+      g_signal_handlers_disconnect_by_func (image_map_tool->config,
+                                            gimp_image_map_tool_config_notify,
+                                            image_map_tool);
+
+      g_object_unref (image_map_tool->config);
+      image_map_tool->config = NULL;
+    }
+
+  if (image_map_tool->undo_desc)
+    {
+      g_free (image_map_tool->undo_desc);
+      image_map_tool->undo_desc = NULL;
+    }
+
+  image_map_tool->operation = klass->get_operation (image_map_tool,
+                                                    &image_map_tool->config,
+                                                    &image_map_tool->undo_desc);
+
+  if (! image_map_tool->undo_desc)
+    image_map_tool->undo_desc =
+      g_strdup (GIMP_TOOL (image_map_tool)->tool_info->blurb);
+
+  if (image_map_tool->config)
+    g_signal_connect_object (image_map_tool->config, "notify",
+                             G_CALLBACK (gimp_image_map_tool_config_notify),
+                             G_OBJECT (image_map_tool), 0);
+
+  if (GIMP_TOOL (image_map_tool)->drawable)
+    gimp_image_map_tool_create_map (image_map_tool);
+}
+
+void
 gimp_image_map_tool_preview (GimpImageMapTool *image_map_tool)
 {
   GimpTool            *tool;
diff --git a/app/tools/gimpimagemaptool.h b/app/tools/gimpimagemaptool.h
index 35efe7b..40bb29c 100644
--- a/app/tools/gimpimagemaptool.h
+++ b/app/tools/gimpimagemaptool.h
@@ -43,6 +43,7 @@ struct _GimpImageMapTool
   GeglNode              *operation;
   GObject               *config;
   GObject               *default_config;
+  gchar                 *undo_desc;
 
   GimpImageMap          *image_map;
 
@@ -68,7 +69,8 @@ struct _GimpImageMapToolClass
 
   /* virtual functions */
   GeglNode  * (* get_operation)   (GimpImageMapTool  *image_map_tool,
-                                   GObject          **config);
+                                   GObject          **config,
+                                   gchar            **undo_desc);
   void        (* map)             (GimpImageMapTool  *image_map_tool);
   void        (* dialog)          (GimpImageMapTool  *image_map_tool);
   void        (* reset)           (GimpImageMapTool  *image_map_tool);
@@ -96,17 +98,15 @@ struct _GimpImageMapToolClass
 };
 
 
-GType   gimp_image_map_tool_get_type   (void) G_GNUC_CONST;
+GType   gimp_image_map_tool_get_type      (void) G_GNUC_CONST;
 
-void    gimp_image_map_tool_preview    (GimpImageMapTool *image_map_tool);
+void    gimp_image_map_tool_preview       (GimpImageMapTool *image_map_tool);
 
-/* temp hack for the gegl tool */
-void    gimp_image_map_tool_create_map (GimpImageMapTool *image_map_tool,
-                                        const gchar      *undo_desc);
+void    gimp_image_map_tool_get_operation (GimpImageMapTool *image_map_tool);
 
-void    gimp_image_map_tool_edit_as    (GimpImageMapTool *image_map_tool,
-                                        const gchar      *new_tool_id,
-                                        GimpConfig       *config);
+void    gimp_image_map_tool_edit_as       (GimpImageMapTool *image_map_tool,
+                                           const gchar      *new_tool_id,
+                                           GimpConfig       *config);
 
 /* accessors for derived classes */
 GtkWidget    * gimp_image_map_tool_dialog_get_vbox        (GimpImageMapTool *tool);
diff --git a/app/tools/gimplevelstool.c b/app/tools/gimplevelstool.c
index 93aa994..525b701 100644
--- a/app/tools/gimplevelstool.c
+++ b/app/tools/gimplevelstool.c
@@ -74,7 +74,8 @@ static gboolean   gimp_levels_tool_initialize     (GimpTool          *tool,
                                                    GError           **error);
 
 static GeglNode * gimp_levels_tool_get_operation  (GimpImageMapTool  *im_tool,
-                                                   GObject          **config);
+                                                   GObject          **config,
+                                                   gchar            **undo_desc);
 static void       gimp_levels_tool_dialog         (GimpImageMapTool  *im_tool);
 static void       gimp_levels_tool_reset          (GimpImageMapTool  *im_tool);
 static gboolean   gimp_levels_tool_settings_import(GimpImageMapTool  *im_tool,
@@ -282,28 +283,23 @@ gimp_levels_tool_initialize (GimpTool     *tool,
 
 static GeglNode *
 gimp_levels_tool_get_operation (GimpImageMapTool  *im_tool,
-                                GObject          **config)
+                                GObject          **config,
+                                gchar            **undo_desc)
 {
   GimpLevelsTool *tool = GIMP_LEVELS_TOOL (im_tool);
-  GeglNode       *node;
-
-  node = g_object_new (GEGL_TYPE_NODE,
-                       "operation", "gimp:levels",
-                       NULL);
 
   tool->config = g_object_new (GIMP_TYPE_LEVELS_CONFIG, NULL);
 
-  *config = G_OBJECT (tool->config);
-
   g_signal_connect_object (tool->config, "notify",
                            G_CALLBACK (gimp_levels_tool_config_notify),
                            G_OBJECT (tool), 0);
 
-  gegl_node_set (node,
-                 "config", tool->config,
-                 NULL);
+  *config = G_OBJECT (tool->config);
 
-  return node;
+  return gegl_node_new_child (NULL,
+                              "operation", "gimp:levels",
+                              "config",    tool->config,
+                              NULL);
 }
 
 
@@ -896,8 +892,6 @@ gimp_levels_tool_config_notify (GObject        *object,
                                 config->high_output[config->channel] *
                                 scale_factor);
     }
-
-  gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (tool));
 }
 
 static void
diff --git a/app/tools/gimpoperationtool.c b/app/tools/gimpoperationtool.c
index d22bde6..259b355 100644
--- a/app/tools/gimpoperationtool.c
+++ b/app/tools/gimpoperationtool.c
@@ -60,7 +60,8 @@ static gboolean    gimp_operation_tool_initialize      (GimpTool          *tool,
                                                         GError           **error);
 
 static GeglNode  * gimp_operation_tool_get_operation   (GimpImageMapTool  *im_tool,
-                                                        GObject          **config);
+                                                        GObject          **config,
+                                                        gchar            **undo_desc);
 static void        gimp_operation_tool_map             (GimpImageMapTool  *im_tool);
 static void        gimp_operation_tool_dialog          (GimpImageMapTool  *im_tool);
 static void        gimp_operation_tool_reset           (GimpImageMapTool  *im_tool);
@@ -77,10 +78,6 @@ static void        gimp_operation_tool_color_picked    (GimpImageMapTool  *im_to
                                                         const Babl        *sample_format,
                                                         const GimpRGB     *color);
 
-static void        gimp_operation_tool_config_notify   (GObject           *object,
-                                                        GParamSpec        *pspec,
-                                                        GimpOperationTool *tool);
-
 
 G_DEFINE_TYPE (GimpOperationTool, gimp_operation_tool,
                GIMP_TYPE_IMAGE_MAP_TOOL)
@@ -185,8 +182,22 @@ gimp_operation_tool_initialize (GimpTool     *tool,
 
 static GeglNode *
 gimp_operation_tool_get_operation (GimpImageMapTool  *im_tool,
-                                   GObject          **config)
+                                   GObject          **config,
+                                   gchar            **undo_desc)
 {
+  GimpOperationTool *tool = GIMP_OPERATION_TOOL (im_tool);
+
+  if (tool->config)
+    *config = g_object_ref (tool->config);
+
+  if (tool->undo_desc)
+    *undo_desc = g_strdup (tool->undo_desc);
+
+  if (tool->operation)
+    return gegl_node_new_child (NULL,
+                                "operation", tool->operation,
+                                NULL);
+
   return g_object_new (GEGL_TYPE_NODE, NULL);
 }
 
@@ -295,14 +306,6 @@ gimp_operation_tool_color_picked (GimpImageMapTool  *im_tool,
                 NULL);
 }
 
-static void
-gimp_operation_tool_config_notify (GObject           *object,
-                                   GParamSpec        *pspec,
-                                   GimpOperationTool *tool)
-{
-  gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (tool));
-}
-
 void
 gimp_operation_tool_set_operation (GimpOperationTool *tool,
                                    const gchar       *operation,
@@ -323,40 +326,19 @@ gimp_operation_tool_set_operation (GimpOperationTool *tool,
       tool->undo_desc = NULL;
     }
 
-  if (tool->config)
-    {
-      g_object_unref (tool->config);
-      tool->config = NULL;
-    }
-
-  if (GIMP_IMAGE_MAP_TOOL (tool)->config)
-    {
-      g_object_unref (GIMP_IMAGE_MAP_TOOL (tool)->config);
-      GIMP_IMAGE_MAP_TOOL (tool)->config = NULL;
-    }
-
   tool->operation = g_strdup (operation);
   tool->undo_desc = g_strdup (undo_desc);
 
-  if (GIMP_IMAGE_MAP_TOOL (tool)->image_map)
+  if (tool->config)
     {
-      gimp_image_map_abort (GIMP_IMAGE_MAP_TOOL (tool)->image_map);
-      g_object_unref (GIMP_IMAGE_MAP_TOOL (tool)->image_map);
-      GIMP_IMAGE_MAP_TOOL (tool)->image_map = NULL;
+      g_object_unref (tool->config);
+      tool->config = NULL;
     }
 
-  gegl_node_set (GIMP_IMAGE_MAP_TOOL (tool)->operation,
-                 "operation", tool->operation,
-                 NULL);
-
-  if (GIMP_TOOL (tool)->drawable)
-    gimp_image_map_tool_create_map (GIMP_IMAGE_MAP_TOOL (tool), undo_desc);
-
   tool->config = gimp_gegl_get_config_proxy (tool->operation,
                                              GIMP_TYPE_IMAGE_MAP_CONFIG);
-  GIMP_IMAGE_MAP_TOOL (tool)->config = g_object_ref (tool->config);
 
-  GIMP_VIEWABLE_GET_CLASS (tool->config)->default_stock_id = GIMP_STOCK_GEGL;
+  gimp_image_map_tool_get_operation (GIMP_IMAGE_MAP_TOOL (tool));
 
   if (undo_desc)
     GIMP_IMAGE_MAP_TOOL_GET_CLASS (tool)->settings_name = "yes"; /* XXX hack */
@@ -371,10 +353,6 @@ gimp_operation_tool_set_operation (GimpOperationTool *tool,
 
   if (tool->config)
     {
-      g_signal_connect_object (tool->config, "notify",
-                               G_CALLBACK (gimp_operation_tool_config_notify),
-                               G_OBJECT (tool), 0);
-
       tool->options_table =
         gimp_prop_table_new (G_OBJECT (tool->config),
                              G_TYPE_FROM_INSTANCE (tool->config),
diff --git a/app/tools/gimpposterizetool.c b/app/tools/gimpposterizetool.c
index 8937599..bcb5ec1 100644
--- a/app/tools/gimpposterizetool.c
+++ b/app/tools/gimpposterizetool.c
@@ -50,7 +50,8 @@ static gboolean   gimp_posterize_tool_initialize     (GimpTool          *tool,
                                                       GError           **error);
 
 static GeglNode * gimp_posterize_tool_get_operation  (GimpImageMapTool  *im_tool,
-                                                      GObject          **config);
+                                                      GObject          **config,
+                                                      gchar            **undo_desc);
 static void       gimp_posterize_tool_dialog         (GimpImageMapTool  *im_tool);
 
 static void       gimp_posterize_tool_config_notify  (GObject           *object,
@@ -133,28 +134,23 @@ gimp_posterize_tool_initialize (GimpTool     *tool,
 
 static GeglNode *
 gimp_posterize_tool_get_operation (GimpImageMapTool  *image_map_tool,
-                                   GObject          **config)
+                                   GObject          **config,
+                                   gchar            **undo_desc)
 {
   GimpPosterizeTool *posterize_tool = GIMP_POSTERIZE_TOOL (image_map_tool);
-  GeglNode          *node;
-
-  node = g_object_new (GEGL_TYPE_NODE,
-                       "operation", "gimp:posterize",
-                       NULL);
 
   posterize_tool->config = g_object_new (GIMP_TYPE_POSTERIZE_CONFIG, NULL);
 
-  *config = G_OBJECT (posterize_tool->config);
-
   g_signal_connect_object (posterize_tool->config, "notify",
                            G_CALLBACK (gimp_posterize_tool_config_notify),
                            G_OBJECT (posterize_tool), 0);
 
-  gegl_node_set (node,
-                 "config", posterize_tool->config,
-                 NULL);
+  *config = G_OBJECT (posterize_tool->config);
 
-  return node;
+  return gegl_node_new_child (NULL,
+                              "operation", "gimp:posterize",
+                              "config",    posterize_tool->config,
+                              NULL);
 }
 
 
@@ -205,8 +201,6 @@ gimp_posterize_tool_config_notify (GObject           *object,
     return;
 
   gtk_adjustment_set_value (posterize_tool->levels_data, config->levels);
-
-  gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (posterize_tool));
 }
 
 static void
diff --git a/app/tools/gimpthresholdtool.c b/app/tools/gimpthresholdtool.c
index a284aac..0c2d08c 100644
--- a/app/tools/gimpthresholdtool.c
+++ b/app/tools/gimpthresholdtool.c
@@ -54,7 +54,8 @@ static gboolean   gimp_threshold_tool_initialize      (GimpTool          *tool,
                                                        GError           **error);
 
 static GeglNode * gimp_threshold_tool_get_operation   (GimpImageMapTool  *im_tool,
-                                                       GObject          **config);
+                                                       GObject          **config,
+                                                       gchar            **undo_desc);
 static void       gimp_threshold_tool_dialog          (GimpImageMapTool  *im_tool);
 
 static void       gimp_threshold_tool_config_notify   (GObject           *object,
@@ -162,28 +163,23 @@ gimp_threshold_tool_initialize (GimpTool     *tool,
 
 static GeglNode *
 gimp_threshold_tool_get_operation (GimpImageMapTool  *image_map_tool,
-                                   GObject          **config)
+                                   GObject          **config,
+                                   gchar            **undo_desc)
 {
   GimpThresholdTool *t_tool = GIMP_THRESHOLD_TOOL (image_map_tool);
-  GeglNode          *node;
-
-  node = g_object_new (GEGL_TYPE_NODE,
-                       "operation", "gimp:threshold",
-                       NULL);
 
   t_tool->config = g_object_new (GIMP_TYPE_THRESHOLD_CONFIG, NULL);
 
-  *config = G_OBJECT (t_tool->config);
-
   g_signal_connect_object (t_tool->config, "notify",
                            G_CALLBACK (gimp_threshold_tool_config_notify),
                            G_OBJECT (t_tool), 0);
 
-  gegl_node_set (node,
-                 "config", t_tool->config,
-                 NULL);
+  *config = G_OBJECT (t_tool->config);
 
-  return node;
+  return gegl_node_new_child (NULL,
+                              "operation", "gimp:threshold",
+                              "config",    t_tool->config,
+                              NULL);
 }
 
 
@@ -260,8 +256,6 @@ gimp_threshold_tool_config_notify (GObject           *object,
   gimp_histogram_view_set_range (t_tool->histogram_box->view,
                                  config->low  * 255.999,
                                  config->high * 255.999);
-
-  gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (t_tool));
 }
 
 static void


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