Bug 1470307 - Fix Lightning preference UI to work with new overlays; r=philipp
authorGeoff Lankow <geoff@darktrojan.net>
Tue, 17 Jul 2018 23:30:23 +1200
changeset 31765 ca94a7325ca9bf00111ad2f0b95cae6a829a760b
parent 31764 07addfefa1b6a42f974d782c6d2676bbdcdfc57d
child 31766 630c57d2b41283e904a7bf62dea5b20b24efa3dc
push id2308
push userclokep@gmail.com
push dateWed, 05 Sep 2018 00:34:58 +0000
treeherdercomm-beta@e326b2dcd127 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilipp
bugs1470307
Bug 1470307 - Fix Lightning preference UI to work with new overlays; r=philipp
calendar/base/content/calendar-ui-utils.js
calendar/base/content/preferences/alarms.xul
calendar/base/content/preferences/categories.js
calendar/base/content/preferences/categories.xul
calendar/base/content/preferences/general.js
calendar/base/content/preferences/general.xul
calendar/base/content/preferences/views.xul
calendar/lightning/content/messenger-overlay-preferences.js
calendar/lightning/content/messenger-overlay-preferences.xul
--- a/calendar/base/content/calendar-ui-utils.js
+++ b/calendar/base/content/calendar-ui-utils.js
@@ -8,17 +8,16 @@
  *          appendCalendarItems, setAttributeToChildren, checkRadioControl,
  *          processEnableCheckbox, updateListboxDeleteButton,
  *          updateUnitLabelPlural, updateMenuLabelsPlural, menuListSelectItem,
  *          getOptimalMinimumWidth, getOptimalMinimumHeight,
  *          getOtherOrientation, updateSelectedLabel, setupAttendanceMenu
  */
 
 ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
