Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom drives #7212

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 37 additions & 1 deletion packages/tree-extension/src/index.ts
Expand Up @@ -18,6 +18,7 @@ import {
FileBrowser,
Uploader,
IDefaultFileBrowser,
IFileBrowserFactory,
} from '@jupyterlab/filebrowser';

import { ISettingRegistry } from '@jupyterlab/settingregistry';
Expand Down Expand Up @@ -263,6 +264,7 @@ const notebookTreeWidget: JupyterFrontEndPlugin<INotebookTree> = {
ITranslator,
ISettingRegistry,
IToolbarWidgetRegistry,
IFileBrowserFactory,
],
optional: [
IRunningSessionManagers,
Expand All @@ -277,13 +279,16 @@ const notebookTreeWidget: JupyterFrontEndPlugin<INotebookTree> = {
translator: ITranslator,
settingRegistry: ISettingRegistry,
toolbarRegistry: IToolbarWidgetRegistry,
factory: IFileBrowserFactory,
manager: IRunningSessionManagers | null,
settingEditorTracker: ISettingEditorTracker | null,
jsonSettingEditorTracker: IJSONSettingEditorTracker | null
): INotebookTree => {
const nbTreeWidget = new NotebookTreeWidget();
nbTreeWidget.tabsMovable = false;

const trans = translator.load('notebook');
const { tracker } = factory;

browser.title.label = trans.__('Files');
browser.node.setAttribute('role', 'region');
Expand All @@ -292,7 +297,6 @@ const notebookTreeWidget: JupyterFrontEndPlugin<INotebookTree> = {

nbTreeWidget.addWidget(browser);
nbTreeWidget.tabBar.addTab(browser.title);
nbTreeWidget.tabsMovable = false;

toolbarRegistry.addFactory(
FILE_BROWSER_FACTORY,
Expand Down Expand Up @@ -381,6 +385,38 @@ const notebookTreeWidget: JupyterFrontEndPlugin<INotebookTree> = {
}
);

const moveDrive = (widget: FileBrowser) => {
if (widget.model.driveName) {
// const parent = widget.parent;
widget.parent = null;
nbTreeWidget.addWidget(widget);
widget.title.label = widget.model.driveName;
nbTreeWidget.tabBar.addTab(widget.title);
// parent?.dispose();
}
};

requestAnimationFrame(() => {
// add drives to the notebook tree widget
tracker.forEach((widget) => {
// move the additional drives to the notebook tree widget
moveDrive(widget);
});

setCurrentToDefaultBrower();
});

// TODO: remove
// Workaround to force the focus on the default file browser
// See https://github.com/jupyterlab/jupyterlab/issues/15629 for more info
const setCurrentToDefaultBrower = () => {
tracker['_pool'].current = browser;
};

tracker.widgetAdded.connect((sender, widget) =>
setCurrentToDefaultBrower()
);

return nbTreeWidget;
},
};
Expand Down