Skip to content

Commit

Permalink
Use the tree resolver as an optional dependency to populate the defau…
Browse files Browse the repository at this point in the history
…lt file browser.
  • Loading branch information
afshin committed Dec 23, 2019
1 parent b98deac commit a1bdf1a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
1 change: 0 additions & 1 deletion packages/application-extension/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ const tree: JupyterFrontEndPlugin<JupyterFrontEnd.ITreeResolver> = {
// If a route is handled by the router without the tree command being
// invoked, resolve to `null` and clean up artifacts.
const listener = () => {
console.log('listener in tree plugin', set.isDisposed);
if (set.isDisposed) {
return;
}
Expand Down
53 changes: 46 additions & 7 deletions packages/filebrowser-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import {
ILabShell,
ILayoutRestorer,
IRouter,
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';
Expand Down Expand Up @@ -134,7 +135,8 @@ const factory: JupyterFrontEndPlugin<IFileBrowserFactory> = {
activate: activateFactory,
id: '@jupyterlab/filebrowser-extension:factory',
provides: IFileBrowserFactory,
requires: [IIconRegistry, IDocumentManager, IStateDB]
requires: [IIconRegistry, IDocumentManager],
optional: [IStateDB, IRouter, JupyterFrontEnd.ITreeResolver]
};

/**
Expand Down Expand Up @@ -209,12 +211,14 @@ export default plugins;
/**
* Activate the file browser factory provider.
*/
function activateFactory(
async function activateFactory(
app: JupyterFrontEnd,
icoReg: IIconRegistry,
docManager: IDocumentManager,
state: IStateDB
): IFileBrowserFactory {
state: IStateDB | null,
router: IRouter | null,
tree: JupyterFrontEnd.ITreeResolver | null
): Promise<IFileBrowserFactory> {
const { commands } = app;
const tracker = new WidgetTracker<FileBrowser>({ namespace });
const createFileBrowser = (
Expand All @@ -228,7 +232,8 @@ function activateFactory(
refreshInterval: options.refreshInterval,
state: options.state === null ? null : options.state || state
});
const widget = new FileBrowser({ id, model });
const restore = options.restore;
const widget = new FileBrowser({ id, model, restore });

// Add a launcher toolbar item.
let launcher = new ToolbarButton({
Expand All @@ -245,9 +250,43 @@ function activateFactory(

return widget;
};
const defaultBrowser = createFileBrowser('filebrowser');

return { createFileBrowser, defaultBrowser, tracker };
// Manually restore the default file browser.
const id = 'filebrowser';
const defaultBrowser = createFileBrowser(id, { restore: false });
const plugin = { createFileBrowser, defaultBrowser, tracker };
const restoring = 'jp-mod-restoring';

defaultBrowser.addClass(restoring);

if (!router) {
void defaultBrowser.model.restore(id).then(() => {
defaultBrowser.removeClass(restoring);
});
return plugin;
}

const listener = async () => {
router.routed.disconnect(listener);

const paths = await tree?.paths;
if (paths) {
// Restore the model without populating it.
await defaultBrowser.model.restore(id, false);
if (paths.file) {
await commands.execute(CommandIDs.openPath, { path: paths.file });
}
if (paths.browser) {
await commands.execute(CommandIDs.openPath, { path: paths.browser });
}
} else {
await defaultBrowser.model.restore(id);
}
defaultBrowser.removeClass(restoring);
};
router.routed.connect(listener);

return plugin;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions packages/filebrowser-extension/style/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
|----------------------------------------------------------------------------*/

@import url('~@jupyterlab/filebrowser/style/index.css');

#filebrowser.jp-mod-restoring .jp-DirListing-content {
display: none;
}

0 comments on commit a1bdf1a

Please sign in to comment.