Hide notebook toolbar icons in diff editor (#17303)

* hide notebook toolbar icons in diff editor

* move showActions to notebookInput

* make showActions readonly
This commit is contained in:
Lucy Zhang
2021-10-15 05:19:14 -07:00
committed by GitHub
parent 58d5f317d3
commit e315115f00
8 changed files with 38 additions and 21 deletions

View File

@@ -24,8 +24,8 @@ export class DiffNotebookInput extends SideBySideEditorInput {
@INotebookService notebookService: INotebookService, @INotebookService notebookService: INotebookService,
@ILogService logService: ILogService @ILogService logService: ILogService
) { ) {
let originalInput = instantiationService.createInstance(FileNotebookInput, diffInput.primary.getName(), diffInput.primary.resource, diffInput.originalInput 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); let modifiedInput = instantiationService.createInstance(FileNotebookInput, diffInput.secondary.getName(), diffInput.secondary.resource, diffInput.modifiedInput as FileEditorInput, false);
super(title, diffInput.getTitle(), modifiedInput, originalInput); super(title, diffInput.getTitle(), modifiedInput, originalInput);
this._notebookService = notebookService; this._notebookService = notebookService;
this._logService = logService; this._logService = logService;

View File

@@ -18,12 +18,13 @@ export class FileNotebookInput extends NotebookInput {
title: string, title: string,
resource: URI, resource: URI,
textInput: FileEditorInput, textInput: FileEditorInput,
showActions: boolean,
@ITextModelService textModelService: ITextModelService, @ITextModelService textModelService: ITextModelService,
@IInstantiationService instantiationService: IInstantiationService, @IInstantiationService instantiationService: IInstantiationService,
@INotebookService notebookService: INotebookService, @INotebookService notebookService: INotebookService,
@IExtensionService extensionService: IExtensionService @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 { public override get textInput(): FileEditorInput {

View File

@@ -237,6 +237,7 @@ export abstract class NotebookInput extends EditorInput implements INotebookInpu
constructor(private _title: string, constructor(private _title: string,
private _resource: URI, private _resource: URI,
private _textInput: TextInput, private _textInput: TextInput,
private _showActions: boolean,
@ITextModelService private textModelService: ITextModelService, @ITextModelService private textModelService: ITextModelService,
@IInstantiationService private instantiationService: IInstantiationService, @IInstantiationService private instantiationService: IInstantiationService,
@INotebookService private notebookService: INotebookService, @INotebookService private notebookService: INotebookService,
@@ -515,6 +516,10 @@ export abstract class NotebookInput extends EditorInput implements INotebookInpu
return this.textInput.matches(otherInput); return this.textInput.matches(otherInput);
} }
} }
public get showActions(): boolean {
return this._showActions;
}
} }
export class NotebookEditorContentLoader implements IContentLoader { export class NotebookEditorContentLoader implements IContentLoader {

View File

@@ -31,7 +31,7 @@ export class NotebookEditorInputAssociation implements ILanguageAssociation {
convertInput(activeEditor: IEditorInput): NotebookInput | DiffNotebookInput | undefined { convertInput(activeEditor: IEditorInput): NotebookInput | DiffNotebookInput | undefined {
if (activeEditor instanceof FileEditorInput) { 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) { } else if (activeEditor instanceof UntitledTextEditorInput) {
return this.instantiationService.createInstance(UntitledNotebookInput, activeEditor.getName(), activeEditor.resource, activeEditor); return this.instantiationService.createInstance(UntitledNotebookInput, activeEditor.getName(), activeEditor.resource, activeEditor);
} else if (activeEditor instanceof DiffEditorInput) { } else if (activeEditor instanceof DiffEditorInput) {
@@ -65,7 +65,7 @@ export class FileNoteBookEditorInputSerializer implements IEditorInputSerializer
deserialize(instantiationService: IInstantiationService, serializedEditorInput: string): FileNotebookInput | undefined { deserialize(instantiationService: IInstantiationService, serializedEditorInput: string): FileNotebookInput | undefined {
const factory = editorInputFactoryRegistry.getEditorInputSerializer(FILE_EDITOR_INPUT_ID); const factory = editorInputFactoryRegistry.getEditorInputSerializer(FILE_EDITOR_INPUT_ID);
const fileEditorInput = factory.deserialize(instantiationService, serializedEditorInput) as FileEditorInput; 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 canSerialize(): boolean { // we can always serialize notebooks

View File

@@ -25,7 +25,7 @@ export class UntitledNotebookInput extends NotebookInput {
@INotebookService notebookService: INotebookService, @INotebookService notebookService: INotebookService,
@IExtensionService extensionService: IExtensionService @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 { public override get textInput(): UntitledTextEditorInput {

View File

@@ -86,6 +86,8 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
public previewFeaturesEnabled: boolean = false; public previewFeaturesEnabled: boolean = false;
public doubleClickEditEnabled: boolean; public doubleClickEditEnabled: boolean;
private _onScroll = new Emitter<void>(); private _onScroll = new Emitter<void>();
// 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( constructor(
@Inject(forwardRef(() => ChangeDetectorRef)) private _changeRef: ChangeDetectorRef, @Inject(forwardRef(() => ChangeDetectorRef)) private _changeRef: ChangeDetectorRef,
@@ -481,12 +483,15 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
{ element: kernelContainer }, { element: kernelContainer },
{ element: attachToContainer }, { element: attachToContainer },
{ element: spacerElement }, { 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 { } else {
let kernelContainer = document.createElement('div'); let kernelContainer = document.createElement('div');
let kernelDropdown = this.instantiationService.createInstance(KernelsDropdown, kernelContainer, this.contextViewService, this.modelReady); 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 }, { action: addTextCellButton },
{ element: kernelContainer }, { element: kernelContainer },
{ element: attachToContainer }, { element: attachToContainer },
{ action: this._trustedAction },
{ action: this._runAllCellsAction }, { 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. * the primary array to the end of the toolbar.
*/ */
private fillInActionsForCurrentContext(): void { private fillInActionsForCurrentContext(): void {
let primary: IAction[] = []; if (this._showToolbarActions) {
let secondary: IAction[] = []; let primary: IAction[] = [];
let notebookBarMenu = this.menuService.createMenu(MenuId.NotebookToolbar, this.contextKeyService); let secondary: IAction[] = [];
let groups = notebookBarMenu.getActions({ arg: null, shouldForwardArgs: true }); let notebookBarMenu = this.menuService.createMenu(MenuId.NotebookToolbar, this.contextKeyService);
fillInActions(groups, { primary, secondary }, false, g => g === '', Number.MAX_SAFE_INTEGER, (action: SubmenuAction, group: string, groupSize: number) => group === undefined || group === ''); let groups = notebookBarMenu.getActions({ arg: null, shouldForwardArgs: true });
this.addPrimaryContributedActions(primary); 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 { private detectChanges(): void {

View File

@@ -66,7 +66,7 @@ suite('Notebook Input', function (): void {
test('File Notebook Input', async function (): Promise<void> { test('File Notebook Input', async function (): Promise<void> {
let fileUri = URI.from({ scheme: Schemas.file, path: 'TestPath' }); let fileUri = URI.from({ scheme: Schemas.file, path: 'TestPath' });
let fileNotebookInput = new FileNotebookInput( let fileNotebookInput = new FileNotebookInput(
testTitle, fileUri, undefined, testTitle, fileUri, undefined, true,
undefined, instantiationService, mockNotebookService.object, mockExtensionService.object); undefined, instantiationService, mockNotebookService.object, mockExtensionService.object);
let inputId = fileNotebookInput.typeId; let inputId = fileNotebookInput.typeId;

View File

@@ -20,6 +20,7 @@ export interface INotebookInput {
readonly contentLoader: IContentLoader; readonly contentLoader: IContentLoader;
readonly standardKernels: IStandardKernelWithProvider[]; readonly standardKernels: IStandardKernelWithProvider[];
readonly providersLoaded: Promise<void>; readonly providersLoaded: Promise<void>;
readonly showActions: boolean;
} }
export function isINotebookInput(value: any): value is INotebookInput { export function isINotebookInput(value: any): value is INotebookInput {