Skip to content

Commit 778c62b

Browse files
committed
instate drive file browser
1 parent fae0f01 commit 778c62b

File tree

3 files changed

+152
-5
lines changed

3 files changed

+152
-5
lines changed

src/icons.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { LabIcon } from '@jupyterlab/ui-components';
22
import driveSvgstr from '../style/drive.svg';
3+
import driveBrowserSvg from '../style/driveIconFileBrowser.svg';
4+
35
export const DriveIcon = new LabIcon({
4-
name: '@jupyter/drives:drive',
6+
name: 'jupyter-drives:drive',
57
svgstr: driveSvgstr
68
});
9+
10+
export const driveBrowserIcon = new LabIcon({
11+
name: 'jupyter-drives:drive-browser',
12+
svgstr: driveBrowserSvg
13+
});

src/index.ts

Lines changed: 135 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
import {
2+
ILabShell,
3+
ILayoutRestorer,
4+
IRouter,
25
JupyterFrontEnd,
36
JupyterFrontEndPlugin
47
} from '@jupyterlab/application';
5-
6-
import { IFileBrowserFactory } from '@jupyterlab/filebrowser';
8+
import { IFileBrowserFactory, FileBrowser } from '@jupyterlab/filebrowser';
79
import { ITranslator } from '@jupyterlab/translation';
810
import { addJupyterLabThemeChangeListener } from '@jupyter/web-components';
911
import { Dialog, showDialog } from '@jupyterlab/apputils';
12+
import { CommandRegistry } from '@lumino/commands';
13+
import { Panel } from '@lumino/widgets';
14+
1015
import { DriveListModel, DriveListView, IDrive } from './drivelistmanager';
11-
import { DriveIcon } from './icons';
16+
import { DriveIcon, driveBrowserIcon } from './icons';
1217

18+
/**
19+
* The command IDs used by the driveBrowser plugin.
20+
*/
1321
namespace CommandIDs {
1422
export const openDrivesDialog = 'drives:open-drives-dialog';
23+
export const openPath = 'filebrowser:open-path';
24+
export const toggleBrowser = 'filebrowser:toggle-main';
1525
}
1626

1727
/**
@@ -129,5 +139,126 @@ const openDriveDialogPlugin: JupyterFrontEndPlugin<void> = {
129139
});
130140
}
131141
};
132-
const plugins: JupyterFrontEndPlugin<any>[] = [plugin, openDriveDialogPlugin];
142+
143+
/**
144+
* The drive file browser factory provider.
145+
*/
146+
const driveFileBrowser: JupyterFrontEndPlugin<void> = {
147+
id: 'jupyter-drives:drive-file-browser',
148+
description: 'The drive file browser factory provider.',
149+
autoStart: true,
150+
requires: [IFileBrowserFactory],
151+
optional: [
152+
IRouter,
153+
JupyterFrontEnd.ITreeResolver,
154+
ILabShell,
155+
ILayoutRestorer
156+
],
157+
activate: async (
158+
app: JupyterFrontEnd,
159+
fileBrowserFactory: IFileBrowserFactory,
160+
router: IRouter | null,
161+
tree: JupyterFrontEnd.ITreeResolver | null,
162+
labShell: ILabShell | null,
163+
restorer: ILayoutRestorer | null
164+
): Promise<void> => {
165+
const { commands } = app;
166+
167+
// create S3 drive
168+
// const S3Drive = new Drive({
169+
// name: auth.bucket,
170+
// root: auth.root,
171+
// config: auth.config
172+
// });
173+
174+
// app.serviceManager.contents.addDrive(S3Drive);
175+
176+
// Manually restore and load the drive file browser.
177+
const driveBrowser = fileBrowserFactory.createFileBrowser('drivebrowser', {
178+
auto: false,
179+
restore: false
180+
// driveName: S3Drive.name
181+
});
182+
183+
// // Set attributes when adding the browser to the UI
184+
driveBrowser.node.setAttribute('role', 'region');
185+
driveBrowser.node.setAttribute('aria-label', 'Drive Browser Section');
186+
187+
// instate Drive Browser Panel
188+
const drivePanel = new Panel();
189+
drivePanel.title.icon = driveBrowserIcon;
190+
drivePanel.title.iconClass = 'jp-sidebar-tabIcon';
191+
drivePanel.title.caption = 'Drive FileBrowser';
192+
drivePanel.id = 'Drive-Browser-Panel';
193+
194+
app.shell.add(drivePanel, 'left', { rank: 102 });
195+
// drivePanel.addWidget(driveBrowser);
196+
if (restorer) {
197+
restorer.add(drivePanel, 'drive-sidepanel');
198+
}
199+
200+
void Private.restoreBrowser(driveBrowser, commands, router, tree, labShell);
201+
}
202+
};
203+
204+
const plugins: JupyterFrontEndPlugin<any>[] = [
205+
plugin,
206+
driveFileBrowser,
207+
openDriveDialogPlugin
208+
];
133209
export default plugins;
210+
211+
namespace Private {
212+
/**
213+
* Restores file browser state and overrides state if tree resolver resolves.
214+
*/
215+
export async function restoreBrowser(
216+
browser: FileBrowser,
217+
commands: CommandRegistry,
218+
router: IRouter | null,
219+
tree: JupyterFrontEnd.ITreeResolver | null,
220+
labShell: ILabShell | null
221+
): Promise<void> {
222+
const restoring = 'jp-mod-restoring';
223+
224+
browser.addClass(restoring);
225+
226+
if (!router) {
227+
await browser.model.restore(browser.id);
228+
await browser.model.refresh();
229+
browser.removeClass(restoring);
230+
return;
231+
}
232+
233+
const listener = async () => {
234+
router.routed.disconnect(listener);
235+
236+
const paths = await tree?.paths;
237+
if (paths?.file || paths?.browser) {
238+
// Restore the model without populating it.
239+
await browser.model.restore(browser.id, false);
240+
if (paths.file) {
241+
await commands.execute(CommandIDs.openPath, {
242+
path: paths.file,
243+
dontShowBrowser: true
244+
});
245+
}
246+
if (paths.browser) {
247+
await commands.execute(CommandIDs.openPath, {
248+
path: paths.browser,
249+
dontShowBrowser: true
250+
});
251+
}
252+
} else {
253+
await browser.model.restore(browser.id);
254+
await browser.model.refresh();
255+
}
256+
browser.removeClass(restoring);
257+
258+
if (labShell?.isEmpty('main')) {
259+
void commands.execute('launcher:create');
260+
}
261+
};
262+
router.routed.connect(listener);
263+
}
264+
}

style/driveIconFileBrowser.svg

Lines changed: 9 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)