Forráskód Böngészése

WIP create new view of cell context menu

Jason Grout 7 éve
szülő
commit
afc6d0deac

+ 27 - 1
packages/notebook-extension/src/index.ts

@@ -39,7 +39,7 @@ import {
 } from '@phosphor/messaging';
 
 import {
-  Menu, Widget
+  Menu, Panel, Widget
 } from '@phosphor/widgets';
 
 
@@ -69,6 +69,9 @@ namespace CommandIDs {
   export
   const createConsole = 'notebook:create-console';
 
+  export
+  const createCellView = 'notebook:create-cell-view';
+
   export
   const clearAllOutputs = 'notebook:clear-all-cell-outputs';
 
@@ -463,6 +466,10 @@ function activateNotebookHandler(app: JupyterLab, mainMenu: IMainMenu, palette:
     command: CommandIDs.split,
     selector: '.jp-Notebook .jp-Cell'
   });
+  app.contextMenu.addItem({
+    command: CommandIDs.createCellView,
+    selector: '.jp-Notebook .jp-Cell'
+  });
   app.contextMenu.addItem({
     type: 'separator',
     selector: '.jp-Notebook',
@@ -1006,6 +1013,25 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
     },
     isEnabled: hasWidget
   });
+  commands.addCommand(CommandIDs.createCellView, {
+    label: 'Create New View for Cell',
+    execute: args => {
+      const current = getCurrent(args);
+      let nb = current.notebook;
+      let index = nb.activeCellIndex;
+      let cellwidget = nb.widgets[index];
+
+      let p = new Panel();
+      p.id = `Cell-${Math.random()}`;
+      p.title.closable = true;
+      p.title.label = 'Cell';
+
+      let newCell = nb.createCell(cellwidget.model);
+      p.addWidget(newCell);
+      shell.addToMainArea(p);
+    },
+    isEnabled: hasWidget
+  });
   commands.addCommand(CommandIDs.createConsole, {
     label: 'Create Console for Notebook',
     execute: args => {

+ 8 - 3
packages/notebook/src/widget.ts

@@ -398,6 +398,13 @@ class StaticNotebook extends Widget {
    * Create a cell widget and insert into the notebook.
    */
   private _insertCell(index: number, cell: ICellModel): void {
+    let widget  = this.createCell(cell);
+    let layout = this.layout as PanelLayout;
+    layout.insertWidget(index, widget);
+    this.onCellInserted(index, widget);
+  }
+
+  createCell(cell: ICellModel): Cell {
     let widget: Cell;
     switch (cell.type) {
     case 'code':
@@ -411,9 +418,7 @@ class StaticNotebook extends Widget {
       widget = this._createRawCell(cell as IRawCellModel);
     }
     widget.addClass(NB_CELL_CLASS);
-    let layout = this.layout as PanelLayout;
-    layout.insertWidget(index, widget);
-    this.onCellInserted(index, widget);
+    return widget;
   }
 
   /**