|
@@ -5,10 +5,6 @@ import {
|
|
|
IKernel, KernelStatus
|
|
|
} from 'jupyter-js-services';
|
|
|
|
|
|
-import {
|
|
|
- showDialog
|
|
|
-} from '../../dialog';
|
|
|
-
|
|
|
import {
|
|
|
IDocumentContext
|
|
|
} from '../../docregistry';
|
|
@@ -268,18 +264,37 @@ class CellTypeSwitcher extends Widget {
|
|
|
constructor(panel: NotebookPanel) {
|
|
|
super();
|
|
|
this.addClass(TOOLBAR_CELLTYPE);
|
|
|
+
|
|
|
let select = this.node.firstChild as HTMLSelectElement;
|
|
|
- // Set the initial value.
|
|
|
- let index = panel.content.activeCellIndex;
|
|
|
- select.value = panel.model.cells.get(index).type;
|
|
|
+ // Change current cell type on a change in the dropdown.
|
|
|
+ select.addEventListener('change', event => {
|
|
|
+ if (!this._changeGuard) {
|
|
|
+ NotebookActions.changeCellType(panel.content, select.value);
|
|
|
+ }
|
|
|
+ });
|
|
|
// Follow the type of the current cell.
|
|
|
panel.content.stateChanged.connect((sender, args) => {
|
|
|
+ if (!panel.model) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (args.name === 'activeCellIndex') {
|
|
|
this._changeGuard = true;
|
|
|
select.value = panel.model.cells.get(args.newValue).type;
|
|
|
this._changeGuard = false;
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ panel.content.modelChanged.connect(() => { this.followModel(); });
|
|
|
+ if (panel.model) {
|
|
|
+ this.followModel();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ followModel(): void {
|
|
|
+ let select = this.node.firstChild as HTMLSelectElement;
|
|
|
+ // Set the initial value.
|
|
|
+ let index = panel.content.activeCellIndex;
|
|
|
+ select.value = panel.model.cells.get(index).type;
|
|
|
// Follow a change in the cells.
|
|
|
panel.content.model.cells.changed.connect((sender, args) => {
|
|
|
index = panel.content.activeCellIndex;
|
|
@@ -287,15 +302,8 @@ class CellTypeSwitcher extends Widget {
|
|
|
select.value = panel.model.cells.get(index).type;
|
|
|
this._changeGuard = false;
|
|
|
});
|
|
|
- // Change current cell type on a change in the dropdown.
|
|
|
- select.addEventListener('change', event => {
|
|
|
- if (!this._changeGuard) {
|
|
|
- NotebookActions.changeCellType(panel.content, select.value);
|
|
|
- }
|
|
|
- });
|
|
|
}
|
|
|
|
|
|
-
|
|
|
private _changeGuard = false;
|
|
|
}
|
|
|
|