]> git.gir.st - VimFx.git/blob - extension/packages/prefs.coffee
Now link markers will always be on top of all other markers even if the link elemens...
[VimFx.git] / extension / packages / prefs.coffee
1 { classes: Cc, interfaces: Ci } = Components
2
3 PREF_BRANCH = "extensions.VimFx.";
4
5 # Default values for the preference
6 # All used preferences should be mentioned here becuase
7 # preference type is derived from here
8 DEFAULT_PREF_VALUES =
9 addon_id: 'VimFx@akhodakivskiy.github.com'
10 hint_chars: 'asdfgercvhjkl;uinm'
11 disabled: false
12 scroll_step: 60
13 scroll_time: 100
14 black_list: '*mail.google.com*'
15 blur_on_esc: true
16
17 getPref = do ->
18 branch = Services.prefs.getBranch PREF_BRANCH
19
20 return (key, defaultValue=undefined) ->
21 type = branch.getPrefType(key)
22
23 switch type
24 when branch.PREF_BOOL
25 return branch.getBoolPref key
26 when branch.PREF_INT
27 return branch.getIntPref key
28 when branch.PREF_STRING
29 return branch.getCharPref key
30 else
31 if defaultValue != undefined
32 return defaultValue
33 else
34 return DEFAULT_PREF_VALUES[key];
35
36 # Assign and save Firefox preference value
37 setPref = do ->
38 branch = Services.prefs.getBranch PREF_BRANCH
39
40 return (key, value) ->
41 switch typeof value
42 when 'boolean'
43 branch.setBoolPref(key, value)
44 when 'number'
45 branch.setIntPref(key, value)
46 when 'string'
47 branch.setCharPref(key, value);
48 else
49 branch.clearUserPref(key);
50
51
52 DISABLED_COMMANDS = do ->
53 str = getPref 'disabled_commands'
54 try
55 return JSON.parse str
56 catch err
57 dc = []
58 try
59 for key in str.split('||')
60 for c in key.split('|')
61 dc.push c if c
62
63 return dc
64
65 # Enables command
66 enableCommand = (key) ->
67 for c in key.split('|')
68 while (idx = DISABLED_COMMANDS.indexOf(c)) > -1
69 DISABLED_COMMANDS.splice(idx, 1)
70
71 setPref 'disabled_commands', JSON.stringify DISABLED_COMMANDS
72
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
78
79 setPref 'disabled_commands', JSON.stringify DISABLED_COMMANDS
80
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
85 return true
86
87 return false
88
89 exports.getPref = getPref
90 exports.setPref = setPref
91 exports.isCommandDisabled = isCommandDisabled
92 exports.disableCommand = disableCommand
93 exports.enableCommand = enableCommand
Imprint / Impressum