1 |
|
2 |
|
3 |
|
4 |
|
5 | import { TextItem } from '@jupyterlab/statusbar';
|
6 | import { nullTranslator } from '@jupyterlab/translation';
|
7 | import { VDomModel, VDomRenderer } from '@jupyterlab/ui-components';
|
8 | import * as React from 'react';
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | function CommandEditComponent(props) {
|
17 | const trans = (props.translator || nullTranslator).load('jupyterlab');
|
18 | return (React.createElement(TextItem, { source: trans.__('Mode: %1', props.modeNames[props.notebookMode]) }));
|
19 | }
|
20 |
|
21 |
|
22 |
|
23 | export class CommandEditStatus extends VDomRenderer {
|
24 | |
25 |
|
26 |
|
27 | constructor(translator) {
|
28 | super(new CommandEditStatus.Model());
|
29 | this.translator = translator || nullTranslator;
|
30 | this._trans = this.translator.load('jupyterlab');
|
31 | this._modeNames = {
|
32 | command: this._trans.__('Command'),
|
33 | edit: this._trans.__('Edit')
|
34 | };
|
35 | }
|
36 | |
37 |
|
38 |
|
39 | render() {
|
40 | if (!this.model) {
|
41 | return null;
|
42 | }
|
43 | this.node.title = this._trans.__('Notebook is in %1 mode', this._modeNames[this.model.notebookMode]);
|
44 | return (React.createElement(CommandEditComponent, { notebookMode: this.model.notebookMode, translator: this.translator, modeNames: this._modeNames }));
|
45 | }
|
46 | }
|
47 |
|
48 |
|
49 |
|
50 | (function (CommandEditStatus) {
|
51 | |
52 |
|
53 |
|
54 | class Model extends VDomModel {
|
55 | constructor() {
|
56 | super(...arguments);
|
57 | |
58 |
|
59 |
|
60 | this._onChanged = (_notebook) => {
|
61 | const oldMode = this._notebookMode;
|
62 | if (this._notebook) {
|
63 | this._notebookMode = _notebook.mode;
|
64 | }
|
65 | else {
|
66 | this._notebookMode = 'command';
|
67 | }
|
68 | this._triggerChange(oldMode, this._notebookMode);
|
69 | };
|
70 | this._notebookMode = 'command';
|
71 | this._notebook = null;
|
72 | }
|
73 | |
74 |
|
75 |
|
76 | get notebookMode() {
|
77 | return this._notebookMode;
|
78 | }
|
79 | |
80 |
|
81 |
|
82 | set notebook(notebook) {
|
83 | const oldNotebook = this._notebook;
|
84 | if (oldNotebook !== null) {
|
85 | oldNotebook.stateChanged.disconnect(this._onChanged, this);
|
86 | oldNotebook.activeCellChanged.disconnect(this._onChanged, this);
|
87 | oldNotebook.modelContentChanged.disconnect(this._onChanged, this);
|
88 | }
|
89 | const oldMode = this._notebookMode;
|
90 | this._notebook = notebook;
|
91 | if (this._notebook === null) {
|
92 | this._notebookMode = 'command';
|
93 | }
|
94 | else {
|
95 | this._notebookMode = this._notebook.mode;
|
96 | this._notebook.stateChanged.connect(this._onChanged, this);
|
97 | this._notebook.activeCellChanged.connect(this._onChanged, this);
|
98 | this._notebook.modelContentChanged.connect(this._onChanged, this);
|
99 | }
|
100 | this._triggerChange(oldMode, this._notebookMode);
|
101 | }
|
102 | |
103 |
|
104 |
|
105 | _triggerChange(oldState, newState) {
|
106 | if (oldState !== newState) {
|
107 | this.stateChanged.emit(void 0);
|
108 | }
|
109 | }
|
110 | }
|
111 | CommandEditStatus.Model = Model;
|
112 | })(CommandEditStatus || (CommandEditStatus = {}));
|
113 |
|
\ | No newline at end of file |