Bug 1534112 - Initialise calendar category colours on first startup. r+a=philipp
authorGeoff Lankow <geoff@darktrojan.net>
Thu, 04 Jul 2019 21:32:39 +1200
changeset 36120 8f2a29618eed9f467cc11c2aeff48a216a29d736
parent 36119 8471b4a999142dfac8de2540abd2b999f53ecffb
child 36121 eef322757b67ee75b7d1cf8834580bf23bcc08e5
push id392
push userclokep@gmail.com
push dateMon, 02 Sep 2019 20:17:19 +0000
bugs1534112
Bug 1534112 - Initialise calendar category colours on first startup. r+a=philipp
calendar/base/content/calendar-chrome-startup.js
calendar/base/content/preferences/categories.js
calendar/base/modules/utils/calCategoryUtils.jsm
--- a/calendar/base/content/calendar-chrome-startup.js
+++ b/calendar/base/content/calendar-chrome-startup.js
@@ -285,17 +285,17 @@ function migrateCalendarUI() {
     }
 }
 
 function setLocaleDefaultPreferences() {
     function setDefaultLocaleValue(aName) {
         let startDefault = calendarInfo.firstDayOfWeek - 1;
         if (aName == "calendar.categories.names" &&
             defaultBranch.getStringPref(aName) == "") {
-            defaultBranch.setStringPref(aName, cal.l10n.getString("categories", "categories2"));
+            cal.category.setupDefaultCategories();
         } else if (aName == "calendar.week.start" &&
                    defaultBranch.getIntPref(aName) != startDefault) {
             defaultBranch.setIntPref(aName, startDefault);
         } else if (aName.startsWith("calendar.week.d")) {
             let weStart = calendarInfo.weekendStart - 1;
             let weEnd = calendarInfo.weekendEnd - 1;
             if (weStart > weEnd) {
                 weEnd += 7;
--- a/calendar/base/content/preferences/categories.js
+++ b/calendar/base/content/preferences/categories.js
@@ -42,25 +42,17 @@ var gCategoriesPane = {
         }
 
         // A list of preferences to be reverted when the dialog is cancelled.
         // It needs to be a property of the parent to be visible onCancel
         if (!("backupPrefList" in parent)) {
             parent.backupPrefList = [];
         }
 
-        let categories = Preferences.get("calendar.categories.names").value;
-
-        // If no categories are configured load a default set from properties file
-        if (!categories) {
-            categories = cal.category.setupDefaultCategories();
-            Preferences.get("calendar.categories.names").value = categories;
-        }
-
-        gCategoryList = cal.category.stringToArray(categories);
+        gCategoryList = cal.category.fromPrefs();
 
         this.updateCategoryList();
 
         this.mCategoryDialog = "chrome://calendar/content/preferences/editCategory.xul";
 
         // Workaround for Bug 1151440 - the HTML color picker won't work
         // in linux when opened from modal dialog
         this.mWinProp = "centerscreen, chrome, resizable=no";
--- a/calendar/base/modules/utils/calCategoryUtils.jsm
+++ b/calendar/base/modules/utils/calCategoryUtils.jsm
@@ -18,26 +18,28 @@ this.EXPORTED_SYMBOLS = ["calcategory"];
 
 var calcategory = {
     /**
      * Sets up the default categories from the localized string
      *
      * @return      The default set of categories as a comma separated string.
      */
     setupDefaultCategories: function() {
+        let defaultBranch = Services.prefs.getDefaultBranch("");
+
         // First, set up the category names
         let categories = cal.l10n.getString("categories", "categories2");
-        Services.prefs.setStringPref("calendar.categories.names", categories);
+        defaultBranch.setStringPref("calendar.categories.names", categories);
 
         // Now, initialize the category default colors
         let categoryArray = calcategory.stringToArray(categories);
         for (let category of categoryArray) {
             let prefName = cal.view.formatStringForCSSRule(category);
-            Services.prefs.setStringPref("calendar.category.color." + prefName,
-                                         cal.view.hashColor(category));
+            defaultBranch.setStringPref("calendar.category.color." + prefName,
+                                        cal.view.hashColor(category));
         }
 
         // Return the list of categories for further processing
         return categories;
     },
 
     /**
      * Get array of category names from preferences or locale default,