Преглед на файлове

Merge pull request #3471 from blink1073/console-command-focus

Fix opening of console
Brian E. Granger преди 7 години
родител
ревизия
906b1fdb17

+ 12 - 5
packages/apputils/src/clientsession.ts

@@ -380,6 +380,9 @@ class ClientSession implements IClientSession {
       this._session.dispose();
       this._session = null;
     }
+    if (this._dialog) {
+      this._dialog.dispose();
+    }
     Signal.clearData(this);
   }
 
@@ -592,11 +595,13 @@ class ClientSession implements IClientSession {
     if (this.isDisposed) {
       return Promise.resolve(void 0);
     }
-    return showDialog({
+    let dialog = this._dialog = new Dialog({
       title: 'Select Kernel',
       body: new Private.KernelSelector(this),
       buttons: [Dialog.cancelButton(), Dialog.okButton({ label: 'SELECT' })]
-    }).then(result => {
+    });
+
+    return dialog.launch().then(result => {
       if (this.isDisposed || !result.button.accept) {
         return;
       }
@@ -607,7 +612,7 @@ class ClientSession implements IClientSession {
       if (model) {
         return this._changeKernel(model).then(() => void 0);
       }
-    }).then(() => void 0);
+    }).then(() => { this._dialog = null; });
   }
 
   /**
@@ -677,12 +682,13 @@ class ClientSession implements IClientSession {
       } catch (err) {
         // no-op
       }
-      return showDialog({
+      let dialog = this._dialog = new Dialog({
         title: 'Error Starting Kernel',
         body: h.pre(message),
         buttons: [Dialog.okButton()]
       });
-    }).then(() => undefined);
+      return dialog.launch();
+    }).then(() => { this._dialog = null; });
   }
 
   /**
@@ -762,6 +768,7 @@ class ClientSession implements IClientSession {
   private _iopubMessage = new Signal<this, KernelMessage.IMessage>(this);
   private _unhandledMessage = new Signal<this, KernelMessage.IMessage>(this);
   private _propertyChanged = new Signal<this, 'path' | 'name' | 'type'>(this);
+  private _dialog: Dialog<any> | null = null;
 }
 
 

+ 1 - 1
packages/apputils/src/dialog.ts

@@ -466,7 +466,7 @@ namespace Dialog {
    * A widget used as a dialog body.
    */
   export
-  interface IBodyWidget<T> extends Widget {
+  interface IBodyWidget<T = string> extends Widget {
     /**
      * Get the serialized value of the widget.
      */

+ 4 - 1
packages/console-extension/src/index.ts

@@ -197,8 +197,9 @@ function activateConsole(app: JupyterLab, mainMenu: IMainMenu, palette: ICommand
    * Create a console for a given path.
    */
   function createConsole(options: ICreateOptions): Promise<ConsolePanel> {
+    let panel: ConsolePanel;
     return manager.ready.then(() => {
-      let panel = new ConsolePanel({
+      panel = new ConsolePanel({
         manager,
         contentFactory,
         mimeTypeService: editorServices.mimeTypeService,
@@ -206,6 +207,8 @@ function activateConsole(app: JupyterLab, mainMenu: IMainMenu, palette: ICommand
         ...options as Partial<ConsolePanel.IOptions>
       });
 
+      return panel.session.ready;
+    }).then(() => {
       // Add the console panel to the tracker.
       tracker.add(panel);
       shell.addToMainArea(

+ 4 - 12
packages/console/src/panel.ts

@@ -87,12 +87,13 @@ class ConsolePanel extends Panel {
     });
     this.addWidget(this.console);
 
-    session.ready.then(() => {
+    session.initialize().then(() => {
       this._connected = new Date();
       this._updateTitle();
     });
 
     this.console.executed.connect(this._onExecuted, this);
+    this._updateTitle();
     session.kernelChanged.connect(this._updateTitle, this);
     session.propertyChanged.connect(this._updateTitle, this);
 
@@ -122,20 +123,11 @@ class ConsolePanel extends Panel {
    * Dispose of the resources held by the widget.
    */
   dispose(): void {
+    this.session.dispose();
     this.console.dispose();
     super.dispose();
   }
 
-  /**
-   * Handle `'after-attach'` messages.
-   */
-  protected onAfterAttach(msg: Message): void {
-    this._session.initialize();
-    let prompt = this.console.promptCell;
-    if (prompt) {
-      prompt.editor.focus();
-    }
-  }
 
   /**
    * Handle `'activate-request'` messages.
@@ -311,7 +303,7 @@ namespace Private {
     if (executed) {
       caption += `\nLast Execution: ${Time.format(executed.toISOString())}`;
     }
-    panel.title.label = session.name;
+    panel.title.label = session.name || 'Console';
     panel.title.caption = caption;
   }
 }

+ 2 - 0
packages/services/src/session/default.ts

@@ -179,6 +179,8 @@ class DefaultSession implements Session.ISession {
     return Kernel.connectTo(this.kernel.model, this.serverSettings).then(kernel => {
       return new DefaultSession({
         path: this._path,
+        name: this._name,
+        type: this._type,
         serverSettings: this.serverSettings
       }, this._id, kernel);
     });

+ 0 - 1
test/src/console/panel.spec.ts

@@ -137,7 +137,6 @@ describe('console/panel', () => {
         MessageLoop.sendMessage(panel, Widget.Msg.CloseRequest);
         expect(panel.methods).to.contain('onCloseRequest');
         expect(panel.isDisposed).to.be(true);
-        return dismissDialog();
       });
 
     });