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