Extract decorateFileEditorLabel to a common function
I previously duplicated this logic. It makes sense to reuse the strings and logic for consistency From #117873
This commit is contained in:
parent
d7f90c7dbc
commit
9f7d229461
2 changed files with 19 additions and 29 deletions
|
@ -11,13 +11,13 @@ import { basename } from 'vs/base/common/path';
|
|||
import { isEqual } from 'vs/base/common/resources';
|
||||
import { assertIsDefined } from 'vs/base/common/types';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { localize } from 'vs/nls';
|
||||
import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { ILabelService } from 'vs/platform/label/common/label';
|
||||
import { IUndoRedoService } from 'vs/platform/undoRedo/common/undoRedo';
|
||||
import { GroupIdentifier, IEditorInput, IRevertOptions, ISaveOptions, Verbosity } from 'vs/workbench/common/editor';
|
||||
import { ICustomEditorModel, ICustomEditorService } from 'vs/workbench/contrib/customEditor/common/customEditor';
|
||||
import { decorateFileEditorLabel } from 'vs/workbench/contrib/files/common/editors/fileEditorInput';
|
||||
import { IWebviewService, WebviewOverlay } from 'vs/workbench/contrib/webview/browser/webview';
|
||||
import { IWebviewWorkbenchService, LazilyResolvedWebviewEditorInput } from 'vs/workbench/contrib/webviewPanel/browser/webviewWorkbenchService';
|
||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
|
@ -105,20 +105,7 @@ export class CustomEditorInput extends LazilyResolvedWebviewEditorInput {
|
|||
private decorateLabel(label: string): string {
|
||||
const orphaned = this._modelRef?.object.isOrphaned();
|
||||
const readonly = this.isReadonly();
|
||||
|
||||
if (orphaned && readonly) {
|
||||
return localize('orphanedReadonlyFile', "{0} (deleted, read-only)", label);
|
||||
}
|
||||
|
||||
if (orphaned) {
|
||||
return localize('orphanedFile', "{0} (deleted)", label);
|
||||
}
|
||||
|
||||
if (readonly) {
|
||||
return localize('readonlyFile', "{0} (read-only)", label);
|
||||
}
|
||||
|
||||
return label;
|
||||
return decorateFileEditorLabel(label, { orphaned: !!orphaned, readonly });
|
||||
}
|
||||
|
||||
public isReadonly(): boolean {
|
||||
|
|
|
@ -188,20 +188,7 @@ export class FileEditorInput extends AbstractTextResourceEditorInput implements
|
|||
private decorateLabel(label: string): string {
|
||||
const orphaned = this.model?.hasState(TextFileEditorModelState.ORPHAN);
|
||||
const readonly = this.isReadonly();
|
||||
|
||||
if (orphaned && readonly) {
|
||||
return localize('orphanedReadonlyFile', "{0} (deleted, read-only)", label);
|
||||
}
|
||||
|
||||
if (orphaned) {
|
||||
return localize('orphanedFile', "{0} (deleted)", label);
|
||||
}
|
||||
|
||||
if (readonly) {
|
||||
return localize('readonlyFile', "{0} (read-only)", label);
|
||||
}
|
||||
|
||||
return label;
|
||||
return decorateFileEditorLabel(label, { orphaned: !!orphaned, readonly });
|
||||
}
|
||||
|
||||
getEncoding(): string | undefined {
|
||||
|
@ -400,3 +387,19 @@ export class FileEditorInput extends AbstractTextResourceEditorInput implements
|
|||
this.cachedTextFileModelReference = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export function decorateFileEditorLabel(label: string, state: { orphaned: boolean, readonly: boolean }): string {
|
||||
if (state.orphaned && state.readonly) {
|
||||
return localize('orphanedReadonlyFile', "{0} (deleted, read-only)", label);
|
||||
}
|
||||
|
||||
if (state.orphaned) {
|
||||
return localize('orphanedFile', "{0} (deleted)", label);
|
||||
}
|
||||
|
||||
if (state.readonly) {
|
||||
return localize('readonlyFile', "{0} (read-only)", label);
|
||||
}
|
||||
|
||||
return label;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue