2 # Copyright Simon Lydell 2015.
4 # This file is part of VimFx.
6 # VimFx is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # VimFx is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with VimFx. If not, see <http://www.gnu.org/licenses/>.
20 help = require('./help')
21 translate = require('./l10n')
23 BUTTON_ID = 'VimFxButton'
25 injectButton = (vimfx, window) ->
26 cui = window.CustomizableUI
30 defaultArea: cui.AREA_NAVBAR
32 tooltiptext: translate('button.tooltip.normal')
34 mode = button.getAttribute('vimfx-mode')
36 help.injectHelp(window, vimfx)
38 vimfx.currentVim.enterMode('normal')
41 button.setAttribute('vimfx-mode', 'normal')
42 vimfx.on('modeChange', updateButton.bind(null, button))
43 vimfx.on('currentVimChange', updateButton.bind(null, button))
45 module.onShutdown(cui.destroyWidget.bind(cui, BUTTON_ID))
47 updateButton = (button, { mode }) ->
48 button.setAttribute('vimfx-mode', mode)
51 translate('button.tooltip.normal')
53 translate('button.tooltip.other_mode', translate("mode.#{ mode }"),
54 translate('mode.normal'))
55 button.setAttribute('tooltiptext', tooltip)