From 5bc8fffc7157dafb2e9500e8d13c01888dac57be Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Mon, 7 Aug 2023 10:23:13 -0300 Subject: [PATCH] views/dazzling: Add cached events to shuffled row Cached events won't be readded by the backend, because they're alread present in the view, so we have to manually add them to the rows. --- src/gui/views/gcal-dazzling-month-view.c | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/gui/views/gcal-dazzling-month-view.c b/src/gui/views/gcal-dazzling-month-view.c index 0db0e196..f04a78af 100644 --- a/src/gui/views/gcal-dazzling-month-view.c +++ b/src/gui/views/gcal-dazzling-month-view.c @@ -149,6 +149,28 @@ update_active_date (GcalDazzlingMonthView *self) g_object_notify (G_OBJECT (self), "active-date"); } +static void +add_cached_events_to_row (GcalDazzlingMonthView *self, + GcalMonthViewRow *row) +{ + g_autoptr (GcalRange) row_range = NULL; + GHashTableIter iter; + GcalEvent *event; + + row_range = gcal_month_view_row_get_range (row); + + g_hash_table_iter_init (&iter, self->events); + while (g_hash_table_iter_next (&iter, (gpointer *) &event, NULL)) + { + GcalRangeOverlap overlap = gcal_range_calculate_overlap (row_range, gcal_event_get_range (event), NULL); + + if (overlap == GCAL_RANGE_NO_OVERLAP) + continue; + + gcal_month_view_row_add_event (row, event); + } +} + static void move_bottom_row_to_top (GcalDazzlingMonthView *self) { @@ -179,6 +201,8 @@ move_bottom_row_to_top (GcalDazzlingMonthView *self) last_row = g_ptr_array_steal_index (self->week_rows, self->week_rows->len - 1); gcal_month_view_row_set_range (GCAL_MONTH_VIEW_ROW (last_row), new_range); g_ptr_array_insert (self->week_rows, 0, last_row); + + add_cached_events_to_row (self, GCAL_MONTH_VIEW_ROW (last_row)); } static void @@ -211,6 +235,8 @@ move_top_row_to_bottom (GcalDazzlingMonthView *self) first_row = g_ptr_array_steal_index (self->week_rows, 0); gcal_month_view_row_set_range (GCAL_MONTH_VIEW_ROW (first_row), new_range); g_ptr_array_insert (self->week_rows, -1, first_row); + + add_cached_events_to_row (self, GCAL_MONTH_VIEW_ROW (first_row)); } static inline void