From 344e2d8bcb7db81f051dd45ee368bd2c6be7822e Mon Sep 17 00:00:00 2001 From: Benjamin Kitt Date: Thu, 27 Jan 2022 20:46:41 -0600 Subject: [PATCH] Update sources in calendar chooser when source connects If calendar chooser is displayed before sources are fully loaded, re-renders sources so that all calendars become available. --- src/EventEdition/InfoPanel.vala | 2 +- src/Widgets/CalendarButton.vala | 1 + src/Widgets/CalendarChooser.vala | 39 ++++++++++++++++++++------------ 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/EventEdition/InfoPanel.vala b/src/EventEdition/InfoPanel.vala index 09b9c3c71..33f663e07 100644 --- a/src/EventEdition/InfoPanel.vala +++ b/src/EventEdition/InfoPanel.vala @@ -163,7 +163,7 @@ public class Maya.View.EventEdition.InfoPanel : Gtk.Grid { // Row: title & calendar attach (title_label, 0, 0, 1, 1); attach (title_entry, 0, 1, 1, 1); - if (calendar_button.sources.length () > 1 && parent_dialog.can_edit) { + if (parent_dialog.can_edit) { attach (calendar_label, 1, 0, 4, 1); attach (calendar_button, 1, 1, 4, 1); } diff --git a/src/Widgets/CalendarButton.vala b/src/Widgets/CalendarButton.vala index 6c1a78586..3392026f4 100644 --- a/src/Widgets/CalendarButton.vala +++ b/src/Widgets/CalendarButton.vala @@ -45,6 +45,7 @@ public class Maya.View.Widgets.CalendarButton : Gtk.MenuButton { var button_grid = new Gtk.Grid (); button_grid.column_spacing = 6; + button_grid.valign = Gtk.Align.CENTER; button_grid.add (current_calendar_grid); button_grid.add (new Gtk.Image.from_icon_name ("pan-down-symbolic", Gtk.IconSize.MENU)); add (button_grid); diff --git a/src/Widgets/CalendarChooser.vala b/src/Widgets/CalendarChooser.vala index 665d2c925..e98ddc1af 100644 --- a/src/Widgets/CalendarChooser.vala +++ b/src/Widgets/CalendarChooser.vala @@ -28,23 +28,17 @@ public class Maya.View.Widgets.CalendarChooser : Gtk.Grid { public GLib.List sources; public E.Source current_source { get; set; } + private Calendar.EventStore calmodel; + private E.SourceRegistry registry; private Gtk.SearchEntry search_entry; + private Gtk.ListBox list_box; construct { - // Set up sources list - sources = new GLib.List (); - var calmodel = Calendar.EventStore.get_default (); - var registry = calmodel.registry; - foreach (var src in registry.list_sources (E.SOURCE_EXTENSION_CALENDAR)) { - if (src.writable == true && src.enabled == true && calmodel.calclient_is_readonly (src) == false) { - sources.append (src); - } - } - - // GUI setup - + calmodel = Calendar.EventStore.get_default (); + registry = calmodel.registry; current_source = registry.default_calendar; + // GUI setup search_entry = new Gtk.SearchEntry (); search_entry.margin = 12; search_entry.margin_bottom = 6; @@ -57,7 +51,7 @@ public class Maya.View.Widgets.CalendarChooser : Gtk.Grid { ); placeholder.show_all (); - var list_box = new Gtk.ListBox (); + list_box = new Gtk.ListBox (); list_box.activate_on_single_click = true; list_box.set_placeholder (placeholder); @@ -123,7 +117,24 @@ public class Maya.View.Widgets.CalendarChooser : Gtk.Grid { // TODO Should active calendar be re-selected? }); - // Populate list_box + // Parse registry list_sources and render list_box; + render_sources (); + + // Re-render sources when a new source connects; + calmodel.connected.connect (() => render_sources ()); + } + + private void render_sources () { + // Set up sources list + sources = new GLib.List (); + foreach (var src in registry.list_sources (E.SOURCE_EXTENSION_CALENDAR)) { + if (src.writable == true && src.enabled == true && calmodel.calclient_is_readonly (src) == false) { + sources.append (src); + } + } + + // Render sources into list_box + list_box.foreach (element => list_box.remove (element)); foreach (var source in sources) { var calrow = new CalendarRow (source); calrow.margin = 6;