提交 2c0a5529 编写于 作者: B Benjamin Pasero

Make the compare action label easier to understand when file names are identical (fixes #30515)

上级 a60a2472
......@@ -1246,26 +1246,38 @@ export class CompareResourcesAction extends Action {
constructor(
resource: URI,
tree: ITree,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IEnvironmentService environmentService: IEnvironmentService
) {
super('workbench.files.action.compareFiles', CompareResourcesAction.computeLabel());
super('workbench.files.action.compareFiles', CompareResourcesAction.computeLabel(resource, contextService, environmentService));
this.tree = tree;
this.resource = resource;
}
private static computeLabel(): string {
private static computeLabel(resource: URI, contextService: IWorkspaceContextService, environmentService: IEnvironmentService): string {
if (globalResourceToCompare) {
return nls.localize('compareWith', "Compare with '{0}'", paths.basename(globalResourceToCompare.fsPath));
let leftResourceName = paths.basename(globalResourceToCompare.fsPath);
let rightResourceName = paths.basename(resource.fsPath);
// If the file names are identical, add more context by looking at the parent folder
if (leftResourceName === rightResourceName) {
const folderPaths = labels.shorten([
labels.getPathLabel(paths.dirname(globalResourceToCompare.fsPath), contextService, environmentService),
labels.getPathLabel(paths.dirname(resource.fsPath), contextService, environmentService)
]);
leftResourceName = paths.join(folderPaths[0], leftResourceName);
rightResourceName = paths.join(folderPaths[1], rightResourceName);
}
return nls.localize('compareWith', "Compare '{0}' with '{1}'", leftResourceName, rightResourceName);
}
return nls.localize('compareFiles', "Compare Files");
}
public getLabel(): string {
return CompareResourcesAction.computeLabel();
}
_isEnabled(): boolean {
// Need at least a resource to compare
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册