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,
@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;

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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

View File

@@ -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 {

View File

@@ -86,6 +86,8 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
public previewFeaturesEnabled: boolean = false;
public doubleClickEditEnabled: boolean;
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(
@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 {

View File

@@ -66,7 +66,7 @@ suite('Notebook Input', function (): void {
test('File Notebook Input', async function (): Promise<void> {
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;

View File

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