From fc5f80e1baa446e22969027e5ecbcf1ed66ea08a Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Wed, 9 Nov 2016 12:07:42 +0100 Subject: [PATCH] title - better simulate mac behaviour when opening path from title --- .../browser/parts/titlebar/titlebarPart.ts | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts b/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts index b69e64f8010..94d7152dd84 100644 --- a/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts +++ b/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts @@ -99,8 +99,21 @@ export class TitlebarPart extends Part implements ITitleService { if (this.representedFileName) { const segments = this.representedFileName.split(paths.sep); for (let i = segments.length; i > 0; i--) { - const path = segments.slice(0, i).join(paths.sep); - actions.push(new ShowItemInFolderAction(path, this.windowsService)); + const isFile = (i === segments.length); + + let pathOffset = i; + if (!isFile) { + pathOffset++; // for segments which are not the file name we want to open the folder + } + + const path = segments.slice(0, pathOffset).join(paths.sep); + + let label = paths.basename(path); + if (!isFile) { + label = paths.basename(paths.dirname(path)); + } + + actions.push(new ShowItemInFolderAction(path, label || paths.sep, this.windowsService)); } } @@ -143,8 +156,8 @@ export class TitlebarPart extends Part implements ITitleService { class ShowItemInFolderAction extends Action { - constructor(private path: string, private windowsService: IWindowsService) { - super('showItemInFolder.action.id', paths.basename(path) || paths.sep); + constructor(private path: string, label: string, private windowsService: IWindowsService) { + super('showItemInFolder.action.id', label); } public run(): TPromise { -- GitLab