diff --git a/src/sql/workbench/contrib/notebook/browser/models/diffNotebookInput.ts b/src/sql/workbench/contrib/notebook/browser/models/diffNotebookInput.ts index 9fbcf5b419..0c7dcbc824 100644 --- a/src/sql/workbench/contrib/notebook/browser/models/diffNotebookInput.ts +++ b/src/sql/workbench/contrib/notebook/browser/models/diffNotebookInput.ts @@ -24,8 +24,8 @@ export class DiffNotebookInput extends SideBySideEditorInput { @INotebookService notebookService: INotebookService, @ILogService logService: ILogService ) { - let originalInput = instantiationService.createInstance(FileNotebookInput, diffInput.primary.getName(), diffInput.primary.resource, diffInput.originalInput as FileEditorInput); - let modifiedInput = instantiationService.createInstance(FileNotebookInput, diffInput.secondary.getName(), diffInput.secondary.resource, diffInput.modifiedInput as FileEditorInput); + let originalInput = instantiationService.createInstance(FileNotebookInput, diffInput.primary.getName(), diffInput.primary.resource, diffInput.originalInput as FileEditorInput, false); + let modifiedInput = instantiationService.createInstance(FileNotebookInput, diffInput.secondary.getName(), diffInput.secondary.resource, diffInput.modifiedInput as FileEditorInput, false); super(title, diffInput.getTitle(), modifiedInput, originalInput); this._notebookService = notebookService; this._logService = logService; diff --git a/src/sql/workbench/contrib/notebook/browser/models/fileNotebookInput.ts b/src/sql/workbench/contrib/notebook/browser/models/fileNotebookInput.ts index aa57ad71a1..78e008e542 100644 --- a/src/sql/workbench/contrib/notebook/browser/models/fileNotebookInput.ts +++ b/src/sql/workbench/contrib/notebook/browser/models/fileNotebookInput.ts @@ -18,12 +18,13 @@ export class FileNotebookInput extends NotebookInput { title: string, resource: URI, textInput: FileEditorInput, + showActions: boolean, @ITextModelService textModelService: ITextModelService, @IInstantiationService instantiationService: IInstantiationService, @INotebookService notebookService: INotebookService, @IExtensionService extensionService: IExtensionService ) { - super(title, resource, textInput, textModelService, instantiationService, notebookService, extensionService); + super(title, resource, textInput, showActions, textModelService, instantiationService, notebookService, extensionService); } public override get textInput(): FileEditorInput { diff --git a/src/sql/workbench/contrib/notebook/browser/models/notebookInput.ts b/src/sql/workbench/contrib/notebook/browser/models/notebookInput.ts index b58982244a..a6dffb384c 100644 --- a/src/sql/workbench/contrib/notebook/browser/models/notebookInput.ts +++ b/src/sql/workbench/contrib/notebook/browser/models/notebookInput.ts @@ -237,6 +237,7 @@ export abstract class NotebookInput extends EditorInput implements INotebookInpu constructor(private _title: string, private _resource: URI, private _textInput: TextInput, + private _showActions: boolean, @ITextModelService private textModelService: ITextModelService, @IInstantiationService private instantiationService: IInstantiationService, @INotebookService private notebookService: INotebookService, @@ -515,6 +516,10 @@ export abstract class NotebookInput extends EditorInput implements INotebookInpu return this.textInput.matches(otherInput); } } + + public get showActions(): boolean { + return this._showActions; + } } export class NotebookEditorContentLoader implements IContentLoader { diff --git a/src/sql/workbench/contrib/notebook/browser/models/notebookInputFactory.ts b/src/sql/workbench/contrib/notebook/browser/models/notebookInputFactory.ts index 518ca1cd81..025734d229 100644 --- a/src/sql/workbench/contrib/notebook/browser/models/notebookInputFactory.ts +++ b/src/sql/workbench/contrib/notebook/browser/models/notebookInputFactory.ts @@ -31,7 +31,7 @@ export class NotebookEditorInputAssociation implements ILanguageAssociation { convertInput(activeEditor: IEditorInput): NotebookInput | DiffNotebookInput | undefined { if (activeEditor instanceof FileEditorInput) { - return this.instantiationService.createInstance(FileNotebookInput, activeEditor.getName(), activeEditor.resource, activeEditor); + return this.instantiationService.createInstance(FileNotebookInput, activeEditor.getName(), activeEditor.resource, activeEditor, true); } else if (activeEditor instanceof UntitledTextEditorInput) { return this.instantiationService.createInstance(UntitledNotebookInput, activeEditor.getName(), activeEditor.resource, activeEditor); } else if (activeEditor instanceof DiffEditorInput) { @@ -65,7 +65,7 @@ export class FileNoteBookEditorInputSerializer implements IEditorInputSerializer deserialize(instantiationService: IInstantiationService, serializedEditorInput: string): FileNotebookInput | undefined { const factory = editorInputFactoryRegistry.getEditorInputSerializer(FILE_EDITOR_INPUT_ID); const fileEditorInput = factory.deserialize(instantiationService, serializedEditorInput) as FileEditorInput; - return instantiationService.createInstance(FileNotebookInput, fileEditorInput.getName(), fileEditorInput.resource, fileEditorInput); + return instantiationService.createInstance(FileNotebookInput, fileEditorInput.getName(), fileEditorInput.resource, fileEditorInput, true); } canSerialize(): boolean { // we can always serialize notebooks diff --git a/src/sql/workbench/contrib/notebook/browser/models/untitledNotebookInput.ts b/src/sql/workbench/contrib/notebook/browser/models/untitledNotebookInput.ts index b5167cfa39..a518424e4b 100644 --- a/src/sql/workbench/contrib/notebook/browser/models/untitledNotebookInput.ts +++ b/src/sql/workbench/contrib/notebook/browser/models/untitledNotebookInput.ts @@ -25,7 +25,7 @@ export class UntitledNotebookInput extends NotebookInput { @INotebookService notebookService: INotebookService, @IExtensionService extensionService: IExtensionService ) { - super(title, resource, textInput, textModelService, instantiationService, notebookService, extensionService); + super(title, resource, textInput, true, textModelService, instantiationService, notebookService, extensionService); } public override get textInput(): UntitledTextEditorInput { diff --git a/src/sql/workbench/contrib/notebook/browser/notebook.component.ts b/src/sql/workbench/contrib/notebook/browser/notebook.component.ts index 24d9c32180..6d32177edc 100644 --- a/src/sql/workbench/contrib/notebook/browser/notebook.component.ts +++ b/src/sql/workbench/contrib/notebook/browser/notebook.component.ts @@ -86,6 +86,8 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe public previewFeaturesEnabled: boolean = false; public doubleClickEditEnabled: boolean; private _onScroll = new Emitter(); + // Don't show the right hand toolbar actions if the notebook is created in a diff editor. + private _showToolbarActions: boolean = this._notebookParams.input.showActions; constructor( @Inject(forwardRef(() => ChangeDetectorRef)) private _changeRef: ChangeDetectorRef, @@ -481,12 +483,15 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe { element: kernelContainer }, { element: attachToContainer }, { element: spacerElement }, - { element: viewsDropdownContainer }, - { action: collapseCellsAction }, - { action: clearResultsButton }, - { action: this._trustedAction }, - { action: runParametersAction }, ]); + + if (this._showToolbarActions) { + this._actionBar.addElement(viewsDropdownContainer); + this._actionBar.addAction(collapseCellsAction); + this._actionBar.addAction(clearResultsButton); + this._actionBar.addAction(this._trustedAction); + this._actionBar.addAction(runParametersAction); + } } else { let kernelContainer = document.createElement('div'); let kernelDropdown = this.instantiationService.createInstance(KernelsDropdown, kernelContainer, this.contextViewService, this.modelReady); @@ -523,11 +528,14 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe { action: addTextCellButton }, { element: kernelContainer }, { element: attachToContainer }, - { action: this._trustedAction }, { action: this._runAllCellsAction }, - { action: clearResultsButton }, - { action: collapseCellsAction }, ]); + + if (this._showToolbarActions) { + this._actionBar.addAction(this._trustedAction); + this._actionBar.addAction(clearResultsButton); + this._actionBar.addAction(collapseCellsAction); + } } } @@ -589,12 +597,14 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe * the primary array to the end of the toolbar. */ private fillInActionsForCurrentContext(): void { - let primary: IAction[] = []; - let secondary: IAction[] = []; - let notebookBarMenu = this.menuService.createMenu(MenuId.NotebookToolbar, this.contextKeyService); - let groups = notebookBarMenu.getActions({ arg: null, shouldForwardArgs: true }); - fillInActions(groups, { primary, secondary }, false, g => g === '', Number.MAX_SAFE_INTEGER, (action: SubmenuAction, group: string, groupSize: number) => group === undefined || group === ''); - this.addPrimaryContributedActions(primary); + if (this._showToolbarActions) { + let primary: IAction[] = []; + let secondary: IAction[] = []; + let notebookBarMenu = this.menuService.createMenu(MenuId.NotebookToolbar, this.contextKeyService); + let groups = notebookBarMenu.getActions({ arg: null, shouldForwardArgs: true }); + fillInActions(groups, { primary, secondary }, false, g => g === '', Number.MAX_SAFE_INTEGER, (action: SubmenuAction, group: string, groupSize: number) => group === undefined || group === ''); + this.addPrimaryContributedActions(primary); + } } private detectChanges(): void { diff --git a/src/sql/workbench/contrib/notebook/test/browser/notebookInput.test.ts b/src/sql/workbench/contrib/notebook/test/browser/notebookInput.test.ts index 2b87d375ec..9a49114c66 100644 --- a/src/sql/workbench/contrib/notebook/test/browser/notebookInput.test.ts +++ b/src/sql/workbench/contrib/notebook/test/browser/notebookInput.test.ts @@ -66,7 +66,7 @@ suite('Notebook Input', function (): void { test('File Notebook Input', async function (): Promise { let fileUri = URI.from({ scheme: Schemas.file, path: 'TestPath' }); let fileNotebookInput = new FileNotebookInput( - testTitle, fileUri, undefined, + testTitle, fileUri, undefined, true, undefined, instantiationService, mockNotebookService.object, mockExtensionService.object); let inputId = fileNotebookInput.typeId; diff --git a/src/sql/workbench/services/notebook/browser/interface.ts b/src/sql/workbench/services/notebook/browser/interface.ts index b0d18b85e1..96b753f6de 100644 --- a/src/sql/workbench/services/notebook/browser/interface.ts +++ b/src/sql/workbench/services/notebook/browser/interface.ts @@ -20,6 +20,7 @@ export interface INotebookInput { readonly contentLoader: IContentLoader; readonly standardKernels: IStandardKernelWithProvider[]; readonly providersLoaded: Promise; + readonly showActions: boolean; } export function isINotebookInput(value: any): value is INotebookInput {