Bug 1229155 - Summary and event dialog: Persisted dimensions are not applied when opening again;r=philipp
authorMakeMyDay <makemyday@gmx-topmail.de>
Sun, 24 Jan 2016 15:55:30 +0100
changeset 18902 a7f447da91bd43b94790bf19a3a80788dbec363a
parent 18901 2ab5229a512de860b0750e553f28bf6b3e4c6ff4
child 18903 8c7b3f55ca1df5e26795a6f516234b4d877ef218
push id11587
push usermakemyday@gmx-topmail.de
push dateSun, 24 Jan 2016 22:40:57 +0000
treeherdercomm-central@a7f447da91bd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilipp
bugs1229155
Bug 1229155 - Summary and event dialog: Persisted dimensions are not applied when opening again;r=philipp
calendar/base/content/dialogs/calendar-dialog-utils.js
--- a/calendar/base/content/dialogs/calendar-dialog-utils.js
+++ b/calendar/base/content/dialogs/calendar-dialog-utils.js
@@ -27,16 +27,17 @@ function dispose() {
  * The original name is stored as new Attribute of the Dialog to set it back later.
  *
  * @param aDialog               The Dialog to be changed.
  * @param aNewId                The new ID as String.
  */
 function setDialogId(aDialog, aNewId) {
     aDialog.setAttribute("originalId", aDialog.getAttribute("id"));
     aDialog.setAttribute("id", aNewId);
+    applyPersitedProperties(aDialog);
 }
 
 /**
  * Sets the Dialog id back to previously stored one,
  * so that the persisted values are correctly saved.
  *
  * @param aDialog               The Dialog which is to be restored.
  */
@@ -44,16 +45,40 @@ function resetDialogId(aDialog) {
     let id = aDialog.getAttribute("originalId");
     if (id != "") {
         aDialog.setAttribute("id", id);
     }
     aDialog.removeAttribute("originalId");
 }
 
 /**
+ * Apply the persisted properties from xulstore.json on a dialog based on the current dialog id.
+ * This needs to be invoked after changing a dialog id while loading to apply the values for the
+ * new dialog id.
+ *
+ * @param aDialog               The Dialog to apply the property values for
+ */
+function applyPersitedProperties(aDialog) {
+    let xulStore = Components.classes["@mozilla.org/xul/xulstore;1"]
+                             .getService(Components.interfaces.nsIXULStore);
+    // first we need to detect which properties are persisted
+    let persistedProps = aDialog.getAttribute("persist") || "";
+    if (persistedProps == "") {
+        return;
+    }
+    let propNames = persistedProps.split(" ");
+    // now let's apply persisted values if applicable
+    for (let propName of propNames) {
+        if (xulStore.hasValue(aDialog.baseURI, aDialog.id, propName)) {
+            aDialog.setAttribute(propName, xulStore.getValue(aDialog.baseURI, aDialog.id, propName));
+        }
+    }
+}
+
+/**
  * Create a calIAlarm from the given menuitem. The menuitem must have the
  * following attributes: unit, length, origin, relation.
  *
  * @param menuitem      The menuitem to create the alarm from.
  * @return              The calIAlarm with information from the menuitem.
  */
 function createReminderFromMenuitem(aMenuitem) {
     let reminder = aMenuitem.reminder || cal.createAlarm();