forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
72 lines (58 loc) · 1.6 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import {
JupyterLab, JupyterLabPlugin
} from '@jupyterlab/application';
import {
ILayoutRestorer, InstanceTracker
} from '@jupyterlab/apputils';
import {
CSVWidget, CSVWidgetFactory
} from '@jupyterlab/csvwidget';
import {
IDocumentRegistry
} from '@jupyterlab/docregistry';
/**
* The name of the factory that creates CSV widgets.
*/
const FACTORY = 'Table';
/**
* The table file handler extension.
*/
const plugin: JupyterLabPlugin<void> = {
activate,
id: 'jupyter.extensions.csv-handler',
requires: [IDocumentRegistry, ILayoutRestorer],
autoStart: true
};
/**
* Export the plugin as default.
*/
export default plugin;
/**
* Activate the table widget extension.
*/
function activate(app: JupyterLab, registry: IDocumentRegistry, restorer: ILayoutRestorer): void {
const factory = new CSVWidgetFactory({
name: FACTORY,
fileExtensions: ['.csv'],
defaultFor: ['.csv']
});
const tracker = new InstanceTracker<CSVWidget>({
namespace: 'csvwidget',
shell: app.shell
});
// Handle state restoration.
restorer.restore(tracker, {
command: 'file-operations:open',
args: widget => ({ path: widget.context.path, factory: FACTORY }),
name: widget => widget.context.path
});
registry.addWidgetFactory(factory);
factory.widgetCreated.connect((sender, widget) => {
// Track the widget.
tracker.add(widget);
// Notify the instance tracker if restore data needs to update.
widget.context.pathChanged.connect(() => { tracker.save(widget); });
});
}