[gimp] app: clean up a lot of werid code in GimpColorOptions and GimpFilterOptions



commit 13b1e6aafc516fa9991de7334629486c36480f8c
Author: Michael Natterer <mitch gimp org>
Date:   Fri May 13 22:00:25 2016 +0200

    app: clean up a lot of werid code in GimpColorOptions and GimpFilterOptions
    
    First of all, derive GimpFilterOptions from GimpColorOptions, not the
    other way around, which was a sick way of magically showing the right
    options for various tools. That approach has failed and needed
    additional hacks to do the right thing. Simply have the right class
    hierarchy and call the right tool options GUI constructors and done.
    
    Remove gimp_histogram_options_gui(), we don't need histogram scale
    controls in tool options when we already have them next to the
    histograms in the tool dialogs.
    
    Also remove gimp_histogram_options_connect_view() and use a simple
    g_object_bind_property() instead.

 app/tools/gimpcolorizetool.c     |    4 ++--
 app/tools/gimpcoloroptions.c     |   10 ++--------
 app/tools/gimpcoloroptions.h     |   14 +++++++-------
 app/tools/gimpcurvestool.c       |    6 ++++--
 app/tools/gimpfilteroptions.c    |    2 +-
 app/tools/gimpfilteroptions.h    |   25 +++++++++++++++----------
 app/tools/gimpfiltertool.c       |    2 +-
 app/tools/gimpgegltool.c         |    4 ++--
 app/tools/gimphistogramoptions.c |   35 +----------------------------------
 app/tools/gimphistogramoptions.h |   17 +++++++++--------
 app/tools/gimplevelstool.c       |    6 ++++--
 app/tools/gimpoperationtool.c    |    4 ++--
 app/tools/gimpthresholdtool.c    |   10 ++++++----
 13 files changed, 56 insertions(+), 83 deletions(-)
---
diff --git a/app/tools/gimpcolorizetool.c b/app/tools/gimpcolorizetool.c
index d97150d..0b49819 100644
--- a/app/tools/gimpcolorizetool.c
+++ b/app/tools/gimpcolorizetool.c
@@ -39,7 +39,7 @@
 #include "display/gimpdisplay.h"
 
 #include "gimpcolorizetool.h"
-#include "gimpcoloroptions.h"
+#include "gimpfilteroptions.h"
 
 #include "gimp-intl.h"
 
