[Pkg-mozext-commits] [tabmixplus] 79/147: Refactor code to ensure textboxes disable state updates when the preference changed by user or by setPrefAfterImport

David Prévot taffit at moszumanska.debian.org
Sat Aug 5 15:27:39 UTC 2017


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository tabmixplus.

commit ce68b10cbd4af49c010b4027c0a091057fd06168
Author: onemen <tabmix.onemen at gmail.com>
Date:   Wed Dec 28 15:12:53 2016 +0200

    Refactor code to ensure textboxes disable state updates when the preference changed by user or by setPrefAfterImport
---
 chrome/content/preferences/events.js  | 43 ++++++++++++-----------------------
 chrome/content/preferences/events.xul |  1 -
 2 files changed, 15 insertions(+), 29 deletions(-)

diff --git a/chrome/content/preferences/events.js b/chrome/content/preferences/events.js
index c87fbd2..bf2e72f 100644
--- a/chrome/content/preferences/events.js
+++ b/chrome/content/preferences/events.js
@@ -50,7 +50,6 @@ var gEventsPane = {
     }
 
     this.alignTabOpeningBoxes();
-    this.loadProgressively.init();
 
     gPrefWindow.initPane("paneEvents");
   },
@@ -144,60 +143,48 @@ var gEventsPane = {
   },
 
   loadProgressively: {
-    init() {
-      this._init("pref_loadProgressively");
-      this._init("pref_restoreOnDemand");
-      this.syncToPref();
-      this.setOnDemandState();
-    },
-
-    _init(id) {
-      const preference = $(id);
+    syncToCheckBox: function(item) {
+      let preference = $(item.getAttribute("preference"));
       if (preference.value == 0) {
         preference.value = 1;
       }
       if (preference.hasAttribute("notChecked")) {
         preference.setAttribute("notChecked", -Math.abs(preference.value));
       }
-    },
-
-    syncToCheckBox: function(item) {
-      let preference = $(item.getAttribute("preference"));
+      this.setOnDemandDisabledState();
       return preference.value > -1;
     },
 
     syncFromCheckBox: function(item) {
       let preference = $(item.getAttribute("preference"));
       let control = $(item.getAttribute("control"));
-      if (preference.hasAttribute("notChecked")) {
-        preference.setAttribute("notChecked", -Math.abs(preference.value));
-      }
       control.disabled = !item.checked;
-      this.setOnDemandState();
       return -preference.value;
     },
 
     syncFromPref(item) {
       const preference = $(item.getAttribute("preference"));
-      return Math.abs(preference.value);
+      const prefValue = Math.abs(preference.value);
+      this.setOnDemandMinValue(item, prefValue);
+      return prefValue;
     },
 
-    syncToPref() {
+    setOnDemandMinValue(item, prefValue) {
+      if (item.id != "loadProgressively") {
+        return;
+      }
       const onDemand = $("restoreOnDemand");
-      const item = $("loadProgressively");
       onDemand.min = item.valueNumber;
       onDemand._enableDisableButtons();
-      const preference = $("pref_loadProgressively");
       const restoreOnDemand = $("pref_restoreOnDemand");
-      if (Math.abs(preference.value) > Math.abs(restoreOnDemand.value)) {
-        const val = Math.abs(preference.value);
-        restoreOnDemand.value = $("chk_restoreOnDemand").checked ? val : -val;
+      if (prefValue > Math.abs(restoreOnDemand.value)) {
+        restoreOnDemand.value = $("chk_restoreOnDemand").checked ? prefValue : -prefValue;
       }
     },
 
-    setOnDemandState() {
-      const disabled = !$("chk_loadProgressively").checked ||
-                       !$("chk_restoreOnDemand").checked;
+    setOnDemandDisabledState() {
+      const disabled = $("pref_loadProgressively").value < 0 ||
+                       $("pref_restoreOnDemand").value < 0;
       gPrefWindow.setDisabled("restoreOnDemand", disabled);
     },
   },
diff --git a/chrome/content/preferences/events.xul b/chrome/content/preferences/events.xul
index 365e2a4..9961f84 100644
--- a/chrome/content/preferences/events.xul
+++ b/chrome/content/preferences/events.xul
@@ -179,7 +179,6 @@
                             onsynctopreference="return gEventsPane.loadProgressively.syncFromCheckBox(this);"/>
               <textbox id="loadProgressively" maxlength="3" size="2" preference="pref_loadProgressively"
                        onsyncfrompreference="return gEventsPane.loadProgressively.syncFromPref(this);"
-                       onsynctopreference="return gEventsPane.loadProgressively.syncToPref(this);"
                        observes="obs_loadProgressively"
                        type="number" min="1" maxwidth="36"/>
               <label value="&tabs.label;"/>

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/tabmixplus.git



More information about the Pkg-mozext-commits mailing list