mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 20:26:08 +00:00
Don't label non-editable custom editors as readonly
We should only use the readonly label when an editable custom editor is on a readonly resource
This commit is contained in:
@@ -16,7 +16,7 @@ import { URI, UriComponents } from 'vs/base/common/uri';
|
||||
import * as modes from 'vs/editor/common/modes';
|
||||
import { localize } from 'vs/nls';
|
||||
import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
|
||||
import { FileChangesEvent, FileChangeType, IFileService } from 'vs/platform/files/common/files';
|
||||
import { FileChangesEvent, FileChangeType, FileSystemProviderCapabilities, IFileService } from 'vs/platform/files/common/files';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { ILabelService } from 'vs/platform/label/common/label';
|
||||
import { IUndoRedoService, UndoRedoElementType } from 'vs/platform/undoRedo/common/undoRedo';
|
||||
@@ -451,8 +451,12 @@ class MainThreadCustomEditorModel extends Disposable implements ICustomEditorMod
|
||||
}
|
||||
}
|
||||
|
||||
public isReadonly() {
|
||||
return !this._editable;
|
||||
public isEditable(): boolean {
|
||||
return this._editable;
|
||||
}
|
||||
|
||||
public isOnReadonlyFileSystem(): boolean {
|
||||
return this._fileService.hasCapability(this.editorResource, FileSystemProviderCapabilities.Readonly);
|
||||
}
|
||||
|
||||
public get viewType() {
|
||||
|
||||
@@ -103,13 +103,20 @@ export class CustomEditorInput extends LazilyResolvedWebviewEditorInput {
|
||||
}
|
||||
|
||||
private decorateLabel(label: string): string {
|
||||
const orphaned = this._modelRef?.object.isOrphaned();
|
||||
const readonly = this.isReadonly();
|
||||
return decorateFileEditorLabel(label, { orphaned: !!orphaned, readonly });
|
||||
const orphaned = !!this._modelRef?.object.isOrphaned();
|
||||
|
||||
const readonly = this._modelRef
|
||||
? !this._modelRef.object.isEditable() || this._modelRef.object.isOnReadonlyFileSystem()
|
||||
: false;
|
||||
|
||||
return decorateFileEditorLabel(label, {
|
||||
orphaned,
|
||||
readonly
|
||||
});
|
||||
}
|
||||
|
||||
public isReadonly(): boolean {
|
||||
return this._modelRef ? this._modelRef.object.isReadonly() : false;
|
||||
return this._modelRef ? !this._modelRef.object.isEditable() : false;
|
||||
}
|
||||
|
||||
public isUntitled(): boolean {
|
||||
|
||||
@@ -63,7 +63,8 @@ export interface ICustomEditorModel extends IDisposable {
|
||||
readonly resource: URI;
|
||||
readonly backupId: string | undefined;
|
||||
|
||||
isReadonly(): boolean;
|
||||
isEditable(): boolean;
|
||||
isOnReadonlyFileSystem(): boolean;
|
||||
|
||||
isOrphaned(): boolean;
|
||||
readonly onDidChangeOrphaned: Event<void>;
|
||||
|
||||
@@ -8,10 +8,11 @@ import { Disposable, IReference } from 'vs/base/common/lifecycle';
|
||||
import { isEqual } from 'vs/base/common/resources';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { IResolvedTextEditorModel, ITextModelService } from 'vs/editor/common/services/resolverService';
|
||||
import { FileSystemProviderCapabilities, IFileService } from 'vs/platform/files/common/files';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IRevertOptions, ISaveOptions } from 'vs/workbench/common/editor';
|
||||
import { ICustomEditorModel } from 'vs/workbench/contrib/customEditor/common/customEditor';
|
||||
import { ITextFileEditorModel, ITextFileService, TextFileEditorModelState } from 'vs/workbench/services/textfile/common/textfiles';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
|
||||
export class CustomTextEditorModel extends Disposable implements ICustomEditorModel {
|
||||
|
||||
@@ -22,9 +23,8 @@ export class CustomTextEditorModel extends Disposable implements ICustomEditorMo
|
||||
): Promise<CustomTextEditorModel> {
|
||||
return instantiationService.invokeFunction(async accessor => {
|
||||
const textModelResolverService = accessor.get(ITextModelService);
|
||||
const textFileService = accessor.get(ITextFileService);
|
||||
const model = await textModelResolverService.createModelReference(resource);
|
||||
return new CustomTextEditorModel(viewType, resource, model, textFileService);
|
||||
return instantiationService.createInstance(CustomTextEditorModel, viewType, resource, model);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -33,11 +33,12 @@ export class CustomTextEditorModel extends Disposable implements ICustomEditorMo
|
||||
private readonly _onDidChangeOrphaned = this._register(new Emitter<void>());
|
||||
public readonly onDidChangeOrphaned = this._onDidChangeOrphaned.event;
|
||||
|
||||
private constructor(
|
||||
constructor(
|
||||
public readonly viewType: string,
|
||||
private readonly _resource: URI,
|
||||
private readonly _model: IReference<IResolvedTextEditorModel>,
|
||||
@ITextFileService private readonly textFileService: ITextFileService,
|
||||
@IFileService private readonly _fileService: IFileService,
|
||||
) {
|
||||
super();
|
||||
|
||||
@@ -60,8 +61,12 @@ export class CustomTextEditorModel extends Disposable implements ICustomEditorMo
|
||||
return this._resource;
|
||||
}
|
||||
|
||||
public isReadonly(): boolean {
|
||||
return this._model.object.isReadonly();
|
||||
public isEditable(): boolean {
|
||||
return !this._model.object.isReadonly();
|
||||
}
|
||||
|
||||
public isOnReadonlyFileSystem(): boolean {
|
||||
return this._fileService.hasCapability(this._resource, FileSystemProviderCapabilities.Readonly);
|
||||
}
|
||||
|
||||
public get backupId() {
|
||||
|
||||
Reference in New Issue
Block a user