forked from MichiSpebach/mammutmap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorialBoxTabs.ts
More file actions
28 lines (24 loc) · 952 Bytes
/
tutorialBoxTabs.ts
File metadata and controls
28 lines (24 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { Box, FileBox, MenuItemFile, RenderElement, applicationMenu } from '../dist/pluginFacade'
applicationMenu.addMenuItemTo('tutorialBoxTabs.js', new MenuItemFile({label: 'activate', click: () => activate()}))
function activate(): void {
Box.Tabs.register({
name: 'TutorialBoxTabs',
isAvailableFor: (box: Box) => box.isFile(),
buildWidget: (box: Box) => buildTabFor(box)
})
}
async function buildTabFor(box: Box): Promise<RenderElement> {
if (!(box instanceof FileBox)) {
console.warn(`tutorialBoxTabs: Box with path '${box.getSrcPath()}' does not represent a file.`)
return {
type: 'div',
style: {color: 'red'},
children: 'Box does not represent a file.'
}
}
const fileContent: string = await box.getBody().getFileContent()
return {
type: 'div',
children: `There are ${fileContent.length} letters in this file.`
}
}