-ChromeUtils.import("resource://gre/modules/Preferences.jsm");
 ChromeUtils.import("resource://gre/modules/PluralForm.jsm");
 
 /**
  * Helper function for filling the form,
  * Set the value of a property of a XUL element
  *
  * @param aElement      ID of XUL element to set, or the element node itself
  * @param aNewValue     value to set property to ( if undefined no change is made )
@@ -236,16 +235,19 @@ function removeChildren(aElement) {
 
 /**
  * Sorts a sorted array of calendars by pref |calendar.list.sortOrder|.
  * Repairs that pref if dangling entries exist.
  *
  * @param calendars     An array of calendars to sort.
  */
 function sortCalendarArray(calendars) {
+    // Be careful not to pollute the window object, as things break.
+    let { Preferences } = ChromeUtils.import("resource://gre/modules/Preferences.jsm", {});
+
     let ret = calendars.concat([]);
     let sortOrder = {};
     let sortOrderPref = Preferences.get("calendar.list.sortOrder", "").split(" ");
     for (let i = 0; i < sortOrderPref.length; ++i) {
         sortOrder[sortOrderPref[i]] = i;
     }
     function sortFunc(cal1, cal2) {
         let orderIdx1 = sortOrder[cal1.id] || -1;
--- a/calendar/base/content/preferences/alarms.xul
+++ b/calendar/base/content/preferences/alarms.xul
@@ -8,26 +8,26 @@
     <!ENTITY % globalDTD SYSTEM "chrome://calendar/locale/global.dtd">
     %alarmsDTD;
     %globalDTD;
 ]>
 
 <overlay id="AlarmsPaneOverlay"
          xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
+    <script type="application/javascript"
+            src="chrome://calendar/content/preferences/alarms.js"/>
+    <script type="application/javascript"
+            src="chrome://calendar/content/calendar-dialog-utils.js"/>
+    <script type="application/javascript"
+            src="chrome://calendar/content/calendar-ui-utils.js"/>
+
     <vbox id="calPreferencesBoxAlarms">
         <stringbundle id="bundleCalendarPreferences"
                       src="chrome://calendar/locale/calendar.properties"/>
-        <script type="application/javascript"
-                src="chrome://calendar/content/preferences/alarms.js"/>
-        <script type="application/javascript"
-                src="chrome://calendar/content/calendar-dialog-utils.js"/>
-        <script type="application/javascript"
-                src="chrome://calendar/content/calendar-ui-utils.js"/>
-
         <preferences>
             <preference id="calendar.alarms.playsound"
                         name="calendar.alarms.playsound"
                         type="bool"
                         onchange="gAlarmsPane.alarmsPlaySoundPrefChanged();"/>
             <preference id="calendar.alarms.soundURL"
                         name="calendar.alarms.soundURL"
                         type="string"
--- a/calendar/base/content/preferences/categories.js
+++ b/calendar/base/content/preferences/categories.js
@@ -1,17 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* exported gCategoriesPane */
 
 ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
-ChromeUtils.import("resource://gre/modules/Preferences.jsm");
 ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
 
 var gCategoryList;
 var categoryPrefBranch = Services.prefs.getBranch("calendar.category.color.");
 
 /**
  * Global Object to hold methods for the categories pref pane
  */
--- a/calendar/base/content/preferences/categories.xul
+++ b/calendar/base/content/preferences/categories.xul
@@ -3,30 +3,30 @@
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <!DOCTYPE overlay SYSTEM "chrome://calendar/locale/preferences/categories.dtd">
 
 <overlay id="CategoriesPaneOverlay"
          xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
-    <vbox id="calPreferencesBoxCategories">
-        <script type="application/javascript"
-                src="chrome://calendar/content/preferences/categories.js"/>
+    <script type="application/javascript"
+            src="chrome://calendar/content/preferences/categories.js"/>
 
-        <!-- Get the localized text for use in the .js -->
-        <script type="application/javascript">
-            var noneLabel  = "&pref.categories.none.label;";
-            var newTitle   = "&pref.categories.new.title;";
-            var editTitle  = "&pref.categories.edit.title;";
-            var overwrite  = "&pref.categories.overwrite;";
-            var overwriteTitle = "&pref.categories.overwrite.title;";
-            var noBlankCategories = "&pref.categories.noBlankCategories;";
-        </script>
+    <!-- Get the localized text for use in the .js -->
+    <script type="application/javascript">
+        var noneLabel  = "&pref.categories.none.label;";
+        var newTitle   = "&pref.categories.new.title;";
+        var editTitle  = "&pref.categories.edit.title;";
+        var overwrite  = "&pref.categories.overwrite;";
+        var overwriteTitle = "&pref.categories.overwrite.title;";
+        var noBlankCategories = "&pref.categories.noBlankCategories;";
+    </script>
 
+    <vbox id="calPreferencesBoxCategories">
         <preferences>
             <preference id="calendar.categories.names"
                         name="calendar.categories.names"
                         type="string"/>
         </preferences>
 
         <listbox id="categorieslist"
                  flex="1"
--- a/calendar/base/content/preferences/general.js
+++ b/calendar/base/content/preferences/general.js
@@ -92,31 +92,24 @@ var gCalendarGeneralPane = {
             let menuitemValue = Number(menuItem.value);
             if (menuitemValue > 7) {
                 menuItem.label = unitPluralForm(menuitemValue / 7, "weeks");
             } else {
                 menuItem.label = unitPluralForm(menuitemValue, "days");
             }
         }
 
-        let prefName = "calendar.agendaListbox.soondays";
-        let soonpref = Preferences.get(prefName, 5);
+        let pref = document.getElementById("calendar.agendaListbox.soondays");
+        let soonpref = pref.value || 5;
 
         // Check if soonDays preference has been edited with a wrong value.
         if (soonpref > 0 && soonpref <= 28) {
             if (soonpref % 7 != 0) {
                 let intSoonpref = Math.floor(soonpref / 7) * 7;
                 soonpref = (intSoonpref == 0 ? soonpref : intSoonpref);
-                Preferences.set(prefName, soonpref, "INT");
+                pref.value = soonpref;
             }
         } else {
             soonpref = soonpref > 28 ? 28 : 1;
-            Preferences.set(prefName, soonpref, "INT");
+            pref.value = soonpref;
         }
-
-        document.getElementById("soondays-menulist").value = soonpref;
-    },
-
-    updateTodaypaneMenu: function() {
-        let soonpref = Number(document.getElementById("soondays-menulist").value);
-        Preferences.set("calendar.agendaListbox.soondays", soonpref);
     }
 };
