Pārlūkot izejas kodu

Delete configuration for cell collapse, scroll, and editable metadata syncing.

This forces all cells to synchronize the view and model metadata always for collapse state, output scrolled state, and editable (readonly) state. It removes the notebook configuration options for turning off this syncing, and removes the notebook tools widgets for controlling the syncing or changing the values.

We might introduce these later, but for now we are simplifying to the basic model that a cell’s visual state should directly represent this metadata at all times, which means that this visual state is saved automatically.

I think removing the notebook tools controls also means that we don’t have a good way to set a cell as readonly.
Jason Grout 6 gadi atpakaļ
vecāks
revīzija
a73737bd2e

+ 0 - 25
packages/notebook-extension/schema/tracker.json

@@ -329,31 +329,6 @@
       "description": "Whether to be able to scroll so the last cell is at the top of the panel",
       "type": "boolean",
       "default": true
-    },
-    "syncOptions": {
-      "title": "Metadata Sync options",
-      "description": "The metadata that is automatically synced.",
-      "properties": {
-        "scrolled": {
-          "type": "boolean",
-          "default": true
-        },
-        "editable": {
-          "type": "boolean",
-          "default": true
-        },
-        "collapsed": {
-          "type": "boolean",
-          "default": false
-        }
-      },
-      "default": {
-        "scrolled": true,
-        "editable": true,
-        "collapsed": true
-      },
-      "additionalProperties": false,
-      "type": "object"
     }
   },
   "additionalProperties": false,

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

@@ -391,13 +391,6 @@ function activateNotebookTools(
   const notebookTools = new NotebookTools({ tracker });
   const activeCellTool = new NotebookTools.ActiveCellTool();
   const slideShow = NotebookTools.createSlideShowSelector();
-  const scrolled = NotebookTools.createScrolledSelector();
-  const editable = NotebookTools.createEditableSelector();
-  const inputHidden = NotebookTools.createInputHiddenSelector();
-  const outputCollapsed = NotebookTools.createOutputCollapsedSelector();
-  const syncScrolledState = new NotebookTools.SyncScrolledState();
-  const syncEditableState = new NotebookTools.SyncEditableState();
-  const syncCollapsedState = new NotebookTools.SyncCollapsedState();
   const editorFactory = editorServices.factoryService.newInlineEditor;
   const cellMetadataEditor = new NotebookTools.CellMetadataEditorTool({
     editorFactory
@@ -445,21 +438,6 @@ function activateNotebookTools(
   notebookTools.title.caption = 'Notebook Tools';
   notebookTools.id = id;
 
-  notebookTools.addItem({
-    tool: syncScrolledState,
-    section: 'notebook',
-    rank: 1
-  });
-  notebookTools.addItem({
-    tool: syncCollapsedState,
-    section: 'notebook',
-    rank: 1
-  });
-  notebookTools.addItem({
-    tool: syncEditableState,
-    section: 'notebook',
-    rank: 1
-  });
   notebookTools.addItem({
     tool: notebookMetadataEditor,
     section: 'notebook',
@@ -467,10 +445,6 @@ function activateNotebookTools(
   });
 
   notebookTools.addItem({ tool: activeCellTool, section: 'cell', rank: 1 });
-  notebookTools.addItem({ tool: editable, section: 'cell', rank: 2 });
-  notebookTools.addItem({ tool: scrolled, section: 'cell', rank: 2 });
-  notebookTools.addItem({ tool: inputHidden, section: 'cell', rank: 2 });
-  notebookTools.addItem({ tool: outputCollapsed, section: 'cell', rank: 2 });
   notebookTools.addItem({ tool: slideShow, section: 'cell', rank: 2 });
   notebookTools.addItem({ tool: cellMetadataEditor, section: 'cell', rank: 4 });
   MessageLoop.installMessageHook(notebookTools, hook);
@@ -636,12 +610,7 @@ function activateNotebookHandler(
     });
     factory.editorConfig = editorConfig = { code, markdown, raw };
     factory.notebookConfig = notebookConfig = {
-      scrollPastEnd: settings.get('scrollPastEnd').composite as boolean,
-      syncOptions: settings.get('syncOptions').composite as {
-        scrolled: boolean;
-        editable: boolean;
-        collapsed: boolean;
-      }
+      scrollPastEnd: settings.get('scrollPastEnd').composite as boolean
     };
   }
 

+ 0 - 86
packages/notebook/src/celltools.ts

@@ -27,7 +27,6 @@ import { IObservableMap, ObservableJSON } from '@jupyterlab/observables';
 
 import { INotebookTracker } from './';
 import { NotebookPanel } from './panel';
-import { NotebookActions } from './actions';
 import { Collapse } from './collapse';
 
 /* tslint:disable */
@@ -386,91 +385,6 @@ export namespace NotebookTools {
     }
   }
 
-  /**
-   * A notebook-level convenience tool to sync state of the view and metadata.
-   */
-  export class SyncState extends Tool {
-    constructor() {
-      super();
-
-      this.node.innerHTML = `${this.label()}<br/>`;
-      const viewToMetadata = document.createElement('button');
-      viewToMetadata.textContent = 'Metadata <- View';
-      viewToMetadata.addEventListener('click', event => this.viewToMetadata());
-
-      const metadataToView = document.createElement('button');
-      metadataToView.textContent = 'Metadata -> View';
-      metadataToView.addEventListener('click', event => this.metadataToView());
-
-      this.node.appendChild(viewToMetadata);
-      this.node.appendChild(metadataToView);
-    }
-
-    protected label(): string {
-      return '';
-    }
-    protected viewToMetadata(): void {
-      /* no-op */
-    }
-    protected metadataToView(): void {
-      /* no-op */
-    }
-  }
-
-  export class SyncScrolledState extends SyncState {
-    protected label() {
-      return 'All Cell Scroll State: ';
-    }
-    protected viewToMetadata() {
-      const panel = this.notebookTools.notebookPanel;
-      if (panel) {
-        NotebookActions.saveScrollState(panel.content);
-      }
-    }
-    protected metadataToView() {
-      const panel = this.notebookTools.notebookPanel;
-      if (panel) {
-        NotebookActions.loadScrollState(panel.content);
-      }
-    }
-  }
-
-  export class SyncCollapsedState extends SyncState {
-    protected label() {
-      return 'All Cell Collapse State: ';
-    }
-    protected viewToMetadata() {
-      const panel = this.notebookTools.notebookPanel;
-      if (panel) {
-        NotebookActions.saveCollapseState(panel.content);
-      }
-    }
-    protected metadataToView() {
-      const panel = this.notebookTools.notebookPanel;
-      if (panel) {
-        NotebookActions.loadCollapseState(panel.content);
-      }
-    }
-  }
-
-  export class SyncEditableState extends SyncState {
-    protected label() {
-      return 'All Cell Editable State: ';
-    }
-    protected viewToMetadata() {
-      const panel = this.notebookTools.notebookPanel;
-      if (panel) {
-        NotebookActions.saveEditableState(panel.content);
-      }
-    }
-    protected metadataToView() {
-      const panel = this.notebookTools.notebookPanel;
-      if (panel) {
-        NotebookActions.loadEditableState(panel.content);
-      }
-    }
-  }
-
   /**
    * A cell tool displaying the active cell contents.
    */

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

@@ -476,10 +476,9 @@ export class StaticNotebook extends Widget {
       updateEditorOnShow: false
     };
     const cell = this.contentFactory.createCodeCell(options, this);
-    const { editable, collapsed, scrolled } = this._notebookConfig.syncOptions;
-    cell.syncCollapse = collapsed;
-    cell.syncEditable = editable;
-    cell.syncScrolled = scrolled;
+    cell.syncCollapse = true;
+    cell.syncEditable = true;
+    cell.syncScrolled = true;
     return cell;
   }
 
@@ -498,9 +497,8 @@ export class StaticNotebook extends Widget {
       updateEditorOnShow: false
     };
     const cell = this.contentFactory.createMarkdownCell(options, this);
-    const { editable, collapsed } = this._notebookConfig.syncOptions;
-    cell.syncCollapse = collapsed;
-    cell.syncEditable = editable;
+    cell.syncCollapse = true;
+    cell.syncEditable = true;
     return cell;
   }
 
