Bug 473661 - Use popupshowing event to hook Lightning into mailContext menus;r=berend
authorIan Neal
Tue, 27 Jan 2009 15:14:18 +0100
changeset 1769 4650662557d98885ff0b189101afd7c67cc8b14f
parent 1768 b8383e5fa1e4eec75ea7b2328add8cb01b0fb5c1
child 1770 b2cb2f44642f705404dc663666fff7e0e39bd62b
push idunknown
push userunknown
push dateunknown
reviewersberend
bugs473661
Bug 473661 - Use popupshowing event to hook Lightning into mailContext menus;r=berend
calendar/base/content/calendar-chrome-startup.js
calendar/lightning/content/imip-bar.js
calendar/lightning/content/messenger-overlay-toolbar.js
--- a/calendar/base/content/calendar-chrome-startup.js
+++ b/calendar/base/content/calendar-chrome-startup.js
@@ -59,30 +59,42 @@ function commonInitCalendar() {
     getViewDeck().addEventListener("itemselect", calendarController.onSelectionChanged, true);
 
     // Start alarm service
     Components.classes["@mozilla.org/calendar/alarm-service;1"]
               .getService(Components.interfaces.calIAlarmService)
               .startup();
     document.getElementById("calsidebar_splitter").addEventListener("command", onCalendarViewResize, false);
     window.addEventListener("resize", onCalendarViewResize, true);
+
+    // Set up listener for mailContext.
+    let mailContextPopup = document.getElementById("mailContext");
+    if (mailContextPopup)
+      mailContextPopup.addEventListener("popupshowing",
+                                        gCalSetupMailContext.popup, false);
 }
 
 /**
  * Common unload steps for calendar chrome windows.
  */
 function commonFinishCalendar() {
     // Unload the calendar manager
     unloadCalendarManager();
 
     // Remove the command controller
     removeCalendarCommandController();
 
     document.getElementById("calsidebar_splitter").removeEventListener("command", onCalendarViewResize, false);
     window.removeEventListener("resize", onCalendarViewResize, true);
+
+    // Remove listener for mailContext.
+    let mailContextPopup = document.getElementById("mailContext");
+    if (mailContextPopup)
+      mailContextPopup.removeEventListener("popupshowing",
+                                           gCalSetupMailContext.popup, false);
 }
 
 /**
  * Handler function to create |viewtype + "viewresized"| events that are
  * dispatched through the calendarviewBroadcaster.
  *
  * XXX this has nothing to do with startup, needs to go somewhere else.
  */
--- a/calendar/lightning/content/imip-bar.js
+++ b/calendar/lightning/content/imip-bar.js
@@ -118,27 +118,16 @@ 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
@@ -229,30 +218,25 @@ 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 = [];
+    cal.getObserverService().removeObserver(ltnOnItipItem, "onItipItemCreation");
 }
 
 addEventListener("messagepane-loaded", ltnImipOnLoad, true);
 addEventListener("messagepane-unloaded", ltnImipOnUnload, true);
 
 var gItipItem = null;
 var gActionFunc = null;
 
--- a/calendar/lightning/content/messenger-overlay-toolbar.js
+++ b/calendar/lightning/content/messenger-overlay-toolbar.js
@@ -131,8 +131,20 @@ function ltnSwitch2Task() {
     var deck = document.getElementById("calendarDisplayDeck");
     deck.selectedPanel = taskBox;
 
     document.commandDispatcher.updateCommands('calendar_commands');
 
     window.setCursor("auto");
   }
 }
+
+const gCalSetupMailContext = {
+    popup: function gCalSetupMailContext_popup() {
+        var hasSelection = (GetFirstSelectedMessage() != null);
+        // Disable the convert menu altogether.
+        setElementValue("mailContext-calendar-convert-menu",
+                        !hasSelection && "true", "hidden");
+    }
+};
+
+
+