mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 10:18:00 +01:00
Move events.prefObserver to options.prefObserver.
This commit is contained in:
@@ -1733,38 +1733,6 @@ function Events() //{{{
|
|||||||
// Stub for something else, presumably. Not in any documented
|
// Stub for something else, presumably. Not in any documented
|
||||||
// interface.
|
// interface.
|
||||||
onLinkIconAvailable: function () {}
|
onLinkIconAvailable: function () {}
|
||||||
},
|
|
||||||
|
|
||||||
// TODO: move to options.js?
|
|
||||||
prefObserver: {
|
|
||||||
register: function ()
|
|
||||||
{
|
|
||||||
// better way to monitor all changes?
|
|
||||||
this._branch = services.get("pref").getBranch("").QueryInterface(Ci.nsIPrefBranch2);
|
|
||||||
this._branch.addObserver("", this, false);
|
|
||||||
},
|
|
||||||
|
|
||||||
unregister: function ()
|
|
||||||
{
|
|
||||||
if (this._branch)
|
|
||||||
this._branch.removeObserver("", this);
|
|
||||||
},
|
|
||||||
|
|
||||||
observe: function (subject, topic, data)
|
|
||||||
{
|
|
||||||
if (topic != "nsPref:changed")
|
|
||||||
return;
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
liberator.mode = value ? modes.CARET : modes.NORMAL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}; //}}}
|
}; //}}}
|
||||||
|
|
||||||
@@ -1782,10 +1750,8 @@ function Events() //{{{
|
|||||||
}
|
}
|
||||||
catch (e) {}
|
catch (e) {}
|
||||||
|
|
||||||
self.prefObserver.register();
|
|
||||||
liberator.registerObserver("shutdown", function () {
|
liberator.registerObserver("shutdown", function () {
|
||||||
self.destroy();
|
self.destroy();
|
||||||
self.prefObserver.unregister();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener("keypress", wrapListener("onKeyPress"), true);
|
window.addEventListener("keypress", wrapListener("onKeyPress"), true);
|
||||||
|
|||||||
@@ -805,7 +805,7 @@ function Options() //{{{
|
|||||||
.map(function (pref) [pref, ""])]);
|
.map(function (pref) [pref, ""])]);
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
const self = {
|
||||||
|
|
||||||
OPTION_SCOPE_GLOBAL: 1,
|
OPTION_SCOPE_GLOBAL: 1,
|
||||||
OPTION_SCOPE_LOCAL: 2,
|
OPTION_SCOPE_LOCAL: 2,
|
||||||
@@ -817,6 +817,37 @@ function Options() //{{{
|
|||||||
return (v for ([k, v] in Iterator(sorted)));
|
return (v for ([k, v] in Iterator(sorted)));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
prefObserver: {
|
||||||
|
register: function ()
|
||||||
|
{
|
||||||
|
// better way to monitor all changes?
|
||||||
|
this._branch = services.get("pref").getBranch("").QueryInterface(Ci.nsIPrefBranch2);
|
||||||
|
this._branch.addObserver("", this, false);
|
||||||
|
},
|
||||||
|
|
||||||
|
unregister: function ()
|
||||||
|
{
|
||||||
|
if (this._branch)
|
||||||
|
this._branch.removeObserver("", this);
|
||||||
|
},
|
||||||
|
|
||||||
|
observe: function (subject, topic, data)
|
||||||
|
{
|
||||||
|
if (topic != "nsPref:changed")
|
||||||
|
return;
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
liberator.mode = value ? modes.CARET : modes.NORMAL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
add: function (names, description, type, defaultValue, extraInfo)
|
add: function (names, description, type, defaultValue, extraInfo)
|
||||||
{
|
{
|
||||||
if (!extraInfo)
|
if (!extraInfo)
|
||||||
@@ -1064,8 +1095,15 @@ function Options() //{{{
|
|||||||
this.popContext();
|
this.popContext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}; //}}}
|
||||||
//}}}
|
|
||||||
|
self.prefObserver.register();
|
||||||
|
liberator.registerObserver("shutdown", function () {
|
||||||
|
self.prefObserver.unregister();
|
||||||
|
});
|
||||||
|
|
||||||
|
return self;
|
||||||
|
|
||||||
}; //}}}
|
}; //}}}
|
||||||
|
|
||||||
// vim: set fdm=marker sw=4 ts=4 et:
|
// vim: set fdm=marker sw=4 ts=4 et:
|
||||||
|
|||||||
Reference in New Issue
Block a user