Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/microsoft/vscode.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/vs/workbench/browser/dnd.ts6
-rw-r--r--src/vs/workbench/browser/panecomposite.ts21
-rw-r--r--src/vs/workbench/browser/panel.ts2
-rw-r--r--src/vs/workbench/browser/parts/editor/baseEditor.ts14
-rw-r--r--src/vs/workbench/browser/parts/editor/binaryEditor.ts1
-rw-r--r--src/vs/workbench/browser/parts/editor/editorControl.ts8
-rw-r--r--src/vs/workbench/browser/parts/editor/rangeDecorations.ts8
-rw-r--r--src/vs/workbench/browser/parts/panel/panelPart.ts1
-rw-r--r--src/vs/workbench/browser/parts/titlebar/titlebarPart.ts1
-rw-r--r--src/vs/workbench/common/editor.ts170
-rw-r--r--src/vs/workbench/common/editor/diffEditorModel.ts11
-rw-r--r--src/vs/workbench/common/editor/resourceEditorInput.ts9
-rw-r--r--src/vs/workbench/common/editor/textDiffEditorModel.ts16
-rw-r--r--src/vs/workbench/common/editor/textResourceEditorInput.ts177
-rw-r--r--src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts5
-rw-r--r--src/vs/workbench/contrib/notebook/browser/notebookEditor.ts2
-rw-r--r--src/vs/workbench/contrib/preferences/browser/settingsEditor2.ts2
-rw-r--r--src/vs/workbench/services/untitled/common/untitledTextEditorInput.ts5
18 files changed, 229 insertions, 230 deletions
diff --git a/src/vs/workbench/browser/dnd.ts b/src/vs/workbench/browser/dnd.ts
index 86e379c3c38..707294b9e45 100644
--- a/src/vs/workbench/browser/dnd.ts
+++ b/src/vs/workbench/browser/dnd.ts
@@ -47,11 +47,7 @@ export class DraggedEditorIdentifier {
export class DraggedEditorGroupIdentifier {
- constructor(private _identifier: GroupIdentifier) { }
-
- get identifier(): GroupIdentifier {
- return this._identifier;
- }
+ constructor(public readonly identifier: GroupIdentifier) { }
}
export interface IDraggedEditor extends IDraggedResource {
diff --git a/src/vs/workbench/browser/panecomposite.ts b/src/vs/workbench/browser/panecomposite.ts
index 3bc12493e02..279916417ec 100644
--- a/src/vs/workbench/browser/panecomposite.ts
+++ b/src/vs/workbench/browser/panecomposite.ts
@@ -27,20 +27,13 @@ export class PaneComposite extends Composite implements IPaneComposite {
constructor(
id: string,
protected readonly viewPaneContainer: ViewPaneContainer,
- @ITelemetryService
- telemetryService: ITelemetryService,
- @IStorageService
- protected storageService: IStorageService,
- @IInstantiationService
- protected instantiationService: IInstantiationService,
- @IThemeService
- themeService: IThemeService,
- @IContextMenuService
- protected contextMenuService: IContextMenuService,
- @IExtensionService
- protected extensionService: IExtensionService,
- @IWorkspaceContextService
- protected contextService: IWorkspaceContextService
+ @ITelemetryService telemetryService: ITelemetryService,
+ @IStorageService protected storageService: IStorageService,
+ @IInstantiationService protected instantiationService: IInstantiationService,
+ @IThemeService themeService: IThemeService,
+ @IContextMenuService protected contextMenuService: IContextMenuService,
+ @IExtensionService protected extensionService: IExtensionService,
+ @IWorkspaceContextService protected contextService: IWorkspaceContextService
) {
super(id, telemetryService, themeService, storageService);
diff --git a/src/vs/workbench/browser/panel.ts b/src/vs/workbench/browser/panel.ts
index 45add441fe7..191d51a4d50 100644
--- a/src/vs/workbench/browser/panel.ts
+++ b/src/vs/workbench/browser/panel.ts
@@ -17,7 +17,7 @@ export abstract class Panel extends PaneComposite implements IPanel { }
*/
export class PanelDescriptor extends CompositeDescriptor<Panel> {
- public static create<Services extends BrandedService[]>(ctor: { new(...services: Services): Panel }, id: string, name: string, cssClass?: string, order?: number, _commandId?: string): PanelDescriptor {
+ static create<Services extends BrandedService[]>(ctor: { new(...services: Services): Panel }, id: string, name: string, cssClass?: string, order?: number, _commandId?: string): PanelDescriptor {
return new PanelDescriptor(ctor as IConstructorSignature0<Panel>, id, name, cssClass, order, _commandId);
}
diff --git a/src/vs/workbench/browser/parts/editor/baseEditor.ts b/src/vs/workbench/browser/parts/editor/baseEditor.ts
index fa05222640f..1c07cd2b501 100644
--- a/src/vs/workbench/browser/parts/editor/baseEditor.ts
+++ b/src/vs/workbench/browser/parts/editor/baseEditor.ts
@@ -106,10 +106,6 @@ export abstract class BaseEditor extends Composite implements IEditorPane {
this.createEditor(parent);
}
- onHide() { }
-
- onWillHide() { }
-
/**
* Called to create the editor in the parent HTMLElement.
*/
@@ -133,6 +129,16 @@ export abstract class BaseEditor extends Composite implements IEditorPane {
this._group = group;
}
+ /**
+ * Called before the editor is being removed from the DOM.
+ */
+ onWillHide() { }
+
+ /**
+ * Called after the editor has been removed from the DOM.
+ */
+ onDidHide() { }
+
protected getEditorMemento<T>(editorGroupService: IEditorGroupsService, key: string, limit: number = 10): IEditorMemento<T> {
const mementoKey = `${this.getId()}${key}`;
diff --git a/src/vs/workbench/browser/parts/editor/binaryEditor.ts b/src/vs/workbench/browser/parts/editor/binaryEditor.ts
index 722efdf0105..4fc47fa281b 100644
--- a/src/vs/workbench/browser/parts/editor/binaryEditor.ts
+++ b/src/vs/workbench/browser/parts/editor/binaryEditor.ts
@@ -160,6 +160,7 @@ export abstract class BaseBinaryResourceEditor extends BaseEditor {
super.dispose();
}
}
+
export interface IResourceDescriptor {
readonly resource: URI;
readonly name: string;
diff --git a/src/vs/workbench/browser/parts/editor/editorControl.ts b/src/vs/workbench/browser/parts/editor/editorControl.ts
index b0e2f9d4a37..d7ccd8c71c8 100644
--- a/src/vs/workbench/browser/parts/editor/editorControl.ts
+++ b/src/vs/workbench/browser/parts/editor/editorControl.ts
@@ -35,6 +35,8 @@ export class EditorControl extends Disposable {
readonly onDidSizeConstraintsChange = this._onDidSizeConstraintsChange.event;
private _activeEditorPane: BaseEditor | null = null;
+ get activeEditorPane(): IVisibleEditorPane | null { return this._activeEditorPane as IVisibleEditorPane | null; }
+
private readonly editorPanes: BaseEditor[] = [];
private readonly activeEditorPaneDisposables = this._register(new DisposableStore());
@@ -53,10 +55,6 @@ export class EditorControl extends Disposable {
this.editorOperation = this._register(new LongRunningOperation(editorProgressService));
}
- get activeEditorPane(): IVisibleEditorPane | null {
- return this._activeEditorPane as IVisibleEditorPane | null;
- }
-
async openEditor(editor: EditorInput, options?: EditorOptions): Promise<IOpenEditorResult> {
// Editor pane
@@ -208,7 +206,7 @@ export class EditorControl extends Disposable {
this._activeEditorPane.onWillHide();
this.parent.removeChild(editorPaneContainer);
hide(editorPaneContainer);
- this._activeEditorPane.onHide();
+ this._activeEditorPane.onDidHide();
}
// Indicate to editor pane
diff --git a/src/vs/workbench/browser/parts/editor/rangeDecorations.ts b/src/vs/workbench/browser/parts/editor/rangeDecorations.ts
index 98304f2366b..5f3a4cf23c5 100644
--- a/src/vs/workbench/browser/parts/editor/rangeDecorations.ts
+++ b/src/vs/workbench/browser/parts/editor/rangeDecorations.ts
@@ -5,7 +5,7 @@
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
-import { Event, Emitter } from 'vs/base/common/event';
+import { Emitter } from 'vs/base/common/event';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IRange } from 'vs/editor/common/core/range';
import { CursorChangeReason, ICursorPositionChangedEvent } from 'vs/editor/common/controller/cursorEvents';
@@ -26,9 +26,11 @@ export class RangeHighlightDecorations extends Disposable {
private readonly editorDisposables = this._register(new DisposableStore());
private readonly _onHighlightRemoved: Emitter<void> = this._register(new Emitter<void>());
- readonly onHighlightRemoved: Event<void> = this._onHighlightRemoved.event;
+ readonly onHighlightRemoved = this._onHighlightRemoved.event;
- constructor(@IEditorService private readonly editorService: IEditorService) {
+ constructor(
+ @IEditorService private readonly editorService: IEditorService
+ ) {
super();
}
diff --git a/src/vs/workbench/browser/parts/panel/panelPart.ts b/src/vs/workbench/browser/parts/panel/panelPart.ts
index e4ed634304e..35d8c2d8c7b 100644
--- a/src/vs/workbench/browser/parts/panel/panelPart.ts
+++ b/src/vs/workbench/browser/parts/panel/panelPart.ts
@@ -317,6 +317,7 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService {
}
private registerListeners(): void {
+
// Panel registration
this._register(this.registry.onDidRegister(panel => this.onDidRegisterPanels([panel])));
this._register(this.registry.onDidDeregister(panel => this.onDidDeregisterPanel(panel.id)));
diff --git a/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts b/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts
index bd4cb681639..dfe56ef6508 100644
--- a/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts
+++ b/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts
@@ -333,7 +333,6 @@ export class TitlebarPart extends Part implements ITitleService {
this.customMenubar = this._register(this.instantiationService.createInstance(CustomMenubarControl));
this.menubar = this.element.insertBefore($('div.menubar'), this.title);
-
this.menubar.setAttribute('role', 'menubar');
this.customMenubar.create(this.menubar);
diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts
index 0aaed3dcb17..b4de3177a80 100644
--- a/src/vs/workbench/common/editor.ts
+++ b/src/vs/workbench/common/editor.ts
@@ -14,20 +14,14 @@ import { IInstantiationService, IConstructorSignature0, ServicesAccessor, Brande
import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
import { Registry } from 'vs/platform/registry/common/platform';
import { ITextModel } from 'vs/editor/common/model';
-import { IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
+import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
import { ICompositeControl, IComposite } from 'vs/workbench/common/composite';
import { ActionRunner, IAction } from 'vs/base/common/actions';
-import { IFileService, FileSystemProviderCapabilities } from 'vs/platform/files/common/files';
+import { IFileService } from 'vs/platform/files/common/files';
import { IPathData } from 'vs/platform/windows/common/windows';
import { coalesce, firstOrDefault } from 'vs/base/common/arrays';
-import { ITextFileSaveOptions, ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
-import { IEditorService, IResourceEditorInputType } from 'vs/workbench/services/editor/common/editorService';
-import { isEqual, dirname } from 'vs/base/common/resources';
+import { IResourceEditorInputType } from 'vs/workbench/services/editor/common/editorService';
import { IRange } from 'vs/editor/common/core/range';
-import { createMemoizer } from 'vs/base/common/decorators';
-import { ILabelService } from 'vs/platform/label/common/label';
-import { Schemas } from 'vs/base/common/network';
-import { IFilesConfigurationService, AutoSaveMode } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService';
export const DirtyWorkingCopiesContext = new RawContextKey<boolean>('dirtyWorkingCopies', false);
export const ActiveEditorContext = new RawContextKey<string | null>('activeEditor', null);
@@ -604,164 +598,6 @@ export abstract class EditorInput extends Disposable implements IEditorInput {
}
}
-export abstract class TextResourceEditorInput extends EditorInput {
-
- private static readonly MEMOIZER = createMemoizer();
-
- constructor(
- public readonly resource: URI,
- @IEditorService protected readonly editorService: IEditorService,
- @IEditorGroupsService protected readonly editorGroupService: IEditorGroupsService,
- @ITextFileService protected readonly textFileService: ITextFileService,
- @ILabelService protected readonly labelService: ILabelService,
- @IFileService protected readonly fileService: IFileService,
- @IFilesConfigurationService protected readonly filesConfigurationService: IFilesConfigurationService
- ) {
- super();
-
- this.registerListeners();
- }
-
- protected registerListeners(): void {
-
- // Clear label memoizer on certain events that have impact
- this._register(this.labelService.onDidChangeFormatters(e => this.onLabelEvent(e.scheme)));
- this._register(this.fileService.onDidChangeFileSystemProviderRegistrations(e => this.onLabelEvent(e.scheme)));
- this._register(this.fileService.onDidChangeFileSystemProviderCapabilities(e => this.onLabelEvent(e.scheme)));
- }
-
- private onLabelEvent(scheme: string): void {
- if (scheme === this.resource.scheme) {
-
- // Clear any cached labels from before
- TextResourceEditorInput.MEMOIZER.clear();
-
- // Trigger recompute of label
- this._onDidChangeLabel.fire();
- }
- }
-
- getName(): string {
- return this.basename;
- }
-
- @TextResourceEditorInput.MEMOIZER
- private get basename(): string {
- return this.labelService.getUriBasenameLabel(this.resource);
- }
-
- getDescription(verbosity: Verbosity = Verbosity.MEDIUM): string | undefined {
- switch (verbosity) {
- case Verbosity.SHORT:
- return this.shortDescription;
- case Verbosity.LONG:
- return this.longDescription;
- case Verbosity.MEDIUM:
- default:
- return this.mediumDescription;
- }
- }
-
- @TextResourceEditorInput.MEMOIZER
- private get shortDescription(): string {
- return this.labelService.getUriBasenameLabel(dirname(this.resource));
- }
-
- @TextResourceEditorInput.MEMOIZER
- private get mediumDescription(): string {
- return this.labelService.getUriLabel(dirname(this.resource), { relative: true });
- }
-
- @TextResourceEditorInput.MEMOIZER
- private get longDescription(): string {
- return this.labelService.getUriLabel(dirname(this.resource));
- }
-
- @TextResourceEditorInput.MEMOIZER
- private get shortTitle(): string {
- return this.getName();
- }
-
- @TextResourceEditorInput.MEMOIZER
- private get mediumTitle(): string {
- return this.labelService.getUriLabel(this.resource, { relative: true });
- }
-
- @TextResourceEditorInput.MEMOIZER
- private get longTitle(): string {
- return this.labelService.getUriLabel(this.resource);
- }
-
- getTitle(verbosity: Verbosity): string {
- switch (verbosity) {
- case Verbosity.SHORT:
- return this.shortTitle;
- case Verbosity.LONG:
- return this.longTitle;
- default:
- case Verbosity.MEDIUM:
- return this.mediumTitle;
- }
- }
-
- isUntitled(): boolean {
- return this.resource.scheme === Schemas.untitled;
- }
-
- isReadonly(): boolean {
- if (this.isUntitled()) {
- return false; // untitled is never readonly
- }
-
- return this.fileService.hasCapability(this.resource, FileSystemProviderCapabilities.Readonly);
- }
-
- isSaving(): boolean {
- if (this.isUntitled()) {
- return false; // untitled is never saving automatically
- }
-
- if (this.filesConfigurationService.getAutoSaveMode() === AutoSaveMode.AFTER_SHORT_DELAY) {
- return true; // a short auto save is configured, treat this as being saved
- }
-
- return false;
- }
-
- async save(group: GroupIdentifier, options?: ITextFileSaveOptions): Promise<IEditorInput | undefined> {
- return this.doSave(group, options, false);
- }
-
- saveAs(group: GroupIdentifier, options?: ITextFileSaveOptions): Promise<IEditorInput | undefined> {
- return this.doSave(group, options, true);
- }
-
- private async doSave(group: GroupIdentifier, options: ISaveOptions | undefined, saveAs: boolean): Promise<IEditorInput | undefined> {
-
- // Save / Save As
- let target: URI | undefined;
- if (saveAs) {
- target = await this.textFileService.saveAs(this.resource, undefined, options);
- } else {
- target = await this.textFileService.save(this.resource, options);
- }
-
- if (!target) {
- return undefined; // save cancelled
- }
-
- if (!isEqual(target, this.resource)) {
- return this.editorService.createEditorInput({ resource: target });
- }
-
- return this;
- }
-
- async revert(group: GroupIdentifier, options?: IRevertOptions): Promise<void> {
- await this.textFileService.revert(this.resource, options);
- }
-}
-
export const enum EncodingMode {
/**
diff --git a/src/vs/workbench/common/editor/diffEditorModel.ts b/src/vs/workbench/common/editor/diffEditorModel.ts
index 93f9d7e7fe8..dfa51d62d4d 100644
--- a/src/vs/workbench/common/editor/diffEditorModel.ts
+++ b/src/vs/workbench/common/editor/diffEditorModel.ts
@@ -13,7 +13,10 @@ import { IEditorModel } from 'vs/platform/editor/common/editor';
export class DiffEditorModel extends EditorModel {
protected readonly _originalModel: IEditorModel | null;
+ get originalModel(): IEditorModel | null { return this._originalModel; }
+
protected readonly _modifiedModel: IEditorModel | null;
+ get modifiedModel(): IEditorModel | null { return this._modifiedModel; }
constructor(originalModel: IEditorModel | null, modifiedModel: IEditorModel | null) {
super();
@@ -22,14 +25,6 @@ export class DiffEditorModel extends EditorModel {
this._modifiedModel = modifiedModel;
}
- get originalModel(): IEditorModel | null {
- return this._originalModel;
- }
-
- get modifiedModel(): IEditorModel | null {
- return this._modifiedModel;
- }
-
async load(): Promise<EditorModel> {
await Promise.all([
this._originalModel?.load(),
diff --git a/src/vs/workbench/common/editor/resourceEditorInput.ts b/src/vs/workbench/common/editor/resourceEditorInput.ts
index 3ea14b511f8..df60cae876e 100644
--- a/src/vs/workbench/common/editor/resourceEditorInput.ts
+++ b/src/vs/workbench/common/editor/resourceEditorInput.ts
@@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
-import { ITextEditorModel, IModeSupport, TextResourceEditorInput } from 'vs/workbench/common/editor';
+import { ITextEditorModel, IModeSupport } 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';
@@ -14,12 +14,13 @@ import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editor
import { IFileService } from 'vs/platform/files/common/files';
import { ILabelService } from 'vs/platform/label/common/label';
import { IFilesConfigurationService } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService';
+import { AbstractTextResourceEditorInput } from 'vs/workbench/common/editor/textResourceEditorInput';
/**
* 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 TextResourceEditorInput implements IModeSupport {
+export class ResourceEditorInput extends AbstractTextResourceEditorInput implements IModeSupport {
static readonly ID: string = 'workbench.editors.resourceEditorInput';
@@ -64,6 +65,7 @@ export class ResourceEditorInput extends TextResourceEditorInput implements IMod
setDescription(description: string): void {
if (this.description !== description) {
this.description = description;
+
this._onDidChangeLabel.fire();
}
}
@@ -87,9 +89,8 @@ export class ResourceEditorInput extends TextResourceEditorInput implements IMod
const ref = await this.modelReference;
- const model = ref.object;
-
// Ensure the resolved model is of expected type
+ const model = ref.object;
if (!(model instanceof ResourceEditorModel)) {
ref.dispose();
this.modelReference = undefined;
diff --git a/src/vs/workbench/common/editor/textDiffEditorModel.ts b/src/vs/workbench/common/editor/textDiffEditorModel.ts
index 579499c30f6..fcb97b428b2 100644
--- a/src/vs/workbench/common/editor/textDiffEditorModel.ts
+++ b/src/vs/workbench/common/editor/textDiffEditorModel.ts
@@ -15,9 +15,13 @@ import { DiffEditorModel } from 'vs/workbench/common/editor/diffEditorModel';
export class TextDiffEditorModel extends DiffEditorModel {
protected readonly _originalModel: BaseTextEditorModel | null;
+ get originalModel(): BaseTextEditorModel | null { return this._originalModel; }
+
protected readonly _modifiedModel: BaseTextEditorModel | null;
+ get modifiedModel(): BaseTextEditorModel | null { return this._modifiedModel; }
private _textDiffEditorModel: IDiffEditorModel | null = null;
+ get textDiffEditorModel(): IDiffEditorModel | null { return this._textDiffEditorModel; }
constructor(originalModel: BaseTextEditorModel, modifiedModel: BaseTextEditorModel) {
super(originalModel, modifiedModel);
@@ -28,14 +32,6 @@ export class TextDiffEditorModel extends DiffEditorModel {
this.updateTextDiffEditorModel();
}
- get originalModel(): BaseTextEditorModel | null {
- return this._originalModel;
- }
-
- get modifiedModel(): BaseTextEditorModel | null {
- return this._modifiedModel;
- }
-
async load(): Promise<EditorModel> {
await super.load();
@@ -63,10 +59,6 @@ export class TextDiffEditorModel extends DiffEditorModel {
}
}
- get textDiffEditorModel(): IDiffEditorModel | null {
- return this._textDiffEditorModel;
- }
-
isResolved(): boolean {
return !!this._textDiffEditorModel;
}
diff --git a/src/vs/workbench/common/editor/textResourceEditorInput.ts b/src/vs/workbench/common/editor/textResourceEditorInput.ts
new file mode 100644
index 00000000000..f31cb198bbb
--- /dev/null
+++ b/src/vs/workbench/common/editor/textResourceEditorInput.ts
@@ -0,0 +1,177 @@
+/*---------------------------------------------------------------------------------------------
+ * Copyright (c) Microsoft Corporation. All rights reserved.
+ * Licensed under the MIT License. See License.txt in the project root for license information.
+ *--------------------------------------------------------------------------------------------*/
+
+import { EditorInput, Verbosity, GroupIdentifier, IEditorInput, ISaveOptions, IRevertOptions } from 'vs/workbench/common/editor';
+import { URI } from 'vs/base/common/uri';
+import { ITextFileService, ITextFileSaveOptions } 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';
+import { IFileService, FileSystemProviderCapabilities } from 'vs/platform/files/common/files';
+import { ILabelService } from 'vs/platform/label/common/label';
+import { IFilesConfigurationService, AutoSaveMode } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService';
+import { createMemoizer } from 'vs/base/common/decorators';
+import { Schemas } from 'vs/base/common/network';
+import { dirname, isEqual } from 'vs/base/common/resources';
+
+/**
+ * The base class for all editor inputs that open in text editors.
+ */
+export abstract class AbstractTextResourceEditorInput extends EditorInput {
+
+ private static readonly MEMOIZER = createMemoizer();
+
+ constructor(
+ public readonly resource: URI,
+ @IEditorService protected readonly editorService: IEditorService,
+ @IEditorGroupsService protected readonly editorGroupService: IEditorGroupsService,
+ @ITextFileService protected readonly textFileService: ITextFileService,
+ @ILabelService protected readonly labelService: ILabelService,
+ @IFileService protected readonly fileService: IFileService,
+ @IFilesConfigurationService protected readonly filesConfigurationService: IFilesConfigurationService
+ ) {
+ super();
+
+ this.registerListeners();
+ }
+
+ protected registerListeners(): void {
+
+ // Clear label memoizer on certain events that have impact
+ this._register(this.labelService.onDidChangeFormatters(e => this.onLabelEvent(e.scheme)));
+ this._register(this.fileService.onDidChangeFileSystemProviderRegistrations(e => this.onLabelEvent(e.scheme)));
+ this._register(this.fileService.onDidChangeFileSystemProviderCapabilities(e => this.onLabelEvent(e.scheme)));
+ }
+
+ private onLabelEvent(scheme: string): void {
+ if (scheme === this.resource.scheme) {
+
+ // Clear any cached labels from before
+ AbstractTextResourceEditorInput.MEMOIZER.clear();
+
+ // Trigger recompute of label
+ this._onDidChangeLabel.fire();
+ }
+ }
+
+ getName(): string {
+ return this.basename;
+ }
+
+ @AbstractTextResourceEditorInput.MEMOIZER
+ private get basename(): string {
+ return this.labelService.getUriBasenameLabel(this.resource);
+ }
+
+ getDescription(verbosity: Verbosity = Verbosity.MEDIUM): string | undefined {
+ switch (verbosity) {
+ case Verbosity.SHORT:
+ return this.shortDescription;
+ case Verbosity.LONG:
+ return this.longDescription;
+ case Verbosity.MEDIUM:
+ default:
+ return this.mediumDescription;
+ }
+ }
+
+ @AbstractTextResourceEditorInput.MEMOIZER
+ private get shortDescription(): string {
+ return this.labelService.getUriBasenameLabel(dirname(this.resource));
+ }
+
+ @AbstractTextResourceEditorInput.MEMOIZER
+ private get mediumDescription(): string {
+ return this.labelService.getUriLabel(dirname(this.resource), { relative: true });
+ }
+
+ @AbstractTextResourceEditorInput.MEMOIZER
+ private get longDescription(): string {
+ return this.labelService.getUriLabel(dirname(this.resource));
+ }
+
+ @AbstractTextResourceEditorInput.MEMOIZER
+ private get shortTitle(): string {
+ return this.getName();
+ }
+
+ @AbstractTextResourceEditorInput.MEMOIZER
+ private get mediumTitle(): string {
+ return this.labelService.getUriLabel(this.resource, { relative: true });
+ }
+
+ @AbstractTextResourceEditorInput.MEMOIZER
+ private get longTitle(): string {
+ return this.labelService.getUriLabel(this.resource);
+ }
+
+ getTitle(verbosity: Verbosity): string {
+ switch (verbosity) {
+ case Verbosity.SHORT:
+ return this.shortTitle;
+ case Verbosity.LONG:
+ return this.longTitle;
+ default:
+ case Verbosity.MEDIUM:
+ return this.mediumTitle;
+ }
+ }
+
+ isUntitled(): boolean {
+ return this.resource.scheme === Schemas.untitled;
+ }
+
+ isReadonly(): boolean {
+ if (this.isUntitled()) {
+ return false; // untitled is never readonly
+ }
+
+ return this.fileService.hasCapability(this.resource, FileSystemProviderCapabilities.Readonly);
+ }
+
+ isSaving(): boolean {
+ if (this.isUntitled()) {
+ return false; // untitled is never saving automatically
+ }
+
+ if (this.filesConfigurationService.getAutoSaveMode() === AutoSaveMode.AFTER_SHORT_DELAY) {
+ return true; // a short auto save is configured, treat this as being saved
+ }
+
+ return false;
+ }
+
+ async save(group: GroupIdentifier, options?: ITextFileSaveOptions): Promise<IEditorInput | undefined> {
+ return this.doSave(group, options, false);
+ }
+
+ saveAs(group: GroupIdentifier, options?: ITextFileSaveOptions): Promise<IEditorInput | undefined> {
+ return this.doSave(group, options, true);
+ }
+
+ private async doSave(group: GroupIdentifier, options: ISaveOptions | undefined, saveAs: boolean): Promise<IEditorInput | undefined> {
+
+ // Save / Save As
+ let target: URI | undefined;
+ if (saveAs) {
+ target = await this.textFileService.saveAs(this.resource, undefined, options);
+ } else {
+ target = await this.textFileService.save(this.resource, options);
+ }
+
+ if (!target) {
+ return undefined; // save cancelled
+ }
+
+ if (!isEqual(target, this.resource)) {
+ return this.editorService.createEditorInput({ resource: target });
+ }
+
+ return this;
+ }
+
+ async revert(group: GroupIdentifier, options?: IRevertOptions): Promise<void> {
+ await this.textFileService.revert(this.resource, options);
+ }
+}
diff --git a/src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts b/src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts
index e4ae372e9d9..acf4173bae3 100644
--- a/src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts
+++ b/src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts
@@ -5,7 +5,8 @@
import { localize } from 'vs/nls';
import { URI } from 'vs/base/common/uri';
-import { EncodingMode, IFileEditorInput, Verbosity, TextResourceEditorInput, GroupIdentifier, IMoveResult, isTextEditorPane } from 'vs/workbench/common/editor';
+import { EncodingMode, IFileEditorInput, Verbosity, GroupIdentifier, IMoveResult, isTextEditorPane } from 'vs/workbench/common/editor';
+import { AbstractTextResourceEditorInput } from 'vs/workbench/common/editor/textResourceEditorInput';
import { BinaryEditorModel } from 'vs/workbench/common/editor/binaryEditorModel';
import { FileOperationError, FileOperationResult, IFileService } from 'vs/platform/files/common/files';
import { ITextFileService, TextFileEditorModelState, TextFileLoadReason, TextFileOperationError, TextFileOperationResult, ITextFileEditorModel } from 'vs/workbench/services/textfile/common/textfiles';
@@ -30,7 +31,7 @@ const enum ForceOpenAs {
/**
* A file editor input is the input type for the file editor of file system resources.
*/
-export class FileEditorInput extends TextResourceEditorInput implements IFileEditorInput {
+export class FileEditorInput extends AbstractTextResourceEditorInput implements IFileEditorInput {
private preferredEncoding: string | undefined;
private preferredMode: string | undefined;
diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts
index d4940146880..b57a56ccfbe 100644
--- a/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts
+++ b/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts
@@ -94,7 +94,7 @@ export class NotebookEditor extends BaseEditor {
}
this._widget?.onWillHide();
- super.onHide();
+ super.onWillHide();
}
setEditorVisible(visible: boolean, group: IEditorGroup | undefined): void {
diff --git a/src/vs/workbench/contrib/preferences/browser/settingsEditor2.ts b/src/vs/workbench/contrib/preferences/browser/settingsEditor2.ts
index dd6f4bc6fd5..293aff77ec4 100644
--- a/src/vs/workbench/contrib/preferences/browser/settingsEditor2.ts
+++ b/src/vs/workbench/contrib/preferences/browser/settingsEditor2.ts
@@ -339,7 +339,7 @@ export class SettingsEditor2 extends BaseEditor {
this.focusSearch();
}
- onHide(): void {
+ onDidHide(): void {
this.searchWidget.onHide();
}
diff --git a/src/vs/workbench/services/untitled/common/untitledTextEditorInput.ts b/src/vs/workbench/services/untitled/common/untitledTextEditorInput.ts
index c5b74a4b9a1..cfa7db772d2 100644
--- a/src/vs/workbench/services/untitled/common/untitledTextEditorInput.ts
+++ b/src/vs/workbench/services/untitled/common/untitledTextEditorInput.ts
@@ -3,7 +3,8 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
-import { IEncodingSupport, EncodingMode, Verbosity, IModeSupport, TextResourceEditorInput } from 'vs/workbench/common/editor';
+import { IEncodingSupport, EncodingMode, Verbosity, IModeSupport } from 'vs/workbench/common/editor';
+import { AbstractTextResourceEditorInput } from 'vs/workbench/common/editor/textResourceEditorInput';
import { IUntitledTextEditorModel } from 'vs/workbench/services/untitled/common/untitledTextEditorModel';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { ILabelService } from 'vs/platform/label/common/label';
@@ -17,7 +18,7 @@ import { basenameOrAuthority } from 'vs/base/common/resources';
/**
* An editor input to be used for untitled text buffers.
*/
-export class UntitledTextEditorInput extends TextResourceEditorInput implements IEncodingSupport, IModeSupport {
+export class UntitledTextEditorInput extends AbstractTextResourceEditorInput implements IEncodingSupport, IModeSupport {
static readonly ID: string = 'workbench.editors.untitledEditorInput';