1 |
|
2 |
|
3 | import { PathExt } from '@jupyterlab/coreutils';
|
4 | import { TextItem } from '@jupyterlab/statusbar';
|
5 | import { VDomModel, VDomRenderer } from '@jupyterlab/ui-components';
|
6 | import React from 'react';
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | function PathStatusComponent(props) {
|
15 | return React.createElement(TextItem, { source: props.name, title: props.fullPath });
|
16 | }
|
17 |
|
18 |
|
19 |
|
20 | export class PathStatus extends VDomRenderer {
|
21 | |
22 |
|
23 |
|
24 | constructor(opts) {
|
25 | super(new PathStatus.Model(opts.docManager));
|
26 | this.node.title = this.model.path;
|
27 | }
|
28 | |
29 |
|
30 |
|
31 | render() {
|
32 | return (React.createElement(PathStatusComponent, { fullPath: this.model.path, name: this.model.name }));
|
33 | }
|
34 | }
|
35 |
|
36 |
|
37 |
|
38 | (function (PathStatus) {
|
39 | |
40 |
|
41 |
|
42 | class Model extends VDomModel {
|
43 | |
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | constructor(docManager) {
|
50 | super();
|
51 | |
52 |
|
53 |
|
54 | this._onTitleChange = (title) => {
|
55 | const oldState = this._getAllState();
|
56 | this._name = title.label;
|
57 | this._triggerChange(oldState, this._getAllState());
|
58 | };
|
59 | |
60 |
|
61 |
|
62 | this._onPathChange = (_documentModel, newPath) => {
|
63 | const oldState = this._getAllState();
|
64 | this._path = newPath;
|
65 | this._name = PathExt.basename(newPath);
|
66 | this._triggerChange(oldState, this._getAllState());
|
67 | };
|
68 | this._path = '';
|
69 | this._name = '';
|
70 | this._widget = null;
|
71 | this._docManager = docManager;
|
72 | }
|
73 | |
74 |
|
75 |
|
76 | get path() {
|
77 | return this._path;
|
78 | }
|
79 | |
80 |
|
81 |
|
82 | get name() {
|
83 | return this._name;
|
84 | }
|
85 | |
86 |
|
87 |
|
88 | get widget() {
|
89 | return this._widget;
|
90 | }
|
91 | set widget(widget) {
|
92 | const oldWidget = this._widget;
|
93 | if (oldWidget !== null) {
|
94 | const oldContext = this._docManager.contextForWidget(oldWidget);
|
95 | if (oldContext) {
|
96 | oldContext.pathChanged.disconnect(this._onPathChange);
|
97 | }
|
98 | else {
|
99 | oldWidget.title.changed.disconnect(this._onTitleChange);
|
100 | }
|
101 | }
|
102 | const oldState = this._getAllState();
|
103 | this._widget = widget;
|
104 | if (this._widget === null) {
|
105 | this._path = '';
|
106 | this._name = '';
|
107 | }
|
108 | else {
|
109 | const widgetContext = this._docManager.contextForWidget(this._widget);
|
110 | if (widgetContext) {
|
111 | this._path = widgetContext.path;
|
112 | this._name = PathExt.basename(widgetContext.path);
|
113 | widgetContext.pathChanged.connect(this._onPathChange);
|
114 | }
|
115 | else {
|
116 | this._path = '';
|
117 | this._name = this._widget.title.label;
|
118 | this._widget.title.changed.connect(this._onTitleChange);
|
119 | }
|
120 | }
|
121 | this._triggerChange(oldState, this._getAllState());
|
122 | }
|
123 | |
124 |
|
125 |
|
126 | _getAllState() {
|
127 | return [this._path, this._name];
|
128 | }
|
129 | |
130 |
|
131 |
|
132 | _triggerChange(oldState, newState) {
|
133 | if (oldState[0] !== newState[0] || oldState[1] !== newState[1]) {
|
134 | this.stateChanged.emit(void 0);
|
135 | }
|
136 | }
|
137 | }
|
138 | PathStatus.Model = Model;
|
139 | })(PathStatus || (PathStatus = {}));
|
140 |
|
\ | No newline at end of file |