[gimp] Bug 605872 - Units dropdown list is not updated
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] Bug 605872 - Units dropdown list is not updated
- Date: Sun, 9 Mar 2014 23:18:32 +0000 (UTC)
commit 66298ba869dac811605e0a93e804cbac257cbf73
Author: Michael Natterer <mitch gimp org>
Date: Mon Mar 10 00:12:31 2014 +0100
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.
libgimpwidgets/gimpunitcombobox.c | 35 +++++++++++++++++++++++++++++--
libgimpwidgets/gimpunitstore.c | 40 +++++++++++++++++++++++++++++++++++++
libgimpwidgets/gimpunitstore.h | 2 +
3 files changed, 74 insertions(+), 3 deletions(-)
---
diff --git a/libgimpwidgets/gimpunitcombobox.c b/libgimpwidgets/gimpunitcombobox.c
index 25a1d4c..d7038d5 100644
--- a/libgimpwidgets/gimpunitcombobox.c
+++ b/libgimpwidgets/gimpunitcombobox.c
@@ -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;
}
}
-
}
diff --git a/libgimpwidgets/gimpunitstore.c b/libgimpwidgets/gimpunitstore.c
index a21682d..db1a01d 100644
--- a/libgimpwidgets/gimpunitstore.c
+++ b/libgimpwidgets/gimpunitstore.c
@@ -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;
+}
diff --git a/libgimpwidgets/gimpunitstore.h b/libgimpwidgets/gimpunitstore.h
index f02f188..25688d6 100644
--- a/libgimpwidgets/gimpunitstore.h
+++ b/libgimpwidgets/gimpunitstore.h
@@ -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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]