Browse Source

More cleanup

ian-r-rose 8 years ago
parent
commit
108abd2945

+ 4 - 13
packages/chatbox-extension/src/index.ts

@@ -33,7 +33,7 @@ namespace CommandIDs {
   const clear = 'chatbox:clear';
 
   export
-  const run = 'chatbox:push';
+  const run = 'chatbox:post';
 
   export
   const linebreak = 'chatbox:linebreak';
@@ -84,7 +84,7 @@ function activateChatbox(app: JupyterLab, rendermime: IRenderMime, palette: ICom
 
   command = CommandIDs.clear;
   commands.addCommand(command, {
-    label: 'Clear Cells',
+    label: 'Clear Chat',
     execute: args => {
       panel.chatbox.clear();
     }
@@ -93,18 +93,9 @@ function activateChatbox(app: JupyterLab, rendermime: IRenderMime, palette: ICom
 
   command = CommandIDs.run;
   commands.addCommand(command, {
-    label: 'Run Cell',
+    label: 'Post Chat Entry',
     execute: args => {
-      return panel.chatbox.execute();
-    }
-  });
-  palette.addItem({ command, category });
-
-  command = CommandIDs.linebreak;
-  commands.addCommand(command, {
-    label: 'Insert Line Break',
-    execute: args => {
-      panel.chatbox.insertLinebreak();
+      return panel.chatbox.post();
     }
   });
   palette.addItem({ command, category });

+ 0 - 11
packages/chatbox/src/panel.ts

@@ -58,8 +58,6 @@ class ChatboxPanel extends Panel {
     });
     this.addWidget(this.chatbox);
 
-    this.chatbox.executed.connect(this._onExecuted, this);
-
     this.title.icon = 'jp-ImageChatbox';
     this.title.closable = true;
     this.id = `chatbox-${count}`;
@@ -92,15 +90,6 @@ class ChatboxPanel extends Panel {
     super.onCloseRequest(msg);
     this.dispose();
   }
-
-  /**
-   * Handle a chatbox execution.
-   */
-  private _onExecuted(sender: Chatbox, args: Date) {
-    this._executed = args;
-  }
-
-  private _executed: Date = null;
 }
 
 

+ 4 - 61
packages/chatbox/src/widget.ts

@@ -13,10 +13,6 @@ import {
   Message
 } from '@phosphor/messaging';
 
-import {
-  ISignal, Signal
-} from '@phosphor/signaling';
-
 import {
   Panel, PanelLayout, Widget
 } from '@phosphor/widgets';
@@ -82,7 +78,6 @@ class Chatbox extends Widget {
 
     // Create the panels that hold the content and input.
     let layout = this.layout = new PanelLayout();
-    this._cells = new ObservableVector<BaseCellWidget>();
     this._content = new Panel();
     this._input = new Panel();
     this._log = new ObservableVector<Chatbox.IChatEntry>();
@@ -103,13 +98,6 @@ class Chatbox extends Widget {
     layout.addWidget(this._input);
   }
 
-  /**
-   * A signal emitted when the chatbox finished executing its prompt.
-   */
-  get executed(): ISignal<this, Date> {
-    return this._executed;
-  }
-
   /**
    * The content factory used by the chatbox.
    */
@@ -125,13 +113,6 @@ class Chatbox extends Widget {
    */
   readonly rendermime: IRenderMime;
 
-  /**
-   * The list of content cells in the chatbox.
-   */
-  get cells(): IObservableVector<BaseCellWidget> {
-    return this._cells;
-  }
-
   /*
    * The chatbox input prompt.
    */
@@ -152,9 +133,6 @@ class Chatbox extends Widget {
    */
   addCell(cell: BaseCellWidget) {
     this._content.addWidget(cell);
-    this._cells.pushBack(cell);
-    cell.disposed.connect(this._onCellDisposed, this);
-    this.update();
   }
 
   /**
@@ -173,58 +151,35 @@ class Chatbox extends Widget {
    */
   dispose() {
     // Do nothing if already disposed.
-    if (this._cells === null) {
+    if (this._log === null) {
       return;
     }
-    let cells = this._cells;
     let log = this._log;
     this._log = null;
-    this._cells = null;
 
     log.dispose();
-    cells.clear();
-
     super.dispose();
   }
 
   /**
    * Execute the current prompt.
    *
-   * @param force - Whether to force execution without checking code
-   * completeness.
-   *
    * @param timeout - The length of time, in milliseconds, that the execution
    * should wait for the API to determine whether code being submitted is
    * incomplete before attempting submission anyway. The default value is `250`.
    */
-  execute(): void {
+  post(): void {
     let prompt = this.prompt;
 
     if (prompt.model.value.text.trim() !== '') {
       this.newPrompt();
       prompt.model.trusted = true;
-      this._execute(prompt);
+      this._post(prompt);
     } else {
       return;
     }
   }
 
-  /**
-   * Insert a line break in the prompt.
-   */
-  insertLinebreak(): void {
-    let prompt = this.prompt;
-    let model = prompt.model;
-    let editor = prompt.editor;
-    // Insert the line break at the cursor position, and move cursor forward.
-    let pos = editor.getCursorPosition();
-    let offset = editor.getOffsetAt(pos);
-    let text = model.value.text;
-    model.value.text = text.substr(0, offset) + '\n' + text.substr(offset);
-    pos = editor.getPositionAt(offset + 1);
-    editor.setCursorPosition(pos);
-  }
-
   /**
    * Serialize the output.
    */
@@ -302,7 +257,6 @@ class Chatbox extends Widget {
     if (prompt) {
       prompt.readOnly = true;
       prompt.removeClass(PROMPT_CLASS);
-      Signal.clearData(prompt.editor);
       (input.layout as PanelLayout).removeWidgetAt(0);
       this.addCell(prompt);
     }
@@ -342,7 +296,7 @@ class Chatbox extends Widget {
   /**
    * Execute the code in the current prompt.
    */
-  private _execute(cell: MarkdownCellWidget): void {
+  private _post(cell: MarkdownCellWidget): void {
     this._log.pushBack({ text: cell.model.value.text, author: null });
     cell.model.contentChanged.connect(this.update, this);
     cell.rendered = true;
@@ -359,22 +313,11 @@ class Chatbox extends Widget {
     return { model, rendermime, contentFactory };
   }
 
-  /**
-   * Handle cell disposed signals.
-   */
-  private _onCellDisposed(sender: Widget, args: void): void {
-    if (!this.isDisposed) {
-      this._cells.remove(sender as MarkdownCellWidget);
-    }
-  }
-
   private _mimeTypeService: IEditorMimeTypeService;
-  private _cells: IObservableVector<BaseCellWidget> = null;
   private _content: Panel = null;
   private _log: IObservableVector<Chatbox.IChatEntry> = null;
   private _input: Panel = null;
   private _mimetype = 'text/x-ipython';
-  private _executed = new Signal<this, Date>(this);
 }
 
 

+ 1 - 1
packages/shortcuts-extension/src/index.ts

@@ -61,7 +61,7 @@ const SHORTCUTS = [
     keys: ['Tab']
   },
   {
-    command: 'chatbox:push',
+    command: 'chatbox:post',
     selector: '.jp-Chatbox-prompt',
     keys: ['Shift Enter']
   },