Bug 473012 - Get Lightning to use nsIObserver for overlaying mailContext menus;patch=Ian Neal;r=berend
authorBerend Cornelius [:berend] <berend.cornelius@sun.com>
Tue, 13 Jan 2009 12:30:57 +0100
changeset 1626 4d2ac69754e9b9d0fecb68ae9341ae0f2a6ba0d1
parent 1625 a048b5420d62dea34f3d8ee230922a6ea736353b
child 1627 f1e4747febbfa6d469a37df2c6e4d379638851ec
push idunknown
push userunknown
push dateunknown
reviewersberend
bugs473012
Bug 473012 - Get Lightning to use nsIObserver for overlaying mailContext menus;patch=Ian Neal;r=berend
calendar/lightning/content/imip-bar.js
calendar/lightning/content/messenger-overlay-sidebar.js
--- a/calendar/lightning/content/imip-bar.js
+++ b/calendar/lightning/content/imip-bar.js
@@ -118,16 +118,27 @@ function ltnGetMsgRecipient() {
 }
 
 function ltnIsSchedulingCalendar(cal) {
     return (isCalendarWritable(cal) &&
             cal.getProperty("organizerId") &&
             cal.getProperty("itip.transport"));
 }
 
+const gCalSetupMailContext = {
+    observe: function gCalSetupMailContext_observer(subject, topic, data) {
+        if (topic == "mail:fillMailContextMenu") {
+            var hasSelection = (GetFirstSelectedMessage() != null);
+            // Disable the convert menu altogether.
+            setElementValue("mailContext-calendar-convert-menu",
+                            !hasSelection && "true", "hidden");
+        }
+    }
+};
+
 const ltnOnItipItem = {
     observe: function ltnOnItipItem_observe(subject, topic, state) {
         if (topic == "onItipItemCreation") {
             let itipItem = null;
             try {
                 if (!subject) {
                     let sinkProps = msgWindow.msgHeaderSink.properties;
                     // This property was set by lightningTextCalendarConverter.js
@@ -218,23 +229,27 @@ function ltnImipOnLoad() {
         },
         onEndHeaders: function onImipEndHeaders() {
         }
     };
     gMessageListeners.push(listener);
 
     // Set up our observers
     cal.getObserverService().addObserver(ltnOnItipItem, "onItipItemCreation", false);
+    cal.getObserverService().addObserver(gCalSetupMailContext,
+                                         "mail:fillMailContextMenu", false);
 }
 
 function ltnImipOnUnload() {
     removeEventListener("messagepane-loaded", ltnImipOnLoad, true);
     removeEventListener("messagepane-unloaded", ltnImipOnUnload, true);
 
     cal.getObserverService().removeObserver(ltnOnItipItem, "onItipItemCreation");
+    cal.getObserverService().removeObserver(gCalSetupMailContext,
+                                            "mail:fillMailContextMenu");
 
     gItipItem = null;
     gCalItemsArrayFound = [];
 }
 
 addEventListener("messagepane-loaded", ltnImipOnLoad, true);
 addEventListener("messagepane-unloaded", ltnImipOnUnload, true);
 
--- a/calendar/lightning/content/messenger-overlay-sidebar.js
+++ b/calendar/lightning/content/messenger-overlay-sidebar.js
@@ -582,26 +582,8 @@ function openInvitationsDialog() {
     getInvitationsManager().openInvitationsDialog(
         gInvitationsOperationListener,
         function oiD_callback() {
             scheduleInvitationsUpdate(FIRST_DELAY_RESCHEDULE);
         });
 }
 
 document.addEventListener("load", ltnOnLoad, true);
-
-/**
- * Sets up the mail context menu. Even though the actual context menu
- * is in messenger-overlay-toolbar.xul, this needs to be in a file that
- * directly overlays messenger.xul or the functions will not be defined.
- */
-function calSetupMailContext() {
-    var hasSelection = (GetFirstSelectedMessage() != null);
-
-    // Disable the convert menu altogether
-    setElementValue("mailContext-calendar-convert-menu",
-                    !hasSelection && "true",
-                    "hidden");
-
-    return calSetupMailContext.originalFillMailContext();
-}
-calSetupMailContext.originalFillMailContext = fillMailContextMenu;
-let fillMailContextMenu = calSetupMailContext;