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 # This file pulls in all the different parts of VimFx, initializes them, and
22 # stiches them together.
24 createAPI = require('./api')
25 button = require('./button')
26 defaults = require('./defaults')
27 UIEventManager = require('./events')
28 messageManager = require('./message-manager')
29 modes = require('./modes')
30 options = require('./options')
31 parsePref = require('./parse-prefs')
32 prefs = require('./prefs')
33 utils = require('./utils')
34 VimFx = require('./vimfx')
35 test = try require('../test/index')
37 Cu.import('resource://gre/modules/AddonManager.jsm')
39 module.exports = (data, reason) ->
41 for pref of defaults.all_options
42 parsedOptions[pref] = parsePref(pref)
43 vimfx = new VimFx(modes, parsedOptions)
45 vimfx.version = data.version
46 AddonManager.getAddonByID(vimfx.id, (info) -> vimfx.info = info)
48 # Setup the public API.
49 apiUrl = "#{ data.resourceURI.spec }lib/public.js"
50 { setAPI } = Cu.import(apiUrl, {})
51 setAPI(createAPI(vimfx))
52 module.onShutdown(-> Cu.unload(apiUrl))
53 prefs.set('apiUrl', apiUrl)
55 utils.loadCss('style')
57 options.observe(vimfx)
59 prefs.observe('', (pref) ->
60 if pref.startsWith('mode.') or pref.startsWith('custom.')
61 vimfx.createKeyTrees()
62 else if pref of defaults.all_options
63 value = parsePref(pref)
64 vimfx.options[pref] = value
67 button.injectButton(vimfx)
71 windows = new WeakSet()
72 messageManager.listen('tabCreated', (data, { target }) ->
73 return false unless target.getAttribute('messagemanagergroup') == 'browsers'
75 window = target.ownerGlobal
78 unless windows.has(window)
80 eventManager = new UIEventManager(vimfx, window)
81 eventManager.addListeners(vimfx, window)
83 return __SCRIPT_URI_SPEC__
86 messageManager.load('bootstrap')