1 |
|
2 |
|
3 |
|
4 |
|
5 | import { Widget } from '@lumino/widgets';
|
6 | import { NotebookActions } from './actions';
|
7 | const NOTEBOOK_FOOTER_CLASS = 'jp-Notebook-footer';
|
8 |
|
9 |
|
10 |
|
11 | export class NotebookFooter extends Widget {
|
12 | |
13 |
|
14 |
|
15 | constructor(notebook) {
|
16 | super({ node: document.createElement('button') });
|
17 | this.notebook = notebook;
|
18 | const trans = notebook.translator.load('jupyterlab');
|
19 | this.addClass(NOTEBOOK_FOOTER_CLASS);
|
20 | this.node.innerText = trans.__('Click to add a cell.');
|
21 | }
|
22 | |
23 |
|
24 |
|
25 | handleEvent(event) {
|
26 | switch (event.type) {
|
27 | case 'click':
|
28 | this.onClick();
|
29 | break;
|
30 | case 'keydown':
|
31 | if (event.key === 'ArrowUp') {
|
32 | this.onArrowUp();
|
33 | break;
|
34 | }
|
35 | }
|
36 | }
|
37 | |
38 |
|
39 |
|
40 | onClick() {
|
41 | if (this.notebook.widgets.length > 0) {
|
42 | this.notebook.activeCellIndex = this.notebook.widgets.length - 1;
|
43 | }
|
44 | NotebookActions.insertBelow(this.notebook);
|
45 | }
|
46 | |
47 |
|
48 |
|
49 | onArrowUp() {
|
50 | this.node.blur();
|
51 | this.notebook.mode = 'command';
|
52 | }
|
53 | |
54 |
|
55 |
|
56 | onAfterAttach(msg) {
|
57 | super.onAfterAttach(msg);
|
58 | this.node.addEventListener('click', this);
|
59 | this.node.addEventListener('keydown', this);
|
60 | }
|
61 | |
62 |
|
63 |
|
64 | onBeforeDetach(msg) {
|
65 | this.node.removeEventListener('click', this);
|
66 | this.node.removeEventListener('keydown', this);
|
67 | super.onBeforeDetach(msg);
|
68 | }
|
69 | }
|
70 |
|
\ | No newline at end of file |