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 translate = require('./l10n')
21 utils = require('./utils')
23 CONTAINER_ID = 'VimFxHelpDialogContainer'
25 injectHelp = (rootWindow, vimfx) ->
26 removeHelp(rootWindow)
28 { document } = rootWindow
30 container = document.createElement('box')
31 container.id = CONTAINER_ID
33 header = createHeader(document, vimfx)
34 container.appendChild(header)
36 content = createContent(document, vimfx)
37 container.appendChild(content)
39 rootWindow.gBrowser.mCurrentBrowser.parentNode.appendChild(container)
41 # Uncomment this line if you want to use `gulp help.html`!
42 # utils.writeToClipboard(container.outerHTML)
44 removeHelp = (rootWindow) ->
45 rootWindow.document.getElementById(CONTAINER_ID)?.remove()
47 createHeader = (document, vimfx) ->
48 $ = utils.createBox.bind(null, document)
52 mainHeading = $('heading-main', header)
53 $('name', mainHeading, 'VimFx')
54 $('title', mainHeading, translate('help_title'))
56 closeButton = $('close-button', header, '×')
57 closeButton.onclick = removeHelp.bind(null, document.defaultView)
61 createContent = (document, vimfx) ->
62 $ = utils.createBox.bind(null, document)
64 content = $('content')
66 for mode in vimfx.getGroupedCommands({enabledOnly: true})
67 modeHeading = $('heading-mode', null, mode.name)
69 for category, index in mode.categories
70 categoryContainer = $('category', content)
72 # Append the mode heading inside the first category container, rather than
73 # before it, for layout purposes.
75 categoryContainer.appendChild(modeHeading)
76 categoryContainer.classList.add('first')
78 $('heading-category', categoryContainer, category.name) if category.name
80 for { command, enabledSequences } in category.commands
81 commandContainer = $('command', categoryContainer)
82 for sequence in enabledSequences
83 $('key-sequence', commandContainer, sequence)
84 $('description', commandContainer, command.description())