Steven Silvester il y a 8 ans
Parent
commit
a3437120ca

+ 22 - 14
src/docregistry/default.ts

@@ -11,7 +11,7 @@ import {
 } from '@jupyterlab/services';
 
 import {
-  defineSignal, ISignal
+  ISignal, Signal
 } from '@phosphor/signaling';
 
 import {
@@ -46,18 +46,22 @@ class DocumentModel extends CodeEditor.Model implements DocumentRegistry.ICodeMo
   constructor(languagePreference?: string) {
     super();
     this._defaultLang = languagePreference || '';
-    this.value.changed.connect(this._onValueChanged, this);
+    this.value.changed.connect(this.triggerContentChange, this);
   }
 
   /**
    * A signal emitted when the document content changes.
    */
-  contentChanged: ISignal<this, void>;
+  get contentChanged(): ISignal<this, void> {
+    return this._contentChanged;
+  }
 
   /**
    * A signal emitted when the document state changes.
    */
-  stateChanged: ISignal<this, IChangedArgs<any>>;
+  get stateChanged(): ISignal<this, IChangedArgs<any>> {
+    return this._stateChanged;
+  }
 
   /**
    * The dirty state of the document.
@@ -71,7 +75,7 @@ class DocumentModel extends CodeEditor.Model implements DocumentRegistry.ICodeMo
     }
     let oldValue = this._dirty;
     this._dirty = newValue;
-    this.stateChanged.emit({ name: 'dirty', oldValue, newValue });
+    this.triggerChange({ name: 'dirty', oldValue, newValue });
   }
 
   /**
@@ -86,7 +90,7 @@ class DocumentModel extends CodeEditor.Model implements DocumentRegistry.ICodeMo
     }
     let oldValue = this._readOnly;
     this._readOnly = newValue;
-    this.stateChanged.emit({ name: 'readOnly', oldValue, newValue });
+    this.triggerChange({ name: 'readOnly', oldValue, newValue });
   }
 
   /**
@@ -144,24 +148,28 @@ class DocumentModel extends CodeEditor.Model implements DocumentRegistry.ICodeMo
   }
 
   /**
-   * Handle a change to the observable value.
+   * Trigger a state change signal.
+   */
+  protected triggerStateChange(args: IChangedArgs<any>): void {
+    this._stateChanged.emit(args);
+  }
+
+  /**
+   * Trigger a content changed signal.
    */
-  private _onValueChanged(sender: IObservableString, args: ObservableString.IChangedArgs): void {
-    this.contentChanged.emit(void 0);
+  protected triggerContentChange(): void {
+    this._contentChanged.emit(void 0);
     this.dirty = true;
   }
 
   private _defaultLang = '';
   private _dirty = false;
   private _readOnly = false;
+  private _contentChanged = new Signal<this, void>(this);
+  private _stateChanged = new Signal<this, IChangedArgs<any>>(this);
 }
 
 
-// Define the signals for the `DocumentModel` class.
-defineSignal(DocumentModel.prototype, 'contentChanged');
-defineSignal(DocumentModel.prototype, 'stateChanged');
-
-
 /**
  * An implementation of a model factory for text files.
  */

+ 1 - 1
src/notebook/default-toolbar.ts

@@ -254,7 +254,7 @@ class CellTypeSwitcher extends Widget {
     }
     let mType: string = widget.activeCell.model.type;
     for (let i = 0; i < widget.widgets.length; i++) {
-      let child = widget.widgets.at(i);
+      let child = widget.widgets[i];
       if (widget.isSelected(child)) {
         if (child.model.type !== mType) {
           mType = '-';

+ 7 - 20
src/notebook/model.ts

@@ -2,17 +2,13 @@
 // Distributed under the terms of the Modified BSD License.
 
 import {
-  nbformat, utils
+  nbformat
 } from '@jupyterlab/services';
 
 import {
   each
 } from '@phosphor/algorithm';
 
-import {
-  JSONValue
-} from '@phosphor/coreutils';
-
 import {
   IObservableVector, ObservableVector
 } from '../common/observablevector';
@@ -103,7 +99,7 @@ class NotebookModel extends DocumentModel implements INotebookModel {
     let name = options.languagePreference || '';
     this._metadata.set('language_info', { name });
     this._ensureMetadata();
-    this._metadata.changed.connect(this._onGenericChange, this);
+    this._metadata.changed.connect(this.triggerContentChange, this);
   }
 
   /**
@@ -250,12 +246,12 @@ class NotebookModel extends DocumentModel implements INotebookModel {
     if (value.nbformat !== this._nbformat) {
       oldValue = this._nbformat;
       this._nbformat = newValue = value.nbformat;
-      this.stateChanged.emit({ name: 'nbformat', oldValue, newValue });
+      this.triggerStateChange({ name: 'nbformat', oldValue, newValue });
     }
     if (value.nbformat_minor > this._nbformatMinor) {
       oldValue = this._nbformatMinor;
       this._nbformatMinor = newValue = value.nbformat_minor;
-      this.stateChanged.emit({ name: 'nbformatMinor', oldValue, newValue });
+      this.triggerStateChange({ name: 'nbformatMinor', oldValue, newValue });
     }
     // Update the metadata.
     this._metadata.clear();
@@ -278,7 +274,7 @@ class NotebookModel extends DocumentModel implements INotebookModel {
     switch (change.type) {
     case 'add':
       each(change.newValues, cell => {
-        cell.contentChanged.connect(this._onGenericChange, this);
+        cell.contentChanged.connect(this.triggerContentChange, this);
       });
       break;
     case 'remove':
@@ -288,7 +284,7 @@ class NotebookModel extends DocumentModel implements INotebookModel {
       break;
     case 'set':
       each(change.newValues, cell => {
-        cell.contentChanged.connect(this._onGenericChange, this);
+        cell.contentChanged.connect(this.triggerContentChange, this);
       });
       each(change.oldValues, cell => {
         cell.dispose();
@@ -308,8 +304,7 @@ class NotebookModel extends DocumentModel implements INotebookModel {
         }
       });
     }
-    this.contentChanged.emit(void 0);
-    this.dirty = true;
+    this.triggerContentChange();
   }
 
   /**
@@ -325,14 +320,6 @@ class NotebookModel extends DocumentModel implements INotebookModel {
     }
   }
 
-  /**
-   * Handle a generic state change.
-   */
-  private _onGenericChange(): void {
-    this.dirty = true;
-    this.contentChanged.emit(void 0);
-  }
-
   private _cells: IObservableUndoableVector<ICellModel> = null;
   private _nbformat = nbformat.MAJOR_VERSION;
   private _nbformatMinor = nbformat.MINOR_VERSION;

+ 17 - 14
src/notebook/panel.ts

@@ -18,7 +18,7 @@ import {
 } from '@phosphor/coreutils';
 
 import {
-  defineSignal, ISignal
+  ISignal, Signal
 } from '@phosphor/signaling';
 
 import {
@@ -117,17 +117,23 @@ class NotebookPanel extends Widget {
   /**
    * A signal emitted when the panel has been activated.
    */
-  readonly activated: ISignal<this, void>;
+  get activated(): ISignal<this, void> {
+    return this._activated;
+  }
 
   /**
    * A signal emitted when the panel context changes.
    */
-  readonly contextChanged: ISignal<this, void>;
+  get contextChanged(): ISignal<this, void> {
+    return this._contextChanged;
+  }
 
   /**
    * A signal emitted when the kernel used by the panel changes.
    */
-  readonly kernelChanged: ISignal<this, Kernel.IKernel>;
+  get kernelChanged(): ISignal<this, Kernel.IKernel> {
+    return this._kernelChanged;
+  }
 
   /**
    * The factory used by the widget.
@@ -153,7 +159,7 @@ class NotebookPanel extends Widget {
    * Get the toolbar used by the widget.
    */
   get toolbar(): Toolbar<Widget> {
-    return (this.layout as PanelLayout).widgets.at(0) as Toolbar<Widget>;
+    return (this.layout as PanelLayout).widgets[0] as Toolbar<Widget>;
   }
 
   /**
@@ -191,7 +197,7 @@ class NotebookPanel extends Widget {
     // Trigger private, protected, and public changes.
     this._onContextChanged(oldValue, newValue);
     this.onContextChanged(oldValue, newValue);
-    this.contextChanged.emit(void 0);
+    this._contextChanged.emit(void 0);
   }
 
   /**
@@ -208,7 +214,7 @@ class NotebookPanel extends Widget {
    */
   protected onActivateRequest(msg: Message): void {
     this.notebook.activate();
-    this.activated.emit(void 0);
+    this._activated.emit(void 0);
   }
 
   /**
@@ -289,7 +295,7 @@ class NotebookPanel extends Widget {
    * Handle a change in the kernel by updating the document metadata.
    */
   private _onKernelChanged(context: DocumentRegistry.IContext<INotebookModel>, kernel: Kernel.IKernel): void {
-    this.kernelChanged.emit(kernel);
+    this._kernelChanged.emit(kernel);
     if (!this.model || !kernel) {
       return;
     }
@@ -339,15 +345,12 @@ class NotebookPanel extends Widget {
   }
 
   private _context: DocumentRegistry.IContext<INotebookModel> = null;
+  private _activated = new Signal<this, void>(this);
+  private _contextChanged = new Signal<this, void>(this);
+  private _kernelChanged = new Signal<this, Kernel.IKernel>(this);
 }
 
 
-// Define the signals for the `NotebookPanel` class.
-defineSignal(NotebookPanel.prototype, 'activated');
-defineSignal(NotebookPanel.prototype, 'contextChanged');
-defineSignal(NotebookPanel.prototype, 'kernelChanged');
-
-
 /**
  * A namespace for `NotebookPanel` statics.
  */

+ 1 - 1
src/notebook/plugin.ts

@@ -730,7 +730,7 @@ function createMenu(app: JupyterLab): Menu {
   menu.addItem({ command: CommandIDs.closeAndShutdown });
   menu.addItem({ command: CommandIDs.trust });
   menu.addItem({ type: 'separator' });
-  menu.addItem({ type: 'submenu', menu: settings });
+  menu.addItem({ type: 'submenu', submenu: settings });
 
   return menu;
 }