Ver código fonte

work in progress

Afshin Darian 8 anos atrás
pai
commit
4d66d4b307

+ 4 - 2
src/application/index.ts

@@ -61,9 +61,12 @@ class JupyterLab extends Application<ApplicationShell> {
 
   /**
    * A promise that resolves when the JupyterLab application has restored state.
+   *
+   * #### Notes
+   * This is just a reference to `shell.restored`.
    */
   get restored(): Promise<void> {
-    return this._restoredDelegate.promise;
+    return this.shell.restored;
   }
 
   /**
@@ -118,7 +121,6 @@ class JupyterLab extends Application<ApplicationShell> {
   private _info: JupyterLab.IInfo;
   private _isStarted = false;
   private _loader: ModuleLoader | null;
-  private _restoredDelegate = new utils.PromiseDelegate<void>();
   private _startedDelegate = new utils.PromiseDelegate<void>();
 }
 

+ 24 - 0
src/application/shell.ts

@@ -1,6 +1,10 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 
+import {
+  utils
+} from '@jupyterlab/services';
+
 import {
   each, toArray
 } from 'phosphor/lib/algorithm/iteration';
@@ -53,6 +57,10 @@ import {
   Widget
 } from 'phosphor/lib/ui/widget';
 
+import {
+  IInstanceRestorer
+} from '../instancerestorer';
+
 
 /**
  * The class name added to AppShell instances.
@@ -162,6 +170,13 @@ class ApplicationShell extends Widget {
     return this._dockPanel.currentWidget;
   }
 
+  /**
+   * A promise that resolves when the shell has restored state.
+   */
+  get restored(): Promise<void> {
+    return this._restored.promise;
+  }
+
   /**
    * True if main area is empty.
    */
@@ -295,11 +310,20 @@ class ApplicationShell extends Widget {
     each(toArray(this._dockPanel.widgets()), widget => { widget.close(); });
   }
 
+  /**
+   * Restore the layout of the application shell.
+   */
+  restore(restorer: IInstanceRestorer): void {
+    // TODO: implement restoration before resolving the promise.
+    this._restored.resolve(void 0);
+  }
+
   private _topPanel: Panel;
   private _hboxPanel: BoxPanel;
   private _dockPanel: DockPanel;
   private _hsplitPanel: SplitPanel;
   private _leftHandler: Private.SideBarHandler;
+  private _restored = new utils.PromiseDelegate<void>();
   private _rightHandler: Private.SideBarHandler;
 }
 

+ 5 - 9
src/instancerestorer/plugin.ts

@@ -26,16 +26,12 @@ const plugin: JupyterLabPlugin<IInstanceRestorer> = {
     const first = app.started;
     const registry = app.commands;
     const shell = app.shell;
-    let layout = new InstanceRestorer({ first, registry, state });
+    let restorer = new InstanceRestorer({ first, registry, state });
     // Activate widgets that have been restored if necessary.
-    layout.activated.connect((sender, id) => { shell.activateMain(id); });
-    // After restoration is complete, listen to the shell for updates.
-    // restorer.restored.then(() => {
-    //   shell.currentChanged.connect((sender, args) => {
-    //     layout.save({ currentWidget: args.newValue });
-    //   });
-    // });
-    return layout;
+    restorer.activated.connect((sender, id) => { shell.activateMain(id); });
+    // After instance restoration is complete, ask app shell to restore layout.
+    restorer.restored.then(() => { app.shell.restore(restorer); });
+    return restorer;
   },
   autoStart: true,
   provides: IInstanceRestorer

+ 1 - 1
src/landing/plugin.ts

@@ -102,7 +102,7 @@ function activateLanding(app: JupyterLab, pathTracker: IPathTracker, palette: IC
   palette.addItem({ category, command });
 
   // Only create a landing page if there are no other tabs open.
-  restorer.restored.then(() => {
+  app.restored.then(() => {
     if (app.shell.mainAreaIsEmpty) {
       app.commands.execute(command, void 0);
     }