From db71a8ffc72f28b33081f9012fecdaa822596740 Mon Sep 17 00:00:00 2001 From: Jehan Date: Fri, 18 Sep 2020 15:19:24 +0200 Subject: [PATCH] =?UTF-8?q?libgimpwidgets:=20add=20a=20"value"=20property?= =?UTF-8?q?=20to=20GimpIntComboBox=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … and have gimp_prop_int_combo_box_new() bind to "value" instead of "active". The "active" property is defined by GtkComboBox and is the index of the combo box, not its values, whereas with gimp_prop_int_combo_box_new(), we want to bind an int property to the combobox value. Therefore the commit 0828a371c2 was only properly working when we were creating a combo box with values starting at 0 and incremented by 1. By adding a "value" property to GimpIntComboBox, I allow binding any property to the int value rather than the index. See also !265 where the issue was raised as it affected our HEIF plug-in. --- libgimpwidgets/gimpintcombobox.c | 30 +++++++++++++++++++++++++++++- libgimpwidgets/gimppropwidgets.c | 2 +- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/libgimpwidgets/gimpintcombobox.c b/libgimpwidgets/gimpintcombobox.c index 5d58ef4a94..364972181d 100644 --- a/libgimpwidgets/gimpintcombobox.c +++ b/libgimpwidgets/gimpintcombobox.c @@ -48,7 +48,8 @@ enum PROP_0, PROP_ELLIPSIZE, PROP_LABEL, - PROP_LAYOUT + PROP_LAYOUT, + PROP_VALUE }; @@ -148,6 +149,21 @@ gimp_int_combo_box_class_init (GimpIntComboBoxClass *klass) GIMP_TYPE_INT_COMBO_BOX_LAYOUT, GIMP_INT_COMBO_BOX_LAYOUT_ABBREVIATED, GIMP_PARAM_READWRITE)); + + /** + * GimpIntComboBox:value: + * + * The active value (different from the "active" property of + * GtkComboBox which is the active index). + * + * Since: 3.0 + */ + g_object_class_install_property (object_class, PROP_VALUE, + g_param_spec_int ("value", + "Value", + "Value of active item", + G_MININT, G_MAXINT, 0, + GIMP_PARAM_READWRITE)); } static void @@ -217,6 +233,10 @@ gimp_int_combo_box_set_property (GObject *object, gimp_int_combo_box_set_layout (GIMP_INT_COMBO_BOX (object), g_value_get_enum (value)); break; + case PROP_VALUE: + gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (object), + g_value_get_int (value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -243,6 +263,14 @@ gimp_int_combo_box_get_property (GObject *object, case PROP_LAYOUT: g_value_set_enum (value, priv->layout); break; + case PROP_VALUE: + { + gint v; + + gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (object), &v); + g_value_set_int (value, v); + } + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); diff --git a/libgimpwidgets/gimppropwidgets.c b/libgimpwidgets/gimppropwidgets.c index a518d2a208..453144f041 100644 --- a/libgimpwidgets/gimppropwidgets.c +++ b/libgimpwidgets/gimppropwidgets.c @@ -411,7 +411,7 @@ gimp_prop_int_combo_box_new (GObject *config, gimp_help_set_help_data (combo_box, blurb, NULL); g_object_bind_property (config, property_name, - combo_box, "active", + combo_box, "value", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); return combo_box;