month-cell: Clone and modify new event when dropping
Instead of modifying the original event, create a new event from it and modify this new event instead. After updating it through gcal_manager_update_event(), GcalMonthView will remove the old instance and add the new one anyway.
This commit is contained in:
@@ -204,6 +204,7 @@ gcal_month_cell_drag_drop (GtkWidget *widget,
|
|||||||
gint y,
|
gint y,
|
||||||
guint time)
|
guint time)
|
||||||
{
|
{
|
||||||
|
g_autoptr (GcalEvent) changed_event = NULL;
|
||||||
GcalRecurrenceModType mod;
|
GcalRecurrenceModType mod;
|
||||||
GcalMonthCell *self;
|
GcalMonthCell *self;
|
||||||
GcalCalendar *calendar;
|
GcalCalendar *calendar;
|
||||||
@@ -228,17 +229,18 @@ gcal_month_cell_drag_drop (GtkWidget *widget,
|
|||||||
GCAL_RETURN (FALSE);
|
GCAL_RETURN (FALSE);
|
||||||
|
|
||||||
event = gcal_event_widget_get_event (GCAL_EVENT_WIDGET (event_widget));
|
event = gcal_event_widget_get_event (GCAL_EVENT_WIDGET (event_widget));
|
||||||
calendar = gcal_event_get_calendar (event);
|
changed_event = gcal_event_new_from_event (event);
|
||||||
|
calendar = gcal_event_get_calendar (changed_event);
|
||||||
|
|
||||||
if (gcal_event_has_recurrence (event) &&
|
if (gcal_event_has_recurrence (changed_event) &&
|
||||||
!ask_recurrence_modification_type (widget, &mod, calendar))
|
!ask_recurrence_modification_type (widget, &mod, calendar))
|
||||||
{
|
{
|
||||||
GCAL_GOTO (out);
|
GCAL_GOTO (out);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Move the event's date */
|
/* Move the event's date */
|
||||||
start_dt = gcal_event_get_date_start (event);
|
start_dt = gcal_event_get_date_start (changed_event);
|
||||||
end_dt = gcal_event_get_date_end (event);
|
end_dt = gcal_event_get_date_end (changed_event);
|
||||||
|
|
||||||
start_month = g_date_time_get_month (start_dt);
|
start_month = g_date_time_get_month (start_dt);
|
||||||
start_year = g_date_time_get_year (start_dt);
|
start_year = g_date_time_get_year (start_dt);
|
||||||
@@ -263,18 +265,18 @@ gcal_month_cell_drag_drop (GtkWidget *widget,
|
|||||||
|
|
||||||
new_start = g_date_time_add_days (start_dt, diff);
|
new_start = g_date_time_add_days (start_dt, diff);
|
||||||
|
|
||||||
gcal_event_set_date_start (event, new_start);
|
gcal_event_set_date_start (changed_event, new_start);
|
||||||
|
|
||||||
/* The event may have a NULL end date, so we have to check it here */
|
/* The event may have a NULL end date, so we have to check it here */
|
||||||
if (end_dt)
|
if (end_dt)
|
||||||
{
|
{
|
||||||
GDateTime *new_end = g_date_time_add (new_start, timespan);
|
GDateTime *new_end = g_date_time_add (new_start, timespan);
|
||||||
|
|
||||||
gcal_event_set_date_end (event, new_end);
|
gcal_event_set_date_end (changed_event, new_end);
|
||||||
g_clear_pointer (&new_end, g_date_time_unref);
|
g_clear_pointer (&new_end, g_date_time_unref);
|
||||||
}
|
}
|
||||||
|
|
||||||
gcal_manager_update_event (gcal_context_get_manager (self->context), event, mod);
|
gcal_manager_update_event (gcal_context_get_manager (self->context), changed_event, mod);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_clear_pointer (&start_dt, g_date_time_unref);
|
g_clear_pointer (&start_dt, g_date_time_unref);
|
||||||
|
|||||||
Reference in New Issue
Block a user