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 # This file creates VimFx’s status panel, similar to the “URL popup” shown when
21 # hovering or focusing links.
23 utils = require('./utils')
25 injectStatusPanel = (browser, vimfx) ->
26 window = browser.ownerGlobal
28 statusPanel = window.document.createElement('statuspanel')
29 utils.setAttributes(statusPanel, {
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())
41 shouldHandleNotification = (vim) ->
42 return vimfx.options.notifications_enabled and
43 vim.window == window and vim == vimfx.getCurrentVim(window)
45 vimfx.on('notification', ({vim, message}) ->
46 return unless shouldHandleNotification(vim)
47 statusPanel.setAttribute('label', message)
48 statusPanel.removeAttribute('inactive')
51 vimfx.on('hideNotification', ({vim}) ->
52 return unless shouldHandleNotification(vim)
53 statusPanel.setAttribute('inactive', 'true')
56 statusPanel.style.pointerEvents = 'auto'
57 utils.listen(statusPanel, 'click', ->
58 vimfx.emit('hideNotification')