diff --git a/src/sql/parts/notebook/cellViews/textCell.component.html b/src/sql/parts/notebook/cellViews/textCell.component.html index 98265758f8..e770ff98aa 100644 --- a/src/sql/parts/notebook/cellViews/textCell.component.html +++ b/src/sql/parts/notebook/cellViews/textCell.component.html @@ -6,8 +6,8 @@ -->
- +
-
+
diff --git a/src/sql/parts/notebook/cellViews/textCell.component.ts b/src/sql/parts/notebook/cellViews/textCell.component.ts index 7ff14e4e06..829ec38fc3 100644 --- a/src/sql/parts/notebook/cellViews/textCell.component.ts +++ b/src/sql/parts/notebook/cellViews/textCell.component.ts @@ -24,6 +24,7 @@ export class TextCellComponent extends CellView implements OnInit { @ViewChild('preview', { read: ElementRef }) private output: ElementRef; @Input() cellModel: ICellModel; private _content: string; + private isEditMode: boolean; constructor( @Inject(forwardRef(() => CommonServiceInterface)) private _bootstrapService: CommonServiceInterface, @Inject(forwardRef(() => ChangeDetectorRef)) private _changeRef: ChangeDetectorRef, @@ -31,6 +32,7 @@ export class TextCellComponent extends CellView implements OnInit { @Inject(ICommandService) private _commandService: ICommandService ) { super(); + this.isEditMode = true; } ngOnChanges() { @@ -41,7 +43,7 @@ export class TextCellComponent extends CellView implements OnInit { if (this._content !== this.cellModel.source) { this._content = this.cellModel.source; // todo: pass in the notebook filename instead of undefined value - this._commandService.executeCommand('notebook.showPreview', undefined, this._content).then((htmlcontent) => { + this._commandService.executeCommand('notebook.showPreview', undefined, this._content).then((htmlcontent) => { let outputElement = this.output.nativeElement; outputElement.innerHTML = htmlcontent; }); @@ -65,4 +67,9 @@ export class TextCellComponent extends CellView implements OnInit { public handleContentChanged(): void { this.updatePreview(); } + + public toggleEditMode(): void { + this.isEditMode = !this.isEditMode; + this._changeRef.detectChanges(); + } } diff --git a/src/sql/parts/notebook/notebook.component.html b/src/sql/parts/notebook/notebook.component.html index 0715fc62b6..16f106af6c 100644 --- a/src/sql/parts/notebook/notebook.component.html +++ b/src/sql/parts/notebook/notebook.component.html @@ -11,7 +11,7 @@
-
+
diff --git a/src/sql/parts/notebook/notebook.component.ts b/src/sql/parts/notebook/notebook.component.ts index ccaa9eb1ba..2b529cd88d 100644 --- a/src/sql/parts/notebook/notebook.component.ts +++ b/src/sql/parts/notebook/notebook.component.ts @@ -89,4 +89,28 @@ export class NotebookComponent extends AngularDisposable implements OnInit { this._changeRef.detectChanges(); } } + + public onKeyDown(event) { + switch (event.key) { + case 'ArrowDown': + case 'ArrowRight': + let nextIndex = (this.findCellIndex(this._activeCell) + 1)%this.cells.length; + this.selectCell(this.cells[nextIndex]); + break; + case 'ArrowUp': + case 'ArrowLeft': + let index = this.findCellIndex(this._activeCell); + if (index === 0) { + index = this.cells.length; + } + this.selectCell(this.cells[--index]); + break; + default: + break; + } + } + + findCellIndex(cellModel: ICellModel): number { + return this.cells.findIndex((cell) => cell.id === cellModel.id); + } } diff --git a/src/sql/services/notebook/localContentManager.ts b/src/sql/services/notebook/localContentManager.ts new file mode 100644 index 0000000000..4d539fda5b --- /dev/null +++ b/src/sql/services/notebook/localContentManager.ts @@ -0,0 +1,32 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the Source EULA. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; +import { nb } from 'sqlops'; + +import * as json from 'vs/base/common/json'; +import * as pfs from 'vs/base/node/pfs'; + +import ContentManager = nb.ContentManager; +import INotebook = nb.INotebook; + +export class LocalContentManager implements ContentManager { + public async getNotebookContents(path: string): Promise { + if (!path) { + return undefined; + } + // Note: intentionally letting caller handle exceptions + let notebookFileBuffer = await pfs.readFile(path); + return json.parse(notebookFileBuffer.toString()); + } + + public async save(path: string, notebook: INotebook): Promise { + // Convert to JSON with pretty-print functionality + let contents = JSON.stringify(notebook, undefined, ' '); + await pfs.writeFile(path, contents); + return notebook; + } + +} diff --git a/src/sql/services/notebook/notebookServiceImpl.ts b/src/sql/services/notebook/notebookServiceImpl.ts index 629c96b044..af8db2c2f7 100644 --- a/src/sql/services/notebook/notebookServiceImpl.ts +++ b/src/sql/services/notebook/notebookServiceImpl.ts @@ -7,8 +7,11 @@ import { nb } from 'sqlops'; import * as nls from 'vs/nls'; -import { INotebookService, INotebookManager, INotebookProvider } from 'sql/services/notebook/notebookService'; +import { INotebookService, INotebookManager, INotebookProvider, DEFAULT_NOTEBOOK_PROVIDER } from 'sql/services/notebook/notebookService'; import URI from 'vs/base/common/uri'; +import { LocalContentManager } from 'sql/services/notebook/localContentManager'; +import { session } from 'electron'; +import { SessionManager } from 'sql/services/notebook/sessionManager'; export class NotebookService implements INotebookService { _serviceBrand: any; @@ -16,6 +19,11 @@ export class NotebookService implements INotebookService { private _providers: Map = new Map(); private _managers: Map = new Map(); + constructor() { + let defaultProvider = new BuiltinProvider(); + this.registerProvider(defaultProvider.providerId, defaultProvider); + } + registerProvider(providerId: string, provider: INotebookProvider): void { this._providers.set(providerId, provider); } @@ -57,4 +65,48 @@ export class NotebookService implements INotebookService { return op(provider); } -} \ No newline at end of file +} + +export class BuiltinProvider implements INotebookProvider { + private manager: BuiltInNotebookManager; + + constructor() { + this.manager = new BuiltInNotebookManager(); + } + public get providerId(): string { + return DEFAULT_NOTEBOOK_PROVIDER; + } + + getNotebookManager(notebookUri: URI): Thenable { + return Promise.resolve(this.manager); + } + handleNotebookClosed(notebookUri: URI): void { + // No-op + } +} + +export class BuiltInNotebookManager implements INotebookManager { + private _contentManager: nb.ContentManager; + private _sessionManager: nb.SessionManager; + + constructor() { + this._contentManager = new LocalContentManager(); + this._sessionManager = new SessionManager(); + } + public get providerId(): string { + return DEFAULT_NOTEBOOK_PROVIDER; + } + + public get contentManager(): nb.ContentManager { + return this._contentManager; + } + + public get serverManager(): nb.ServerManager { + return undefined; + } + + public get sessionManager(): nb.SessionManager { + return this._sessionManager; + } + +} diff --git a/src/sql/services/notebook/sessionManager.ts b/src/sql/services/notebook/sessionManager.ts new file mode 100644 index 0000000000..5ac4dc1f0a --- /dev/null +++ b/src/sql/services/notebook/sessionManager.ts @@ -0,0 +1,31 @@ +'use strict'; + +import { nb } from 'sqlops'; +import { Session } from 'electron'; + +export class SessionManager implements nb.SessionManager { + private _sessionManager: nb.SessionManager; + + constructor() { + + } + public get isReady(): boolean { + return this._sessionManager.isReady; + } + + public get ready(): Thenable { + return this._sessionManager.ready; + } + public get specs(): nb.IAllKernels { + return this._sessionManager.specs; + } + + startNew(options: nb.ISessionOptions): Thenable { + return this._sessionManager.startNew(options); + } + + shutdown(id: string): Thenable { + return this.shutdown(id); + } + +}