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