@@ -517,9 +515,8 @@ export class StaticNotebook extends Widget {
       updateEditorOnShow: false
     };
     const cell = this.contentFactory.createRawCell(options, this);
-    const { editable, collapsed } = this._notebookConfig.syncOptions;
-    cell.syncCollapse = collapsed;
-    cell.syncEditable = editable;
+    cell.syncCollapse = true;
+    cell.syncEditable = true;
     return cell;
   }
 
@@ -611,16 +608,6 @@ export class StaticNotebook extends Widget {
       'jp-mod-scrollPastEnd',
       this._notebookConfig.scrollPastEnd
     );
-
-    // Apply cell sync settings.
-    const { editable, collapsed, scrolled } = this._notebookConfig.syncOptions;
-    this.widgets.forEach(cell => {
-      cell.syncCollapse = collapsed;
-      cell.syncEditable = editable;
-      if (cell.model.type === 'code') {
-        (cell as CodeCell).syncScrolled = scrolled;
-      }
-    });
   }
 
   private _editorConfig = StaticNotebook.defaultEditorConfig;
@@ -752,26 +739,12 @@ export namespace StaticNotebook {
      * Enable scrolling past the last cell
      */
     scrollPastEnd: boolean;
-
-    /**
-     * Synced properties
-     */
-    syncOptions: {
-      scrolled: boolean;
-      editable: boolean;
-      collapsed: boolean;
-    };
   }
   /**
    * Default configuration options for notebooks.
    */
   export const defaultNotebookConfig: INotebookConfig = {
-    scrollPastEnd: true,
-    syncOptions: {
-      scrolled: true,
-      editable: true,
-      collapsed: false
-    }
+    scrollPastEnd: true
   };
 
   /**