[california] Refinements to Toolkit.Deck/Toolkit.Card



commit f739187f80bbb5284341ae95d2b1202b00fdf2e8
Author: Jim Nelson <jim yorba org>
Date:   Fri Nov 21 16:03:06 2014 -0800

    Refinements to Toolkit.Deck/Toolkit.Card

 src/event-editor/event-editor-attendees-card.vala |    9 +++----
 src/event-editor/event-editor-date-time-card.vala |    6 ++++-
 src/event-editor/event-editor-main-card.vala      |   16 ++++++++++---
 src/event-editor/event-editor-recurring-card.vala |    6 ++++-
 src/host/host-main-window.vala                    |    8 +-----
 src/toolkit/toolkit-card.vala                     |    2 -
 src/toolkit/toolkit-deck.vala                     |   24 +++++++++++++-------
 7 files changed, 43 insertions(+), 28 deletions(-)
---
diff --git a/src/event-editor/event-editor-attendees-card.vala 
b/src/event-editor/event-editor-attendees-card.vala
index fa3566c..4ee391e 100644
--- a/src/event-editor/event-editor-attendees-card.vala
+++ b/src/event-editor/event-editor-attendees-card.vala
@@ -8,7 +8,7 @@ namespace California.EventEditor {
 
 [GtkTemplate (ui = "/org/yorba/california/rc/event-editor-attendees-card.ui")]
 public class AttendeesCard : Gtk.Box, Toolkit.Card {
-    private const string ID = "CaliforniaEventEditorAttendees";
+    public const string ID = "CaliforniaEventEditorAttendees";
     
     private class Message : Object {
         public Component.Event event;
@@ -127,9 +127,8 @@ public class AttendeesCard : Gtk.Box, Toolkit.Card {
         return true;
     }
     
-    public static void pass_message(Toolkit.Card caller, Component.Event event,
-        Backing.CalendarSource calendar_source) {
-        caller.jump_to_card_by_id(ID, new Message(event, calendar_source));
+    public static Value? make_message(Component.Event event, Backing.CalendarSource calendar_source) {
+        return new Message(event, calendar_source);
     }
     
     public void jumped_to(Toolkit.Card? from, Toolkit.Card.Jump reason, Value? message_value) {
@@ -227,7 +226,7 @@ public class AttendeesCard : Gtk.Box, Toolkit.Card {
         event.clear_attendees();
         event.add_attendees(guest_model.all());
         
-        jump_to_card_by_id(MainCard.ID, event);
+        jump_to_card_by_id(MainCard.ID, MainCard.make_message_event(event));
     }
     
     [GtkCallback]
diff --git a/src/event-editor/event-editor-date-time-card.vala 
b/src/event-editor/event-editor-date-time-card.vala
index 9558a5a..8279602 100644
--- a/src/event-editor/event-editor-date-time-card.vala
+++ b/src/event-editor/event-editor-date-time-card.vala
@@ -110,6 +110,10 @@ public class DateTimeCard : Gtk.Box, Toolkit.Card {
         return true;
     }
     
+    public static Value? make_message(Message date_time_message) {
+        return date_time_message;
+    }
+    
     public void jumped_to(Toolkit.Card? from, Toolkit.Card.Jump reason, Value? message_value) {
         message = (Message) message_value;
         
@@ -159,7 +163,7 @@ public class DateTimeCard : Gtk.Box, Toolkit.Card {
         else
             message.reset_exact_time_span(get_exact_time_span());
         
-        jump_to_card_by_id(MainCard.ID, message);
+        jump_to_card_by_id(MainCard.ID, MainCard.make_message_date_time(message));
     }
     
     private void freeze_widget_notifications() {
diff --git a/src/event-editor/event-editor-main-card.vala b/src/event-editor/event-editor-main-card.vala
index 604681a..ff5fcfa 100644
--- a/src/event-editor/event-editor-main-card.vala
+++ b/src/event-editor/event-editor-main-card.vala
@@ -133,8 +133,16 @@ public class MainCard : Gtk.Grid, Toolkit.Card {
         return true;
     }
     
+    public static Value? make_message_event(Component.Event event) {
+        return event;
+    }
+    
+    public static Value? make_message_date_time(DateTimeCard.Message date_time) {
+        return date_time;
+    }
+    
     public void jumped_to(Toolkit.Card? from, Toolkit.Card.Jump reason, Value? message) {
-        // if no message, leave everything as it is
+        // if no message, leave everything as it is (i.e. jumped back to)
         if (message == null)
             return;
         
@@ -258,7 +266,7 @@ public class MainCard : Gtk.Grid, Toolkit.Card {
         update_component(event, true);
         
         // send off to recurring editor
-        jump_to_card_by_id(RecurringCard.ID, event);
+        jump_to_card_by_id(RecurringCard.ID, RecurringCard.make_message(event));
     }
     
     [GtkCallback]
@@ -269,13 +277,13 @@ public class MainCard : Gtk.Grid, Toolkit.Card {
         // save changes with what's in the component now
         update_component(event, true);
         
-        jump_to_card_by_id(DateTimeCard.ID, dt);
+        jump_to_card_by_id(DateTimeCard.ID, DateTimeCard.make_message(dt));
     }
     
     [GtkCallback]
     private void on_attendees_button_clicked() {
         if (calendar_model.active != null)
-            AttendeesCard.pass_message(this, event, calendar_model.active);
+            jump_to_card_by_id(AttendeesCard.ID, AttendeesCard.make_message(event, calendar_model.active));
     }
     
     private void on_accept_button_clicked() {
diff --git a/src/event-editor/event-editor-recurring-card.vala 
b/src/event-editor/event-editor-recurring-card.vala
index 16a29c5..208bf7f 100644
--- a/src/event-editor/event-editor-recurring-card.vala
+++ b/src/event-editor/event-editor-recurring-card.vala
@@ -236,6 +236,10 @@ public class RecurringCard : Gtk.Grid, Toolkit.Card {
         return true;
     }
     
+    public static Value? make_message(Component.Event event) {
+        return event;
+    }
+    
     public void jumped_to(Toolkit.Card? from, Toolkit.Card.Jump reason, Value? message) {
         assert(message != null);
         
@@ -492,7 +496,7 @@ public class RecurringCard : Gtk.Grid, Toolkit.Card {
     [GtkCallback]
     private void on_ok_button_clicked() {
         update_master();
-        jump_to_card_by_id(MainCard.ID, event);
+        jump_to_card_by_id(MainCard.ID, MainCard.make_message_event(event));
     }
     
     private bool can_make_rrule() {
diff --git a/src/host/host-main-window.vala b/src/host/host-main-window.vala
index 936f86f..61e3df6 100644
--- a/src/host/host-main-window.vala
+++ b/src/host/host-main-window.vala
@@ -451,9 +451,7 @@ public class MainWindow : Gtk.ApplicationWindow {
         
         QuickCreateEvent quick_create = new QuickCreateEvent(use_deck_window);
         
-        Toolkit.Deck deck = new Toolkit.Deck();
-        deck.add_cards(iterate<Toolkit.Card>(quick_create).to_array_list());
-        
+        Toolkit.Deck deck = new Toolkit.Deck(quick_create);
         deck.go_home(initial);
         
         deck.dismiss.connect(() => {
@@ -471,9 +469,7 @@ public class MainWindow : Gtk.ApplicationWindow {
         Gdk.Point? for_location) {
         ShowEvent show_event = new ShowEvent();
         
-        Toolkit.Deck deck = new Toolkit.Deck();
-        deck.add_cards(iterate<Toolkit.Card>(show_event).to_array_list());
-        
+        Toolkit.Deck deck = new Toolkit.Deck(show_event);
         deck.go_home(event);
         
         deck.dismiss.connect(() => {
diff --git a/src/toolkit/toolkit-card.vala b/src/toolkit/toolkit-card.vala
index 2150176..3b566ca 100644
--- a/src/toolkit/toolkit-card.vala
+++ b/src/toolkit/toolkit-card.vala
@@ -98,8 +98,6 @@ public interface Card : Gtk.Widget {
     
     /**
      * Fired when the { link Card} wishes to jump to another Card by its name.
-     *
-     * @see jump_to_card
      */
     public signal void jump_to_card_by_id(string id, Value? message);
     
diff --git a/src/toolkit/toolkit-deck.vala b/src/toolkit/toolkit-deck.vala
index b1a5646..224cb61 100644
--- a/src/toolkit/toolkit-deck.vala
+++ b/src/toolkit/toolkit-deck.vala
@@ -69,12 +69,18 @@ public class Deck : Gtk.Stack {
      * By default the Deck configures the underlying Gtk.Stack to slide left and right, depending
      * on the position of the { link Card}s.  This can be changed, but the recommended
      * transition types are SLIDE_LEFT_RIGHT and SLIDE_UP_DOWN.
+     *
+     * If a { link Card} is passed, that will be the first Card added to the Deck and therefore the
+     * { link home} Card.
      */
-    public Deck() {
+    public Deck(Card? home = null) {
         transition_type = Gtk.StackTransitionType.SLIDE_LEFT_RIGHT;
         transition_duration = DEFAULT_STACK_TRANSITION_DURATION_MSEC;
         
         notify["visible-child"].connect(on_child_to_top);
+        
+        if (home != null)
+            add_card(home);
     }
     
     ~Deck() {
@@ -241,7 +247,7 @@ public class Deck : Gtk.Stack {
         home.jumped_to(null, Card.Jump.HOME, strip_null_value(message));
     }
     
-    private void on_jump_to_card(Card card, Card next, Card.Jump reason, Value? message) {
+    private void jump_to_card(Card caller, Card next, Card.Jump reason, Value? message) {
         // do nothing if already visible
         if (get_visible_child() == next) {
             debug("Already showing card %s", next.card_id);
@@ -257,29 +263,29 @@ public class Deck : Gtk.Stack {
         }
         
         set_visible_child(next);
-        next.jumped_to(card, reason, strip_null_value(message));
+        next.jumped_to(caller, reason, strip_null_value(message));
     }
     
-    private void on_jump_to_card_by_id(Card card, string id, Value? message) {
+    private void on_jump_to_card_by_id(Card caller, string id, Value? message) {
         Card? next = ids.get(id);
         if (next != null)
-            on_jump_to_card(card, next, Card.Jump.DIRECT, message);
+            jump_to_card(caller, next, Card.Jump.DIRECT, message);
         else
             GLib.message("Card %s not found in Deck", name);
     }
     
-    private void on_jump_back(Card card) {
+    private void on_jump_back(Card caller) {
         // if still not empty, next card is "back", so pop that off and jump to it
         if (!navigation_stack.is_empty)
-            on_jump_to_card(card, navigation_stack.poll_head(), Card.Jump.BACK, null);
+            jump_to_card(caller, navigation_stack.poll_head(), Card.Jump.BACK, null);
     }
     
-    private void on_jump_home(Card card) {
+    private void on_jump_home(Card caller) {
         // jumping home clears the navigation stack
         navigation_stack.clear();
         
         if (home != null)
-            on_jump_to_card(card, home, Card.Jump.HOME, null);
+            jump_to_card(caller, home, Card.Jump.HOME, null);
         else
             message("No home card in Deck");
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]