Skip to content

Commit 432961c

Browse files
author
Benjamin Pasero
committed
editors - let resource editor extend text editor
1 parent 7130288 commit 432961c

4 files changed

Lines changed: 21 additions & 40 deletions

File tree

src/vs/workbench/common/editor/resourceEditorInput.ts

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { EditorInput, ITextEditorModel, IModeSupport, GroupIdentifier, isTextEditor } from 'vs/workbench/common/editor';
6+
import { ITextEditorModel, IModeSupport, TextEditorInput } from 'vs/workbench/common/editor';
77
import { URI } from 'vs/base/common/uri';
88
import { IReference } from 'vs/base/common/lifecycle';
99
import { ITextModelService } from 'vs/editor/common/services/resolverService';
1010
import { ResourceEditorModel } from 'vs/workbench/common/editor/resourceEditorModel';
1111
import { basename } from 'vs/base/common/resources';
12-
import { ITextFileSaveOptions, ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
13-
import { IEditorViewState } from 'vs/editor/common/editorCommon';
12+
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
1413
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
14+
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
1515

1616
/**
1717
* A read-only text editor input whos contents are made of the provided resource that points to an existing
1818
* code editor model.
1919
*/
20-
export class ResourceEditorInput extends EditorInput implements IModeSupport {
20+
export class ResourceEditorInput extends TextEditorInput implements IModeSupport {
2121

2222
static readonly ID: string = 'workbench.editors.resourceEditorInput';
2323

@@ -27,17 +27,14 @@ export class ResourceEditorInput extends EditorInput implements IModeSupport {
2727
constructor(
2828
private name: string | undefined,
2929
private description: string | undefined,
30-
private readonly resource: URI,
30+
resource: URI,
3131
private preferredMode: string | undefined,
3232
@ITextModelService private readonly textModelResolverService: ITextModelService,
33-
@ITextFileService private readonly textFileService: ITextFileService,
34-
@IEditorService private readonly editorService: IEditorService
33+
@ITextFileService textFileService: ITextFileService,
34+
@IEditorService editorService: IEditorService,
35+
@IEditorGroupsService editorGroupService: IEditorGroupsService
3536
) {
36-
super();
37-
38-
this.name = name;
39-
this.description = description;
40-
this.resource = resource;
37+
super(resource, editorService, editorGroupService, textFileService);
4138
}
4239

4340
getResource(): URI {
@@ -109,28 +106,6 @@ export class ResourceEditorInput extends EditorInput implements IModeSupport {
109106
return model;
110107
}
111108

112-
async saveAs(group: GroupIdentifier, options?: ITextFileSaveOptions): Promise<boolean> {
113-
114-
// Preserve view state by opening the editor first. In addition
115-
// this allows the user to review the contents of the editor.
116-
let viewState: IEditorViewState | undefined = undefined;
117-
const editor = await this.editorService.openEditor(this, undefined, group);
118-
if (isTextEditor(editor)) {
119-
viewState = editor.getViewState();
120-
}
121-
122-
// Save as
123-
const target = await this.textFileService.saveAs(this.resource, undefined, options);
124-
if (!target) {
125-
return false; // save cancelled
126-
}
127-
128-
// Open the target
129-
await this.editorService.openEditor({ resource: target, options: { viewState, pinned: true } }, group);
130-
131-
return true;
132-
}
133-
134109
matches(otherInput: unknown): boolean {
135110
if (super.matches(otherInput) === true) {
136111
return true;

src/vs/workbench/contrib/output/browser/logViewer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ export class LogViewerInput extends ResourceEditorInput {
2828
private readonly outputChannelDescriptor: IFileOutputChannelDescriptor,
2929
@ITextModelService textModelResolverService: ITextModelService,
3030
@ITextFileService textFileService: ITextFileService,
31-
@IEditorService editorService: IEditorService
31+
@IEditorService editorService: IEditorService,
32+
@IEditorGroupsService editorGroupService: IEditorGroupsService
3233
) {
33-
super(basename(outputChannelDescriptor.file.path), dirname(outputChannelDescriptor.file.path), URI.from({ scheme: LOG_SCHEME, path: outputChannelDescriptor.id }), undefined, textModelResolverService, textFileService, editorService);
34+
super(basename(outputChannelDescriptor.file.path), dirname(outputChannelDescriptor.file.path), URI.from({ scheme: LOG_SCHEME, path: outputChannelDescriptor.id }), undefined, textModelResolverService, textFileService, editorService, editorGroupService);
3435
}
3536

3637
getTypeId(): string {

src/vs/workbench/contrib/performance/electron-browser/perfviewEditor.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { mergeSort } from 'vs/base/common/arrays';
2323
import product from 'vs/platform/product/common/product';
2424
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
2525
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
26+
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
2627

2728
export class PerfviewContrib {
2829

@@ -48,7 +49,8 @@ export class PerfviewInput extends ResourceEditorInput {
4849
constructor(
4950
@ITextModelService textModelResolverService: ITextModelService,
5051
@ITextFileService textFileService: ITextFileService,
51-
@IEditorService editorService: IEditorService
52+
@IEditorService editorService: IEditorService,
53+
@IEditorGroupsService editorGroupService: IEditorGroupsService
5254
) {
5355
super(
5456
localize('name', "Startup Performance"),
@@ -57,7 +59,8 @@ export class PerfviewInput extends ResourceEditorInput {
5759
undefined,
5860
textModelResolverService,
5961
textFileService,
60-
editorService
62+
editorService,
63+
editorGroupService
6164
);
6265
}
6366

src/vs/workbench/services/preferences/common/preferencesEditorInput.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { IPreferencesService } from 'vs/workbench/services/preferences/common/pr
1515
import { Settings2EditorModel } from 'vs/workbench/services/preferences/common/preferencesModels';
1616
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
1717
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
18+
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
1819

1920
export class PreferencesEditorInput extends SideBySideEditorInput {
2021
static readonly ID: string = 'workbench.editorinputs.preferencesEditorInput';
@@ -34,9 +35,10 @@ export class DefaultPreferencesEditorInput extends ResourceEditorInput {
3435
defaultSettingsResource: URI,
3536
@ITextModelService textModelResolverService: ITextModelService,
3637
@ITextFileService textFileService: ITextFileService,
37-
@IEditorService editorService: IEditorService
38+
@IEditorService editorService: IEditorService,
39+
@IEditorGroupsService editorGroupService: IEditorGroupsService
3840
) {
39-
super(nls.localize('settingsEditorName', "Default Settings"), '', defaultSettingsResource, undefined, textModelResolverService, textFileService, editorService);
41+
super(nls.localize('settingsEditorName', "Default Settings"), '', defaultSettingsResource, undefined, textModelResolverService, textFileService, editorService, editorGroupService);
4042
}
4143

4244
getTypeId(): string {

0 commit comments

Comments
 (0)