Bug 1514483 - [calendar] simplified loops for Services.catMan.enumerateCategory; r=Fallen
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Sat, 15 Dec 2018 15:42:38 +0200
changeset 34010 33c3ec8edd93be541453acfe23b4f9b2ac5725b5
parent 34009 8de5f19ac58cce60d4f6a8a0787fbcaf524dcb22
child 34011 c550aac138145e16c2c28419e336787e4d913916
push id389
push userclokep@gmail.com
push dateMon, 18 Mar 2019 19:01:53 +0000
reviewersFallen
bugs1514483
Bug 1514483 - [calendar] simplified loops for Services.catMan.enumerateCategory; r=Fallen Affected places: - File | Print - with a calendar open. - Events & Tasks | Import ... (file types to show) - Events & Tasks | Export ... (file types to show)
calendar/base/content/dialogs/calendar-print-dialog.js
calendar/base/content/import-export.js
--- a/calendar/base/content/dialogs/calendar-print-dialog.js
+++ b/calendar/base/content/dialogs/calendar-print-dialog.js
@@ -32,25 +32,21 @@ function loadCalendarPrintDialog() {
         document.getElementById("printCurrentViewRadio").setAttribute("disabled", true);
     }
     if (!theView || !theView.getSelectedItems({}).length) {
         document.getElementById("selected").setAttribute("disabled", true);
     }
     document.getElementById(theView ? "printCurrentViewRadio" : "custom-range")
             .setAttribute("selected", true);
 
-    // Get a list of formatters
-    let catenum = Services.catMan.enumerateCategory("cal-print-formatters");
-
-    // Walk the list, adding items to the layout menupopup
+    // Get a list of formatters.
+    // Walk the list, adding items to the layout menupopup.
     let layoutList = document.getElementById("layout-field");
-    while (catenum.hasMoreElements()) {
-        let entry = catenum.getNext();
-        entry = entry.QueryInterface(Components.interfaces.nsISupportsCString);
-        let contractid = Services.catMan.getCategoryEntry("cal-print-formatters", entry);
+    for (let {data} of Services.catMan.enumerateCategory("cal-print-formatters")) {
+        let contractid = Services.catMan.getCategoryEntry("cal-print-formatters", data);
         let formatter = Components.classes[contractid]
                                   .getService(Components.interfaces.calIPrintFormatter);
         // Use the contractid as value
         layoutList.appendItem(formatter.name, contractid);
     }
     layoutList.selectedIndex = 0;
 
     opener.setCursor("auto");
--- a/calendar/base/content/import-export.js
+++ b/calendar/base/content/import-export.js
@@ -25,23 +25,20 @@ function loadEventsFromFile(aCalendar) {
                            .createInstance(nsIFilePicker);
     picker.init(window,
                 cal.l10n.getCalString("filepickerTitleImport"),
                 nsIFilePicker.modeOpen);
     picker.defaultExtension = "ics";
 
     // Get a list of importers
     let contractids = [];
-    let catenum = Services.catMan.enumerateCategory("cal-importers");
     let currentListLength = 0;
     let defaultCIDIndex = 0;
-    while (catenum.hasMoreElements()) {
-        let entry = catenum.getNext();
-        entry = entry.QueryInterface(Components.interfaces.nsISupportsCString);
-        let contractid = Services.catMan.getCategoryEntry("cal-importers", entry);
+    for (let {data} of Services.catMan.enumerateCategory("cal-importers")) {
+        let contractid = Services.catMan.getCategoryEntry("cal-importers", data);
         let importer;
         try {
             importer = Components.classes[contractid]
                                  .getService(Components.interfaces.calIImporter);
         } catch (e) {
             cal.WARN("Could not initialize importer: " + contractid + "\nError: " + e);
             continue;
         }
@@ -233,23 +230,20 @@ function saveEventsToFile(calendarEventA
     } else {
         picker.defaultString = cal.l10n.getCalString("defaultFileName");
     }
 
     picker.defaultExtension = "ics";
 
     // Get a list of exporters
     let contractids = [];
-    let catenum = Services.catMan.enumerateCategory("cal-exporters");
     let currentListLength = 0;
     let defaultCIDIndex = 0;
-    while (catenum.hasMoreElements()) {
-        let entry = catenum.getNext();
-        entry = entry.QueryInterface(Components.interfaces.nsISupportsCString);
-        let contractid = Services.catMan.getCategoryEntry("cal-exporters", entry);
+    for (let {data} of Services.catMan.enumerateCategory("cal-exporters")) {
+        let contractid = Services.catMan.getCategoryEntry("cal-exporters", data);
         let exporter;
         try {
             exporter = Components.classes[contractid]
                                  .getService(Components.interfaces.calIExporter);
         } catch (e) {
             cal.WARN("Could not initialize exporter: " + contractid + "\nError: " + e);
             continue;
         }