Bug 1621791 - Update new item commands on calendar enable/disable. r=darktrojan
authorPaul Morris <paul@thunderbird.net>
Tue, 17 Mar 2020 12:40:50 +0200
changeset 38504 bd92c86971d7cd014206df89b25ad071bd0362a6
parent 38503 50e95bf7986d08be42c8bf51cc3e3587e7a53f90
child 38505 f02ab1a74c31cb19d611937722dc63add4eaf0e3
push id400
push userclokep@gmail.com
push dateMon, 04 May 2020 18:56:09 +0000
reviewersdarktrojan
bugs1621791
Bug 1621791 - Update new item commands on calendar enable/disable. r=darktrojan
calendar/base/content/calendar-command-controller.js
calendar/base/content/calendar-management.js
--- a/calendar/base/content/calendar-command-controller.js
+++ b/calendar/base/content/calendar-command-controller.js
@@ -875,41 +875,33 @@ function deleteSelectedItems() {
   if (calendarController.todo_tasktree_focused) {
     deleteToDoCommand();
   } else if (calendarController.isInMode("calendar")) {
     deleteSelectedEvents();
   }
 }
 
 function calendarUpdateNewItemsCommand() {
-  // define command set to update
-  let eventCommands = ["calendar_new_event_command", "calendar_new_event_context_command"];
-  let taskCommands = [
-    "calendar_new_todo_command",
-    "calendar_new_todo_context_command",
-    "calendar_new_todo_todaypane_command",
-  ];
-
-  // re-calculate command status
-  CalendarNewEventsCommandEnabled = false;
-  CalendarNewTasksCommandEnabled = false;
+  // Re-calculate command status.
   let calendars = cal
     .getCalendarManager()
     .getCalendars()
     .filter(cal.acl.isCalendarWritable)
     .filter(cal.acl.userCanAddItemsToCalendar);
-  if (calendars.some(cal.item.isEventCalendar)) {
-    CalendarNewEventsCommandEnabled = true;
-  }
-  if (calendars.some(cal.item.isTaskCalendar)) {
-    CalendarNewTasksCommandEnabled = true;
-  }
+
+  CalendarNewEventsCommandEnabled = calendars.some(cal.item.isEventCalendar);
+  CalendarNewTasksCommandEnabled = calendars.some(cal.item.isTaskCalendar);
 
-  eventCommands.forEach(goUpdateCommand);
-  taskCommands.forEach(goUpdateCommand);
+  [
+    "calendar_new_event_command",
+    "calendar_new_event_context_command",
+    "calendar_new_todo_command",
+    "calendar_new_todo_context_command",
+    "calendar_new_todo_todaypane_command",
+  ].forEach(goUpdateCommand);
 }
 
 function calendarUpdateDeleteCommand(selectedItems) {
   let oldValue = CalendarDeleteCommandEnabled;
   CalendarDeleteCommandEnabled = selectedItems.length > 0;
 
   /* we must disable "delete" when at least one item cannot be deleted */
   for (let item of selectedItems) {
--- a/calendar/base/content/calendar-management.js
+++ b/calendar/base/content/calendar-management.js
@@ -609,28 +609,36 @@ function showOnlyCalendar(aCalendar) {
   composite.endBatch();
 }
 
 var compositeObserver = {
   QueryInterface: cal.generateQI([Ci.calIObserver, Ci.calICompositeObserver]),
 
   onStartBatch() {},
   onEndBatch() {},
-  onAddItem() {},
-  onModifyItem() {},
-  onDeleteItem() {},
-  onError() {},
-  onPropertyChanged() {},
-  onPropertyDeleting() {},
 
   onLoad() {
     calendarUpdateNewItemsCommand();
     document.commandDispatcher.updateCommands("calendar_commands");
   },
 
+  onAddItem() {},
+  onModifyItem() {},
+  onDeleteItem() {},
+  onError() {},
+
+  onPropertyChanged(calendar, name, value, oldValue) {
+    // Update commands when a calendar is enabled or disabled.
+    if (name == "disabled") {
+      calendarUpdateNewItemsCommand();
+    }
+  },
+
+  onPropertyDeleting() {},
+
   onCalendarAdded(aCalendar) {
     // Update the calendar commands for number of remote calendars and for
     // more than one calendar
     document.commandDispatcher.updateCommands("calendar_commands");
   },
 
   onCalendarRemoved(aCalendar) {
     // Update commands to disallow deleting the last calendar and only