--- a/calendar/base/content/preferences/general.xul
+++ b/calendar/base/content/preferences/general.xul
@@ -10,27 +10,28 @@
     %generalDTD;
     %globalDTD;
     %eventDTD;
 ]>
 
 <overlay id="CalendarGeneralPaneOverlay"
          xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
-    <vbox id="calPreferencesBoxGeneral">
-        <script type="application/javascript"
-                src="chrome://calendar/content/preferences/general.js"/>
-        <script type="application/javascript"
-                src="chrome://calendar/content/calendar-ui-utils.js"/>
+    <script type="application/javascript"
+            src="chrome://calendar/content/preferences/general.js"/>
+    <script type="application/javascript"
+            src="chrome://calendar/content/calendar-ui-utils.js"/>
 
-        <!-- Get the localized text for use in the .js -->
-        <script type="application/javascript">
-            var labelLong  = "&pref.dateformat.long;";
-            var labelShort = "&pref.dateformat.short;";
-        </script>
+    <!-- Get the localized text for use in the .js -->
+    <script type="application/javascript">
+        var labelLong  = "&pref.dateformat.long;";
+        var labelShort = "&pref.dateformat.short;";
+    </script>
+
+    <vbox id="calPreferencesBoxGeneral">
 
         <preferences>
             <preference id="calendar.date.format"
                         name="calendar.date.format"
                         type="int"/>
             <preference id="calendar.event.defaultlength"
                         name="calendar.event.defaultlength"
                         type="int"/>
@@ -263,18 +264,17 @@
 
         <groupbox>
             <caption label="&pref.calendar.todaypane.agenda.caption;"/>
             <hbox align="center">
                 <label value="&pref.soondays2.label;"
                        accesskey="&pref.soondays2.accesskey;"
                        control="soondays-menulist"/>
                 <menulist id="soondays-menulist"
-                          preference="calendar.agendaListbox.soondays"
-                          oncommand="gCalendarGeneralPane.updateTodaypaneMenu()">
+                          preference="calendar.agendaListbox.soondays">
                     <menupopup id="soondaysdurationpopup">
                         <menuitem value="1"/>
                         <menuitem value="2"/>
                         <menuitem value="3"/>
                         <menuitem value="4"/>
                         <menuitem value="5"/>
                         <menuitem value="6"/>
                         <menuitem value="7"/>
--- a/calendar/base/content/preferences/views.xul
+++ b/calendar/base/content/preferences/views.xul
@@ -8,22 +8,22 @@
     <!ENTITY % globalDTD SYSTEM "chrome://calendar/locale/global.dtd">
     %viewsDTD;
     %globalDTD;
 ]>
 
 <overlay id="ViewsPaneOverlay"
          xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
+    <script type="application/javascript"
+            src="chrome://calendar/content/preferences/views.js"/>
+    <script type="application/javascript"
+            src="chrome://calendar/content/calendar-ui-utils.js"/>
+
     <vbox id="calPreferencesBoxViews">
-        <script type="application/javascript"
-                src="chrome://calendar/content/preferences/views.js"/>
-        <script type="application/javascript"
-                src="chrome://calendar/content/calendar-ui-utils.js"/>
-
         <preferences>
             <preference id="calendar.week.start"
                         name="calendar.week.start"
                         type="int"/>
             <preference id="calendar.view-minimonth.showWeekNumber"
                         name="calendar.view-minimonth.showWeekNumber"
                         type="bool"/>
             <preference id="calendar.week.d0sundaysoff"
