diff --git a/libgimpwidgets/gimpintstore.c b/libgimpwidgets/gimpintstore.c index b370785963..703634abce 100644 --- a/libgimpwidgets/gimpintstore.c +++ b/libgimpwidgets/gimpintstore.c @@ -293,7 +293,7 @@ gimp_int_store_new (const gchar *first_label, } /** - * gimp_int_store_new_valist: + * gimp_int_store_new_valist: (skip) * @first_label: the label of the first item * @first_value: the value of the first item * @values: a va_list with more values @@ -332,6 +332,47 @@ gimp_int_store_new_valist (const gchar *first_label, return store; } +/** + * gimp_int_store_new_array: (rename-to gimp_int_store_new) + * @n_values: the number of values + * @labels: (array length=n_values): an array of labels + * + * A variant of gimp_int_store_new() that takes an array of labels. + * The array indices are used as values. + * + * Returns: a new #GtkListStore. + * + * Since: 3.0 + **/ +GtkListStore * +gimp_int_store_new_array (gint n_values, + const gchar *labels[]) +{ + GtkListStore *store; + gint i; + + g_return_val_if_fail (n_values >= 0, NULL); + g_return_val_if_fail (labels != NULL || n_values == 0, NULL); + + store = g_object_new (GIMP_TYPE_INT_STORE, NULL); + + for (i = 0; i < n_values; i++) + { + GtkTreeIter iter; + + if (labels[i]) + { + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, + GIMP_INT_STORE_VALUE, i, + GIMP_INT_STORE_LABEL, gettext (labels[i]), + -1); + } + } + + return store; +} + /** * gimp_int_store_lookup_by_value: * @model: a #GimpIntStore diff --git a/libgimpwidgets/gimpintstore.h b/libgimpwidgets/gimpintstore.h index c5791b6092..838f88cff1 100644 --- a/libgimpwidgets/gimpintstore.h +++ b/libgimpwidgets/gimpintstore.h @@ -95,6 +95,8 @@ GtkListStore * gimp_int_store_new (const gchar *first_label, GtkListStore * gimp_int_store_new_valist (const gchar *first_label, gint first_value, va_list values); +GtkListStore * gimp_int_store_new_array (gint n_values, + const gchar *labels[]); gboolean gimp_int_store_lookup_by_value (GtkTreeModel *model, gint value, diff --git a/libgimpwidgets/gimpwidgets.def b/libgimpwidgets/gimpwidgets.def index d7c32f82de..ff45ddbfde 100644 --- a/libgimpwidgets/gimpwidgets.def +++ b/libgimpwidgets/gimpwidgets.def @@ -241,6 +241,7 @@ EXPORTS gimp_int_store_lookup_by_user_data gimp_int_store_lookup_by_value gimp_int_store_new + gimp_int_store_new_array gimp_int_store_new_valist gimp_label_color_get_color_widget gimp_label_color_get_type