]> git.gir.st - VimFx.git/blob - extension/lib/button.coffee
Move Text Input mode into Normal mode
[VimFx.git] / extension / lib / button.coffee
1 ###
2 # Copyright Simon Lydell 2015.
3 #
4 # This file is part of VimFx.
5 #
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.
10 #
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.
15 #
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/>.
18 ###
19
20 help = require('./help')
21 translate = require('./l10n')
22
23 BUTTON_ID = 'VimFxButton'
24
25 injectButton = (vimfx, window) ->
26 cui = window.CustomizableUI
27 button = null
28 cui.createWidget({
29 id: BUTTON_ID
30 defaultArea: cui.AREA_NAVBAR
31 label: 'VimFx'
32 tooltiptext: translate('button.tooltip.normal')
33 onCommand: ->
34 mode = button.getAttribute('vimfx-mode')
35 if mode == 'normal'
36 help.injectHelp(window, vimfx)
37 else
38 vimfx.currentVim.enterMode('normal')
39 onCreated: (node) ->
40 button = node
41 button.setAttribute('vimfx-mode', 'normal')
42 vimfx.on('modeChange', updateButton.bind(null, button))
43 vimfx.on('currentVimChange', updateButton.bind(null, button))
44 })
45 module.onShutdown(cui.destroyWidget.bind(cui, BUTTON_ID))
46
47 updateButton = (button, { mode }) ->
48 button.setAttribute('vimfx-mode', mode)
49 tooltip =
50 if mode == 'normal'
51 translate('button.tooltip.normal')
52 else
53 translate('button.tooltip.other_mode', translate("mode.#{ mode }"),
54 translate('mode.normal'))
55 button.setAttribute('tooltiptext', tooltip)
56
57 module.exports = {
58 injectButton
59 BUTTON_ID
60 }
Imprint / Impressum