Bladeren bron

Remove ForeignHandler.

ian-r-rose 8 jaren geleden
bovenliggende
commit
c833c120ca

+ 0 - 19
packages/chatbox-extension/src/index.ts

@@ -74,9 +74,6 @@ namespace CommandIDs {
   export
   const open = 'chatbox:open';
 
-  export
-  const inject = 'chatbox:inject';
-
   export
   const switchKernel = 'chatbox:switch-kernel';
 };
@@ -333,22 +330,6 @@ function activateChatbox(app: JupyterLab, manager: IServiceManager, rendermime:
     }
   });
 
-  command = CommandIDs.inject;
-  commands.addCommand(command, {
-    execute: (args: JSONObject) => {
-      let path = args['path'];
-      tracker.find(widget => {
-        if (widget.chatbox.session.path === path) {
-          if (args['activate'] !== false) {
-            tracker.activate(widget);
-          }
-          widget.chatbox.inject(args['code'] as string);
-          return true;
-        }
-      });
-    }
-  });
-
   command = CommandIDs.switchKernel;
   commands.addCommand(command, {
     label: 'Switch Kernel',

+ 0 - 207
packages/chatbox/src/foreign.ts

@@ -1,207 +0,0 @@
-// Copyright (c) Jupyter Development Team.
-// Distributed under the terms of the Modified BSD License.
-
-import {
-  KernelMessage
-} from '@jupyterlab/services';
-
-import {
-  IDisposable
-} from '@phosphor/disposable';
-
-import {
-  Signal
-} from '@phosphor/signaling';
-
-import {
-  IClientSession
-} from '@jupyterlab/apputils';
-
-import {
-  BaseCellWidget, CodeCellWidget
-} from '@jupyterlab/cells';
-
-import {
-  nbformat
-} from '@jupyterlab/coreutils';
-
-
-/**
- * A handler for capturing API messages from other sessions that should be
- * rendered in a given parent.
- */
-export
-class ForeignHandler implements IDisposable {
-  /**
-   * Construct a new foreign message handler.
-   */
-  constructor(options: ForeignHandler.IOptions) {
-    this.session = options.session;
-    this.session.iopubMessage.connect(this.onIOPubMessage, this);
-    this._factory = options.cellFactory;
-    this._parent = options.parent;
-  }
-
-  /**
-   * Set whether the handler is able to inject foreign cells into a chatbox.
-   */
-  get enabled(): boolean {
-    return this._enabled;
-  }
-  set enabled(value: boolean) {
-    this._enabled = value;
-  }
-
-  /**
-   * The client session used by the foreign handler.
-   */
-  readonly session: IClientSession;
-
-  /**
-   * The foreign handler's parent receiver.
-   */
-  get parent(): ForeignHandler.IReceiver {
-    return this._parent;
-  }
-
-  /**
-   * Test whether the handler is disposed.
-   */
-  get isDisposed(): boolean {
-    return this._cells === null;
-  }
-
-  /**
-   * Dispose the resources held by the handler.
-   */
-  dispose(): void {
-    if (this._cells === null) {
-      return;
-    }
-    let cells = this._cells;
-    this._cells = null;
-    cells.clear();
-    Signal.clearData(this);
-  }
-
-  /**
-   * Handler IOPub messages.
-   *
-   * @returns `true` if the message resulted in a new cell injection or a
-   * previously injected cell being updated and `false` for all other messages.
-   */
-  protected onIOPubMessage(sender: IClientSession, msg: KernelMessage.IIOPubMessage): boolean {
-    // Only process messages if foreign cell injection is enabled.
-    if (!this._enabled) {
-      return false;
-    }
-    let kernel = this.session.kernel;
-    if (!kernel) {
-      return;
-    }
-
-    // Check whether this message came from an external session.
-    let parent = this._parent;
-    let session = (msg.parent_header as KernelMessage.IHeader).session;
-    if (session === kernel.clientId) {
-      return false;
-    }
-    let msgType = msg.header.msg_type;
-    let parentHeader = msg.parent_header as KernelMessage.IHeader;
-    let parentMsgId = parentHeader.msg_id as string;
-    let cell: CodeCellWidget;
-    switch (msgType) {
-    case 'execute_input':
-      let inputMsg = msg as KernelMessage.IExecuteInputMsg;
-      cell = this._newCell(parentMsgId);
-      let model = cell.model;
-      model.executionCount = inputMsg.content.execution_count;
-      model.value.text = inputMsg.content.code;
-      model.trusted = true;
-      parent.update();
-      return true;
-    case 'execute_result':
-    case 'display_data':
-    case 'stream':
-    case 'error':
-      if (!this._cells.has(parentMsgId)) {
-        // This is an output from an input that was broadcast before our
-        // session started listening. We will ignore it.
-        console.warn('Ignoring output with no associated input cell.');
-        return false;
-      }
-      let output = msg.content as nbformat.IOutput;
-      cell = this._cells.get(parentMsgId);
-      output.output_type = msgType as nbformat.OutputType;
-      cell.model.outputs.add(output);
-      parent.update();
-      return true;
-    case 'clear_output':
-      let wait = (msg as KernelMessage.IClearOutputMsg).content.wait;
-      cell = this._cells.get(parentMsgId);
-      cell.model.outputs.clear(wait);
-      return true;
-    default:
-      return false;
-    }
-  }
-
-  /**
-   * Create a new code cell for an input originated from a foreign session.
-   */
-  private _newCell(parentMsgId: string): CodeCellWidget {
-    let cell = this._factory();
-    this._cells.set(parentMsgId, cell);
-    this._parent.addCell(cell);
-    return cell;
-  }
-
-  private _cells = new Map<string, CodeCellWidget>();
-  private _enabled = true;
-  private _parent: ForeignHandler.IReceiver = null;
-  private _factory: () => CodeCellWidget = null;
-}
-
-
-/**
- * A namespace for `ForeignHandler` statics.
- */
-export
-namespace ForeignHandler {
-  /**
-   * The instantiation options for a foreign handler.
-   */
-  export
-  interface IOptions {
-    /**
-     * The client session used by the foreign handler.
-     */
-    session: IClientSession;
-
-    /**
-     * The parent into which the handler will inject code cells.
-     */
-    parent: IReceiver;
-
-    /**
-     * The cell factory for foreign handlers.
-     */
-    cellFactory: () => CodeCellWidget;
-  }
-
-  /**
-   * A receiver of newly created foreign cells.
-   */
-  export
-  interface IReceiver {
-    /**
-     * Add a newly created foreign cell.
-     */
-    addCell(cell: BaseCellWidget): void;
-
-    /**
-     * Trigger a rendering update on the receiver.
-     */
-    update(): void;
-  }
-}

+ 0 - 1
packages/chatbox/src/index.ts

@@ -1,7 +1,6 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 
-export * from './foreign';
 export * from './history';
 export * from './panel';
 export * from './tracker';

+ 1 - 1
packages/chatbox/src/panel.ts

@@ -49,7 +49,7 @@ import {
 /**
  * The class name added to chatbox panels.
  */
-const PANEL_CLASS = 'jp-ChatboxPanel';
+const PANEL_CLASS = 'jp-ConsolePanel';
 
 
 /**

+ 1 - 1
packages/chatbox/src/tracker.ts

@@ -19,7 +19,7 @@ import {
  * The chatbox tracker token.
  */
 export
-const IChatboxTracker = new Token<IChatboxTracker>('jupyter.services.chatboxs');
+const IChatboxTracker = new Token<IChatboxTracker>('jupyter.services.chatbox');
 /* tslint:enable */
 
 

+ 7 - 78
packages/chatbox/src/widget.ts

@@ -51,10 +51,6 @@ import {
   IRenderMime
 } from '@jupyterlab/rendermime';
 
-import {
-  ForeignHandler
-} from './foreign';
-
 import {
   ChatboxHistory, IChatboxHistory
 } from './history';
@@ -63,32 +59,27 @@ import {
 /**
  * The class name added to chatbox widgets.
  */
-const CONSOLE_CLASS = 'jp-CodeChatbox';
+const CONSOLE_CLASS = 'jp-CodeConsole';
 
 /**
  * The class name added to the chatbox banner.
  */
-const BANNER_CLASS = 'jp-CodeChatbox-banner';
-
-/**
- * The class name of a cell whose input originated from a foreign session.
- */
-const FOREIGN_CELL_CLASS = 'jp-CodeChatbox-foreignCell';
+const BANNER_CLASS = 'jp-CodeConsole-banner';
 
 /**
  * The class name of the active prompt
  */
-const PROMPT_CLASS = 'jp-CodeChatbox-prompt';
+const PROMPT_CLASS = 'jp-CodeConsole-prompt';
 
 /**
  * The class name of the panel that holds cell content.
  */
-const CONTENT_CLASS = 'jp-CodeChatbox-content';
+const CONTENT_CLASS = 'jp-CodeConsole-content';
 
 /**
  * The class name of the panel that holds prompts.
  */
-const INPUT_CLASS = 'jp-CodeChatbox-input';
+const INPUT_CLASS = 'jp-CodeConsole-input';
 
 /**
  * The timeout in ms for execution requests to the kernel.
@@ -145,13 +136,6 @@ class CodeChatbox extends Widget {
     banner.readOnly = true;
     this._content.addWidget(banner);
 
-    // Set up the foreign iopub handler.
-    this._foreignHandler = factory.createForeignHandler({
-      session: this.session,
-      parent: this,
-      cellFactory: () => this._createForeignCell(),
-    });
-
     this._history = factory.createChatboxHistory({
       session: this.session
     });
@@ -250,17 +234,14 @@ class CodeChatbox extends Widget {
    */
   dispose() {
     // Do nothing if already disposed.
-    if (this._foreignHandler === null) {
+    if (this._cells === null) {
       return;
     }
-    let foreignHandler = this._foreignHandler;
-    let history = this._history;
     let cells = this._cells;
-    this._foreignHandler = null;
+    let history = this._history;
     this._history = null;
     this._cells = null;
 
-    foreignHandler.dispose();
     history.dispose();
     cells.clear();
 
@@ -304,20 +285,6 @@ class CodeChatbox extends Widget {
     });
   }
 
-  /**
-   * Inject arbitrary code for the chatbox to execute immediately.
-   *
-   * @param code - The code contents of the cell being injected.
-   *
-   * @returns A promise that indicates when the injected cell's execution ends.
-   */
-  inject(code: string): Promise<void> {
-    let cell = this._createForeignCell();
-    cell.model.value.text = code;
-    this.addCell(cell);
-    return this._execute(cell);
-  }
-
   /**
    * Insert a line break in the prompt.
    */
@@ -505,19 +472,6 @@ class CodeChatbox extends Widget {
     }
   }
 
-  /**
-   * Create a new foreign cell.
-   */
-  private _createForeignCell(): CodeCellWidget {
-    let factory = this.contentFactory;
-    let options = this._createCodeCellOptions();
-    let cell = factory.createForeignCell(options, this);
-    cell.readOnly = true;
-    cell.model.mimeType = this._mimetype;
-    cell.addClass(FOREIGN_CELL_CLASS);
-    return cell;
-  }
-
   /**
    * Create the options used to initialize a code cell widget.
    */
@@ -594,7 +548,6 @@ class CodeChatbox extends Widget {
   private _mimeTypeService: IEditorMimeTypeService;
   private _cells: IObservableVector<BaseCellWidget> = null;
   private _content: Panel = null;
-  private _foreignHandler: ForeignHandler =  null;
   private _history: IChatboxHistory = null;
   private _input: Panel = null;
   private _mimetype = 'text/x-ipython';
@@ -664,11 +617,6 @@ namespace CodeChatbox {
      */
     createChatboxHistory(options: ChatboxHistory.IOptions): IChatboxHistory;
 
-    /**
-     * The foreign handler for a chatbox widget.
-     */
-    createForeignHandler(options: ForeignHandler.IOptions): ForeignHandler;
-
     /**
      * Create a new banner widget.
      */
@@ -678,11 +626,6 @@ namespace CodeChatbox {
      * Create a new prompt widget.
      */
     createPrompt(options: CodeCellWidget.IOptions, parent: CodeChatbox): CodeCellWidget;
-
-    /**
-     * Create a code cell whose input originated from a foreign session.
-     */
-    createForeignCell(options: CodeCellWidget.IOptions, parent: CodeChatbox): CodeCellWidget;
   }
 
   /**
@@ -731,13 +674,6 @@ namespace CodeChatbox {
       return new ChatboxHistory(options);
     }
 
-    /**
-     * The foreign handler for a chatbox widget.
-     */
-    createForeignHandler(options: ForeignHandler.IOptions):
-    ForeignHandler {
-      return new ForeignHandler(options);
-    }
     /**
      * Create a new banner widget.
      */
@@ -751,13 +687,6 @@ namespace CodeChatbox {
     createPrompt(options: CodeCellWidget.IOptions, parent: CodeChatbox): CodeCellWidget {
       return new CodeCellWidget(options);
     }
-
-    /**
-     * Create a new code cell widget for an input from a foreign session.
-     */
-    createForeignCell(options: CodeCellWidget.IOptions, parent: CodeChatbox): CodeCellWidget {
-      return new CodeCellWidget(options);
-    }
   }
   /**
    * An initialize options for `ContentFactory`.