Bug 780404 - Make today pane in chat and mail tabs independent. r=darktrojan
authorPaul Morris <paul@thunderbird.net>
Fri, 27 Sep 2019 20:43:10 -0400
changeset 37075 b1d22780fc37de740014210bbb93bda19a69f9bd
parent 37074 1daf024a9ced503a886cdc78c01da4836a933238
child 37076 5462c8d4451abb572f3c36afae2e2b043100d076
push id395
push userclokep@gmail.com
push dateMon, 02 Dec 2019 19:38:57 +0000
reviewersdarktrojan
bugs780404
Bug 780404 - Make today pane in chat and mail tabs independent. r=darktrojan Make it so that the today pane can be displayed in chat tabs but not mail tabs and vice versa, with separate settings for each.
calendar/base/content/today-pane.xul
calendar/lightning/content/messenger-overlay-sidebar.js
calendar/lightning/content/messenger-overlay-sidebar.xul
calendar/test/browser/browser_todayPane_visibility.js
calendar/test/browser/head.js
--- a/calendar/base/content/today-pane.xul
+++ b/calendar/base/content/today-pane.xul
@@ -26,25 +26,25 @@
   <script src="chrome://calendar/content/calendar-management.js"/>
   <script src="chrome://calendar/content/calendar-dnd-listener.js"/>
   <script src="chrome://calendar/content/calendar-item-editing.js"/>
 
   <script src="chrome://calendar/content/calFilter.js"/>
   <script src="chrome://calendar/content/calendar-task-tree-utils.js"/>
 
   <calendar-modevbox id="today-pane-panel"
-                     mode="mail,calendar,task"
-                     modewidths="200,200,200"
-                     modesplitterstates="open,open,open"
+                     mode="mail,calendar,task,chat"
+                     modewidths="200,200,200,200"
+                     modesplitterstates="open,open,open,open"
                      refcontrol="calendar_toggle_todaypane_command"
                      persist="modewidths">
     <sidebarheader align="center">
       <label id="today-pane-header"/>
       <spacer flex="1"/>
-      <calendar-modebox mode="mail,calendar">
+      <calendar-modebox mode="mail,calendar,chat">
         <toolbarbutton id="today-pane-cycler-prev"
                        dir="prev"
                        class="today-pane-cycler"
                        oncommand="TodayPane.cyclePaneView(-1);"/>
         <toolbarbutton id="today-pane-cycler-next"
                        dir="next"
                        class="today-pane-cycler"
                        oncommand="TodayPane.cyclePaneView(1);"/>
@@ -53,36 +53,36 @@
       <toolbarbutton id="today-closer" class="today-closebutton close-icon"
                      oncommand="document.getElementById('today-pane-panel').setVisible(false, true, true);
                                 TodayPane.updateDisplay();
                                 TodayPane.updateSplitterState();"/>
     </sidebarheader>
     <vbox flex="1">
       <calendar-modevbox id="agenda-panel"
                          flex="1"
-                         mode="mail,calendar,task"
+                         mode="mail,calendar,task,chat"
                          collapsedinmodes="calendar"
                          persist="collapsed height collapsedinmodes">
         <calendar-modebox id="today-none-box"
-                          mode="mail,calendar,task"
-                          collapsedinmodes="mail,calendar,task"
+                          mode="mail,calendar,task,chat"
+                          collapsedinmodes="mail,calendar,task,chat"
                           refcontrol="ltnTodayPaneDisplayNone"
                           persist="collapsedinmodes"/>
         <calendar-modebox id="today-minimonth-box"
                           pack="center"
                           class="today-subpane"
-                          mode="mail,calendar,task"
-                          collapsedinmodes="mail,calendar,task"
+                          mode="mail,calendar,task,chat"
+                          collapsedinmodes="mail,calendar,task,chat"
                           refcontrol="ltnTodayPaneDisplayMinimonth"
                           persist="collapsedinmodes">
           <calendar-minimonth id="today-minimonth"
                               onchange="TodayPane.setDaywithjsDate(this.value);"/>
         </calendar-modebox>
         <calendar-modebox id="mini-day-box"
-                          mode="mail,calendar,task"
+                          mode="mail,calendar,task,chat"
                           class="today-subpane"
                           refcontrol="ltnTodayPaneDisplayMiniday"
                           collapsedinmodes=""
                           persist="collapsedinmodes"
                           onDOMMouseScroll="TodayPane.advance(event.detail > 0 ? 1 : -1);">
           <stack flex="1">
             <image id="mini-day-image" flex="1"/>
             <hbox flex="1">
