-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.ts
93 lines (77 loc) · 2.46 KB
/
index.ts
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import {
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';
import { IDisposable, DisposableDelegate } from '@lumino/disposable';
import { PanelLayout } from '@lumino/widgets';
import { ToolbarButton } from '@jupyterlab/apputils';
import { DocumentRegistry } from '@jupyterlab/docregistry';
import {
NotebookActions,
NotebookPanel,
INotebookModel
} from '@jupyterlab/notebook';
import '../style/index.css';
/**
* Initialization data for the jupyterlab_hide_code extension.
*/
const plugin: JupyterFrontEndPlugin<void> = {
id: 'jupyterlab_hide_code:plugin',
description:
'A button in JupyterLab to run the code cells and then to hide the code cells.',
autoStart: true,
activate: (app: JupyterFrontEnd) => {
app.docRegistry.addWidgetExtension('Notebook', new ButtonExtension());
console.log('JupyterLab extension jupyterlab_hide_code is activated!');
}
};
export class ButtonExtension
implements DocumentRegistry.IWidgetExtension<NotebookPanel, INotebookModel>
{
createNew(
panel: NotebookPanel,
context: DocumentRegistry.IContext<INotebookModel>
): IDisposable {
const hideInputCode = () => {
NotebookActions.runAll(panel.content, context.sessionContext);
panel.content.widgets.forEach(cell => {
if (cell.model.type === 'code') {
const layout = cell.layout as PanelLayout;
layout.widgets[1].hide();
}
});
buttonHideInput.hide();
buttonShowInput.show();
};
const showInputCode = () => {
panel.content.widgets.forEach(cell => {
if (cell.model.type === 'code') {
const layout = cell.layout as PanelLayout;
layout.widgets[1].show();
}
});
buttonHideInput.show();
buttonShowInput.hide();
};
const buttonHideInput = new ToolbarButton({
className: 'myButton',
iconClass: 'fa fa-sm fa-eye-slash fontawesome-colors',
onClick: hideInputCode,
tooltip: 'Hide Input'
});
const buttonShowInput = new ToolbarButton({
className: 'myButton',
iconClass: 'fa fa-sm fa-eye fontawesome-colors',
onClick: showInputCode,
tooltip: 'Show Input'
});
buttonShowInput.hide();
panel.toolbar.insertItem(11, 'hideInput', buttonHideInput);
panel.toolbar.insertItem(11, 'showInput', buttonShowInput);
return new DisposableDelegate(() => {
buttonHideInput.dispose();
buttonShowInput.dispose();
});
}
}
export default plugin;