Skip to content

Commit a6471db

Browse files
committed
Do not use the restorer on tree view, and do not restore widgets from trackers
1 parent 97bc03b commit a6471db

File tree

5 files changed

+53
-25
lines changed

5 files changed

+53
-25
lines changed

packages/application-extension/src/index.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
JupyterFrontEnd,
1010
JupyterFrontEndPlugin,
1111
JupyterLab,
12-
LayoutRestorer,
1312
} from '@jupyterlab/application';
1413

1514
import {
@@ -20,7 +19,6 @@ import {
2019
IToolbarWidgetRegistry,
2120
IWindowResolver,
2221
showErrorMessage,
23-
WindowResolver,
2422
} from '@jupyterlab/apputils';
2523

2624
import { ConsolePanel } from '@jupyterlab/console';
@@ -57,8 +55,11 @@ import {
5755
SidePanelPalette,
5856
INotebookPathOpener,
5957
defaultNotebookPathOpener,
58+
NotebookLayoutRestorer,
6059
} from '@jupyter-notebook/application';
6160

61+
import { NotebookTreeWidget } from '@jupyter-notebook/tree';
62+
6263
import { jupyterIcon } from '@jupyter-notebook/ui-components';
6364

6465
import { PromiseDelegate } from '@lumino/coreutils';
@@ -196,23 +197,32 @@ const layoutRestorer: JupyterFrontEndPlugin<ILayoutRestorer | null> = {
196197
notebookShell: INotebookShell | null
197198
) => {
198199
if (!notebookShell) {
199-
console.log('No layout for this view');
200200
return null;
201201
}
202-
203202
const first = app.started;
204203
const registry = app.commands;
205204

206-
const restorer = new LayoutRestorer({
205+
const restorer = new NotebookLayoutRestorer({
207206
connector: state,
208207
first,
209208
registry,
210209
});
211210

212-
// Restore the layout.
213-
void notebookShell.restoreLayout(restorer, {}).then(() => {
214-
notebookShell.layoutModified.connect(() => {
215-
void restorer.save(notebookShell.saveLayout());
211+
// Restore the layout when the main widget is loaded.
212+
void notebookShell.mainWidgetLoaded.then(() => {
213+
// Whether to actually restore the layout or not (not for the tree view).
214+
const restoreLayout = !(
215+
notebookShell.currentWidget instanceof NotebookTreeWidget
216+
);
217+
218+
// Call the restorer even if the layout must not be restored, to resolve the
219+
// promise.
220+
void notebookShell.restoreLayout(restorer, restoreLayout).then(() => {
221+
if (restoreLayout) {
222+
notebookShell.layoutModified.connect(() => {
223+
void restorer.save(notebookShell.saveLayout());
224+
});
225+
}
216226
});
217227
});
218228

@@ -519,15 +529,10 @@ const resolver: JupyterFrontEndPlugin<IWindowResolver> = {
519529
description: 'Provides the window name resolver.',
520530
autoStart: true,
521531
provides: IWindowResolver,
522-
requires: [JupyterFrontEnd.IPaths, IRouter],
523-
activate: async (
524-
app: JupyterFrontEnd,
525-
paths: JupyterFrontEnd.IPaths,
526-
router: IRouter
527-
) => {
528-
const solver = new WindowResolver();
529-
(solver as any)._name = 'nb-default';
530-
return solver;
532+
activate: async (app: JupyterFrontEnd) => {
533+
return {
534+
name: 'nb-default',
535+
};
531536
},
532537
};
533538

packages/application/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
export * from './app';
55
export * from './shell';
6+
export * from './layoutrestorer';
67
export * from './panelhandler';
78
export * from './pathopener';
89
export * from './tokens';
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { LayoutRestorer } from '@jupyterlab/application';
2+
import { WidgetTracker } from '@jupyterlab/apputils';
3+
import { IRestorer } from '@jupyterlab/statedb';
4+
import { Widget } from '@lumino/widgets';
5+
6+
export class NotebookLayoutRestorer extends LayoutRestorer {
7+
// Override the restore function, that adds widget tracker state to the restorer.
8+
async restore(
9+
tracker: WidgetTracker,
10+
options: IRestorer.IOptions<Widget>
11+
): Promise<any> {
12+
// no-op as we don't want to restore widgets, only the layout.
13+
}
14+
}

packages/application/src/shell.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,13 @@ export class NotebookShell extends Widget implements JupyterFrontEnd.IShell {
267267
return this._layoutModified;
268268
}
269269

270+
/**
271+
* Promise that resolves when the main widget is loaded.
272+
*/
273+
get mainWidgetLoaded(): Promise<void> {
274+
return this._mainWidgetLoaded.promise;
275+
}
276+
270277
/**
271278
* Promise that resolves when the main widget is loaded and the layout restored.
272279
*/
@@ -495,10 +502,14 @@ export class NotebookShell extends Widget implements JupyterFrontEnd.IShell {
495502
*/
496503
async restoreLayout(
497504
layoutRestorer: LayoutRestorer,
498-
configuration: {
499-
[m: string]: INotebookShell.IUserLayout;
500-
} = {}
505+
restore: boolean
501506
): Promise<void> {
507+
// If no restoration is expected for the current view, resolve the promise.
508+
if (!restore) {
509+
this._restored.resolve();
510+
return;
511+
}
512+
502513
// Get the layout from the restorer
503514
const layout = await layoutRestorer.fetch();
504515

packages/docmanager-extension/src/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ const opener: JupyterFrontEndPlugin<IDocumentWidgetOpener> = {
4545
options?: DocumentRegistry.IOpenOptions
4646
) {
4747
const widgetName = options?.type ?? '';
48-
49-
// Should we consider ref === null or ref === undefined as different the '_noref' ?
50-
const ref = options?.ref ?? '_noref';
51-
48+
const ref = options?.ref;
5249
// check if there is an setting override and if it would add the widget in the main area
5350
const userLayoutArea = notebookShell?.userLayout?.[widgetName]?.area;
5451

0 commit comments

Comments
 (0)