Allow setting global prefs from Zotero.Prefs.set()

Pass true as third argument
This commit is contained in:
Dan Stillman 2017-01-04 17:28:18 -05:00
parent 42a72fe8aa
commit 612066d749

View file

@ -1992,40 +1992,46 @@ Zotero.Prefs = new function(){
/**
* Set a preference
**/
function set(pref, value) {
function set(pref, value, global) {
try {
switch (this.prefBranch.getPrefType(pref)){
case this.prefBranch.PREF_BOOL:
return this.prefBranch.setBoolPref(pref, value);
case this.prefBranch.PREF_STRING:
if (global) {
var branch = Services.prefs.getBranch("");
}
else {
var branch = this.prefBranch;
}
switch (branch.getPrefType(pref)) {
case branch.PREF_BOOL:
return branch.setBoolPref(pref, value);
case branch.PREF_STRING:
let str = Cc["@mozilla.org/supports-string;1"]
.createInstance(Ci.nsISupportsString);
str.data = value;
return this.prefBranch.setComplexValue(pref, Ci.nsISupportsString, str);
case this.prefBranch.PREF_INT:
return this.prefBranch.setIntPref(pref, value);
return branch.setComplexValue(pref, Ci.nsISupportsString, str);
case branch.PREF_INT:
return branch.setIntPref(pref, value);
// If not an existing pref, create appropriate type automatically
case 0:
if (typeof value == 'boolean') {
Zotero.debug("Creating boolean pref '" + pref + "'");
return this.prefBranch.setBoolPref(pref, value);
return branch.setBoolPref(pref, value);
}
if (typeof value == 'string') {
Zotero.debug("Creating string pref '" + pref + "'");
return this.prefBranch.setCharPref(pref, value);
return branch.setCharPref(pref, value);
}
if (parseInt(value) == value) {
Zotero.debug("Creating integer pref '" + pref + "'");
return this.prefBranch.setIntPref(pref, value);
return branch.setIntPref(pref, value);
}
throw ("Invalid preference value '" + value + "' for pref '" + pref + "'");
throw new Error("Invalid preference value '" + value + "' for pref '" + pref + "'");
}
}
catch (e) {
Components.utils.reportError(e);
Zotero.debug(e, 1);
throw ("Invalid preference '" + pref + "'");
Zotero.logError(e);
throw new Error("Invalid preference '" + pref + "'");
}
}