]> git.donarmstrong.com Git - dactyl.git/blobdiff - common/modules/prefs.jsm
Import 1.0rc1 supporting Firefox up to 11.*
[dactyl.git] / common / modules / prefs.jsm
index 13500685dbb10318a2925b33be7ced0a96db680f..f8e7e403713ddeac9d6e2c2cecd91d87157d3285 100644 (file)
@@ -4,17 +4,18 @@
 //
 // This work is licensed for reuse under an MIT license. Details are
 // given in the LICENSE.txt file included with this file.
-"use strict";
+/* use strict */
 
 try {
 
 Components.utils.import("resource://dactyl/bootstrap.jsm");
 defineModule("prefs", {
     exports: ["Prefs", "localPrefs", "prefs"],
-    require: ["services", "util"],
-    use: ["config", "messages", "template"]
+    require: ["services", "util"]
 }, this);
 
+this.lazyRequire("messages", ["_"]);
+
 var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), {
     ORIGINAL: "extensions.dactyl.original.",
     RESTORE: "extensions.dactyl.restore.",
@@ -44,7 +45,7 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
 
     cleanup: function cleanup(reason) {
         if (this.defaults != this)
-            this.defaults.cleanup();
+            this.defaults.cleanup(reason);
 
         this._observers = {};
         if (this.observe) {
@@ -62,7 +63,7 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
                 this.branches.saved.resetBranch();
             }
 
-            if (reason == "uninstall" && this == prefs)
+            if (reason == "uninstall")
                 localPrefs.resetBranch();
         }
     },
@@ -112,7 +113,7 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
 
         if (!this._observers[pref])
             this._observers[pref] = [];
-        this._observers[pref].push(!strong ? Cu.getWeakReference(callback) : { get: function () callback });
+        this._observers[pref].push(!strong ? util.weakReference(callback) : { get: function () callback });
     },
 
     /**
@@ -198,10 +199,18 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
      */
     getNames: function getNames(branch) this.branch.getChildList(branch || "", { value: 0 }),
 
+    /**
+     * Returns true if the current branch has the given preference.
+     *
+     * @param {string} name The preference name.
+     * @returns {boolean}
+     */
+    has: function get(name) this.branch.getPrefType(name) != 0,
+
     _checkSafe: function _checkSafe(name, message, value) {
         let curval = this.get(name, null);
 
-        if (this.branches.original.get(name) == null)
+        if (this.branches.original.get(name) == null && !this.branches.saved.has(name))
             this.branches.original.set(name, curval, true);
 
         if (arguments.length > 2 && curval === value)