@@ -75,7 +75,7 @@ gimp_colorize_tool_register (GimpToolRegisterCallback  callback,
                              gpointer                  data)
 {
   (* callback) (GIMP_TYPE_COLORIZE_TOOL,
-                GIMP_TYPE_COLOR_OPTIONS,
+                GIMP_TYPE_FILTER_OPTIONS,
                 gimp_color_options_gui,
                 0,
                 "gimp-colorize-tool",
diff --git a/app/tools/gimpcoloroptions.c b/app/tools/gimpcoloroptions.c
index 9c11888..3411004 100644
--- a/app/tools/gimpcoloroptions.c
+++ b/app/tools/gimpcoloroptions.c
@@ -27,7 +27,6 @@
 
 #include "widgets/gimppropwidgets.h"
 
-#include "gimphistogramoptions.h"
 #include "gimpcoloroptions.h"
 #include "gimptooloptions-gui.h"
 
@@ -54,7 +53,7 @@ static void   gimp_color_options_get_property (GObject      *object,
 
 
 G_DEFINE_TYPE (GimpColorOptions, gimp_color_options,
-               GIMP_TYPE_FILTER_OPTIONS)
+               GIMP_TYPE_TOOL_OPTIONS)
 
 
 static void
@@ -146,16 +145,11 @@ GtkWidget *
 gimp_color_options_gui (GimpToolOptions *tool_options)
 {
   GObject   *config = G_OBJECT (tool_options);
-  GtkWidget *vbox;
+  GtkWidget *vbox   = gimp_tool_options_gui (tool_options);
   GtkWidget *frame;
   GtkWidget *scale;
   GtkWidget *button;
 
-  if (GIMP_IS_HISTOGRAM_OPTIONS (tool_options))
-    vbox = gimp_histogram_options_gui (tool_options);
-  else
-    vbox = gimp_tool_options_gui (tool_options);
-
   /*  the sample average options  */
   frame = gimp_frame_new (NULL);
   gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
diff --git a/app/tools/gimpcoloroptions.h b/app/tools/gimpcoloroptions.h
index 886f84c..a4ca0a5 100644
--- a/app/tools/gimpcoloroptions.h
+++ b/app/tools/gimpcoloroptions.h
@@ -19,7 +19,7 @@
 #define __GIMP_COLOR_OPTIONS_H__
 
 
-#include "gimpfilteroptions.h"
+#include "core/gimptooloptions.h"
 
 
 #define GIMP_TYPE_COLOR_OPTIONS            (gimp_color_options_get_type ())
@@ -30,20 +30,20 @@
 #define GIMP_COLOR_OPTIONS_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_COLOR_OPTIONS, 
GimpColorOptionsClass))
 
 
-typedef struct _GimpColorOptionsClass  GimpColorOptionsClass;
+typedef struct _GimpColorOptionsClass GimpColorOptionsClass;
 
 struct _GimpColorOptions
 {
-  GimpFilterOptions  parent_instance;
+  GimpToolOptions  parent_instance;
 
-  gboolean           sample_merged;
-  gboolean           sample_average;
-  gdouble            average_radius;
+  gboolean         sample_merged;
+  gboolean         sample_average;
+  gdouble          average_radius;
 };
 
 struct _GimpColorOptionsClass
 {
-  GimpFilterOptionsClass  parent_instance;
+  GimpToolOptionsClass  parent_instance;
 };
 
 
diff --git a/app/tools/gimpcurvestool.c b/app/tools/gimpcurvestool.c
index b2f17de..e271397 100644
--- a/app/tools/gimpcurvestool.c
+++ b/app/tools/gimpcurvestool.c
@@ -541,8 +541,10 @@ gimp_curves_tool_dialog (GimpFilterTool *filter_tool)
   gtk_container_add (GTK_CONTAINER (frame), tool->graph);
   gtk_widget_show (tool->graph);
 
-  gimp_histogram_options_connect_view (GIMP_HISTOGRAM_OPTIONS (tool_options),
-                                       GIMP_HISTOGRAM_VIEW (tool->graph));
+  g_object_bind_property (G_OBJECT (tool_options), "histogram-scale",
+                          G_OBJECT (tool->graph),  "histogram-scale",
+                          G_BINDING_SYNC_CREATE |
+                          G_BINDING_BIDIRECTIONAL);
 
   /*  The bottom color bar  */
   hbox2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
diff --git a/app/tools/gimpfilteroptions.c b/app/tools/gimpfilteroptions.c
index def24ba..406dea4 100644
--- a/app/tools/gimpfilteroptions.c
+++ b/app/tools/gimpfilteroptions.c
@@ -54,7 +54,7 @@ static void   gimp_filter_options_get_property (GObject      *object,
 
 
 G_DEFINE_TYPE (GimpFilterOptions, gimp_filter_options,
-               GIMP_TYPE_TOOL_OPTIONS)
+               GIMP_TYPE_COLOR_OPTIONS)
 
 #define parent_class gimp_filter_options_parent_class
 
diff --git a/app/tools/gimpfilteroptions.h b/app/tools/gimpfilteroptions.h
index 569ab61..7916ccf 100644
--- a/app/tools/gimpfilteroptions.h
+++ b/app/tools/gimpfilteroptions.h
@@ -19,7 +19,7 @@
 #define __GIMP_FILTER_OPTIONS_H__
 
 
-#include "core/gimptooloptions.h"
+#include "gimpcoloroptions.h"
 
 
 #define GIMP_TYPE_FILTER_OPTIONS            (gimp_filter_options_get_type ())
@@ -30,20 +30,25 @@
 #define GIMP_FILTER_OPTIONS_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_FILTER_OPTIONS, 
GimpFilterOptionsClass))
 
 
-typedef struct _GimpToolOptionsClass  GimpFilterOptionsClass;
+typedef struct _GimpFilterOptionsClass GimpFilterOptionsClass;
 
 struct _GimpFilterOptions
 {
-  GimpToolOptions    parent_instance;
+  GimpColorOptions    parent_instance;
 
-  gboolean           preview;
-  gboolean           preview_split;
-  GimpAlignmentType  preview_alignment;
-  gdouble            preview_position;
-  GimpFilterRegion   region;
-  gboolean           gamma_hack;
+  gboolean            preview;
+  gboolean            preview_split;
+  GimpAlignmentType   preview_alignment;
+  gdouble             preview_position;
+  GimpFilterRegion    region;
+  gboolean            gamma_hack;
 
-  GFile             *settings;
+  GFile              *settings;
+};
+
+struct _GimpFilterOptionsClass
+{
+  GimpColorOptionsClass  parent_instance;
 };
 
 
diff --git a/app/tools/gimpfiltertool.c b/app/tools/gimpfiltertool.c
index 85edd97..4858e70 100644
--- a/app/tools/gimpfiltertool.c
+++ b/app/tools/gimpfiltertool.c
@@ -66,7 +66,7 @@
 #include "display/gimpdisplayshell-transform.h"
 #include "display/gimptoolgui.h"
 
