minor refactoring.

2007-02-12  Sven Neumann  <sven@gimp.org>

	* app/widgets/gimpcontrollereditor.c: minor refactoring.

	* libgimpwidgets/gimppropwidgets.c (gimp_prop_label_new): allow
	this function to be used with properties that are transformable 
to
	string values, not only with string properties.


svn path=/trunk/; revision=21896
This commit is contained in:
Sven Neumann 2007-02-12 08:44:25 +00:00 committed by Sven Neumann
parent 3eeb93fee5
commit 6ea68a7d48
3 changed files with 141 additions and 65 deletions

View File

@ -1,3 +1,11 @@
2007-02-12 Sven Neumann <sven@gimp.org>
* app/widgets/gimpcontrollereditor.c: minor refactoring.
* libgimpwidgets/gimppropwidgets.c (gimp_prop_label_new): allow
this function to be used with properties that are transformable to
string values, not only with string properties.
2007-02-12 Sven Neumann <sven@gimp.org>
* modules/cdisplay_colorblind.c: set translation domain for the

View File

@ -101,6 +101,12 @@ static void gimp_controller_editor_edit_response (GtkWidget *dialog,
gint response_id,
GimpControllerEditor *editor);
static GtkWidget * gimp_controller_editor_string_view_new (GObject *controller,
GParamSpec *pspec);
static GtkWidget * gimp_controller_editor_int_view_new (GObject *controller,
GParamSpec *pspec,
GParamSpec *next_pspec);
G_DEFINE_TYPE (GimpControllerEditor, gimp_controller_editor, GTK_TYPE_VBOX)
@ -236,68 +242,37 @@ gimp_controller_editor_constructor (GType type,
for (i = 0; i < n_property_specs; i++)
{
GParamSpec *prop_spec = property_specs[i];
GtkWidget *widget = NULL;
GParamSpec *pspec = property_specs[i];
GtkWidget *widget;
if (prop_spec->owner_type == GIMP_TYPE_CONTROLLER)
if (pspec->owner_type == GIMP_TYPE_CONTROLLER)
continue;
if (G_IS_PARAM_SPEC_STRING (prop_spec))
if (G_IS_PARAM_SPEC_STRING (pspec))
{
if (prop_spec->flags & G_PARAM_WRITABLE)
widget = gimp_prop_entry_new (G_OBJECT (controller),
prop_spec->name, -1);
else
widget = gimp_prop_label_new (G_OBJECT (controller),
prop_spec->name);
widget =
gimp_controller_editor_string_view_new (G_OBJECT (controller),
pspec);
gimp_table_attach_aligned (GTK_TABLE (table), 0, row++,
g_param_spec_get_nick (prop_spec),
g_param_spec_get_nick (pspec),
0.0, 0.5,
widget,
1, FALSE);
}
else if (G_IS_PARAM_SPEC_INT (prop_spec))
else if (G_IS_PARAM_SPEC_INT (pspec))
{
if (prop_spec->flags & G_PARAM_WRITABLE)
{
GimpIntStore *model = NULL;
gchar *model_name = g_strdup_printf ("%s-values",
prop_spec->name);
GParamSpec *next = (i + 1 < n_property_specs ?
property_specs[i + 1] : NULL);
if (((i + 1) < n_property_specs) &&
! strcmp (model_name, property_specs[i + 1]->name) &&
G_IS_PARAM_SPEC_OBJECT (property_specs[i + 1]) &&
g_type_is_a (property_specs[i + 1]->value_type,
GIMP_TYPE_INT_STORE))
{
g_object_get (controller,
property_specs[i + 1]->name, &model,
NULL);
}
widget = gimp_controller_editor_int_view_new (G_OBJECT (controller),
pspec, next);
g_free (model_name);
if (model)
{
widget = gimp_prop_int_combo_box_new (G_OBJECT (controller),
prop_spec->name,
model);
g_object_unref (model);
}
else
{
widget = gimp_prop_spin_button_new (G_OBJECT (controller),
prop_spec->name,
1, 8, 0);
}
gimp_table_attach_aligned (GTK_TABLE (table), 0, row++,
g_param_spec_get_nick (prop_spec),
0.0, 0.5,
widget,
1, TRUE);
}
gimp_table_attach_aligned (GTK_TABLE (table), 0, row++,
g_param_spec_get_nick (pspec),
0.0, 0.5,
widget,
1, TRUE);
}
}
@ -838,3 +813,71 @@ gimp_controller_editor_edit_response (GtkWidget *dialog,
gtk_widget_destroy (dialog);
}
static GtkWidget *
gimp_controller_editor_string_view_new (GObject *controller,
GParamSpec *pspec)
{
GtkWidget *widget = NULL;
g_return_val_if_fail (G_IS_PARAM_SPEC_STRING (pspec), NULL);
if (pspec->flags & G_PARAM_WRITABLE)
{
widget = gimp_prop_entry_new (controller, pspec->name, -1);
}
else
{
widget = gimp_prop_label_new (controller, pspec->name);
}
return widget;
}
static GtkWidget *
gimp_controller_editor_int_view_new (GObject *controller,
GParamSpec *pspec,
GParamSpec *next_pspec)
{
GtkWidget *widget = NULL;
g_return_val_if_fail (G_IS_PARAM_SPEC_INT (pspec), NULL);
if (pspec->flags & G_PARAM_WRITABLE)
{
GimpIntStore *model = NULL;
if (next_pspec)
{
gchar *model_name = g_strdup_printf ("%s-values", pspec->name);
if (next_pspec && strcmp (model_name, next_pspec->name) &&
G_IS_PARAM_SPEC_OBJECT (next_pspec) &&
g_type_is_a (next_pspec->value_type, GIMP_TYPE_INT_STORE))
{
g_object_get (controller,
next_pspec->name, &model,
NULL);
}
g_free (model_name);
}
if (model)
{
widget = gimp_prop_int_combo_box_new (controller, pspec->name, model);
g_object_unref (model);
}
else
{
widget = gimp_prop_spin_button_new (controller, pspec->name, 1, 8, 0);
}
}
else
{
widget = gimp_prop_label_new (controller, pspec->name);
}
return widget;
}

View File

@ -1598,8 +1598,9 @@ static void gimp_prop_label_notify (GObject *config,
* @config: Object to which property is attached.
* @property_name: Name of string property.
*
* Creates a #GtkLabel to display the value of the specified String
* property. If the user should be able to edit the string, use
* Creates a #GtkLabel to display the value of the specified property.
* The property should be a string property or at least transformable
* to a string. If the user should be able to edit the string, use
* gimp_prop_entry_new() instead.
*
* Return value: A new #GtkLabel widget.
@ -1612,22 +1613,25 @@ gimp_prop_label_new (GObject *config,
{
GParamSpec *param_spec;
GtkWidget *label;
gchar *value;
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
g_return_val_if_fail (property_name != NULL, NULL);
param_spec = check_param_spec (config, property_name,
G_TYPE_PARAM_STRING, G_STRFUNC);
param_spec = find_param_spec (config, property_name, G_STRFUNC);
if (! param_spec)
return NULL;
g_object_get (config,
property_name, &value,
NULL);
if (! g_value_type_transformable (param_spec->value_type, G_TYPE_STRING))
{
g_warning ("%s: property '%s' of %s is not transformable to string",
G_STRLOC,
param_spec->name,
g_type_name (param_spec->owner_type));
return NULL;
}
label = gtk_label_new (value ? value : "");
g_free (value);
label = gtk_label_new (NULL);
set_param_spec (G_OBJECT (label), label, param_spec);
@ -1635,6 +1639,8 @@ gimp_prop_label_new (GObject *config,
G_CALLBACK (gimp_prop_label_notify),
label);
gimp_prop_label_notify (config, param_spec, label);
return label;
}
@ -1643,15 +1649,34 @@ gimp_prop_label_notify (GObject *config,
GParamSpec *param_spec,
GtkWidget *label)
{
gchar *value;
GValue value = { 0, };
g_object_get (config,
param_spec->name, &value,
NULL);
g_value_init (&value, param_spec->value_type);
gtk_label_set_text (GTK_LABEL (label), value ? value : "");
g_object_get_property (config, param_spec->name, &value);
g_free (value);
if (G_VALUE_HOLDS_STRING (&value))
{
const gchar *str = g_value_get_string (&value);
gtk_label_set_text (GTK_LABEL (label), str ? str : "");
}
else
{
GValue str_value = { 0, };
const gchar *str;
g_value_init (&str_value, G_TYPE_STRING);
g_value_transform (&value, &str_value);
str = g_value_get_string (&str_value);
gtk_label_set_text (GTK_LABEL (label), str ? str : "");
g_value_unset (&str_value);
}
g_value_unset (&value);
}