3 { utils: Cu, classes: Cc, interfaces: Ci } = Components
5 Cu.import "resource://gre/modules/Services.jsm"
6 Cu.import "resource://gre/modules/AddonManager.jsm"
8 # Populate the global namespace with console, require, and include
10 baseURI = Services.io.newURI __SCRIPT_URI_SPEC__, null, null
11 getResourceURI = (path) -> Services.io.newURI path, null, baseURI
13 loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader);
15 include = (src, scope = {}) ->
17 uri = getResourceURI src
18 loader.loadSubScript uri.spec, scope
20 dump "Failed to load #{ src }: #{ error }\n"
35 include "packages/#{ src }.js", scope
37 return modules[src] = scope.exports;
39 global.include = include
40 global.require = require
41 global.getResourceURI = getResourceURI
43 # Include into global scope
44 include("includes/#{ name }.js", global) for name in [
50 # Init localization `underscore` method
51 global._ = require('l10n').l10n "vimfx.properties"
53 # Requires for startup/install
54 { loadCss } = require 'utils'
55 { addEventListeners } = require 'events'
57 , transferPrefs } = require 'prefs'
58 { setButtonInstallPosition
59 , addToolbarButton } = require 'button'
60 wu = require 'window-utils'
62 # Firefox will call this method on startup/enabling
63 global.startup = (data, reason) ->
65 if reason == ADDON_INSTALL
66 # Position the toolbar button right before the default Bookmarks button
67 # If Bookmarks button is hidden - then VimFx button will be appended to the toolbar
68 setButtonInstallPosition 'nav-bar', 'bookmarks-menu-button-container'
69 else if reason == ADDON_UPGRADE
70 if data["version"] > "0.3.3"
71 transferPrefs "extension.VimFx.", "extensions.VimFx."
74 wu.watchWindows addEventListeners, 'navigator:browser'
75 wu.watchWindows addToolbarButton, 'navigator:browser'
77 # Firefox will call this method on shutdown/disabling
78 global.shutdown = (data, reason) ->
79 # Don't bother to clean up if the browser is shutting down
80 if reason != APP_SHUTDOWN
83 global.install = (data, reason) ->
85 global.uninstall = (data, reason) ->