]> git.gir.st - VimFx.git/blob - extension/lib/status-panel.coffee
Merge pull request #615 from akhodakivskiy/rework-notifications
[VimFx.git] / extension / lib / status-panel.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 # This file creates VimFx’s status panel, similar to the “URL popup” shown when
21 # hovering or focusing links.
22
23 utils = require('./utils')
24
25 injectStatusPanel = (browser, vimfx) ->
26 window = browser.ownerGlobal
27
28 statusPanel = window.document.createElement('statuspanel')
29 utils.setAttributes(statusPanel, {
30 inactive: 'true'
31 layer: 'true'
32 mirror: 'true'
33 })
34
35 # The current browser can usually be retrieved from `window`. However, this
36 # runs too early. Instead a browser known to exist is passed in. (_Which_
37 # browser is passed doesn’t matter since only their common container is used.)
38 window.gBrowser.getBrowserContainer(browser).appendChild(statusPanel)
39 module.onShutdown(-> statusPanel.remove())
40
41 shouldHandleNotification = (vim) ->
42 return vimfx.options.notifications_enabled and
43 vim.window == window and vim == vimfx.getCurrentVim(window)
44
45 vimfx.on('notification', ({vim, message}) ->
46 return unless shouldHandleNotification(vim)
47 statusPanel.setAttribute('label', message)
48 statusPanel.removeAttribute('inactive')
49 )
50
51 vimfx.on('hideNotification', ({vim}) ->
52 return unless shouldHandleNotification(vim)
53 statusPanel.setAttribute('inactive', 'true')
54 )
55
56 statusPanel.style.pointerEvents = 'auto'
57 utils.listen(statusPanel, 'click', ->
58 vimfx.emit('hideNotification')
59 )
60
61 module.exports = {
62 injectStatusPanel
63 }
Imprint / Impressum