libgimpwidgets: change gimp_int_store_new()'s signature

to match gimp_int_combo_box_new(), and add gimp_int_store_new_valist().

Move the va_list of (name, value) parsing code to
gimp_int_store_new_valist() and use it from
gimp_int_combo_box_new_valist().

This makes the entire GimpIntStore/GimpIntComboBox stuff useable much
more generically for the price of an incompatible change of a public
function that is used exactly once outside of libgimpwidgets.
This commit is contained in:
Michael Natterer 2019-09-24 00:16:55 +02:00
parent f3eef8fe83
commit e80c90e17d
5 changed files with 74 additions and 22 deletions

View File

@ -138,7 +138,7 @@ gimp_symmetry_editor_set_image (GimpImageEditor *image_editor,
GList *sym_iter;
GimpSymmetry *symmetry;
store = gimp_int_store_new ();
store = g_object_new (GIMP_TYPE_INT_STORE, NULL);
/* The menu of available symmetries. */
syms = gimp_image_symmetry_list ();

View File

@ -158,7 +158,7 @@ gimp_int_combo_box_init (GimpIntComboBox *combo_box)
combo_box->priv = priv = gimp_int_combo_box_get_instance_private (combo_box);
store = gimp_int_store_new ();
store = g_object_new (GIMP_TYPE_INT_STORE, NULL);
gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box), GTK_TREE_MODEL (store));
g_object_unref (store);
@ -292,7 +292,7 @@ gimp_int_combo_box_new (const gchar *first_label,
* @values: a va_list with more values
*
* A variant of gimp_int_combo_box_new() that takes a va_list of
* label/value pairs. Probably only useful for language bindings.
* label/value pairs.
*
* Returns: a new #GimpIntComboBox.
*
@ -305,25 +305,14 @@ gimp_int_combo_box_new_valist (const gchar *first_label,
{
GtkWidget *combo_box;
GtkListStore *store;
const gchar *label;
gint value;
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
store = gimp_int_store_new_valist (first_label, first_value, values);
store = GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box)));
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX,
"model", store,
NULL);
for (label = first_label, value = first_value;
label;
label = va_arg (values, const gchar *), value = va_arg (values, gint))
{
GtkTreeIter iter = { 0, };
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
GIMP_INT_STORE_VALUE, value,
GIMP_INT_STORE_LABEL, label,
-1);
}
g_object_unref (store);
return combo_box;
}

View File

@ -260,19 +260,76 @@ gimp_int_store_add_empty (GimpIntStore *store)
/**
* gimp_int_store_new:
* @first_label: the label of the first item
* @first_value: the value of the first item
* @...: a %NULL terminated list of more label, value pairs
*
* Creates a #GtkListStore with a number of useful columns.
* #GimpIntStore is especially useful if the items you want to store
* are identified using an integer value.
*
* If you need to construct an empty #GimpIntStore, it's best to use
* g_object_new (GIMP_TYPE_INT_STORE, NULL).
*
* Returns: a new #GimpIntStore.
*
* Since: 2.2
**/
GtkListStore *
gimp_int_store_new (void)
gimp_int_store_new (const gchar *first_label,
gint first_value,
...)
{
return g_object_new (GIMP_TYPE_INT_STORE, NULL);
GtkListStore *store;
va_list args;
va_start (args, first_value);
store = gimp_int_store_new_valist (first_label, first_value, args);
va_end (args);
return store;
}
/**
* gimp_int_store_new_valist:
* @first_label: the label of the first item
* @first_value: the value of the first item
* @values: a va_list with more values
*
* A variant of gimp_int_store_new() that takes a va_list of
* label/value pairs.
*
* Returns: a new #GimpIntStore.
*
* Since: 3.0
**/
GtkListStore *
gimp_int_store_new_valist (const gchar *first_label,
gint first_value,
va_list values)
{
GtkListStore *store;
const gchar *label;
gint value;
store = g_object_new (GIMP_TYPE_INT_STORE, NULL);
for (label = first_label, value = first_value;
label;
label = va_arg (values, const gchar *), value = va_arg (values, gint))
{
GtkTreeIter iter = { 0, };
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
GIMP_INT_STORE_VALUE, value,
GIMP_INT_STORE_LABEL, label,
-1);
}
return store;
}
/**

View File

@ -89,7 +89,12 @@ struct _GimpIntStoreClass
GType gimp_int_store_get_type (void) G_GNUC_CONST;
GtkListStore * gimp_int_store_new (void);
GtkListStore * gimp_int_store_new (const gchar *first_label,
gint first_value,
...) G_GNUC_NULL_TERMINATED;
GtkListStore * gimp_int_store_new_valist (const gchar *first_label,
gint first_value,
va_list values);
gboolean gimp_int_store_lookup_by_value (GtkTreeModel *model,
gint value,

View File

@ -223,6 +223,7 @@ EXPORTS
gimp_int_store_lookup_by_user_data
gimp_int_store_lookup_by_value
gimp_int_store_new
gimp_int_store_new_valist
gimp_label_set_attributes
gimp_memsize_entry_get_spinbutton
gimp_memsize_entry_get_type