mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-01-31 13:55:46 +01:00
Fix some major mode changing bugs. Closes issue #55.
--HG-- branch : mode-refactoring
This commit is contained in:
@@ -646,13 +646,15 @@ const Options = Module("options", {
|
||||
|
||||
observe: function (subject, topic, data) {
|
||||
if (topic == "nsPref:changed") {
|
||||
// subject is the nsIPrefBranch we're observing (after appropriate QI)
|
||||
// data is the name of the pref that's been changed (relative to subject)
|
||||
switch (data) {
|
||||
case "accessibility.browsewithcaret":
|
||||
let value = options.getPref("accessibility.browsewithcaret", false);
|
||||
dactyl.mode = value ? modes.CARET : modes.NORMAL;
|
||||
break;
|
||||
let observers = this._observers[data];
|
||||
if (observers) {
|
||||
let value = options.getPref(data, false);
|
||||
this._observers[data] = observers.filter(function (callback) {
|
||||
if (!callback.get())
|
||||
return false;
|
||||
dactyl.trapErrors(callback.get(), null, value);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -798,6 +800,20 @@ const Options = Module("options", {
|
||||
template.options(config.host + " Options", prefs()));
|
||||
},
|
||||
|
||||
_observers: Class.memoize(function () ({})),
|
||||
/**
|
||||
* Adds a new preference observer for the given preference.
|
||||
*
|
||||
* @param {string} pref The preference to observe.
|
||||
* @param {function(object)} callback The callback, called with the
|
||||
* new value of the preference whenever it changes.
|
||||
*/
|
||||
observePref: function (pref, callback, weak) {
|
||||
if (!this._observers[pref])
|
||||
this._observers[pref] = [];
|
||||
this._observers[pref].push(weak ? Cu.getWeakReference(callback) : { get: function () callback });
|
||||
},
|
||||
|
||||
/**
|
||||
* Parses a :set command's argument string.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user