Skip to content

Commit 429e255

Browse files
committed
Adds a token on the notebook tree widget, in order to easily add widgets in it from external extension
1 parent c6faa5c commit 429e255

File tree

16 files changed

+229
-81
lines changed

16 files changed

+229
-81
lines changed

app/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"@jupyter-notebook/help-extension": "~7.0.0-alpha.5",
2020
"@jupyter-notebook/notebook-extension": "~7.0.0-alpha.5",
2121
"@jupyter-notebook/terminal-extension": "~7.0.0-alpha.5",
22+
"@jupyter-notebook/tree": "~7.0.0-alpha.5",
2223
"@jupyter-notebook/tree-extension": "~7.0.0-alpha.5",
2324
"@jupyter-notebook/ui-components": "~7.0.0-alpha.5",
2425
"@jupyterlab/application": "~4.0.0-alpha.10",
@@ -104,6 +105,7 @@
104105
"@jupyter-notebook/help-extension": "^7.0.0-alpha.5",
105106
"@jupyter-notebook/notebook-extension": "^7.0.0-alpha.5",
106107
"@jupyter-notebook/terminal-extension": "^7.0.0-alpha.5",
108+
"@jupyter-notebook/tree": "^7.0.0-alpha.5",
107109
"@jupyter-notebook/tree-extension": "^7.0.0-alpha.5",
108110
"@jupyter-notebook/ui-components": "^7.0.0-alpha.5",
109111
"@jupyterlab/application-extension": "^4.0.0-alpha.10",
@@ -194,6 +196,7 @@
194196
"@jupyterlab/user-extension"
195197
],
196198
"singletonPackages": [
199+
"@jupyter-notebook/tree",
197200
"@jupyterlab/application",
198201
"@jupyterlab/apputils",
199202
"@jupyterlab/cell-toolbar",

packages/_metapackage/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"@jupyter-notebook/lab-extension": "file:../lab-extension",
3030
"@jupyter-notebook/notebook-extension": "file:../notebook-extension",
3131
"@jupyter-notebook/terminal-extension": "file:../terminal-extension",
32+
"@jupyter-notebook/tree": "file:../tree",
3233
"@jupyter-notebook/tree-extension": "file:../tree-extension",
3334
"@jupyter-notebook/ui-components": "file:../ui-components"
3435
},

packages/_metapackage/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ import '@jupyter-notebook/help-extension';
77
import '@jupyter-notebook/lab-extension';
88
import '@jupyter-notebook/notebook-extension';
99
import '@jupyter-notebook/terminal-extension';
10+
import '@jupyter-notebook/tree';
1011
import '@jupyter-notebook/tree-extension';
1112
import '@jupyter-notebook/ui-components';

