From 432961cb0dc9b032e09bb3cf3ea990202704e54d Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Sun, 26 Jan 2020 09:29:34 +0100 Subject: [PATCH] editors - let resource editor extend text editor --- .../common/editor/resourceEditorInput.ts | 43 ++++--------------- .../contrib/output/browser/logViewer.ts | 5 ++- .../electron-browser/perfviewEditor.ts | 7 ++- .../common/preferencesEditorInput.ts | 6 ++- 4 files changed, 21 insertions(+), 40 deletions(-) diff --git a/src/vs/workbench/common/editor/resourceEditorInput.ts b/src/vs/workbench/common/editor/resourceEditorInput.ts index c97918ed39a..25ce5ca8fb4 100644 --- a/src/vs/workbench/common/editor/resourceEditorInput.ts +++ b/src/vs/workbench/common/editor/resourceEditorInput.ts @@ -3,21 +3,21 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { EditorInput, ITextEditorModel, IModeSupport, GroupIdentifier, isTextEditor } from 'vs/workbench/common/editor'; +import { ITextEditorModel, IModeSupport, TextEditorInput } from 'vs/workbench/common/editor'; import { URI } from 'vs/base/common/uri'; import { IReference } from 'vs/base/common/lifecycle'; import { ITextModelService } from 'vs/editor/common/services/resolverService'; import { ResourceEditorModel } from 'vs/workbench/common/editor/resourceEditorModel'; import { basename } from 'vs/base/common/resources'; -import { ITextFileSaveOptions, ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; -import { IEditorViewState } from 'vs/editor/common/editorCommon'; +import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; +import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; /** * A read-only text editor input whos contents are made of the provided resource that points to an existing * code editor model. */ -export class ResourceEditorInput extends EditorInput implements IModeSupport { +export class ResourceEditorInput extends TextEditorInput implements IModeSupport { static readonly ID: string = 'workbench.editors.resourceEditorInput'; @@ -27,17 +27,14 @@ export class ResourceEditorInput extends EditorInput implements IModeSupport { constructor( private name: string | undefined, private description: string | undefined, - private readonly resource: URI, + resource: URI, private preferredMode: string | undefined, @ITextModelService private readonly textModelResolverService: ITextModelService, - @ITextFileService private readonly textFileService: ITextFileService, - @IEditorService private readonly editorService: IEditorService + @ITextFileService textFileService: ITextFileService, + @IEditorService editorService: IEditorService, + @IEditorGroupsService editorGroupService: IEditorGroupsService ) { - super(); - - this.name = name; - this.description = description; - this.resource = resource; + super(resource, editorService, editorGroupService, textFileService); } getResource(): URI { @@ -109,28 +106,6 @@ export class ResourceEditorInput extends EditorInput implements IModeSupport { return model; } - async saveAs(group: GroupIdentifier, options?: ITextFileSaveOptions): Promise { - - // Preserve view state by opening the editor first. In addition - // this allows the user to review the contents of the editor. - let viewState: IEditorViewState | undefined = undefined; - const editor = await this.editorService.openEditor(this, undefined, group); - if (isTextEditor(editor)) { - viewState = editor.getViewState(); - } - - // Save as - const target = await this.textFileService.saveAs(this.resource, undefined, options); - if (!target) { - return false; // save cancelled - } - - // Open the target - await this.editorService.openEditor({ resource: target, options: { viewState, pinned: true } }, group); - - return true; - } - matches(otherInput: unknown): boolean { if (super.matches(otherInput) === true) { return true; diff --git a/src/vs/workbench/contrib/output/browser/logViewer.ts b/src/vs/workbench/contrib/output/browser/logViewer.ts index 33c74fdae1f..fab74175772 100644 --- a/src/vs/workbench/contrib/output/browser/logViewer.ts +++ b/src/vs/workbench/contrib/output/browser/logViewer.ts @@ -28,9 +28,10 @@ export class LogViewerInput extends ResourceEditorInput { private readonly outputChannelDescriptor: IFileOutputChannelDescriptor, @ITextModelService textModelResolverService: ITextModelService, @ITextFileService textFileService: ITextFileService, - @IEditorService editorService: IEditorService + @IEditorService editorService: IEditorService, + @IEditorGroupsService editorGroupService: IEditorGroupsService ) { - super(basename(outputChannelDescriptor.file.path), dirname(outputChannelDescriptor.file.path), URI.from({ scheme: LOG_SCHEME, path: outputChannelDescriptor.id }), undefined, textModelResolverService, textFileService, editorService); + super(basename(outputChannelDescriptor.file.path), dirname(outputChannelDescriptor.file.path), URI.from({ scheme: LOG_SCHEME, path: outputChannelDescriptor.id }), undefined, textModelResolverService, textFileService, editorService, editorGroupService); } getTypeId(): string { diff --git a/src/vs/workbench/contrib/performance/electron-browser/perfviewEditor.ts b/src/vs/workbench/contrib/performance/electron-browser/perfviewEditor.ts index 31ab953bff3..bb5033348d3 100644 --- a/src/vs/workbench/contrib/performance/electron-browser/perfviewEditor.ts +++ b/src/vs/workbench/contrib/performance/electron-browser/perfviewEditor.ts @@ -23,6 +23,7 @@ import { mergeSort } from 'vs/base/common/arrays'; import product from 'vs/platform/product/common/product'; import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; +import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; export class PerfviewContrib { @@ -48,7 +49,8 @@ export class PerfviewInput extends ResourceEditorInput { constructor( @ITextModelService textModelResolverService: ITextModelService, @ITextFileService textFileService: ITextFileService, - @IEditorService editorService: IEditorService + @IEditorService editorService: IEditorService, + @IEditorGroupsService editorGroupService: IEditorGroupsService ) { super( localize('name', "Startup Performance"), @@ -57,7 +59,8 @@ export class PerfviewInput extends ResourceEditorInput { undefined, textModelResolverService, textFileService, - editorService + editorService, + editorGroupService ); } diff --git a/src/vs/workbench/services/preferences/common/preferencesEditorInput.ts b/src/vs/workbench/services/preferences/common/preferencesEditorInput.ts index 501a673894f..4201d713077 100644 --- a/src/vs/workbench/services/preferences/common/preferencesEditorInput.ts +++ b/src/vs/workbench/services/preferences/common/preferencesEditorInput.ts @@ -15,6 +15,7 @@ import { IPreferencesService } from 'vs/workbench/services/preferences/common/pr import { Settings2EditorModel } from 'vs/workbench/services/preferences/common/preferencesModels'; import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; +import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; export class PreferencesEditorInput extends SideBySideEditorInput { static readonly ID: string = 'workbench.editorinputs.preferencesEditorInput'; @@ -34,9 +35,10 @@ export class DefaultPreferencesEditorInput extends ResourceEditorInput { defaultSettingsResource: URI, @ITextModelService textModelResolverService: ITextModelService, @ITextFileService textFileService: ITextFileService, - @IEditorService editorService: IEditorService + @IEditorService editorService: IEditorService, + @IEditorGroupsService editorGroupService: IEditorGroupsService ) { - super(nls.localize('settingsEditorName', "Default Settings"), '', defaultSettingsResource, undefined, textModelResolverService, textFileService, editorService); + super(nls.localize('settingsEditorName', "Default Settings"), '', defaultSettingsResource, undefined, textModelResolverService, textFileService, editorService, editorGroupService); } getTypeId(): string {