2 # Copyright Anton Khodakivskiy 2012, 2013, 2014.
3 # Copyright Simon Lydell 2013, 2014.
4 # Copyright Wang Zhuochun 2013.
6 # This file is part of VimFx.
8 # VimFx is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # VimFx is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with VimFx. If not, see <http://www.gnu.org/licenses/>.
22 { classes: Cc, interfaces: Ci } = Components
24 PREF_BRANCH = 'extensions.VimFx.'
25 DEFAULT_PREFS_FILE = 'defaults/preferences/defaults.js'
27 # Default values for preferences are now specified in
28 # defaults/preferences/defaults.js.
30 prefs = Services.prefs
31 vimfxBranch = prefs.getBranch(PREF_BRANCH)
33 getBranchPref = (branch, key, defaultValue = undefined) ->
34 type = branch.getPrefType(key)
37 branch.getBoolPref(key)
39 branch.getIntPref(key)
40 when branch.PREF_STRING
41 branch.getCharPref(key)
46 return vimfxBranch.prefHasUserValue(key)
48 getPref = getBranchPref.bind(undefined, vimfxBranch)
51 getComplexPref = (key) ->
52 return vimfxBranch.getComplexValue(key, Ci.nsISupportsString).data
54 setBranchPref = (branch, key, value) ->
57 branch.setBoolPref(key, value)
59 branch.setIntPref(key, value)
61 branch.setCharPref(key, value)
63 branch.clearUserPref(key)
65 setPref = setBranchPref.bind(undefined, vimfxBranch)
68 baseUri = Services.io.newURI(__SCRIPT_URI_SPEC__, null, null)
69 uri = Services.io.newURI(DEFAULT_PREFS_FILE, null, baseUri)
71 branch = prefs.getDefaultBranch('')
72 scope = {pref: setBranchPref.bind(undefined, branch)}
73 Services.scriptloader.loadSubScript(uri.spec, scope)
75 exports.isPrefSet = isPrefSet
76 exports.getPref = getPref
77 exports.getComplexPref = getComplexPref
78 exports.setPref = setPref
79 exports.setDefaultPrefs = setDefaultPrefs