]> git.gir.st - VimFx.git/blob - extension/lib/help.coffee
Major refactor: Rework all UI and related improvements
[VimFx.git] / extension / lib / help.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 translate = require('./l10n')
21 utils = require('./utils')
22
23 CONTAINER_ID = 'VimFxHelpDialogContainer'
24
25 injectHelp = (rootWindow, vimfx) ->
26 removeHelp(rootWindow)
27
28 { document } = rootWindow
29
30 container = document.createElement('box')
31 container.id = CONTAINER_ID
32
33 header = createHeader(document, vimfx)
34 container.appendChild(header)
35
36 content = createContent(document, vimfx)
37 container.appendChild(content)
38
39 rootWindow.gBrowser.mCurrentBrowser.parentNode.appendChild(container)
40
41 # Uncomment this line if you want to use `gulp help.html`!
42 # utils.writeToClipboard(container.outerHTML)
43
44 removeHelp = (rootWindow) ->
45 rootWindow.document.getElementById(CONTAINER_ID)?.remove()
46
47 createHeader = (document, vimfx) ->
48 $ = utils.createBox.bind(null, document)
49
50 header = $('header')
51
52 mainHeading = $('heading-main', header)
53 $('name', mainHeading, 'VimFx')
54 $('title', mainHeading, translate('help_title'))
55
56 closeButton = $('close-button', header, '×')
57 closeButton.onclick = removeHelp.bind(null, document.defaultView)
58
59 return header
60
61 createContent = (document, vimfx) ->
62 $ = utils.createBox.bind(null, document)
63
64 content = $('content')
65
66 for mode in vimfx.getGroupedCommands({enabledOnly: true})
67 modeHeading = $('heading-mode', null, mode.name)
68
69 for category, index in mode.categories
70 categoryContainer = $('category', content)
71
72 # Append the mode heading inside the first category container, rather than
73 # before it, for layout purposes.
74 if index == 0
75 categoryContainer.appendChild(modeHeading)
76 categoryContainer.classList.add('first')
77
78 $('heading-category', categoryContainer, category.name) if category.name
79
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())
85
86 return content
87
88 module.exports = {
89 injectHelp
90 removeHelp
91 }
Imprint / Impressum