[california/wip/725767-week] Move Month.Controller to Toolkit.StackModel
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [california/wip/725767-week] Move Month.Controller to Toolkit.StackModel
- Date: Fri, 2 May 2014 23:22:05 +0000 (UTC)
commit 8585410bc89c17908507a9ea174ad9f68f9b88ab
Author: Jim Nelson <jim yorba org>
Date: Fri May 2 16:21:19 2014 -0700
Move Month.Controller to Toolkit.StackModel
Still some bugs: re-introduced bug where transition doesn't occur
if jumping to Today from far out; month view is not hooked up at
start.
src/view/month/month-controller.vala | 103 +++++++++++-----------------------
1 files changed, 33 insertions(+), 70 deletions(-)
---
diff --git a/src/view/month/month-controller.vala b/src/view/month/month-controller.vala
index 918bfe0..2d957bf 100644
--- a/src/view/month/month-controller.vala
+++ b/src/view/month/month-controller.vala
@@ -73,7 +73,8 @@ public class Controller : BaseObject, View.Controllable {
private MasterGrid master_grid;
private Gtk.Stack stack = new Gtk.Stack();
- private Gee.HashMap<Calendar.MonthOfYear, Grid> month_grids = new Gee.HashMap<Calendar.MonthOfYear,
Grid>();
+ private Toolkit.StackModel<Calendar.MonthOfYear> stack_model;
+ private Calendar.MonthSpan cache_span;
public Controller() {
master_grid = new MasterGrid(this);
@@ -85,6 +86,10 @@ public class Controller : BaseObject, View.Controllable {
stack.transition_duration = TRANSITION_DURATION_MSEC;
+ stack_model = new Toolkit.StackModel<Calendar.MonthOfYear>(stack,
+ Toolkit.StackModel.OrderedTransitionType.SLIDE_LEFT_RIGHT, model_presentation,
+ trim_presentation_from_cache, ensure_presentation_in_cache);
+
// insert labels for days of the week across top of master grid
for (int col = 0; col < Grid.COLS; col++) {
Gtk.Label dow_label = new Gtk.Label(null);
@@ -118,49 +123,32 @@ public class Controller : BaseObject, View.Controllable {
Calendar.System.instance.today_changed.disconnect(on_today_changed);
}
- // Creates a new Grid for the MonthOfYear, storing locally and adding to the GtkStack. Will
- // reuse existing Grids whenever possible.
- private void ensure_month_grid_exists(Calendar.MonthOfYear month_of_year) {
- if (month_grids.has_key(month_of_year))
- return;
+ private Gtk.Widget model_presentation(Calendar.MonthOfYear moy, out string? id) {
+ debug("Creating month grid for %s", moy.to_string());
- Grid month_grid = new Grid(this, month_of_year);
- month_grid.show_all();
+ Grid grid = new Grid(this, moy);
+ id = grid.id;
- // add to local store and to the GtkStack itself
- month_grids.set(month_of_year, month_grid);
- stack.add_named(month_grid, month_grid.id);
+ return grid;
}
- // Performs Grid caching by ensuring that Grids are available for the current, next, and
- // previous month and that Grids outside that range are dropped. The current chronological
- // month is never discarded.
- private void update_month_grid_cache() {
- Calendar.MonthSpan cache_span = new Calendar.MonthSpan.from_months(
- month_of_year.adjust(0 - (CACHE_NEIGHBORS_COUNT / 2)),
- month_of_year.adjust(CACHE_NEIGHBORS_COUNT / 2));
+ private bool trim_presentation_from_cache(Calendar.MonthOfYear moy, Calendar.MonthOfYear? visible_moy) {
+ // always keep current month in cache
+ if (moy.equal_to(Calendar.System.today.month_of_year()))
+ return false;
- // trim cache
- Gee.MapIterator<Calendar.MonthOfYear, Grid> iter = month_grids.map_iterator();
- while (iter.next()) {
- Calendar.MonthOfYear grid_moy = iter.get_key();
-
- // always keep current month
- if (grid_moy.equal_to(Calendar.System.today.month_of_year()))
- continue;
-
- // keep if grid is in cache span
- if (cache_span.has(grid_moy))
- continue;
-
- // drop, remove from GtkStack and local storage
- stack.remove(iter.get_value());
- iter.unset();
- }
+ return !(cache_span.has(moy));
+ }
+
+ private Gee.Collection<Calendar.MonthOfYear>? ensure_presentation_in_cache(
+ Calendar.MonthOfYear? visible_moy) {
+ // convert cache span into a collection on months
+ Gee.List<Calendar.MonthOfYear> months = cache_span.as_list();
- // ensure all-months in span are available
- foreach (Calendar.MonthOfYear moy in cache_span)
- ensure_month_grid_exists(moy);
+ // add today's month
+ months.add(Calendar.System.today.month_of_year());
+
+ return months;
}
private unowned Grid? get_current_month_grid() {
@@ -221,39 +209,14 @@ public class Controller : BaseObject, View.Controllable {
current_label = month_of_year.full_name;
update_is_viewing_today();
- // set up transition to give appearance of moving chronologically through the pages of
- // a calendar
- Grid? current_grid = get_current_month_grid();
- if (current_grid != null) {
- Calendar.MonthOfYear current_moy = current_grid.month_of_year;
- int compare = month_of_year.compare_to(current_moy);
- if (compare < 0)
- stack.transition_type = Gtk.StackTransitionType.SLIDE_RIGHT;
- else if (compare > 0)
- stack.transition_type = Gtk.StackTransitionType.SLIDE_LEFT;
- else
- return;
- }
-
- // because grid cache is populated/trimmed after sliding month into view, ensure the
- // desired month already exists
- ensure_month_grid_exists(month_of_year);
+ // update cache span, splitting down the middle of the current month
+ Calendar.DateSpan date_span = new Calendar.DateSpan(
+ month_of_year.adjust(0 - (CACHE_NEIGHBORS_COUNT / 2)).start_date,
+ month_of_year.adjust(CACHE_NEIGHBORS_COUNT / 2).end_date);
+ cache_span = new Calendar.MonthSpan(date_span);
- // make visible using proper transition type
- stack.set_visible_child(month_grids.get(month_of_year));
-
- // now update the cache to store current month and neighbors ... do this after doing above
- // comparison because this update affects the GtkStack, which may revert to another page
- // when the cache is trimmed, making the notion of "current" indeterminate; the most
- // visible symptom of this is navigating far from today's month then clicking the Today
- // button and no transition occurs because, when the cache is trimmed, today's month is
- // the current child ... to avoid dropping the Widget before the transition completes,
- // wait before doing this; 3.12's "transition-running" property would be useful here
- Idle.add(() => {
- update_month_grid_cache();
-
- return false;
- }, Priority.LOW);
+ // show (and add if not present) the current month
+ stack_model.show(month_of_year);
}
public override string to_string() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]