-#include "gimpcoloroptions.h"
+#include "gimpfilteroptions.h"
 #include "gimpfiltertool.h"
 #include "gimpfiltertool-settings.h"
 #include "gimpguidetool.h"
diff --git a/app/tools/gimpgegltool.c b/app/tools/gimpgegltool.c
index 21963ea..fce78e5 100644
--- a/app/tools/gimpgegltool.c
+++ b/app/tools/gimpgegltool.c
@@ -32,7 +32,7 @@
 #include "widgets/gimphelp-ids.h"
 #include "widgets/gimppropwidgets.h"
 
-#include "gimpcoloroptions.h"
+#include "gimpfilteroptions.h"
 #include "gimpgegltool.h"
 
 #include "gimp-intl.h"
@@ -65,7 +65,7 @@ gimp_gegl_tool_register (GimpToolRegisterCallback  callback,
                          gpointer                  data)
 {
   (* callback) (GIMP_TYPE_GEGL_TOOL,
-                GIMP_TYPE_COLOR_OPTIONS,
+                GIMP_TYPE_FILTER_OPTIONS,
                 gimp_color_options_gui,
                 0,
                 "gimp-gegl-tool",
diff --git a/app/tools/gimphistogramoptions.c b/app/tools/gimphistogramoptions.c
index 8a82ab4..2edf626 100644
--- a/app/tools/gimphistogramoptions.c
+++ b/app/tools/gimphistogramoptions.c
@@ -21,16 +21,10 @@
 #include <gtk/gtk.h>
 
 #include "libgimpconfig/gimpconfig.h"
-#include "libgimpwidgets/gimpwidgets.h"
 
 #include "tools-types.h"
 
-#include "config/gimpconfig-utils.h"
-
-#include "widgets/gimphistogramview.h"
-
 #include "gimphistogramoptions.h"
-#include "gimptooloptions-gui.h"
 
 #include "gimp-intl.h"
 
@@ -53,7 +47,7 @@ static void   gimp_histogram_options_get_property (GObject      *object,
 
 
 G_DEFINE_TYPE (GimpHistogramOptions, gimp_histogram_options,
-               GIMP_TYPE_COLOR_OPTIONS)
+               GIMP_TYPE_FILTER_OPTIONS)
 
 
 static void
@@ -117,30 +111,3 @@ gimp_histogram_options_get_property (GObject    *object,
       break;
     }
 }
-
-GtkWidget *
-gimp_histogram_options_gui (GimpToolOptions *tool_options)
-{
-  GObject   *config = G_OBJECT (tool_options);
-  GtkWidget *vbox   = gimp_tool_options_gui (tool_options);
-  GtkWidget *frame;
-
-  frame = gimp_prop_enum_radio_frame_new (config, "histogram-scale", NULL,
-                                          0, 0);
-  gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
-  gtk_widget_show (frame);
-
-  return vbox;
-}
-
-void
-gimp_histogram_options_connect_view (GimpHistogramOptions *options,
-                                     GimpHistogramView    *view)
-{
-  g_return_if_fail (GIMP_IS_HISTOGRAM_OPTIONS (options));
-  g_return_if_fail (GIMP_IS_HISTOGRAM_VIEW (view));
-
-  gimp_config_connect (G_OBJECT (options), G_OBJECT (view), "histogram-scale");
-
-  g_object_notify (G_OBJECT (options), "histogram-scale");
-}
diff --git a/app/tools/gimphistogramoptions.h b/app/tools/gimphistogramoptions.h
index 3fdedbe..3705d08 100644
--- a/app/tools/gimphistogramoptions.h
+++ b/app/tools/gimphistogramoptions.h
@@ -19,7 +19,7 @@
 #define __GIMP_HISTOGRAM_OPTIONS_H__
 
 
-#include "gimpcoloroptions.h"
+#include "gimpfilteroptions.h"
 
 
 #define GIMP_TYPE_HISTOGRAM_OPTIONS            (gimp_histogram_options_get_type ())
@@ -30,22 +30,23 @@
 #define GIMP_HISTOGRAM_OPTIONS_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GIMP_TYPE_HISTOGRAM_OPTIONS, GimpHistogramOptionsClass))
 
 
-typedef struct _GimpHistogramOptions  GimpHistogramOptions;
-typedef         GimpColorOptionsClass GimpHistogramOptionsClass;
+typedef struct _GimpHistogramOptions      GimpHistogramOptions;
+typedef struct _GimpHistogramOptionsClass GimpHistogramOptionsClass;
 
 struct _GimpHistogramOptions
 {
-  GimpColorOptions    parent_instance;
+  GimpFilterOptions    parent_instance;
 
   GimpHistogramScale  scale;
 };
 
+struct _GimpHistogramOptionsClass
+{
+  GimpFilterOptionsClass  parent_class;
+};
 
-GType       gimp_histogram_options_get_type     (void) G_GNUC_CONST;
 
-GtkWidget * gimp_histogram_options_gui          (GimpToolOptions      *tool_options);
-void        gimp_histogram_options_connect_view (GimpHistogramOptions *options,
-                                                 GimpHistogramView    *view);
+GType   gimp_histogram_options_get_type (void) G_GNUC_CONST;
 
 
 #endif /* __GIMP_HISTOGRAM_OPTIONS_H__ */
diff --git a/app/tools/gimplevelstool.c b/app/tools/gimplevelstool.c
index 0031dc1..e114c73 100644
--- a/app/tools/gimplevelstool.c
+++ b/app/tools/gimplevelstool.c
@@ -425,8 +425,10 @@ gimp_levels_tool_dialog (GimpFilterTool *filter_tool)
   gtk_box_pack_start (GTK_BOX (vbox2), tool->histogram_view, TRUE, TRUE, 0);
   gtk_widget_show (GTK_WIDGET (tool->histogram_view));
 
-  gimp_histogram_options_connect_view (GIMP_HISTOGRAM_OPTIONS (tool_options),
-                                       GIMP_HISTOGRAM_VIEW (tool->histogram_view));
+  g_object_bind_property (G_OBJECT (tool_options),         "histogram-scale",
+                          G_OBJECT (tool->histogram_view), "histogram-scale",
+                          G_BINDING_SYNC_CREATE |
+                          G_BINDING_BIDIRECTIONAL);
 
   g_object_get (tool->histogram_view, "border-width", &border, NULL);
 
diff --git a/app/tools/gimpoperationtool.c b/app/tools/gimpoperationtool.c
index be08761..7f5b268 100644
--- a/app/tools/gimpoperationtool.c
+++ b/app/tools/gimpoperationtool.c
@@ -51,7 +51,7 @@
 #include "display/gimpdisplay.h"
 #include "display/gimptoolgui.h"
 
-#include "gimpcoloroptions.h"
+#include "gimpfilteroptions.h"
 #include "gimpoperationtool.h"
 
 #include "gimp-intl.h"
@@ -124,7 +124,7 @@ gimp_operation_tool_register (GimpToolRegisterCallback  callback,
                               gpointer                  data)
 {
   (* callback) (GIMP_TYPE_OPERATION_TOOL,
-                GIMP_TYPE_COLOR_OPTIONS,
+                GIMP_TYPE_FILTER_OPTIONS,
                 gimp_color_options_gui,
                 GIMP_CONTEXT_PROP_MASK_FOREGROUND |
                 GIMP_CONTEXT_PROP_MASK_BACKGROUND,
diff --git a/app/tools/gimpthresholdtool.c b/app/tools/gimpthresholdtool.c
index 76e6cdd..10429e4 100644
--- a/app/tools/gimpthresholdtool.c
+++ b/app/tools/gimpthresholdtool.c
@@ -27,7 +27,6 @@
 
 #include "core/gimpdrawable.h"
 #include "core/gimpdrawable-histogram.h"
-#include "core/gimperror.h"
 #include "core/gimphistogram.h"
 #include "core/gimpimage.h"
 
@@ -39,6 +38,7 @@
 
 #include "gimphistogramoptions.h"
 #include "gimpthresholdtool.h"
+#include "gimptooloptions-gui.h"
 
 #include "gimp-intl.h"
 
@@ -84,7 +84,7 @@ gimp_threshold_tool_register (GimpToolRegisterCallback  callback,
 {
   (* callback) (GIMP_TYPE_THRESHOLD_TOOL,
                 GIMP_TYPE_HISTOGRAM_OPTIONS,
-                gimp_histogram_options_gui,
+                NULL,
                 0,
                 "gimp-threshold-tool",
                 _("Threshold"),
@@ -231,8 +231,10 @@ gimp_threshold_tool_dialog (GimpFilterTool *filter_tool)
                     G_CALLBACK (gimp_threshold_tool_histogram_range),
                     t_tool);
 
-  gimp_histogram_options_connect_view (GIMP_HISTOGRAM_OPTIONS (tool_options),
-                                       t_tool->histogram_box->view);
+  g_object_bind_property (G_OBJECT (tool_options),                "histogram-scale",
+                          G_OBJECT (t_tool->histogram_box->view), "histogram-scale",
+                          G_BINDING_SYNC_CREATE |
+                          G_BINDING_BIDIRECTIONAL);
 
   hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
   gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);


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