Bug 1436488 - Move window related functions into calWindowUtils.jsm - manual changes. r=MakeMyDay
authorPhilipp Kewisch <mozilla@kewis.ch>
Sat, 03 Feb 2018 14:45:58 +0100
changeset 31097 6101dbce66cca8ac8a2e8895595bde34a0075296
parent 31096 932be9f104648a1359c16532ad50f71edfd31067
child 31098 1fad79cf6e7f60f20ca6ab7541c6e202c70193f2
push id383
push userclokep@gmail.com
push dateMon, 07 May 2018 21:52:48 +0000
reviewersMakeMyDay
bugs1436488
Bug 1436488 - Move window related functions into calWindowUtils.jsm - manual changes. r=MakeMyDay MozReview-Commit-ID: L0qzPmWuAg
calendar/base/modules/calUtils.jsm
calendar/base/modules/calUtilsCompat.jsm
calendar/base/modules/calWindowUtils.jsm
calendar/base/modules/moz.build
calendar/base/src/calUtils.js
calendar/providers/gdata/modules/calUtilsShim.jsm
--- a/calendar/base/modules/calUtils.jsm
+++ b/calendar/base/modules/calUtils.jsm
@@ -673,25 +673,16 @@ var cal = {
         if (monthForm == "nominative") {
             // Fall back to the default name format
             monthForm = "name";
         }
 
         return cal.calGetString("dateFormat", "month." + aMonthNum + "." + monthForm);
     },
 
-
-    /**
-     * Returns the most recent calendar window in an application independent way
-     */
-    getCalendarWindow: function() {
-        return Services.wm.getMostRecentWindow("calendarMainWindow") ||
-               Services.wm.getMostRecentWindow("mail:3pane");
-    },
-
     /**
      * Adds an observer listening for the topic.
      *
      * @param func function to execute on topic
      * @param topic topic to listen for
      * @param oneTime whether to listen only once
      */
     addObserver: function(func, topic, oneTime) {
@@ -761,16 +752,17 @@ var cal = {
 };
 
 // Sub-modules for calUtils
 XPCOMUtils.defineLazyModuleGetter(cal, "data", "resource://calendar/modules/calDataUtils.jsm", "caldata");
 XPCOMUtils.defineLazyModuleGetter(cal, "dtz", "resource://calendar/modules/calDateTimeUtils.jsm", "caldtz");
 XPCOMUtils.defineLazyModuleGetter(cal, "acl", "resource://calendar/modules/calACLUtils.jsm", "calacl");
 XPCOMUtils.defineLazyModuleGetter(cal, "item", "resource://calendar/modules/calItemUtils.jsm", "calitem");
 XPCOMUtils.defineLazyModuleGetter(cal, "view", "resource://calendar/modules/calViewUtils.jsm", "calview");
+XPCOMUtils.defineLazyModuleGetter(cal, "window", "resource://calendar/modules/calWindowUtils.jsm", "calwindow");
 
 /**
  * Returns a function that provides access to the given service.
  *
  * @param cid           The contract id to create
  * @param iid           The interface id to create with
  * @return {function}   A function that returns the given service
  */
--- a/calendar/base/modules/calUtilsCompat.jsm
+++ b/calendar/base/modules/calUtilsCompat.jsm
@@ -59,16 +59,22 @@ var migrations = {
         applyAttributeToMenuChildren: "applyAttributeToMenuChildren",
         removeChildElementsByAttribute: "removeChildElementsByAttribute",
         getParentNodeOrThis: "getParentNodeOrThis",
         getParentNodeOrThisByAttribute: "getParentNodeOrThisByAttribute",
         formatStringForCSSRule: "formatStringForCSSRule",
         getCompositeCalendar: "getCompositeCalendar",
         hashColor: "hashColor",
         getContrastingTextColor: "getContrastingTextColor"
+    },
+    window: {
+        openCalendarWizard: "openCalendarWizard",
+        openCalendarProperties: "openCalendarProperties",
+        calPrint: "openPrintDialog",
+        getCalendarWindow: "getCalendarWindow"
     }
 };
 
 /**
  * Generate a forward function on the given global, for the namespace from the
  * migrations data.
  *
  * @param global        The global object to inject on.
new file mode 100644
--- /dev/null
+++ b/calendar/base/modules/calWindowUtils.jsm
@@ -0,0 +1,60 @@
+/* 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/. */
+
+ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
+ChromeUtils.import("resource://gre/modules/Services.jsm");
+
+this.EXPORTED_SYMBOLS = ["calwindow"]; /* exported calwindow */
+
+var calwindow = {
+    /**
+     * Opens the Create Calendar wizard
+     *
+     * @param aCallback  a function to be performed after calendar creation
+     */
+    openCalendarWizard: function(aCallback, aWindow=null) {
+        let window = aWindow || calwindow.getCalendarWindow();
+        window.openDialog("chrome://calendar/content/calendarCreation.xul", "caEditServer",
+                          // Workaround for Bug 1151440 - the HTML color picker won't work
+                          // in linux when opened from modal dialog
+                          AppConstants.platform == "linux"
+                              ? "chrome,titlebar,resizable"
+                              : "modal,chrome,titlebar,resizable",
+                          aCallback);
+    },
+
+    /**
+     * Opens the calendar properties window for aCalendar
+     *
+     * @param aCalendar  the calendar whose properties should be displayed
+     */
+    openCalendarProperties: function(aCalendar, aWindow=null) {
+        let window = aWindow || calwindow.getCalendarWindow();
+        window.openDialog("chrome://calendar/content/calendar-properties-dialog.xul",
+                          "CalendarPropertiesDialog",
+                          // Workaround for Bug 1151440 - the HTML color picker won't work
+                          // in linux when opened from modal dialog
+                          AppConstants.platform == "linux"
+                              ? "chrome,titlebar,resizable"
+                              : "modal,chrome,titlebar,resizable",
+                          { calendar: aCalendar });
+    },
+
+    /**
+     * Opens the print dialog
+     */
+    openPrintDialog: function(aWindow=null) {
+        let window = aWindow || calwindow.getCalendarWindow();
+        window.openDialog("chrome://calendar/content/calendar-print-dialog.xul", "Print",
+                          "centerscreen,chrome,resizable");
+    },
+
+    /**
+     * Returns the most recent calendar window in an application independent way
+     */
+    getCalendarWindow: function() {
+        return Services.wm.getMostRecentWindow("calendarMainWindow") ||
+               Services.wm.getMostRecentWindow("mail:3pane");
+    }
+};
--- a/calendar/base/modules/moz.build
+++ b/calendar/base/modules/moz.build
@@ -16,12 +16,13 @@ EXTRA_JS_MODULES += [
     'calIteratorUtils.jsm',
     'calItipUtils.jsm',
     'calPrintUtils.jsm',
     'calProviderUtils.jsm',
     'calRecurrenceUtils.jsm',
     'calUtils.jsm',
     'calUtilsCompat.jsm',
     'calViewUtils.jsm',
+    'calWindowUtils.jsm',
     'calXMLUtils.jsm',
     'ical.js',
 ]
 
