common/date-chooser: Use GcalMultiChoice::user-changed
At the moment `gcal_date_chooser_set_date()` is automatically setting the day to 1, which is undesirable behavior for a method that is designed to "just" set the date. By connecting to `GcalMultiChoice::explicitly-changed`, we can simply have the day set to 1 to accompanying callbacks. Currently, `multi_choice_changed()` is invoked 50 times at startup. By using `GcalMultiChoice::explicitly-changed`, `multi_choice_changed()` is only invoked 10 times. This is still more than ideal, but it's a significant drop. Fixes: https://gitlab.gnome.org/GNOME/gnome-calendar/-/work_items/1639 Part-of: <https://gitlab.gnome.org/GNOME/gnome-calendar/-/merge_requests/837>
This commit is contained in:
@@ -16,7 +16,7 @@ template $GcalDateChooser: Adw.Bin {
|
|||||||
previous-button-tooltip: _("Previous Month");
|
previous-button-tooltip: _("Previous Month");
|
||||||
next-button-tooltip: _("Next Month");
|
next-button-tooltip: _("Next Month");
|
||||||
visible: bind $get_split_choice_visible(template.show-heading, template.split-month-year) as <bool>;
|
visible: bind $get_split_choice_visible(template.show-heading, template.split-month-year) as <bool>;
|
||||||
notify::value => $split_multi_choice_changed() swapped;
|
user-changed => $on_split_multi_choice_user_changed() swapped;
|
||||||
|
|
||||||
layout {
|
layout {
|
||||||
column: 0;
|
column: 0;
|
||||||
@@ -33,7 +33,7 @@ template $GcalDateChooser: Adw.Bin {
|
|||||||
category: _("Year");
|
category: _("Year");
|
||||||
previous-button-tooltip: _("Previous Year");
|
previous-button-tooltip: _("Previous Year");
|
||||||
next-button-tooltip: _("Next Year");
|
next-button-tooltip: _("Next Year");
|
||||||
notify::value => $split_multi_choice_changed() swapped;
|
user-changed => $on_split_multi_choice_user_changed() swapped;
|
||||||
|
|
||||||
layout {
|
layout {
|
||||||
column: 1;
|
column: 1;
|
||||||
@@ -53,7 +53,7 @@ template $GcalDateChooser: Adw.Bin {
|
|||||||
category: _("Month");
|
category: _("Month");
|
||||||
previous-button-tooltip: _("Previous Month");
|
previous-button-tooltip: _("Previous Month");
|
||||||
next-button-tooltip: _("Next Month");
|
next-button-tooltip: _("Next Month");
|
||||||
notify::value => $combined_multi_choice_changed() swapped;
|
user-changed => $on_combined_multi_choice_user_changed() swapped;
|
||||||
|
|
||||||
layout {
|
layout {
|
||||||
column: 0;
|
column: 0;
|
||||||
@@ -92,6 +92,7 @@ Popover popover {
|
|||||||
previous-button-tooltip: bind month_choice.previous-button-tooltip;
|
previous-button-tooltip: bind month_choice.previous-button-tooltip;
|
||||||
next-button-tooltip: bind month_choice.next-button-tooltip;
|
next-button-tooltip: bind month_choice.next-button-tooltip;
|
||||||
string-list: bind month_choice.string-list;
|
string-list: bind month_choice.string-list;
|
||||||
|
user-changed => $on_split_multi_choice_user_changed() swapped;
|
||||||
}
|
}
|
||||||
|
|
||||||
$GcalMultiChoice {
|
$GcalMultiChoice {
|
||||||
@@ -102,6 +103,7 @@ Popover popover {
|
|||||||
previous-button-tooltip: bind year_choice.previous-button-tooltip;
|
previous-button-tooltip: bind year_choice.previous-button-tooltip;
|
||||||
next-button-tooltip: bind year_choice.next-button-tooltip;
|
next-button-tooltip: bind year_choice.next-button-tooltip;
|
||||||
string-list: bind year_choice.string-list;
|
string-list: bind year_choice.string-list;
|
||||||
|
user-changed => $on_split_multi_choice_user_changed() swapped;
|
||||||
}
|
}
|
||||||
|
|
||||||
styles [
|
styles [
|
||||||
|
|||||||
@@ -600,9 +600,6 @@ gcal_date_chooser_set_date (GcalView *view,
|
|||||||
g_date_time_get_ymd (self->date, &y1, &m1, &d1);
|
g_date_time_get_ymd (self->date, &y1, &m1, &d1);
|
||||||
g_date_time_get_ymd (date, &y2, &m2, &d2);
|
g_date_time_get_ymd (date, &y2, &m2, &d2);
|
||||||
|
|
||||||
if (y1 != y2 || m1 != m2)
|
|
||||||
d2 = 1;
|
|
||||||
|
|
||||||
gcal_set_date_time (&self->date, date);
|
gcal_set_date_time (&self->date, date);
|
||||||
|
|
||||||
if (y1 != y2 || m1 != m2 || d1 != d2)
|
if (y1 != y2 || m1 != m2 || d1 != d2)
|
||||||
@@ -871,30 +868,25 @@ multi_choice_changed (GcalDateChooser *self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
combined_multi_choice_changed (GcalDateChooser *self)
|
on_combined_multi_choice_user_changed (GcalDateChooser *self)
|
||||||
{
|
{
|
||||||
gint year, month, day, value;
|
int year, month, value;
|
||||||
|
|
||||||
value = gcal_multi_choice_get_value (GCAL_MULTI_CHOICE (self->combined_choice));
|
value = gcal_multi_choice_get_value (GCAL_MULTI_CHOICE (self->combined_choice));
|
||||||
decode_combined_choice_value (value, &year, &month, &day);
|
decode_combined_choice_value (value, &year, &month, NULL);
|
||||||
|
|
||||||
multi_choice_changed (self, year, month, day);
|
multi_choice_changed (self, year, month, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
split_multi_choice_changed (GcalDateChooser *self)
|
on_split_multi_choice_user_changed (GcalDateChooser *self)
|
||||||
{
|
{
|
||||||
gint year, month, day;
|
int year, month;
|
||||||
|
|
||||||
year = gcal_multi_choice_get_value (GCAL_MULTI_CHOICE (self->year_choice));
|
year = gcal_multi_choice_get_value (GCAL_MULTI_CHOICE (self->year_choice));
|
||||||
month = gcal_multi_choice_get_value (GCAL_MULTI_CHOICE (self->month_choice)) + 1;
|
month = gcal_multi_choice_get_value (GCAL_MULTI_CHOICE (self->month_choice)) + 1;
|
||||||
|
|
||||||
day = g_date_time_get_day_of_month (self->date);
|
multi_choice_changed (self, year, month, 1);
|
||||||
|
|
||||||
/* Make sure the day is valid at that month */
|
|
||||||
day = MIN (day, month_length[leap (year)][month]);
|
|
||||||
|
|
||||||
multi_choice_changed (self, year, month, day);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@@ -1028,10 +1020,10 @@ gcal_date_chooser_class_init (GcalDateChooserClass *class)
|
|||||||
gtk_widget_class_bind_template_child (widget_class, GcalDateChooser, grid);
|
gtk_widget_class_bind_template_child (widget_class, GcalDateChooser, grid);
|
||||||
gtk_widget_class_bind_template_child (widget_class, GcalDateChooser, gizmo);
|
gtk_widget_class_bind_template_child (widget_class, GcalDateChooser, gizmo);
|
||||||
|
|
||||||
gtk_widget_class_bind_template_callback (widget_class, combined_multi_choice_changed);
|
gtk_widget_class_bind_template_callback (widget_class, on_combined_multi_choice_user_changed);
|
||||||
gtk_widget_class_bind_template_callback (widget_class, get_combined_choice_visible);
|
gtk_widget_class_bind_template_callback (widget_class, get_combined_choice_visible);
|
||||||
gtk_widget_class_bind_template_callback (widget_class, get_split_choice_visible);
|
gtk_widget_class_bind_template_callback (widget_class, get_split_choice_visible);
|
||||||
gtk_widget_class_bind_template_callback (widget_class, split_multi_choice_changed);
|
gtk_widget_class_bind_template_callback (widget_class, on_split_multi_choice_user_changed);
|
||||||
|
|
||||||
gtk_widget_class_set_css_name (widget_class, "datechooser");
|
gtk_widget_class_set_css_name (widget_class, "datechooser");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user