From 4b5350f96bed5476b0a3a2c9bf64f7c9cb2d4bf2 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Wed, 16 Mar 2022 08:54:04 +0100 Subject: [PATCH] history - tweak editor labels --- src/vs/workbench/common/editor.ts | 4 ++-- .../localHistory/browser/localHistoryCommands.ts | 12 +++++------- .../localHistory/browser/localHistoryTimeline.ts | 11 ++++------- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index b6c81081ee2..42fe3227026 100644 --- a/src/vs/workbench/common/editor.ts +++ b/src/vs/workbench/common/editor.ts @@ -574,8 +574,8 @@ class SaveSourceFactory { return sourceDescriptor.source; } - getSourceLabel(source: SaveSource): string | undefined { - return this.mapIdToSaveSource.get(source)?.label; + getSourceLabel(source: SaveSource): string { + return this.mapIdToSaveSource.get(source)?.label ?? source; } } diff --git a/src/vs/workbench/contrib/localHistory/browser/localHistoryCommands.ts b/src/vs/workbench/contrib/localHistory/browser/localHistoryCommands.ts index 6c0d891eaf7..5856570b5f3 100644 --- a/src/vs/workbench/contrib/localHistory/browser/localHistoryCommands.ts +++ b/src/vs/workbench/contrib/localHistory/browser/localHistoryCommands.ts @@ -98,8 +98,7 @@ registerAction2(class extends Action2 { async function openEntry(entry: IWorkingCopyHistoryEntry, editorService: IEditorService): Promise { await editorService.openEditor({ resource: LocalHistoryFileSystemProvider.toLocalHistoryFileSystem({ location: entry.location, associatedResource: entry.workingCopy.resource, label: entry.workingCopy.name }), - label: localize('localHistoryEditorLabel', "{0} ({1})", entry.workingCopy.name, entry.timestamp.label), - description: entry?.source ? SaveSourceRegistry.getSourceLabel(entry.source) : undefined + label: localize('localHistoryEditorLabel', "{0} ({1} {2})", entry.workingCopy.name, SaveSourceRegistry.getSourceLabel(entry.source), entry.timestamp.label) }); } @@ -322,7 +321,7 @@ registerAction2(class extends Action2 { inputBox.title = localize('renameLocalHistoryEntryTitle', "Rename Local History Entry"); inputBox.ignoreFocusOut = true; inputBox.placeholder = localize('renameLocalHistoryPlaceholder', "Enter the new name of the local history entry"); - inputBox.value = SaveSourceRegistry.getSourceLabel(entry.source) ?? entry.source; + inputBox.value = SaveSourceRegistry.getSourceLabel(entry.source); inputBox.show(); inputBox.onDidAccept(() => { if (inputBox.value) { @@ -424,7 +423,6 @@ export function toDiffEditorArguments(arg1: IWorkingCopyHistoryEntry, arg2: IWor const originalResource = LocalHistoryFileSystemProvider.toLocalHistoryFileSystem({ location: arg1.location, associatedResource: arg1.workingCopy.resource, label: arg1.workingCopy.name }); let label: string; - let description = arg1?.source ? SaveSourceRegistry.getSourceLabel(arg1.source) : undefined; // Right hand side depends on how the method was called // and is either another working copy history entry @@ -437,7 +435,7 @@ export function toDiffEditorArguments(arg1: IWorkingCopyHistoryEntry, arg2: IWor const resource = arg2; modifiedResource = resource; - label = localize('localHistoryCompareToFileEditorLabel', "{0} ({1}) ↔ {2}", arg1.workingCopy.name, arg1.timestamp.label, arg1.workingCopy.name); + label = localize('localHistoryCompareToFileEditorLabel', "{0} ({1} {2}) ↔ {3}", arg1.workingCopy.name, SaveSourceRegistry.getSourceLabel(arg1.source), arg1.timestamp.label, arg1.workingCopy.name); } // Compare with another entry @@ -445,13 +443,13 @@ export function toDiffEditorArguments(arg1: IWorkingCopyHistoryEntry, arg2: IWor const modified = arg2; modifiedResource = LocalHistoryFileSystemProvider.toLocalHistoryFileSystem({ location: modified.location, associatedResource: modified.workingCopy.resource, label: modified.workingCopy.name }); - label = localize('localHistoryCompareToPreviousEditorLabel', "{0} ({1}) ↔ {2} ({3})", arg1.workingCopy.name, arg1.timestamp.label, modified.workingCopy.name, modified.timestamp.label); + label = localize('localHistoryCompareToPreviousEditorLabel', "{0} ({1} {2}) ↔ {3} ({4} {5})", arg1.workingCopy.name, SaveSourceRegistry.getSourceLabel(arg1.source), arg1.timestamp.label, modified.workingCopy.name, SaveSourceRegistry.getSourceLabel(modified.source), modified.timestamp.label); } return [ originalResource, modifiedResource, - { label, description }, + label, undefined // important to keep order of arguments in command proper ]; } diff --git a/src/vs/workbench/contrib/localHistory/browser/localHistoryTimeline.ts b/src/vs/workbench/contrib/localHistory/browser/localHistoryTimeline.ts index ea600e02359..8200bb274b6 100644 --- a/src/vs/workbench/contrib/localHistory/browser/localHistoryTimeline.ts +++ b/src/vs/workbench/contrib/localHistory/browser/localHistoryTimeline.ts @@ -123,11 +123,8 @@ export class LocalHistoryTimeline extends Disposable implements IWorkbenchContri const entries = await this.workingCopyHistoryService.getEntries(resource, token); // Convert to timeline items - for (let i = 0; i < entries.length; i++) { - const entry = entries[i]; - const previousEntry: IWorkingCopyHistoryEntry | undefined = entries[i - 1]; - - items.push(this.toTimelineItem(entry, previousEntry)); + for (const entry of entries) { + items.push(this.toTimelineItem(entry)); } } @@ -137,10 +134,10 @@ export class LocalHistoryTimeline extends Disposable implements IWorkbenchContri }; } - private toTimelineItem(entry: IWorkingCopyHistoryEntry, previousEntry: IWorkingCopyHistoryEntry | undefined): TimelineItem { + private toTimelineItem(entry: IWorkingCopyHistoryEntry): TimelineItem { return { handle: entry.id, - label: SaveSourceRegistry.getSourceLabel(entry.source) ?? entry.source, + label: SaveSourceRegistry.getSourceLabel(entry.source), description: entry.timestamp.label, source: LocalHistoryTimeline.ID, timestamp: entry.timestamp.value,