mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-14 20:34:30 +01:00
editors - let resource editor extend text editor
This commit is contained in:
@@ -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<boolean> {
|
||||
|
||||
// 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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user