diff --git a/src/sql/parts/notebook/media/dark/save_inverse.svg b/src/sql/parts/notebook/media/dark/save_inverse.svg deleted file mode 100644 index 1758622f77..0000000000 --- a/src/sql/parts/notebook/media/dark/save_inverse.svg +++ /dev/null @@ -1 +0,0 @@ -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 deleted file mode 100644 index 6ebd2a1d3c..0000000000 --- a/src/sql/parts/notebook/media/light/save.svg +++ /dev/null @@ -1 +0,0 @@ -save \ No newline at end of file diff --git a/src/sql/parts/notebook/models/modelInterfaces.ts b/src/sql/parts/notebook/models/modelInterfaces.ts index 89bfadcf22..0148b75f39 100644 --- a/src/sql/parts/notebook/models/modelInterfaces.ts +++ b/src/sql/parts/notebook/models/modelInterfaces.ts @@ -370,12 +370,6 @@ export interface INotebookModel { */ deleteCell(cellModel: ICellModel): void; - /** - * Save the model to its backing content manager. - * Serializes the model and then calls through to save it - */ - saveModel(): Promise; - /** * Serialize notebook cell content to JSON */ diff --git a/src/sql/parts/notebook/models/notebookModel.ts b/src/sql/parts/notebook/models/notebookModel.ts index 40c8bf53a1..3c3988a692 100644 --- a/src/sql/parts/notebook/models/notebookModel.ts +++ b/src/sql/parts/notebook/models/notebookModel.ts @@ -766,20 +766,6 @@ export class NotebookModel extends Disposable implements INotebookModel { return name; } - public async saveModel(): Promise { - let notebook = this.toJSON(); - if (!notebook) { - return false; - } - // TODO: refactor ContentManager out from NotebookManager - await this.notebookManagers[0].contentManager.save(this._notebookOptions.notebookUri, notebook); - this._contentChangedEmitter.fire({ - changeType: NotebookChangeType.DirtyStateChanged, - isDirty: false - }); - return true; - } - private async updateKernelInfo(kernel: nb.IKernel): Promise { if (kernel) { try { diff --git a/src/sql/parts/notebook/notebook.component.ts b/src/sql/parts/notebook/notebook.component.ts index 8d52d303b6..e324fb9f45 100644 --- a/src/sql/parts/notebook/notebook.component.ts +++ b/src/sql/parts/notebook/notebook.component.ts @@ -18,12 +18,6 @@ import { IAction, Action, IActionItem } from 'vs/base/common/actions'; import { IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { fillInActions, LabeledMenuItemActionItem } from 'vs/platform/actions/browser/menuItemActionItem'; -import { Schemas } from 'vs/base/common/network'; -import { URI } from 'vs/base/common/uri'; -import { IHistoryService } from 'vs/workbench/services/history/common/history'; -import * as paths from 'vs/base/common/paths'; -import { IWindowService } from 'vs/platform/windows/common/windows'; -import { TPromise } from 'vs/base/common/winjs.base'; import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet'; import { VIEWLET_ID, IExtensionsViewlet } from 'vs/workbench/parts/extensions/common/extensions'; @@ -32,7 +26,7 @@ import { AngularDisposable } from 'sql/base/node/lifecycle'; import { CellTypes, CellType } from 'sql/parts/notebook/models/contracts'; import { ICellModel, IModelFactory, INotebookModel, NotebookContentChange, notebookConstants } from 'sql/parts/notebook/models/modelInterfaces'; import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement'; -import { INotebookService, INotebookParams, INotebookManager, INotebookEditor, DEFAULT_NOTEBOOK_FILETYPE, DEFAULT_NOTEBOOK_PROVIDER, SQL_NOTEBOOK_PROVIDER } from 'sql/workbench/services/notebook/common/notebookService'; +import { INotebookService, INotebookParams, INotebookManager, INotebookEditor, DEFAULT_NOTEBOOK_PROVIDER, SQL_NOTEBOOK_PROVIDER } from 'sql/workbench/services/notebook/common/notebookService'; import { IBootstrapParams } from 'sql/services/bootstrap/bootstrapService'; import { NotebookModel } from 'sql/parts/notebook/models/notebookModel'; import { ModelFactory } from 'sql/parts/notebook/models/modelFactory'; @@ -40,11 +34,10 @@ import * as notebookUtils from 'sql/parts/notebook/notebookUtils'; import { Deferred } from 'sql/base/common/promise'; import { IConnectionProfile } from 'sql/platform/connection/common/interfaces'; import { Taskbar } from 'sql/base/browser/ui/taskbar/taskbar'; -import { KernelsDropdown, AttachToDropdown, AddCellAction, TrustedAction, SaveNotebookAction } from 'sql/parts/notebook/notebookActions'; +import { KernelsDropdown, AttachToDropdown, AddCellAction, TrustedAction } from 'sql/parts/notebook/notebookActions'; import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/common/objectExplorerService'; import * as TaskUtilities from 'sql/workbench/common/taskUtilities'; import { ISingleNotebookEditOperation } from 'sql/workbench/api/common/sqlExtHostTypes'; -import { IResourceInput } from 'vs/platform/editor/common/editor'; import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService'; import { IEditorGroupsService } from 'vs/workbench/services/group/common/editorGroupsService'; import { IConnectionDialogService } from 'sql/workbench/services/connection/common/connectionDialogService'; @@ -90,11 +83,7 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe @Inject(IContextKeyService) private contextKeyService: IContextKeyService, @Inject(IMenuService) private menuService: IMenuService, @Inject(IKeybindingService) private keybindingService: IKeybindingService, - @Inject(IHistoryService) private historyService: IHistoryService, - @Inject(IWindowService) private windowService: IWindowService, @Inject(IViewletService) private viewletService: IViewletService, - @Inject(IUntitledEditorService) private untitledEditorService: IUntitledEditorService, - @Inject(IEditorGroupsService) private editorGroupService: IEditorGroupsService, @Inject(ICapabilitiesService) private capabilitiesService: ICapabilitiesService ) { super(); @@ -316,6 +305,7 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe } return this._notebookParams.modelFactory; } + private handleModelError(notification: INotification): void { this.notificationService.notify(notification); } @@ -367,8 +357,6 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe 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, { actionItemProvider: action => this.actionItemProvider(action as Action) }); this._actionBar.context = this; @@ -377,101 +365,11 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe { element: attachToContainer }, { action: addCodeCellButton }, { action: addTextCellButton }, - { action: saveNotebookButton }, { action: this._trustedAction } ]); } - // Gets file path from recent workspace in local - private getLastActiveFilePath(untitledResource: URI): string { - let fileName = untitledResource.path + '.' + DEFAULT_NOTEBOOK_FILETYPE.toLocaleLowerCase(); - - let lastActiveFile = this.historyService.getLastActiveFile(Schemas.file); - if (lastActiveFile) { - return URI.file(paths.join(paths.dirname(lastActiveFile.fsPath), fileName)).fsPath; - } - - let lastActiveFolder = this.historyService.getLastActiveWorkspaceRoot('file'); - if (lastActiveFolder) { - return URI.file(paths.join(lastActiveFolder.fsPath, fileName)).fsPath; - } - return fileName; - } - - promptForPath(defaultPath: string): TPromise { - return this.windowService.showSaveDialog({ - defaultPath: defaultPath, - filters: [{ name: localize('notebookFile', 'Notebook'), extensions: ['ipynb'] }] - }); - } - - // Entry point to save notebook - public async save(): Promise { - let self = this; - let notebookUri = this.notebookParams.notebookUri; - if (notebookUri.scheme === Schemas.untitled) { - let dialogPath = this.getLastActiveFilePath(notebookUri); - return this.promptForPath(dialogPath).then(path => { - if (path) { - let target = URI.file(path); - let resource = self._model.notebookUri; - self._model.notebookUri = target; - this.saveNotebook().then(result => { - if (result) { - return this.replaceUntitledNotebookEditor(resource, target); - } - return result; - }); - } - return false; // User clicks cancel - }); - } - else { - return await this.saveNotebook(); - } - } - - // Replaces untitled notebook editor with the saved file name - private async replaceUntitledNotebookEditor(resource: URI, target: URI): Promise { - let encodingOfSource = this.untitledEditorService.getEncoding(resource); - const replacement: IResourceInput = { - resource: target, - encoding: encodingOfSource, - options: { - pinned: true - } - }; - - return TPromise.join(this.editorGroupService.groups.map(g => - this.editorService.replaceEditors([{ - editor: { resource }, - replacement - }], g))).then(() => { - this.notebookService.renameNotebookEditor(resource, target, this); - return true; - }); - } - - private async saveNotebook(): Promise { - try { - let saved = await this._model.saveModel(); - if (saved) { - this.setDirty(false); - } - return saved; - } catch (err) { - this.notificationService.error(localize('saveFailed', 'Failed to save notebook: {0}', notebookUtils.getErrorMessage(err))); - return false; - } - } - - private setDirty(isDirty: boolean): void { - if (this._notebookParams.input) { - this._notebookParams.input.setDirty(isDirty); - } - } - private actionItemProvider(action: Action): IActionItem { // Check extensions to create ActionItem; otherwise, return undefined // This is similar behavior that exists in MenuItemActionItem diff --git a/src/sql/parts/notebook/notebook.css b/src/sql/parts/notebook/notebook.css index 45364a574b..b6078b40e1 100644 --- a/src/sql/parts/notebook/notebook.css +++ b/src/sql/parts/notebook/notebook.css @@ -68,19 +68,11 @@ 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"); -} - .moreActions .action-label.icon.toggle-more { height: 20px; width: 20px; } + .moreActions.actionhidden { visibility: hidden } diff --git a/src/sql/parts/notebook/notebookActions.ts b/src/sql/parts/notebook/notebookActions.ts index b7e7771d38..327abd2dfc 100644 --- a/src/sql/parts/notebook/notebookActions.ts +++ b/src/sql/parts/notebook/notebookActions.ts @@ -53,26 +53,6 @@ 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 }); - } - return saved; - } -} - export interface IToggleableState { baseClass?: string; shouldToggleTooltip?: boolean; diff --git a/src/sql/workbench/api/node/mainThreadNotebookDocumentsAndEditors.ts b/src/sql/workbench/api/node/mainThreadNotebookDocumentsAndEditors.ts index 4658d95f92..58f1498f68 100644 --- a/src/sql/workbench/api/node/mainThreadNotebookDocumentsAndEditors.ts +++ b/src/sql/workbench/api/node/mainThreadNotebookDocumentsAndEditors.ts @@ -77,7 +77,7 @@ class MainThreadNotebookEditor extends Disposable { } public save(): Thenable { - return this.editor.save(); + return this.editor.notebookParams.input.save(); } public matches(input: NotebookInput): boolean { diff --git a/src/sql/workbench/services/notebook/common/notebookService.ts b/src/sql/workbench/services/notebook/common/notebookService.ts index 0f19bd3988..7daf5a9fb5 100644 --- a/src/sql/workbench/services/notebook/common/notebookService.ts +++ b/src/sql/workbench/services/notebook/common/notebookService.ts @@ -106,7 +106,6 @@ export interface INotebookEditor { isDirty(): boolean; isActive(): boolean; isVisible(): boolean; - save(): Promise; executeEdits(edits: ISingleNotebookEditOperation[]): boolean; runCell(cell: ICellModel): Promise; } \ No newline at end of file diff --git a/src/sqltest/parts/notebook/common.ts b/src/sqltest/parts/notebook/common.ts index edd42b0979..3728a00778 100644 --- a/src/sqltest/parts/notebook/common.ts +++ b/src/sqltest/parts/notebook/common.ts @@ -89,9 +89,6 @@ export class NotebookModelStub implements INotebookModel { deleteCell(cellModel: ICellModel): void { throw new Error('Method not implemented.'); } - saveModel(): Promise { - throw new Error('Method not implemented.'); - } pushEditOperations(edits: ISingleNotebookEditOperation[]): void { throw new Error('Method not implemented.'); }