packages/tree-extension/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
},
4141
"dependencies": {
4242
"@jupyter-notebook/application": "^7.0.0-alpha.5",
43+
"@jupyter-notebook/tree": "^7.0.0-alpha.5",
4344
"@jupyterlab/application": "^4.0.0-alpha.10",
4445
"@jupyterlab/apputils": "^4.0.0-alpha.10",
4546
"@jupyterlab/coreutils": "^6.0.0-alpha.10",

packages/tree-extension/src/index.ts

Lines changed: 87 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ import { ITranslator } from '@jupyterlab/translation';
2727
import {
2828
caretDownIcon,
2929
folderIcon,
30-
runningIcon,
31-
TabBarSvg
30+
runningIcon
3231
} from '@jupyterlab/ui-components';
3332

34-
import { Menu, MenuBar, TabPanel } from '@lumino/widgets';
33+
import { Menu, MenuBar } from '@lumino/widgets';
34+
35+
import { NotebookTreeWidget } from '@jupyter-notebook/tree';
36+
import { INotebookTree } from '@jupyter-notebook/tree';
3537

3638
/**
3739
* The file browser factory.
@@ -93,10 +95,87 @@ const createNew: JupyterFrontEndPlugin<void> = {
9395
}
9496
};
9597

98+
function activateNotebookTreeWidget(
99+
app: JupyterFrontEnd,
100+
factory: IFileBrowserFactory,
101+
translator: ITranslator,
102+
settingRegistry: ISettingRegistry,
103+
toolbarRegistry: IToolbarWidgetRegistry,
104+
manager: IRunningSessionManagers | null
105+
): INotebookTree {
106+
const notebookTreeWidget = new NotebookTreeWidget();
107+
// const tabPanel = new TabPanel({
108+
// tabPlacement: 'top',
109+
// tabsMovable: true,
110+
// renderer: TabBarSvg.defaultRenderer
111+
// });
112+
// tabPanel.addClass('jp-TreePanel');
113+
114+
const trans = translator.load('notebook');
115+
116+
const { defaultBrowser: browser } = factory;
117+
browser.title.label = trans.__('Files');
118+
browser.node.setAttribute('role', 'region');
119+
browser.node.setAttribute('aria-label', trans.__('File Browser Section'));
120+
browser.title.icon = folderIcon;
121+
122+
notebookTreeWidget.addWidget(browser);
123+
notebookTreeWidget.tabBar.addTab(browser.title);
124+
125+
// Toolbar
126+
toolbarRegistry.addFactory(
127+
FILE_BROWSER_FACTORY,
128+
'uploader',
129+
(browser: FileBrowser) =>
130+
new Uploader({
131+
model: browser.model,
132+
translator,
133+
label: trans.__('Upload')
134+
})
135+
);
136+
137+
setToolbar(
138+
browser,
139+
createToolbarFactory(
140+
toolbarRegistry,
141+
settingRegistry,
142+
FILE_BROWSER_FACTORY,
143+
notebookTreeWidget.id,
144+
translator
145+
)
146+
);
147+
148+
if (manager) {
149+
const running = new RunningSessions(manager, translator);
150+
running.id = 'jp-running-sessions';
151+
running.title.label = trans.__('Running');
152+
running.title.icon = runningIcon;
153+
notebookTreeWidget.addWidget(running);
154+
notebookTreeWidget.tabBar.addTab(running.title);
155+
}
156+
157+
// show checkboxes by default if there is no user setting override
158+
const settings = settingRegistry.load(FILE_BROWSER_PLUGIN_ID);
159+
Promise.all([settings, app.restored])
160+
.then(([settings]) => {
161+
if (settings.user.showFileCheckboxes !== undefined) {
162+
return;
163+
}
164+
void settings.set('showFileCheckboxes', true);
165+
})
166+
.catch((reason: Error) => {
167+
console.error(reason.message);
168+
});
169+
170+
app.shell.add(notebookTreeWidget, 'main', { rank: 100 });
171+
172+
return notebookTreeWidget;
173+
}
174+
96175
/**
97-
* A plugin to add the file browser widget to an ILabShell
176+
* A plugin to add the file browser widget to an INotebookShell
98177
*/
99-
const browserWidget: JupyterFrontEndPlugin<void> = {
178+
const notebookTreeWidget: JupyterFrontEndPlugin<INotebookTree> = {
100179
id: '@jupyter-notebook/tree-extension:widget',
101180
requires: [
102181
IFileBrowserFactory,
@@ -106,83 +185,12 @@ const browserWidget: JupyterFrontEndPlugin<void> = {
106185
],
107186
optional: [IRunningSessionManagers],
108187
autoStart: true,
109-
activate: (
110-
app: JupyterFrontEnd,
111-
factory: IFileBrowserFactory,
112-
translator: ITranslator,
113-
settingRegistry: ISettingRegistry,
114-
toolbarRegistry: IToolbarWidgetRegistry,
115-
manager: IRunningSessionManagers | null
116-
): void => {
117-
const tabPanel = new TabPanel({
118-
tabPlacement: 'top',
119-
tabsMovable: true,
120-
renderer: TabBarSvg.defaultRenderer
121-
});
122-
tabPanel.addClass('jp-TreePanel');
123-
124-
const trans = translator.load('notebook');
125-
126-
const { defaultBrowser: browser } = factory;
127-
browser.title.label = trans.__('Files');
128-
browser.node.setAttribute('role', 'region');
129-
browser.node.setAttribute('aria-label', trans.__('File Browser Section'));
130-
browser.title.icon = folderIcon;
131-
132-
tabPanel.addWidget(browser);
133-
tabPanel.tabBar.addTab(browser.title);
134-
135-
// Toolbar
136-
toolbarRegistry.addFactory(
137-
FILE_BROWSER_FACTORY,
138-
'uploader',
139-
(browser: FileBrowser) =>
140-
new Uploader({
141-
model: browser.model,
142-
translator,
143-
label: trans.__('Upload')
144-
})
145-
);
146-
147-
setToolbar(
148-
browser,
149-
createToolbarFactory(
150-
toolbarRegistry,
151-
settingRegistry,
152-
FILE_BROWSER_FACTORY,
153-
browserWidget.id,
154-
translator
155-
)
156-
);
157-
158-
if (manager) {
159-
const running = new RunningSessions(manager, translator);
160-
running.id = 'jp-running-sessions';
161-
running.title.label = trans.__('Running');
162-
running.title.icon = runningIcon;
163-
tabPanel.addWidget(running);
164-
tabPanel.tabBar.addTab(running.title);
165-
}
166-
167-
// show checkboxes by default if there is no user setting override
168-
const settings = settingRegistry.load(FILE_BROWSER_PLUGIN_ID);
169-
Promise.all([settings, app.restored])
170-
.then(([settings]) => {
171-
if (settings.user.showFileCheckboxes !== undefined) {
172-
return;
173-
}
174-
void settings.set('showFileCheckboxes', true);
175-
})
176-
.catch((reason: Error) => {
177-
console.error(reason.message);
178-
});
179-
180-
app.shell.add(tabPanel, 'main', { rank: 100 });
181-
}
188+
provides: INotebookTree,
189+
activate: activateNotebookTreeWidget
182190
};
183191

184192
/**
185193
* Export the plugins as default.
186194
*/
187-
const plugins: JupyterFrontEndPlugin<any>[] = [createNew, browserWidget];
195+
const plugins: JupyterFrontEndPlugin<any>[] = [createNew, notebookTreeWidget];
188196
export default plugins;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
@import url('~@jupyterlab/filebrowser/style/index.css');
22

3-
@import url('./base.css');
3+
@import url('~@jupyter-notebook/tree/style/index.css');
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import '@jupyterlab/filebrowser/style/index.js';
22

3-
import './base.css';
3+
import '@jupyter-notebook/tree/style/index.js';

packages/tree/package.json

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"name": "@jupyter-notebook/tree",
3+
"version": "7.0.0-alpha.5",
4+
"description": "Jupyter Notebook - Tree ",
5+
"homepage": "https://github.com/jupyter/notebook",
6+
"bugs": {
7+
"url": "https://github.com/jupyter/notebook/issues"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/jupyter/notebook.git"
12+
},
13+
"license": "BSD-3-Clause",
14+
"author": "Project Jupyter",
15+
"sideEffects": [
16+
"style/**/*.css",
17+
"style/index.js"
18+
],
19+
"main": "lib/index.js",
20+
"types": "lib/index.d.ts",
21+
"style": "style/index.css",
22+
"directories": {
23+
"lib": "lib/"
24+
},
25+
"files": [
26+
"lib/*.d.ts",
27+
"lib/*.js.map",
28+
"lib/*.js",
29+
"schema/*.json",
30+
"style/**/*.css",
31+
"style/index.js"
32+
],
33+
"scripts": {
34+
"build": "tsc -b",
35+
"build:prod": "tsc -b",
36+
"clean": "rimraf lib && rimraf tsconfig.tsbuildinfo",
37+
"docs": "typedoc src",
38+
"prepublishOnly": "npm run build",
39+
"watch": "tsc -b --watch"
40+
},
41+
"dependencies": {
42+
"@jupyter-notebook/application": "^7.0.0-alpha.5",
43+
"@jupyterlab/application": "^4.0.0-alpha.10",
44+
"@jupyterlab/apputils": "^4.0.0-alpha.10",
45+
"@jupyterlab/coreutils": "^6.0.0-alpha.10",
46+
"@jupyterlab/docmanager": "^4.0.0-alpha.10",
47+
"@jupyterlab/filebrowser": "^4.0.0-alpha.10",
48+
"@jupyterlab/mainmenu": "^4.0.0-alpha.10",
49+
"@jupyterlab/services": "^7.0.0-alpha.10",
50+
"@jupyterlab/settingregistry": "^4.0.0-alpha.10",
51+
"@jupyterlab/statedb": "^4.0.0-alpha.10",
52+
"@jupyterlab/translation": "^4.0.0-alpha.10",
53+
"@jupyterlab/ui-components": "^4.0.0-alpha.25",
54+
"@lumino/algorithm": "^1.9.1",
55+
"@lumino/commands": "^1.20.0",
56+
"@lumino/widgets": "^1.32.0"
57+
},
58+
"devDependencies": {
59+
"rimraf": "~3.0.0",
60+
"typescript": "~4.6.3"
61+
},
62+
"publishConfig": {
63+
"access": "public"
64+
},
65+
"styleModule": "style/index.js"
66+
}

packages/tree/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './notebook-tree';
2+
export * from './token';

packages/tree/src/notebook-tree.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { TabBarSvg } from '@jupyterlab/ui-components';
2+
3+
import { TabPanel } from '@lumino/widgets';
4+
5+
import { INotebookTree } from './token';
6+
7+
export class NotebookTreeWidget extends TabPanel implements INotebookTree {
8+
constructor() {
9+
super({
10+
tabPlacement: 'top',
11+
tabsMovable: true,
12+
renderer: TabBarSvg.defaultRenderer
13+
});
14+
this.addClass('jp-TreePanel');
15+
}
16+
}

0 commit comments

Comments
 (0)