[california] Retain selected calendar btwn Quick Add and event editor: Bug #741613



commit a6a9533d6f79f9708d1991be4f2b205e21eefe6c
Author: Jim Nelson <jim yorba org>
Date:   Mon Dec 22 15:32:20 2014 -0800

    Retain selected calendar btwn Quick Add and event editor: Bug #741613

 src/component/component-event.vala    |   15 ++++++++++++---
 src/component/component-instance.vala |    7 ++++++-
 src/host/host-main-window.vala        |    2 +-
 src/host/host-quick-create-event.vala |   27 +++++++++++++++++++++------
 4 files changed, 40 insertions(+), 11 deletions(-)
---
diff --git a/src/component/component-event.vala b/src/component/component-event.vala
index c21ee7c..db842a1 100644
--- a/src/component/component-event.vala
+++ b/src/component/component-event.vala
@@ -261,10 +261,19 @@ public class Event : Instance, Gee.Comparable<Event> {
     /**
      * @inheritDoc
      */
-    public override Component.Instance clone() throws Error {
-        Component.Event cloned_event = new Component.Event(calendar_source, ical_component);
+    public override Component.Instance clone(Backing.Source? clone_source) throws Error {
+        Backing.CalendarSource clone_calendar_source = null;
+        if (clone_source != null) {
+            clone_calendar_source = clone_source as Backing.CalendarSource;
+            if (clone_calendar_source == null)
+                throw new BackingError.INVALID("Supplied backing source for clone not a CalendarSource");
+        } else {
+            clone_calendar_source = calendar_source;
+        }
+        
+        Component.Event cloned_event = new Component.Event(clone_calendar_source, ical_component);
         if (master != null)
-            cloned_event.master = new Component.Event(master.calendar_source, master.ical_component);
+            cloned_event.master = new Component.Event(clone_calendar_source, master.ical_component);
         
         return cloned_event;
     }
diff --git a/src/component/component-instance.vala b/src/component/component-instance.vala
index 258b6a7..a116dd1 100644
--- a/src/component/component-instance.vala
+++ b/src/component/component-instance.vala
@@ -485,9 +485,14 @@ public abstract class Instance : BaseObject, Gee.Hashable<Instance> {
      * editing (where a number of changes are made and stored in the Instance, only being submitted
      * when the user gives the okay).
      *
+     * If a { link Backing.Source} is provided, it will be used as the source of the cloned
+     * instance.  Note that this does ''not'' move instances between sources, but is a convenience
+     * for when editing, etc.  If the Source is not appropriate to the child class of the Instance,
+     * an error will be thrown.
+     *
      * Cloning will also clone the { link master}, if present.
      */
-    public abstract Component.Instance clone() throws Error;
+    public abstract Component.Instance clone(Backing.Source? clone_source) throws Error;
     
     /**
      * Add a { link RecurrenceRule} to the { link Instance}.
diff --git a/src/host/host-main-window.vala b/src/host/host-main-window.vala
index 17e7a4c..494f438 100644
--- a/src/host/host-main-window.vala
+++ b/src/host/host-main-window.vala
@@ -501,7 +501,7 @@ public class MainWindow : Gtk.ApplicationWindow {
         // pass a clone of the existing event for editing
         Component.Event clone;
         try {
-            clone = event.clone() as Component.Event;
+            clone = event.clone(null) as Component.Event;
         } catch (Error err) {
             Application.instance.error_message(this, _("Unable to edit event: %s").printf(err.message));
             
diff --git a/src/host/host-quick-create-event.vala b/src/host/host-quick-create-event.vala
index b3ac1eb..f644363 100644
--- a/src/host/host-quick-create-event.vala
+++ b/src/host/host-quick-create-event.vala
@@ -107,6 +107,15 @@ public class QuickCreateEvent : Gtk.Grid, Toolkit.Card {
         if (String.is_empty(details))
             return;
         
+        // if event was supplied, make sure new event is for selected calendar
+        if (event != null && event.calendar_source != calendar_model.active) {
+            try {
+                event = (Component.Event) event.clone(calendar_model.active);
+            } catch (Error err) {
+                debug("Unable to clone event: %s", err.message);
+            }
+        }
+        
         Component.DetailsParser parser = new Component.DetailsParser(details, calendar_model.active,
             event);
         event = parser.event;
@@ -121,13 +130,19 @@ public class QuickCreateEvent : Gtk.Grid, Toolkit.Card {
     [GtkCallback]
     private void on_edit_button_clicked() {
         // empty text okay
-        string details = details_entry.text.strip();
-        if (!String.is_empty(details)) {
-            Component.DetailsParser parser = new Component.DetailsParser(details, calendar_model.active,
-                event);
-            event = parser.event;
+        // if event was supplied, make sure final event is for selected calendar
+        if (event != null && event.calendar_source != calendar_model.active) {
+            try {
+                event = (Component.Event) event.clone(calendar_model.active);
+            } catch (Error err) {
+                debug("Unable to clone event: %s", err.message);
+            }
         }
         
+        Component.DetailsParser parser = new Component.DetailsParser(details_entry.text, 
calendar_model.active,
+            event);
+        event = parser.event;
+        
         // always edit
         edit_event();
     }
@@ -140,7 +155,7 @@ public class QuickCreateEvent : Gtk.Grid, Toolkit.Card {
     private void edit_event() {
         // Must pass some kind of event to create/update, so use blank if required
         if (event == null)
-            event = new Component.Event.blank();
+            event = new Component.Event.blank(calendar_model.active);
         
         // ensure it's at least valid
         if (!event.is_valid(false))


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