From 1affc760e613eb79b1b71dea05adb45113d63edd Mon Sep 17 00:00:00 2001 From: Raj <44002319+rajmusuku@users.noreply.github.com> Date: Thu, 29 Nov 2018 14:10:16 -0800 Subject: [PATCH] Notebook save functionality through button (#3340) * 3268: Notebook save using button * 3268: Misc change * Handle promise while saving notebook * Async await functions to run action --- .../notebook/media/dark/save_inverse.svg | 1 + src/sql/parts/notebook/media/light/save.svg | 1 + src/sql/parts/notebook/notebook.component.ts | 11 ++++++---- src/sql/parts/notebook/notebook.css | 9 ++++++++ src/sql/parts/notebook/notebookActions.ts | 22 +++++++++++++++++++ 5 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 src/sql/parts/notebook/media/dark/save_inverse.svg create mode 100644 src/sql/parts/notebook/media/light/save.svg diff --git a/src/sql/parts/notebook/media/dark/save_inverse.svg b/src/sql/parts/notebook/media/dark/save_inverse.svg new file mode 100644 index 0000000000..1758622f77 --- /dev/null +++ b/src/sql/parts/notebook/media/dark/save_inverse.svg @@ -0,0 +1 @@ +save_inverse \ No newline at end of file diff --git a/src/sql/parts/notebook/media/light/save.svg b/src/sql/parts/notebook/media/light/save.svg new file mode 100644 index 0000000000..6ebd2a1d3c --- /dev/null +++ b/src/sql/parts/notebook/media/light/save.svg @@ -0,0 +1 @@ +save \ No newline at end of file diff --git a/src/sql/parts/notebook/notebook.component.ts b/src/sql/parts/notebook/notebook.component.ts index c3e72cc48e..33efd46f37 100644 --- a/src/sql/parts/notebook/notebook.component.ts +++ b/src/sql/parts/notebook/notebook.component.ts @@ -31,7 +31,7 @@ import { IConnectionProfile } from 'sql/parts/connection/common/interfaces'; import { Taskbar } from 'sql/base/browser/ui/taskbar/taskbar'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IContextMenuService, IContextViewService } from 'vs/platform/contextview/browser/contextView'; -import { KernelsDropdown, AttachToDropdown, AddCellAction, TrustedAction } from 'sql/parts/notebook/notebookActions'; +import { KernelsDropdown, AttachToDropdown, AddCellAction, TrustedAction, SaveNotebookAction } from 'sql/parts/notebook/notebookActions'; import { attachSelectBoxStyler } from 'vs/platform/theme/common/styler'; export const NOTEBOOK_SELECTOR: string = 'notebook-component'; @@ -252,15 +252,18 @@ export class NotebookComponent extends AngularDisposable implements OnInit { this._trustedAction = this.instantiationService.createInstance(TrustedAction, 'notebook.Trusted'); this._trustedAction.enabled = false; + let saveNotebookButton = this.instantiationService.createInstance(SaveNotebookAction, 'notebook.SaveNotebook', localize('save', 'Save'), 'notebook-button icon-save'); + let taskbar = this.toolbar.nativeElement; this._actionBar = new Taskbar(taskbar, this.contextMenuService); this._actionBar.context = this; this._actionBar.setContent([ { element: kernelContainer }, { element: attachToContainer }, - { action: addCodeCellButton}, - { action: addTextCellButton}, - { action: this._trustedAction} + { action: addCodeCellButton }, + { action: addTextCellButton }, + { action: saveNotebookButton }, + { action: this._trustedAction } ]); } diff --git a/src/sql/parts/notebook/notebook.css b/src/sql/parts/notebook/notebook.css index 3bf2adce55..155981d051 100644 --- a/src/sql/parts/notebook/notebook.css +++ b/src/sql/parts/notebook/notebook.css @@ -61,4 +61,13 @@ .vs-dark .notebookEditor .notebook-button.icon-notTrusted, .hc-black .notebookEditor .notebook-button.icon-notTrusted{ background-image: url("./media/dark/nottrusted_inverse.svg"); +} + +.notebookEditor .notebook-button.icon-save{ + background-image: url("./media/light/save.svg"); +} + +.vs-dark .notebookEditor .notebook-button.icon-save, +.hc-black .notebookEditor .notebook-button.icon-save{ + background-image: url("./media/dark/save_inverse.svg"); } \ No newline at end of file diff --git a/src/sql/parts/notebook/notebookActions.ts b/src/sql/parts/notebook/notebookActions.ts index 3b9dc00464..c0777acf85 100644 --- a/src/sql/parts/notebook/notebookActions.ts +++ b/src/sql/parts/notebook/notebookActions.ts @@ -48,6 +48,28 @@ export class AddCellAction extends Action { } } +export class SaveNotebookAction extends Action { + private static readonly notebookSavedMsg = localize('notebookSavedMsg', 'Notebook saved successfully.'); + private static readonly notebookFailedSaveMsg = localize('notebookFailedSaveMsg', 'Failed to save Notebook.'); + constructor( + id: string, label: string, cssClass: string, + @INotificationService private _notificationService: INotificationService + ) { + super(id, label, cssClass); + } + + public async run(context: NotebookComponent): TPromise { + const actions: INotificationActions = { primary: [] }; + let saved = await context.save(); + if (saved) { + this._notificationService.notify({ severity: Severity.Info, message: SaveNotebookAction.notebookSavedMsg, actions }); + } else { + this._notificationService.error(SaveNotebookAction.notebookFailedSaveMsg); + } + return saved; + } +} + export interface IToggleableState { baseClass?: string; shouldToggleTooltip?: boolean;