Steven Silvester пре 9 година
родитељ
комит
146fedf7b0
2 измењених фајлова са 52 додато и 34 уклоњено
  1. 15 15
      src/notebook/notebook/actions.ts
  2. 37 19
      src/notebook/notebook/model.ts

+ 15 - 15
src/notebook/notebook/actions.ts

@@ -143,7 +143,7 @@ namespace NotebookActions {
       }
     }
     if (!model.cells.length) {
-      let cell = model.cellFactory.newCodeCell();
+      let cell = model.newCodeCell();
       model.cells.add(cell);
     }
     model.cells.endCompoundOperation();
@@ -155,7 +155,7 @@ namespace NotebookActions {
    */
   export
   function insertAbove(widget: Notebook): void {
-    let cell = widget.model.cellFactory.newCodeCell();
+    let cell = widget.model.newCodeCell();
     widget.model.cells.insert(widget.activeCellIndex, cell);
     Private.deselectCells(widget);
   }
@@ -165,7 +165,7 @@ namespace NotebookActions {
    */
   export
   function insertBelow(widget: Notebook): void {
-    let cell = widget.model.cellFactory.newCodeCell();
+    let cell = widget.model.newCodeCell();
     widget.model.cells.insert(widget.activeCellIndex + 1, cell);
     Private.deselectCells(widget);
   }
@@ -188,13 +188,13 @@ namespace NotebookActions {
       let newCell: ICellModel;
       switch (value) {
       case 'code':
-        newCell = model.cellFactory.newCodeCell(child.model.toJSON());
+        newCell = model.newCodeCell(child.model.toJSON());
         break;
       case 'markdown':
-        newCell = model.cellFactory.newMarkdownCell(child.model.toJSON());
+        newCell = model.newMarkdownCell(child.model.toJSON());
         break;
       default:
-        newCell = model.cellFactory.newRawCell(child.model.toJSON());
+        newCell = model.newRawCell(child.model.toJSON());
       }
       model.cells.replace(i, 1, [newCell]);
       if (value === 'markdown') {
@@ -242,7 +242,7 @@ namespace NotebookActions {
     run(widget, kernel);
     let model = widget.model;
     if (widget.activeCellIndex === widget.childCount() - 1) {
-      let cell = model.cellFactory.newCodeCell();
+      let cell = model.newCodeCell();
       model.cells.add(cell);
       widget.mode = 'edit';
     } else {
@@ -259,7 +259,7 @@ namespace NotebookActions {
   function runAndInsert(widget: Notebook, kernel?: IKernel): void {
     run(widget, kernel);
     let model = widget.model;
-    let cell = model.cellFactory.newCodeCell();
+    let cell = model.newCodeCell();
     model.cells.insert(widget.activeCellIndex + 1, cell);
     widget.activeCellIndex++;
     widget.mode = 'edit';
@@ -396,7 +396,7 @@ namespace NotebookActions {
       }
     }
     if (!model.cells.length) {
-      let cell = model.cellFactory.newCodeCell();
+      let cell = model.newCodeCell();
       model.cells.add(cell);
     }
     model.cells.endCompoundOperation();
@@ -418,13 +418,13 @@ namespace NotebookActions {
     for (let value of values) {
       switch (value.cell_type) {
       case 'code':
-        cells.push(model.cellFactory.newCodeCell(value));
+        cells.push(model.newCodeCell(value));
         break;
       case 'markdown':
-        cells.push(model.cellFactory.newMarkdownCell(value));
+        cells.push(model.newMarkdownCell(value));
         break;
       default:
-        cells.push(model.cellFactory.newRawCell(value));
+        cells.push(model.newRawCell(value));
         break;
       }
     }
@@ -538,11 +538,11 @@ namespace Private {
   function cloneCell(model: INotebookModel, cell: ICellModel): ICellModel {
     switch (cell.type) {
     case 'code':
-      return model.cellFactory.newCodeCell(cell.toJSON());
+      return model.newCodeCell(cell.toJSON());
     case 'markdown':
-      return model.cellFactory.newMarkdownCell(cell.toJSON());
+      return model.newMarkdownCell(cell.toJSON());
     default:
-      return model.cellFactory.newRawCell(cell.toJSON());
+      return model.newRawCell(cell.toJSON());
     }
   }
 

+ 37 - 19
src/notebook/notebook/model.ts

@@ -46,7 +46,7 @@ import {
  * The definition of a model object for a notebook widget.
  */
 export
-interface INotebookModel extends IDocumentModel {
+interface INotebookModel extends IDocumentModel, ICellModelFactory {
   /**
    * A signal emitted when a model state changes.
    */
@@ -65,14 +65,6 @@ interface INotebookModel extends IDocumentModel {
    */
   cells: ObservableUndoableList<ICellModel>;
 
-  /**
-   * The factory for creating new cell models.
-   *
-   * #### Notes
-   * This is a read-only property.
-   */
-  cellFactory: ICellModelFactory;
-
   /**
    * The major version number of the nbformat.
    *
@@ -230,16 +222,6 @@ class NotebookModel extends DocumentModel implements INotebookModel {
     return info ? info.name : '';
   }
 
-  /**
-   * Get the factory used to create cell models.
-   *
-   * #### Notes
-   * This is a read-only property.
-   */
-  get cellFactory(): ICellModelFactory {
-    return this._factory;
-  }
-
   /**
    * Dispose of the resources held by the model.
    */
@@ -398,6 +380,42 @@ class NotebookModel extends DocumentModel implements INotebookModel {
     return Object.keys(this._metadata);
   }
 
+  /**
+   * Create a new code cell.
+   *
+   * @param source - The data to use for the original source data.
+   *
+   * @returns A new code cell. If a source cell is provided, the
+   *   new cell will be intialized with the data from the source.
+   */
+  newCodeCell(source?: nbformat.IBaseCell): ICodeCellModel {
+    return this._factory.newCodeCell(source);
+  }
+
+  /**
+   * Create a new markdown cell.
+   *
+   * @param source - The data to use for the original source data.
+   *
+   * @returns A new markdown cell. If a source cell is provided, the
+   *   new cell will be intialized with the data from the source.
+   */
+  newMarkdownCell(source?: nbformat.IBaseCell): IMarkdownCellModel {
+    return this._factory.newMarkdownCell(source);
+  }
+
+  /**
+   * Create a new raw cell.
+   *
+   * @param source - The data to use for the original source data.
+   *
+   * @returns A new raw cell. If a source cell is provided, the
+   *   new cell will be intialized with the data from the source.
+   */
+  newRawCell(source?: nbformat.IBaseCell): IRawCellModel {
+    return this._factory.newRawCell(source);
+  }
+
   /**
    * Set the cursor data for a given field.
    */