Bug 605872 - Units dropdown list is not updated

Add private API _gimp_unit_store_sync_units() which emits
"row-inserted" on each unit that didn't exist when the GimpUnitStore
was created, or when sync_units() was called the last time.

In GimpUnitComboBox, call sync_units() each time the combo is popped
up, or a unit is set on the combo.
This commit is contained in:
Michael Natterer 2014-03-10 00:12:31 +01:00
parent 626ef7b30f
commit 66298ba869
3 changed files with 74 additions and 3 deletions

View File

@ -40,8 +40,10 @@
**/
static void gimp_unit_combo_box_style_set (GtkWidget *widget,
GtkStyle *prev_style);
static void gimp_unit_combo_box_style_set (GtkWidget *widget,
GtkStyle *prev_style);
static void gimp_unit_combo_box_popup_shown (GtkWidget *widget,
const GParamSpec *pspec);
G_DEFINE_TYPE (GimpUnitComboBox, gimp_unit_combo_box, GTK_TYPE_COMBO_BOX)
@ -76,6 +78,10 @@ gimp_unit_combo_box_init (GimpUnitComboBox *combo)
gtk_cell_layout_set_attributes (layout, cell,
"text", GIMP_UNIT_STORE_UNIT_LONG_FORMAT,
NULL);
g_signal_connect (combo, "notify::popup-shown",
G_CALLBACK (gimp_unit_combo_box_popup_shown),
NULL);
}
static void
@ -103,6 +109,28 @@ gimp_unit_combo_box_style_set (GtkWidget *widget,
NULL);
}
static void
gimp_unit_combo_box_popup_shown (GtkWidget *widget,
const GParamSpec *pspec)
{
GimpUnitStore *store;
gboolean shown;
g_object_get (widget,
"model", &store,
"popup-shown", &shown,
NULL);
if (store)
{
if (shown)
_gimp_unit_store_sync_units (store);
g_object_unref (store);
}
}
/**
* gimp_unit_combo_box_new:
*
@ -168,6 +196,8 @@ gimp_unit_combo_box_set_active (GimpUnitComboBox *combo,
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
_gimp_unit_store_sync_units (GIMP_UNIT_STORE (model));
for (iter_valid = gtk_tree_model_get_iter_first (model, &iter);
iter_valid;
iter_valid = gtk_tree_model_iter_next (model, &iter))
@ -184,5 +214,4 @@ gimp_unit_combo_box_set_active (GimpUnitComboBox *combo,
break;
}
}
}

View File

@ -51,6 +51,8 @@ typedef struct
gdouble *values;
gdouble *resolutions;
GimpUnit synced_unit;
} GimpUnitStorePrivate;
#define GET_PRIVATE(obj) G_TYPE_INSTANCE_GET_PRIVATE (obj, \
@ -177,6 +179,7 @@ gimp_unit_store_init (GimpUnitStore *store)
private->has_percent = FALSE;
private->short_format = g_strdup ("%a");
private->long_format = g_strdup ("%p");
private->synced_unit = gimp_unit_get_number_of_units () - 1;
}
static void
@ -896,3 +899,40 @@ gimp_unit_store_get_values (GimpUnitStore *store,
va_end (args);
}
void
_gimp_unit_store_sync_units (GimpUnitStore *store)
{
GimpUnitStorePrivate *private;
GtkTreeModel *model;
GtkTreeIter iter;
gboolean iter_valid;
g_return_if_fail (GIMP_IS_UNIT_STORE (store));
private = GET_PRIVATE (store);
model = GTK_TREE_MODEL (store);
for (iter_valid = gtk_tree_model_get_iter_first (model, &iter);
iter_valid;
iter_valid = gtk_tree_model_iter_next (model, &iter))
{
gint unit;
gtk_tree_model_get (model, &iter,
GIMP_UNIT_STORE_UNIT, &unit,
-1);
if (unit > private->synced_unit)
{
GtkTreePath *path;
path = gtk_tree_model_get_path (model, &iter);
gtk_tree_model_row_inserted (model, path, &iter);
gtk_tree_path_free (path);
}
}
private->synced_unit = gimp_unit_get_number_of_units () - 1;
}

View File

@ -105,6 +105,8 @@ void gimp_unit_store_get_values (GimpUnitStore *store,
gdouble *first_value,
...);
void _gimp_unit_store_sync_units (GimpUnitStore *store);
G_END_DECLS