Skip to content

Commit db85bee

Browse files
authored
Merge pull request #97 from gjmooney/running_panel_reopen
Add session context patch to include drive name in path
2 parents 5dcf3be + 04795b1 commit db85bee

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import { JupyterFrontEndPlugin } from '@jupyterlab/application';
22
import {
33
driveFileBrowser,
44
openDriveDialogPlugin,
5-
launcherPlugin
5+
launcherPlugin,
6+
sessionContextPatch
67
} from './plugins';
78

89
const plugins: JupyterFrontEndPlugin<any>[] = [
910
driveFileBrowser,
1011
openDriveDialogPlugin,
11-
launcherPlugin
12+
launcherPlugin,
13+
sessionContextPatch
1214
];
1315

1416
export default plugins;

src/plugins/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './driveBrowserPlugin';
22
export * from './launcherPlugin';
33
export * from './driveDialogPlugin';
4+
export * from './sessionContextPatch';

src/plugins/sessionContextPatch.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import {
2+
JupyterFrontEndPlugin,
3+
JupyterFrontEnd
4+
} from '@jupyterlab/application';
5+
import { SessionContext } from '@jupyterlab/apputils';
6+
import {
7+
IDocumentManager,
8+
IDocumentWidgetOpener
9+
} from '@jupyterlab/docmanager';
10+
11+
/**
12+
* A plugin to patch the session context path so it includes the drive name.
13+
* associated with.
14+
*/
15+
export const sessionContextPatch: JupyterFrontEndPlugin<void> = {
16+
id: '@jupyterlite/application-extension:session-context-patch',
17+
autoStart: true,
18+
requires: [IDocumentManager, IDocumentWidgetOpener],
19+
activate: (
20+
app: JupyterFrontEnd,
21+
docManager: IDocumentManager,
22+
widgetOpener: IDocumentWidgetOpener
23+
) => {
24+
const contents = app.serviceManager.contents;
25+
26+
widgetOpener.opened.connect((_, widget) => {
27+
const context = docManager.contextForWidget(widget);
28+
const driveName = contents.driveName(context?.path ?? '');
29+
if (driveName === '') {
30+
// do nothing if this is the default drive
31+
return;
32+
}
33+
const sessionContext = widget.context.sessionContext as SessionContext;
34+
35+
// Path the session context to include the drive name
36+
sessionContext['_path'] = context?.path;
37+
});
38+
}
39+
};

0 commit comments

Comments
 (0)