Bug 703922 - Toggle boolean prefs with one click (and fix typo that broke pref types). r=mfinkle
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Tue, 22 Nov 2011 16:44:04 -0800
changeset 83580 6cdbeceb28464b93ed8b99951e891f496e0351e3
parent 83579 522b28c81dfe1969cb50f73e422ff50d1d2ecdc3
child 83581 2ab85c27e43548678b3777e9b613fe632db80847
push id519
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 00:38:35 +0000
treeherdermozilla-beta@788ea1ef610b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs703922
milestone11.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 703922 - Toggle boolean prefs with one click (and fix typo that broke pref types). r=mfinkle
mobile/android/chrome/content/config.xhtml
mobile/android/locales/en-US/chrome/config.properties
--- a/mobile/android/chrome/content/config.xhtml
+++ b/mobile/android/chrome/content/config.xhtml
@@ -139,24 +139,30 @@
       },
 
       // Mostly copied from toolkit config.js
       modifyPref: function AC_modifyPref(aPref) {
         if (aPref.locked)
           return;
   
         let title = gStringBundle.GetStringFromName("modifyPref.label");
-        let result = { value: aPref.value };
 
         if (aPref.type == Ci.nsIPrefBranch.PREF_BOOL) {
-          let text = gStringBundle.formatStringFromName("modifyPref.selectText", [aPref.name], 1);
-          if (!Services.prompt.select(window, title, text, 2, [false, true], result))
-            return;
+          // If the pref already exists, we just want to toggle the boolean
+          let result = { value: aPref.value == "false" };
+          // If the pref doesn't exist, we need to prompt the user to choose an initial value
+          if (!aPref.value) {
+            let text = gStringBundle.formatStringFromName("modifyPref.selectText", [aPref.name], 1);
+            if (!Services.prompt.select(window, title, text, 2, [false, true], result))
+              return;
+          }
+
           Services.prefs.setBoolPref(aPref.name, result.value);
         } else {
+          let result = { value: aPref.value };
           let text = gStringBundle.formatStringFromName("modifyPref.promptText", [aPref.name], 1);
           if (!Services.prompt.prompt(window, title, text, result, null, {}))
             return;
   
           if (aPref.type == Ci.nsIPrefBranch.PREF_INT) {
             // | 0 converts to integer or 0; - 0 to float or NaN.
             // Thus, this check should catch all cases.
             let val = result.value | 0;
@@ -195,17 +201,17 @@
 
           // Just stick the item at the beginning of the list so that we don't
           // need to scroll to it
           this._container.insertBefore(item, this._container.firstChild);
           return;
         }
 
         // Check to see if the pref was removed
-        if (pref.type = Ci.nsIPrefBranch.PREF_INVALID) {
+        if (pref.type == Ci.nsIPrefBranch.PREF_INVALID) {
           this._container.removeChild(item);
           return;
         }
 
         // Otherwise, just replace the item with an updated item
         this._container.replaceChild(this._createItem(pref), item);
       },
 
@@ -279,17 +285,20 @@
         name.textContent = aPref.name;
   
         let value = document.createElement("div");
         value.className = "pref-value";
         value.textContent = aPref.value;
 
         let modifyButton = document.createElement("button");
         modifyButton.className = "modify-pref-button";
-        modifyButton.textContent = gStringBundle.GetStringFromName("modifyPref.label");
+
+        modifyButton.textContent = aPref.type == Ci.nsIPrefBranch.PREF_BOOL ?
+                                   gStringBundle.GetStringFromName("togglePref.label") :
+                                   gStringBundle.GetStringFromName("modifyPref.label");
         modifyButton.addEventListener("click", function(event) {
           this.modifyPref(aPref);  
         }.bind(this), false);
 
         let resetButton = document.createElement("button");
         resetButton.className = "reset-pref-button";
         resetButton.textContent = gStringBundle.GetStringFromName("resetPref.label");
         resetButton.addEventListener("click", function(event) {
--- a/mobile/android/locales/en-US/chrome/config.properties
+++ b/mobile/android/locales/en-US/chrome/config.properties
@@ -1,14 +1,15 @@
 addPref.title=Add
 addPref.selectType=Select type:
 addPref.type.string=String
 addPref.type.integer=Integer
 addPref.type.boolean=Boolean
 addPref.enterName=Enter name:
 
+togglePref.label=Toggle
 modifyPref.label=Modify
 modifyPref.selectText=Select value for %1$S:
 modifyPref.promptText=Enter value for %1$S:
 modifyPref.numberErrorTitle=Invalid Value
 modifyPref.numberErrorText=The text you entered was not a number
 
 resetPref.label=Reset