--- a/calendar/base/src/calUtils.js
+++ b/calendar/base/src/calUtils.js
@@ -3,17 +3,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* This file contains commonly used functions in a centralized place so that
  * various components (and other js scopes) don't need to replicate them. Note
  * that loading this file twice in the same scope will throw errors.
  */
 
 /* exported getCalendarDirectory, attendeeMatchesAddresses,
- *          openCalendarWizard, openCalendarProperties, calPrint,
  *          calRadioGroupSelectItem, getPrefCategoriesArray,
  *          setPrefCategoriesFromArray, calTryWrappedJSObject, compareArrays,
  *          compareObjects, LOG, WARN, ERROR, showError,
  *          getContrastingTextColor, sendMailTo, applyAttributeToMenuChildren,
  *          isPropertyValueSame, getParentNodeOrThis,
  *          getParentNodeOrThisByAttribute, calIterateEmailIdentities,
  *          binaryInsert, getCompositeCalendar
  */
@@ -72,59 +71,16 @@ function attendeeMatchesAddresses(anAtte
             return true;
         }
     }
 
     return false;
 }
 
 /**
- * Opens the Create Calendar wizard
- *
- * @param aWindow The window to show the dialog in.
- * @param aCallback  a function to be performed after calendar creation
- */
-function openCalendarWizard(aWindow, aCallback) {
-    aWindow.openDialog("chrome://calendar/content/calendarCreation.xul", "caEditServer",
-                       // Workaround for Bug 1151440 - the HTML color picker won't work
-                       // in linux when opened from modal dialog
-                       AppConstants.platform == "linux"
-                           ? "chrome,titlebar,resizable"
-                           : "modal,chrome,titlebar,resizable",
-                       aCallback);
-}
-
-/**
- * Opens the calendar properties window for aCalendar
- *
- * @param aWindow The window to show the dialog in.
- * @param aCalendar  the calendar whose properties should be displayed
- */
-function openCalendarProperties(aWindow, aCalendar) {
-    aWindow.openDialog("chrome://calendar/content/calendar-properties-dialog.xul",
-                       "CalendarPropertiesDialog",
-                       // Workaround for Bug 1151440 - the HTML color picker won't work
-                       // in linux when opened from modal dialog
-                       AppConstants.platform == "linux"
-                           ? "chrome,titlebar,resizable"
-                           : "modal,chrome,titlebar,resizable",
-                       { calendar: aCalendar });
-}
-
-/**
- * Opens the print dialog
- *
- * @param aWindow The window to show the dialog in.
- */
-function calPrint(aWindow) {
-    aWindow.openDialog("chrome://calendar/content/calendar-print-dialog.xul", "Print",
-                       "centerscreen,chrome,resizable");
-}
-
-/**
  * Other functions
  */
 
 /**
  * Get array of category names from preferences or locale default,
  * unescaping any commas in each category name.
  * @return array of category names
  */
--- a/calendar/providers/gdata/modules/calUtilsShim.jsm
+++ b/calendar/providers/gdata/modules/calUtilsShim.jsm
@@ -59,8 +59,16 @@ if (!cal.view || !cal.view.hashColor) {
         getParentNodeOrThisByAttribute: (...args) => cal.getParentNodeOrThisByAttribute(...args),
         formatStringForCSSRule: (...args) => cal.formatStringForCSSRule(...args),
         getCompositeCalendar: (...args) => cal.getCompositeCalendar(...args),
         hashColor: (...args) => cal.hashColor(...args),
         getContrastingTextColor: (...args) => cal.getContrastingTextColor(...args),
         /* cal.view.compareItems stays the same, just a different import */
     });
 }
+
+if (typeof cal.window == "undefined") {
+    cal.window = {
+        getCalendarWindow: function() {
+            return cal.getCalendarWindow();
+        }
+    };
+}