//
// 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.",
cleanup: function cleanup(reason) {
if (this.defaults != this)
- this.defaults.cleanup();
+ this.defaults.cleanup(reason);
this._observers = {};
if (this.observe) {
this.branches.saved.resetBranch();
}
- if (reason == "uninstall" && this == prefs)
+ if (reason == "uninstall")
localPrefs.resetBranch();
}
},
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 });
},
/**
*/
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)