2 # Copyright Anton Khodakivskiy 2012, 2013, 2014.
3 # Copyright Simon Lydell 2013, 2014.
5 # This file is part of VimFx.
7 # VimFx is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # VimFx is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with VimFx. If not, see <http://www.gnu.org/licenses/>.
21 createAPI = require('./api')
22 button = require('./button')
23 defaults = require('./defaults')
24 { addEventListeners } = require('./events')
25 messageManager = require('./message-manager')
26 modes = require('./modes')
27 options = require('./options')
28 parsePref = require('./parse-prefs')
29 prefs = require('./prefs')
30 utils = require('./utils')
31 VimFx = require('./vimfx')
32 test = try require('../test/index')
34 Cu.import('resource://gre/modules/AddonManager.jsm')
36 module.exports = (data, reason) ->
38 for pref of defaults.all_options
39 parsedOptions[pref] = parsePref(pref)
40 vimfx = new VimFx(modes, parsedOptions)
42 vimfx.version = data.version
43 AddonManager.getAddonByID(vimfx.id, (info) -> vimfx.info = info)
45 # Setup the public API.
46 apiUrl = "#{ data.resourceURI.spec }lib/public.js"
47 { setAPI } = Cu.import(apiUrl, {})
48 setAPI(createAPI(vimfx))
49 module.onShutdown(-> Cu.unload(apiUrl))
50 prefs.set('apiUrl', apiUrl)
52 vimfx.windows = new WeakSet()
56 utils.loadCss('style')
58 options.observe(vimfx)
60 prefs.observe('', (pref) ->
61 if pref.startsWith('mode.') or pref.startsWith('custom.')
62 vimfx.createKeyTrees()
63 else if pref of defaults.all_options
64 vimfx.options[pref] = parsePref(pref)
67 messageManager.listen(null, 'tabCreated', ({ target }) ->
68 return false unless target.getAttribute('messagemanagergroup') == 'browsers'
70 window = target.ownerGlobal
71 unless vimfx.windows.has(window)
72 vimfx.windows.add(window)
73 button.injectButton(vimfx, window)
74 addEventListeners(vimfx, window)
76 return __SCRIPT_URI_SPEC__
78 messageManager.load(null, 'bootstrap')