Add saved and executed events to notebook changed (#5848)

- Updated the notebook API to add a change kind, and support saved, executed and other simplified status
- Plumbed this through to the main thread classes
- Support sending the events from cell / input to the notebook model so they loop over the extension host as a content changed event
- Add executed event from the cell
This commit is contained in:
Kevin Cunnane
2019-06-05 16:34:26 -07:00
committed by GitHub
parent 7d67711336
commit 44d6bb66da
20 changed files with 128 additions and 29 deletions

View File

@@ -39,7 +39,7 @@ export class OutputComponent extends AngularDisposable implements OnInit {
@Inject(IThemeService) private _themeService: IThemeService
) {
super();
this.registry = _notebookService.getMimeRegistry();
this.registry = this._notebookService.getMimeRegistry();
}
ngOnInit() {

View File

@@ -13,11 +13,13 @@ import * as notebookUtils from '../notebookUtils';
import { CellTypes, CellType, NotebookChangeType } from 'sql/workbench/parts/notebook/models/contracts';
import { NotebookModel } from 'sql/workbench/parts/notebook/models/notebookModel';
import { ICellModel, notebookConstants, IOutputChangedEvent } from 'sql/workbench/parts/notebook/models/modelInterfaces';
import { ICellModelOptions, IModelFactory, FutureInternal, CellExecutionState } from './modelInterfaces';
import { ICellModelOptions, FutureInternal, CellExecutionState } from './modelInterfaces';
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
import { Schemas } from 'vs/base/common/network';
import { INotebookService } from 'sql/workbench/services/notebook/common/notebookService';
import { optional } from 'vs/platform/instantiation/common/instantiation';
let modelId = 0;
export class CellModel implements ICellModel {
@@ -39,7 +41,10 @@ export class CellModel implements ICellModel {
private _connectionManagementService: IConnectionManagementService;
private _stdInHandler: nb.MessageHandler<nb.IStdinMessage>;
constructor(private factory: IModelFactory, cellData?: nb.ICellContents, private _options?: ICellModelOptions) {
constructor(cellData: nb.ICellContents,
private _options: ICellModelOptions,
@optional(INotebookService) private _notebookService?: INotebookService
) {
this.id = `${modelId++}`;
if (cellData) {
// Read in contents if available
@@ -178,6 +183,12 @@ export class CellModel implements ICellModel {
this._onExecutionStateChanged.fire(this.executionState);
}
private notifyExecutionComplete(): void {
if (this._notebookService) {
this._notebookService.serializeNotebookStateChange(this.notebookModel.notebookUri, NotebookChangeType.CellExecuted);
}
}
public get executionState(): CellExecutionState {
let isRunning = !!(this._future && this._future.inProgress);
if (isRunning) {
@@ -256,6 +267,7 @@ export class CellModel implements ICellModel {
} finally {
this.disposeFuture();
this.fireExecutionStateChanged();
this.notifyExecutionComplete();
}
return true;

View File

@@ -43,5 +43,7 @@ export enum NotebookChangeType {
CellOutputUpdated,
DirtyStateChanged,
KernelChanged,
TrustChanged
TrustChanged,
Saved,
CellExecuted
}

View File

@@ -8,11 +8,15 @@ import { nb } from 'azdata';
import { CellModel } from './cell';
import { IClientSession, IClientSessionOptions, ICellModelOptions, ICellModel, IModelFactory } from './modelInterfaces';
import { ClientSession } from './clientSession';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
export class ModelFactory implements IModelFactory {
constructor(private instantiationService: IInstantiationService) {
}
public createCell(cell: nb.ICellContents, options: ICellModelOptions): ICellModel {
return new CellModel(this, cell, options);
return this.instantiationService.createInstance(CellModel, cell, options);
}
public createClientSession(options: IClientSessionOptions): IClientSession {

View File

@@ -401,6 +401,9 @@ export interface INotebookModel {
/** Event fired once we get call back from ConfigureConnection method in sqlops extension */
readonly onValidConnectionSelected: Event<boolean>;
serializationStateChanged(changeType: NotebookChangeType): void;
}
export interface NotebookContentChange {

View File

@@ -954,4 +954,13 @@ export class NotebookModel extends Disposable implements INotebookModel {
this._contentChangedEmitter.fire(changeInfo);
}
serializationStateChanged(changeType: NotebookChangeType): void {
let changeInfo: NotebookContentChange = {
changeType: changeType,
cells: undefined
};
this._contentChangedEmitter.fire(changeInfo);
}
}

View File

@@ -345,7 +345,7 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
private get modelFactory(): IModelFactory {
if (!this._notebookParams.modelFactory) {
this._notebookParams.modelFactory = new ModelFactory();
this._notebookParams.modelFactory = new ModelFactory(this.instantiationService);
}
return this._notebookParams.modelFactory;
}

View File

@@ -11,7 +11,7 @@ import * as resources from 'vs/base/common/resources';
import * as azdata from 'azdata';
import { IStandardKernelWithProvider, getProvidersForFileName, getStandardKernelsForProvider } from 'sql/workbench/parts/notebook/notebookUtils';
import { INotebookService, DEFAULT_NOTEBOOK_PROVIDER, IProviderInfo, SerializationStateChangeType } from 'sql/workbench/services/notebook/common/notebookService';
import { INotebookService, DEFAULT_NOTEBOOK_PROVIDER, IProviderInfo } from 'sql/workbench/services/notebook/common/notebookService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
import { INotebookModel, IContentManager, NotebookContentChange } from 'sql/workbench/parts/notebook/models/modelInterfaces';
@@ -118,7 +118,7 @@ export class NotebookEditorModel extends EditorModel {
private sendNotebookSerializationStateChange() {
let notebookModel = this.getNotebookModel();
if (notebookModel) {
this.notebookService.serializeNotebookStateChange(this.notebookUri, SerializationStateChangeType.Saved);
this.notebookService.serializeNotebookStateChange(this.notebookUri, NotebookChangeType.Saved);
}
}
@@ -127,7 +127,7 @@ export class NotebookEditorModel extends EditorModel {
}
private getNotebookModel(): INotebookModel {
let editor = this.notebookService.listNotebookEditors().find(n => n.id === this.notebookUri.toString());
let editor = this.notebookService.findNotebookEditor(this.notebookUri);
if (editor) {
return editor.model;
}