1 # This file provides an API a bit more easy to use than the very low-level
4 defaults = require('./defaults')
10 user: prefs.getBranch(defaults.BRANCH)
11 default: prefs.getDefaultBranch(defaults.BRANCH)
15 default: prefs.getDefaultBranch('')
19 get = (branch, key) ->
20 return switch branch.getPrefType(key)
22 branch.getBoolPref(key)
24 branch.getIntPref(key)
25 when branch.PREF_STRING
26 branch.getComplexValue(key, Ci.nsISupportsString).data
28 set = (branch, key, value) ->
31 branch.setBoolPref(key, value)
33 branch.setIntPref(key, value) # `value` will be `Math.floor`ed.
35 str = Cc['@mozilla.org/supports-string;1']
36 .createInstance(Ci.nsISupportsString)
38 branch.setComplexValue(key, Ci.nsISupportsString, str)
41 branch.clearUserPref(key)
44 "VimFx: Options may only be set to a boolean, number, string or null.
48 has = (branch, key) ->
49 branch.prefHasUserValue(key)
51 tmp = (branch, pref, temporaryValue) ->
52 previousValue = if has(branch, pref) then get(branch, pref) else null
53 set(branch, pref, temporaryValue)
54 return -> set(branch, pref, previousValue)
56 observe = (branch, domain, callback) ->
57 observer = {observe: (branch, topic, changedPref) -> callback(changedPref)}
58 branch.addObserver(domain, observer, false)
60 branch.removeObserver(domain, observer)
64 get: get.bind(null, branches.addon.user)
65 set: set.bind(null, branches.addon.user)
66 has: has.bind(null, branches.addon.user)
67 tmp: tmp.bind(null, branches.addon.user)
68 observe: observe.bind(null, branches.addon.user)
70 get: get.bind(null, branches.addon.default)
71 set: set.bind(null, branches.addon.default)
73 for key, value of defaults.all_prefs
74 module.exports.default.set(key, value)
78 get: get.bind(null, branches.root.user)
79 set: set.bind(null, branches.root.user)
80 has: has.bind(null, branches.root.user)
81 tmp: tmp.bind(null, branches.root.user)
82 observe: observe.bind(null, branches.root.user)
84 get: get.bind(null, branches.root.default)
85 set: set.bind(null, branches.root.default)
88 unbound: {get, set, has, tmp, observe}