@@ -370,18 +370,18 @@
                           checked="false"
                           persist="checked"/>
           </richlistbox>
         </vbox>
       </calendar-modevbox>
       <splitter id="today-pane-splitter" persist="hidden"/>
       <calendar-modevbox id="todo-tab-panel"
                          flex="1"
-                         mode="mail,calendar"
-                         collapsedinmodes="mail,task"
+                         mode="mail,calendar,chat"
+                         collapsedinmodes="mail,task,chat"
                          persist="height collapsedinmodes"
                          ondragstart="nsDragAndDrop.startDrag(event, calendarTaskButtonDNDObserver);"
                          ondragover="nsDragAndDrop.dragOver(event, calendarTaskButtonDNDObserver);"
                          ondrop="nsDragAndDrop.drop(event, calendarTaskButtonDNDObserver);">
         <!-- This second vbox means all of this is added to the DOM at once,
              so the label's binding doesn't complain about not having a control. -->
         <vbox flex="1">
           <box id="show-completed-checkbox-box" align="center">
--- a/calendar/lightning/content/messenger-overlay-sidebar.js
+++ b/calendar/lightning/content/messenger-overlay-sidebar.js
@@ -54,16 +54,19 @@ var calendarTabMonitor = {
     // Change the mode (gCurrentMode) to match the new tab.
     switch (aNewTab.mode.name) {
       case "calendar":
         calSwitchToCalendarMode();
         break;
       case "tasks":
         calSwitchToTaskMode();
         break;
+      case "chat":
+        calSwitchToMode("chat");
+        break;
       case "preferencesTab":
       case "contentTab":
         calSwitchToMode("special");
         break;
       default:
         calSwitchToMode("mail");
         break;
     }
@@ -612,16 +615,17 @@ function openInvitationsDialog() {
   );
 }
 
 /**
  * The current mode defining the current mode we're in. Allowed values are:
  *  - 'mail'
  *  - 'calendar'
  *  - 'task'
+ *  - 'chat'
  *  - 'special' - For special tabs like preferences, add-ons manager, about:xyz, etc.
  * @global
  */
 var gCurrentMode = "mail";
 
 /**
  * Changes the mode (gCurrentMode) and adapts the UI to the new mode.
  * @param {string} [mode="mail"] - the new mode: 'mail', 'calendar', 'task', etc.
@@ -644,23 +648,23 @@ function changeMode(mode = "mail") {
 
   TodayPane.onModeModified();
   if (gCurrentMode != "calendar") {
     timeIndicator.cancel();
   }
 }
 
 /**
- * For switching to modes like "mail" or "special". (For switching to "calendar"
+ * For switching to modes like "mail", "chat", or "special". (For switching to "calendar"
  * and "task" modes use calSwitchToCalendarMode and calSwitchToTaskMode.)
  *
  * @param {string} mode  The mode to switch to.
  */
 function calSwitchToMode(mode) {
-  if (mode != "mail" && mode != "special") {
+  if (!["mail", "chat", "special"].includes(mode)) {
     cal.WARN("Attempted to switch to unknown mode: " + mode);
     return;
   }
   if (gCurrentMode != mode) {
     const previousMode = gCurrentMode;
     changeMode(mode);
 
     if (previousMode == "calendar" || previousMode == "task") {
--- a/calendar/lightning/content/messenger-overlay-sidebar.xul
+++ b/calendar/lightning/content/messenger-overlay-sidebar.xul
@@ -351,17 +351,17 @@
              hidden="true"/>
       <label id="status-freebusy-busy-label"
              value="&event.freebusy.legend.busy;"
              hidden="true"/>
     </hbox>
     <!-- end event/task in tab statusbarpanels -->
     <calendar-modebox id="calendar-show-todaypane-panel"
                       class="statusbarpanel"
-                      mode="mail,calendar,task"
+                      mode="mail,calendar,task,chat"
                       collapsedinmodes="special"
                       pack="center">
       <toolbarbutton id="calendar-status-todaypane-button"
                      type="checkbox"
                      label="&todaypane.statusButton.label;"
                      tooltiptext="&calendar.todaypane.button.tooltip;"
                      observes="calendar_toggle_todaypane_command"
                      command="calendar_toggle_todaypane_command"/>
--- a/calendar/test/browser/browser_todayPane_visibility.js
+++ b/calendar/test/browser/browser_todayPane_visibility.js
@@ -1,13 +1,13 @@
 /* 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/. */
 
-/* globals openAddonsTab, openCalendarTab, openTasksTab, selectFolderTab,
+/* globals openAddonsTab, openCalendarTab, openChatTab, openTasksTab, selectFolderTab,
   openPreferencesTab */
 
 async function clickTodayPaneButton() {
   const button = document.getElementById("calendar-status-todaypane-button");
   // The today pane button will be hidden for certain tabs (e.g. preferences), and then
   // the user won't be able to click it, so we shouldn't be able to here either.
   if (BrowserTestUtils.is_visible(button)) {
     EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 });
@@ -29,23 +29,29 @@ add_task(async () => {
   await openCalendarTab();
   if (BrowserTestUtils.is_visible(todayPane)) {
     await clickTodayPaneButton();
   }
   await openTasksTab();
   if (BrowserTestUtils.is_visible(todayPane)) {
     await clickTodayPaneButton();
   }
+  await openChatTab();
+  if (BrowserTestUtils.is_visible(todayPane)) {
+    await clickTodayPaneButton();
+  }
 
   await selectFolderTab();
   ok(BrowserTestUtils.is_visible(todayPane), "today pane is visible in folder tab");
   await openCalendarTab();
   is(BrowserTestUtils.is_visible(todayPane), false, "today pane is collapsed in calendar tab");
   await openTasksTab();
   is(BrowserTestUtils.is_visible(todayPane), false, "today pane is collapsed in tasks tab");
+  await openChatTab();
+  is(BrowserTestUtils.is_visible(todayPane), false, "today pane is collapsed in chat tab");
   await openPreferencesTab();
   is(BrowserTestUtils.is_visible(todayPane), false, "today pane is collapsed in preferences tab");
   await openAddonsTab();
   is(BrowserTestUtils.is_visible(todayPane), false, "today pane is collapsed in addons tab");
 
   // Show today pane in calendar tab, but not in other tabs.
   // Hide it in folder tab.
   await selectFolderTab();
@@ -55,16 +61,18 @@ add_task(async () => {
   await clickTodayPaneButton();
 
   await selectFolderTab();
   is(BrowserTestUtils.is_visible(todayPane), false, "today pane is collapsed in folder tab");
   await openCalendarTab();
   ok(BrowserTestUtils.is_visible(todayPane), "today pane is visible in calendar tab");
   await openTasksTab();
   is(BrowserTestUtils.is_visible(todayPane), false, "today pane is collapsed in tasks tab");
+  await openChatTab();
+  is(BrowserTestUtils.is_visible(todayPane), false, "today pane is collapsed in chat tab");
   await openPreferencesTab();
   is(BrowserTestUtils.is_visible(todayPane), false, "today pane is collapsed in preferences tab");
   await openAddonsTab();
   is(BrowserTestUtils.is_visible(todayPane), false, "today pane is collapsed in addons tab");
 
   // Show today pane in tasks tab, but not in other tabs.
   // Hide it in calendar tab.
   await openCalendarTab();
@@ -74,26 +82,51 @@ add_task(async () => {
   await clickTodayPaneButton();
 
   await selectFolderTab();
   is(BrowserTestUtils.is_visible(todayPane), false, "today pane is collapsed in folder tab");
   await openCalendarTab();
   is(BrowserTestUtils.is_visible(todayPane), false, "today pane is collapsed in calendar tab");
   await openTasksTab();
   ok(BrowserTestUtils.is_visible(todayPane), "today pane is visible in tasks tab");
+  await openChatTab();
+  is(BrowserTestUtils.is_visible(todayPane), false, "today pane is collapsed in chat tab");
+  await openPreferencesTab();
+  is(BrowserTestUtils.is_visible(todayPane), false, "today pane is collapsed in preferences tab");
+  await openAddonsTab();
+  is(BrowserTestUtils.is_visible(todayPane), false, "today pane is collapsed in addons tab");
+
+  // Show today pane in chat tab, but not in other tabs.
+  // Hide it in tasks tab.
+  await openTasksTab();
+  await clickTodayPaneButton();
+  // Show it in chat tab.
+  await openChatTab();
+  await clickTodayPaneButton();
+
+  await selectFolderTab();
+  is(BrowserTestUtils.is_visible(todayPane), false, "today pane is collapsed in folder tab");
+  await openCalendarTab();
+  is(BrowserTestUtils.is_visible(todayPane), false, "today pane is collapsed in calendar tab");
+  await openTasksTab();
+  is(BrowserTestUtils.is_visible(todayPane), false, "today pane is collapsed in tasks tab");
+  await openChatTab();
+  ok(BrowserTestUtils.is_visible(todayPane), "today pane is visible in chat tab");
   await openPreferencesTab();
   is(BrowserTestUtils.is_visible(todayPane), false, "today pane is collapsed in preferences tab");
   await openAddonsTab();
   is(BrowserTestUtils.is_visible(todayPane), false, "today pane is collapsed in addons tab");
 
   // Check the visibility of the today pane button.
   const button = document.getElementById("calendar-status-todaypane-button");
   await selectFolderTab();
   ok(BrowserTestUtils.is_visible(button), "today pane button is visible in folder tab");
   await openCalendarTab();
   ok(BrowserTestUtils.is_visible(button), "today pane button is visible in calendar tab");
   await openTasksTab();
   ok(BrowserTestUtils.is_visible(button), "today pane button is visible in tasks tab");
+  await openChatTab();
+  ok(BrowserTestUtils.is_visible(button), "today pane button is visible in chat tab");
   await openPreferencesTab();
   is(BrowserTestUtils.is_visible(button), false, "today pane button is hidden in preferences tab");
   await openAddonsTab();
   is(BrowserTestUtils.is_visible(button), false, "today pane button is hidden in addons tab");
 });
--- a/calendar/test/browser/head.js
+++ b/calendar/test/browser/head.js
@@ -1,15 +1,15 @@
 /* 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 openCalendarTab, setCalendarView, closeCalendarTab, openTasksTab,
- * closeTasksTab, selectFolderTab, openPreferencesTab, closePreferencesTab,
- * openAddonsTab, closeAddonsTab
+ * closeTasksTab, selectFolderTab, openChatTab, closeChatTab, openPreferencesTab,
+ * closePreferencesTab, openAddonsTab, closeAddonsTab
  */
 
 /* import-globals-from ../../base/content/calendar-views-utils.js */
 
 /* globals openOptionsDialog, openAddonsMgr */
 
 async function openCalendarTab() {
   let tabmail = document.getElementById("tabmail");
@@ -92,16 +92,45 @@ async function selectFolderTab() {
   tabmail.selectedTab = folderMode.tabs[0];
 
   is(folderMode.tabs.length > 0, true, "at least one folder tab is open");
   is(tabmail.selectedTab, folderMode.tabs[0], "a folder tab is selected");
 
   await new Promise(resolve => setTimeout(resolve));
 }
 
+async function openChatTab() {
+  let tabmail = document.getElementById("tabmail");
+  let chatMode = tabmail.tabModes.chat;
+
+  if (chatMode.tabs.length == 1) {
+    tabmail.selectedTab = chatMode.tabs[0];
+  } else {
+    window.showChatTab();
+  }
+
+  is(chatMode.tabs.length, 1, "chat tab is open");
+  is(tabmail.selectedTab, chatMode.tabs[0], "chat tab is selected");
+
+  await new Promise(resolve => setTimeout(resolve));
+}
+
+async function closeChatTab() {
+  let tabmail = document.getElementById("tabmail");
+  let chatMode = tabmail.tabModes.chat;
+
+  if (chatMode.tabs.length == 1) {
+    tabmail.closeTab(chatMode.tabs[0]);
+  }
+
+  is(chatMode.tabs.length, 0, "chat tab is not open");
+
+  await new Promise(resolve => setTimeout(resolve));
+}
+
 async function openPreferencesTab() {
   const tabmail = document.getElementById("tabmail");
   const prefsMode = tabmail.tabModes.preferencesTab;
 
   if (prefsMode.tabs.length == 1) {
     tabmail.selectedTab = prefsMode.tabs[0];
   } else {
     openOptionsDialog();
@@ -153,11 +182,12 @@ async function closeAddonsTab() {
   is(contentMode.tabs.length, 0, "addons tab is not open");
 
   await new Promise(resolve => setTimeout(resolve));
 }
 
 registerCleanupFunction(async () => {
   await closeCalendarTab();
   await closeTasksTab();
+  await closeChatTab();
   await closePreferencesTab();
   await closeAddonsTab();
 });