1 { classes: Cc, interfaces: Ci } = Components
3 PREF_BRANCH = "extensions.VimFx.";
5 # Default values for the preference
6 # All used preferences should be mentioned here becuase
7 # preference type is derived from here
9 addon_id: 'VimFx@akhodakivskiy.github.com'
10 hint_chars: 'asdfgercvhjkl;uinm'
14 black_list: '*mail.google.com*'
18 branch = Services.prefs.getBranch PREF_BRANCH
20 return (key, defaultValue=undefined) ->
21 type = branch.getPrefType(key)
25 return branch.getBoolPref key
27 return branch.getIntPref key
28 when branch.PREF_STRING
29 return branch.getCharPref key
31 if defaultValue != undefined
34 return DEFAULT_PREF_VALUES[key];
36 # Assign and save Firefox preference value
38 branch = Services.prefs.getBranch PREF_BRANCH
40 return (key, value) ->
43 branch.setBoolPref(key, value)
45 branch.setIntPref(key, value)
47 branch.setCharPref(key, value);
49 branch.clearUserPref(key);
52 DISABLED_COMMANDS = do ->
53 str = getPref 'disabled_commands'
58 for key in str.split('||')
59 for c in key.split('|')
65 enableCommand = (key) ->
66 for c in key.split('|')
67 while (idx = DISABLED_COMMANDS.indexOf(c)) > -1
68 DISABLED_COMMANDS.splice(idx, 1)
70 setPref 'disabled_commands', JSON.stringify DISABLED_COMMANDS
72 # Adds command to the disabled list
73 disableCommand = (key) ->
74 for c in key.split('|')
75 if DISABLED_COMMANDS.indexOf(c) == -1
76 DISABLED_COMMANDS.push c
78 setPref 'disabled_commands', JSON.stringify DISABLED_COMMANDS
80 # Checks if given command is disabled in the preferences
81 isCommandDisabled = (key) ->
82 for c in key.split('|')
83 if DISABLED_COMMANDS.indexOf(c) > -1
88 exports.getPref = getPref
89 exports.setPref = setPref
90 exports.isCommandDisabled = isCommandDisabled
91 exports.disableCommand = disableCommand
92 exports.enableCommand = enableCommand