-
-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update sources in calendar chooser when source connects #742
Open
benjaminkitt
wants to merge
6
commits into
elementary:master
Choose a base branch
from
benjaminkitt:add-event-update-sources
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+27
−15
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
344e2d8
Update sources in calendar chooser when source connects
benjaminkitt c2ab1b3
Merge branch 'master' into add-event-update-sources
benjaminkitt 7038315
Merge branch 'master' into add-event-update-sources
benjaminkitt 8edfe1e
Merge branch 'master' into add-event-update-sources
995d2ed
Merge branch 'master' into add-event-update-sources
zeebok bee3b36
Merge branch 'master' into add-event-update-sources
jeremypw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,23 +28,17 @@ public class Maya.View.Widgets.CalendarChooser : Gtk.Grid { | |
public GLib.List<E.Source> 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<E.Source> (); | ||
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 () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extracted render code into a private method so it can be used both in the initial constructor and as an event handler. |
||
// Set up sources list | ||
sources = new GLib.List<E.Source> (); | ||
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; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered adding this element only once all sources were initialized but given that the registry is accessed within the CalendarChooser component, it would have led to a lot of extra code. The only downside to this approach is that a user who only has one calendar will only have one source to select from in the dropdown. I think this is a reasonably minor UX tradeoff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a fine tradeoff. From my perspective (not on the UX team) having the selector present even with only one source may be good for consistency.
My only concern is that this could lead to a state where not all the sources are available in the chooser. Depending how long that state lasts it may be worthwhile to add a spinner or something of the sort, if there's an easy way to access a state that indicates we're still loading sources. This may not be much of an issue though.