1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-09 18:25:46 +01:00

Trigger setters on option change.

This commit is contained in:
Kris Maglione
2008-09-11 03:15:36 +00:00
parent 56155a6032
commit 86b9415ad9
2 changed files with 18 additions and 7 deletions

View File

@@ -123,7 +123,7 @@ liberator.Option = function (names, description, type, defaultValue, extraInfo)
if (liberator.has("tabs") && (scope & liberator.options.OPTION_SCOPE_LOCAL))
liberator.tabs.options[this.name] = newValue;
if (scope & liberator.options.OPTION_SCOPE_GLOBAL)
if (scope & liberator.options.OPTION_SCOPE_GLOBAL && newValue != this.globalValue)
this.globalvalue = newValue;
this.hasChanged = true;
@@ -159,12 +159,21 @@ liberator.Options = function () //{{{
////////////////////// PRIVATE SECTION /////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
liberator.storage.newObject("options", false);
var prefService = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
var options = [];
function optionObserver(key, event, option)
{
// Trigger any setters.
let opt = liberator.options.get(option);
if(event == "change" && opt)
opt.set(opt.value, liberator.options.OPTION_SCOPE_GLOBAL)
}
liberator.storage.newObject("options", false);
liberator.storage.addObserver("options", optionObserver);
function storePreference(name, value)
{
var type = prefService.getPrefType(name);
@@ -811,6 +820,7 @@ liberator.Options = function () //{{{
if (loadPreference("dom.popup_allowed_events", "change click dblclick mouseup reset submit")
== popupAllowedEvents + " keypress")
storePreference("dom.popup_allowed_events", popupAllowedEvents);
liberator.storage.removeObserver("options", optionObserver);
},
get: function (name, scope)

View File

@@ -83,12 +83,13 @@ function ObjectStore(name, store)
this.set = function set(key, val)
{
var defined = key in object;
var orig = object[key];
object[key] = val;
if (orig == val)
this.fireEvent("change", key);
else
if (!defined)
this.fireEvent("add", key);
else if (orig != val)
this.fireEvent("change", key);
};
this.remove = function remove(key)
@@ -207,7 +208,7 @@ var storage = {
{
if(!(key in observers))
observers[key] = [];
if(observers[key].indexOf(key) >= 0)
if(observers[key].indexOf(callback) >= 0)
return;
observers[key].push(callback);
},