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'
59 for key in str.split('||')
60 for c in key.split('|')
66 enableCommand = (key) ->
67 for c in key.split('|')
68 while (idx = DISABLED_COMMANDS.indexOf(c)) > -1
69 DISABLED_COMMANDS.splice(idx, 1)
71 setPref 'disabled_commands', JSON.stringify DISABLED_COMMANDS
73 # Adds command to the disabled list
74 disableCommand = (key) ->
75 for c in key.split('|')
76 if DISABLED_COMMANDS.indexOf(c) == -1
77 DISABLED_COMMANDS.push c
79 setPref 'disabled_commands', JSON.stringify DISABLED_COMMANDS
81 # Checks if given command is disabled in the preferences
82 isCommandDisabled = (key) ->
83 for c in key.split('|')
84 if DISABLED_COMMANDS.indexOf(c) > -1
89 exports.getPref = getPref
90 exports.setPref = setPref
91 exports.isCommandDisabled = isCommandDisabled
92 exports.disableCommand = disableCommand
93 exports.enableCommand = enableCommand