Skip to content

Commit 3ba4a76

Browse files
authored
AgendaView: rewrite find without get_children (#895)
1 parent d00f4ee commit 3ba4a76

1 file changed

Lines changed: 25 additions & 28 deletions

File tree

src/AgendaView.vala

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -313,27 +313,31 @@ public class Maya.View.AgendaView : Gtk.Box {
313313
}
314314
}
315315

316-
private static int search_calcomp (Gtk.Widget widget, ECal.Component comp) {
317-
unowned AgendaEventRow row = widget as AgendaEventRow;
318-
return Calendar.Util.ecalcomponent_compare_func (row.calevent, comp);
316+
private bool find_row_for_component (Gtk.ListBox listbox, ECal.Component component, out AgendaEventRow? row) {
317+
for (int i = 0; listbox.get_row_at_index (i) != null; i++) {
318+
var current_row = (AgendaEventRow) listbox.get_row_at_index (i);
319+
if (Calendar.Util.ecalcomponent_compare_func (current_row.calevent, component) == 0) {
320+
row = current_row;
321+
return true;
322+
}
323+
}
324+
325+
row = null;
326+
return false;
319327
}
320328

321329
/**
322330
* Events for the given source have been updated.
323331
*/
324332
private void on_events_updated (E.Source source, Gee.Collection<ECal.Component> events) {
325-
GLib.List<weak Gtk.Widget> selected_date_events_children = selected_date_events_list.get_children ();
326-
GLib.List<weak Gtk.Widget> upcoming_events_children = upcoming_events_list.get_children ();
327-
328333
foreach (var event in events) {
329-
unowned List<weak Gtk.Widget> found = selected_date_events_children.search<ECal.Component> (event, search_calcomp);
330-
if (found != null) {
331-
((AgendaEventRow) found.data).update (event);
334+
AgendaEventRow row = null;
335+
if (find_row_for_component (selected_date_events_list, event, out row)) {
336+
row.update (event);
332337
}
333338

334-
unowned List<weak Gtk.Widget> found2 = upcoming_events_children.search<ECal.Component> (event, search_calcomp);
335-
if (found2 != null) {
336-
((AgendaEventRow) found2.data).update (event);
339+
if (find_row_for_component (upcoming_events_list, event, out row)) {
340+
row.update (event);
337341
}
338342
}
339343
}
@@ -342,25 +346,21 @@ public class Maya.View.AgendaView : Gtk.Box {
342346
* Events for the given source have been removed.
343347
*/
344348
private void on_events_removed (E.Source source, Gee.Collection<ECal.Component> events) {
345-
GLib.List<weak Gtk.Widget> selected_date_events_children = selected_date_events_list.get_children ();
346-
GLib.List<weak Gtk.Widget> upcoming_events_children = upcoming_events_list.get_children ();
347-
348349
foreach (var event in events) {
349-
unowned List<weak Gtk.Widget> found = selected_date_events_children.search<ECal.Component> (event, search_calcomp);
350-
if (found != null) {
351-
var row = ((AgendaEventRow) found.data);
352-
row.revealer.set_reveal_child (false);
350+
AgendaEventRow row = null;
351+
if (find_row_for_component (selected_date_events_list, event, out row)) {
352+
row.revealer.reveal_child = false;
353353
GLib.Timeout.add (row.revealer.transition_duration, () => {
354+
row.unparent ();
354355
row.destroy ();
355356
return GLib.Source.REMOVE;
356357
});
357358
}
358359

359-
unowned List<weak Gtk.Widget> found2 = upcoming_events_children.search<ECal.Component> (event, search_calcomp);
360-
if (found2 != null) {
361-
var row = ((AgendaEventRow) found2.data);
362-
row.revealer.set_reveal_child (false);
360+
if (find_row_for_component (upcoming_events_list, event, out row)) {
361+
row.revealer.reveal_child = false;
363362
GLib.Timeout.add (row.revealer.transition_duration, () => {
363+
row.unparent ();
364364
row.destroy ();
365365
return GLib.Source.REMOVE;
366366
});
@@ -372,14 +372,11 @@ public class Maya.View.AgendaView : Gtk.Box {
372372
* Calendar model parameters have been updated.
373373
*/
374374
private void on_model_parameters_changed () {
375-
GLib.List<weak Gtk.Widget> selected_date_events_children = selected_date_events_list.get_children ();
376-
GLib.List<weak Gtk.Widget> upcoming_events_children = upcoming_events_list.get_children ();
377-
378-
foreach (unowned Gtk.Widget row in selected_date_events_children) {
375+
foreach (unowned var row in selected_date_events_list.get_children ()) {
379376
row.destroy ();
380377
}
381378

382-
foreach (unowned Gtk.Widget row in upcoming_events_children) {
379+
foreach (unowned var row in upcoming_events_list.get_children ()) {
383380
row.destroy ();
384381
}
385382
}

0 commit comments

Comments
 (0)