--- a/calendar/lightning/content/messenger-overlay-preferences.js
+++ b/calendar/lightning/content/messenger-overlay-preferences.js
@@ -4,24 +4,40 @@
 
 /* exported gLightningPane */
 
 var gLightningPane = {
     mInitialized: false,
 
     init: function() {
         let preference = document.getElementById("calendar.preferences.lightning.selectedTabIndex");
+        let ltnPrefs = document.getElementById("calPreferencesTabbox");
         if (preference.value) {
-            let ltnPrefs = document.getElementById("calPreferencesTabbox");
             ltnPrefs.selectedIndex = preference.value;
         }
+        ltnPrefs.addEventListener("select", gLightningPane.tabSelectionChanged.bind(this));
         this.mInitialized = true;
+
+        let lightningButton = document.documentElement._makePaneButton(document.getElementById("paneLightning"));
+        let advancedButton = document.querySelector('#category-box radio[pane="paneAdvanced"]');
+        advancedButton.parentNode.insertBefore(lightningButton, advancedButton);
+
+        let elements = document.querySelectorAll("#paneLightning preference");
+        for (let element of elements) {
+            element.updateElements();
+        }
     },
 
     tabSelectionChanged: function() {
         if (!this.mInitialized) {
             return;
         }
         let ltnPrefs = document.getElementById("calPreferencesTabbox");
         let preference = document.getElementById("calendar.preferences.lightning.selectedTabIndex");
         preference.valueFromPreferences = ltnPrefs.selectedIndex;
     }
 };
+
+gCalendarGeneralPane.init();
+gAlarmsPane.init();
+gCategoriesPane.init();
+gViewsPane.init();
+gLightningPane.init();
--- a/calendar/lightning/content/messenger-overlay-preferences.xul
+++ b/calendar/lightning/content/messenger-overlay-preferences.xul
@@ -13,28 +13,24 @@
 
 <?xml-stylesheet href="chrome://lightning/skin/lightning.css"?>
 
 <overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
     <prefwindow id="MailPreferences">
         <prefpane id="paneLightning"
                   insertbefore="paneAdvanced"
-                  label="&lightning.preferencesLabel;"
-                  onpaneload="gCalendarGeneralPane.init(); gAlarmsPane.init();
-                              gCategoriesPane.init(); gViewsPane.init();
-                              gLightningPane.init();">
+                  label="&lightning.preferencesLabel;">
             <preferences>
                 <preference id="calendar.preferences.lightning.selectedTabIndex"
                             name="calendar.preferences.lightning.selectedTabIndex"
                             type="int"/>
             </preferences>
             <tabbox id="calPreferencesTabbox"
-                    flex="1"
-                    onselect="gLightningPane.tabSelectionChanged();">
+                    flex="1">
                 <tabs>
                     <tab id="calPreferencesTabGeneral"
                          label="&paneGeneral.title;"/>
                     <tab id="calPreferencesTabAlarms"
                          label="&paneAlarms.title;"/>
                     <tab id="calPreferencesTabCategories"
                          label="&paneCategories.title;"/>
                     <tab id="calPreferencesTabViews"
@@ -52,14 +48,14 @@
                     </tabpanel>
                     <tabpanel orient="vertical">
                         <vbox id="calPreferencesBoxViews"/>
                     </tabpanel>
                 </tabpanels>
             </tabbox>
         </prefpane>
 
-        <script type="application/javascript"
-                src="chrome://lightning/content/messenger-overlay-preferences.js"/>
-
     </prefwindow>
 
+    <script type="application/javascript"
+            src="chrome://lightning/content/messenger-overlay-preferences.js"/>
+
 </overlay>