From 612066d7496850db7a416a6c024e0c6bc11247b5 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 4 Jan 2017 17:28:18 -0500 Subject: [PATCH] Allow setting global prefs from Zotero.Prefs.set() Pass true as third argument --- chrome/content/zotero/xpcom/zotero.js | 36 ++++++++++++++++----------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index f896833ccd..e7fce87de8 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -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 + "'"); } }