33
44import {
55 ILabStatus ,
6+ ILayoutRestorer ,
67 IRouter ,
78 ITreePathUpdater ,
89 JupyterFrontEnd ,
910 JupyterFrontEndPlugin ,
1011 JupyterLab ,
12+ LayoutRestorer ,
1113} from '@jupyterlab/application' ;
1214
1315import {
@@ -16,7 +18,9 @@ import {
1618 ISanitizer ,
1719 ISplashScreen ,
1820 IToolbarWidgetRegistry ,
21+ IWindowResolver ,
1922 showErrorMessage ,
23+ WindowResolver ,
2024} from '@jupyterlab/apputils' ;
2125
2226import { ConsolePanel } from '@jupyterlab/console' ;
@@ -40,6 +44,8 @@ import {
4044
4145import { ISettingRegistry } from '@jupyterlab/settingregistry' ;
4246
47+ import { IStateDB } from '@jupyterlab/statedb' ;
48+
4349import { ITranslator , nullTranslator } from '@jupyterlab/translation' ;
4450
4551import {
@@ -176,6 +182,46 @@ const info: JupyterFrontEndPlugin<JupyterLab.IInfo> = {
176182 } ,
177183} ;
178184
185+ /**
186+ * The default layout restorer provider.
187+ */
188+ const layoutRestorer : JupyterFrontEndPlugin < ILayoutRestorer | null > = {
189+ id : '@jupyter-notebook/application-extension:layout' ,
190+ description : 'Provides the shell layout restorer.' ,
191+ requires : [ IStateDB ] ,
192+ optional : [ INotebookShell ] ,
193+ activate : async (
194+ app : JupyterFrontEnd ,
195+ state : IStateDB ,
196+ notebookShell : INotebookShell | null
197+ ) => {
198+ if ( ! notebookShell ) {
199+ console . log ( 'No layout for this view' ) ;
200+ return null ;
201+ }
202+
203+ const first = app . started ;
204+ const registry = app . commands ;
205+
206+ const restorer = new LayoutRestorer ( {
207+ connector : state ,
208+ first,
209+ registry,
210+ } ) ;
211+
212+ // Restore the layout.
213+ void notebookShell . restoreLayout ( restorer , { } ) . then ( ( ) => {
214+ notebookShell . layoutModified . connect ( ( ) => {
215+ void restorer . save ( notebookShell . saveLayout ( ) ) ;
216+ } ) ;
217+ } ) ;
218+
219+ return restorer ;
220+ } ,
221+ autoStart : true ,
222+ provides : ILayoutRestorer ,
223+ } ;
224+
179225/**
180226 * The logo plugin.
181227 */
@@ -465,6 +511,26 @@ const rendermime: JupyterFrontEndPlugin<IRenderMimeRegistry> = {
465511 } ,
466512} ;
467513
514+ /**
515+ * The default window name resolver provider.
516+ */
517+ const resolver : JupyterFrontEndPlugin < IWindowResolver > = {
518+ id : '@jupyter-notebook/apputils-extension:resolver' ,
519+ description : 'Provides the window name resolver.' ,
520+ autoStart : true ,
521+ 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 ;
531+ } ,
532+ } ;
533+
468534/**
469535 * The default Jupyter Notebook application shell.
470536 */
@@ -491,7 +557,7 @@ const shell: JupyterFrontEndPlugin<INotebookShell> = {
491557 const customLayout = settings . composite [ 'layout' ] as any ;
492558
493559 // Restore the layout.
494- void notebookShell . restoreLayout ( customLayout ) ;
560+ void notebookShell . restoreLayoutConf ( customLayout ) ;
495561 } )
496562 . catch ( ( reason ) => {
497563 console . error ( 'Fail to load settings for the layout restorer.' ) ;
@@ -1189,6 +1255,7 @@ const zen: JupyterFrontEndPlugin<void> = {
11891255const plugins : JupyterFrontEndPlugin < any > [ ] = [
11901256 dirty ,
11911257 info ,
1258+ layoutRestorer ,
11921259 logo ,
11931260 menus ,
11941261 menuSpacer ,
@@ -1197,6 +1264,7 @@ const plugins: JupyterFrontEndPlugin<any>[] = [
11971264 pathOpener ,
11981265 paths ,
11991266 rendermime ,
1267+ resolver ,
12001268 shell ,
12011269 sidePanelVisibility ,
12021270 shortcuts ,
0 commit comments