[gnome-calendar] Update GcalMultiChoice label when format callback changes
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] Update GcalMultiChoice label when format callback changes
- Date: Tue, 1 Oct 2019 17:51:58 +0000 (UTC)
commit b034bd4bf0da4d2b8b476019407cc1c895b63746
Author: Nick Gasson <nick nickg me uk>
Date: Tue Oct 1 14:31:05 2019 +0100
Update GcalMultiChoice label when format callback changes
Currently the label text is only updated when set_value is called and
the new value is different to the current value. So if a format callback
is configured after the GcalMultiChoice is created, this won't be
applied until the value is changed to something other than the default.
The problem in issue #100 is that the default value for "month" is
0=>January. gcal_date_chooser_init sets the format callback and then
calls gcal_multi_choice_set_value with value==0 which won't update the
label.
Fix by having gcal_multi_choice_set_format_callback update the label
text with the result of applying the format callback to the current
value.
Fixes #100
src/gui/gcal-multi-choice.c | 31 ++++++++++++++++++++-----------
1 file changed, 20 insertions(+), 11 deletions(-)
---
diff --git a/src/gui/gcal-multi-choice.c b/src/gui/gcal-multi-choice.c
index 35bf6983..9e3382a9 100644
--- a/src/gui/gcal-multi-choice.c
+++ b/src/gui/gcal-multi-choice.c
@@ -79,21 +79,13 @@ get_value_string (GcalMultiChoice *self,
}
static void
-set_value (GcalMultiChoice *self,
- gint value,
- GtkStackTransitionType transition)
+apply_value (GcalMultiChoice *self,
+ GtkStackTransitionType transition)
{
GtkWidget *label;
const gchar *name;
gchar *text;
- value = CLAMP (value, self->min_value, self->max_value);
-
- if (self->value == value)
- return;
-
- self->value = value;
-
if (gtk_stack_get_visible_child (GTK_STACK (self->stack)) == self->label1)
{
name = "label2";
@@ -105,7 +97,7 @@ set_value (GcalMultiChoice *self,
label = self->label1;
}
- text = get_value_string (self, value);
+ text = get_value_string (self, self->value);
gtk_label_set_text (GTK_LABEL (label), text);
g_free (text);
@@ -118,6 +110,21 @@ set_value (GcalMultiChoice *self,
self->wrap || self->value > self->min_value);
gtk_widget_set_sensitive (self->up_button,
self->wrap || self->value < self->max_value);
+}
+
+static void
+set_value (GcalMultiChoice *self,
+ gint value,
+ GtkStackTransitionType transition)
+{
+ value = CLAMP (value, self->min_value, self->max_value);
+
+ if (self->value == value)
+ return;
+
+ self->value = value;
+
+ apply_value (self, transition);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_VALUE]);
}
@@ -489,4 +496,6 @@ gcal_multi_choice_set_format_callback (GcalMultiChoice *self,
self->format_cb = callback;
self->format_data = user_data;
self->format_destroy = destroy;
+
+ apply_value (self, GTK_STACK_TRANSITION_TYPE_NONE);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]