From c6f6e227308dac3e37ddc7fc67ae6f65e0fafc6b Mon Sep 17 00:00:00 2001 From: Igor Vinokur Date: Thu, 24 Sep 2020 16:09:59 +0300 Subject: [PATCH] Apply revealInExplorer vscode command Signed-off-by: Igor Vinokur --- .../src/browser/navigator-contribution.ts | 4 ++- .../plugin-vscode-commands-contribution.ts | 28 ++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/packages/navigator/src/browser/navigator-contribution.ts b/packages/navigator/src/browser/navigator-contribution.ts index da3dfc4b29d9c..5244968cfbc05 100644 --- a/packages/navigator/src/browser/navigator-contribution.ts +++ b/packages/navigator/src/browser/navigator-contribution.ts @@ -155,6 +155,8 @@ export namespace NavigatorContextMenu { export const OPEN_WITH = [...NAVIGATION, 'open_with']; } +export const FILE_NAVIGATOR_TOGGLE_COMMAND_ID = 'fileNavigator:toggle'; + @injectable() export class FileNavigatorContribution extends AbstractViewContribution implements FrontendApplicationContribution, TabBarToolbarContribution { @@ -200,7 +202,7 @@ export class FileNavigatorContribution extends AbstractViewContribution commands.executeCommand(FileNavigatorCommands.COPY_RELATIVE_FILE_PATH.id) }); + commands.registerCommand({ + id: 'revealInExplorer' + }, { + execute: async (resource: URI | object) => { + if (!URI.isUri(resource)) { + return; + } + let navigator = await this.shell.revealWidget(FILE_NAVIGATOR_ID); + if (!navigator) { + await this.commandService.executeCommand(FILE_NAVIGATOR_TOGGLE_COMMAND_ID); + navigator = await this.shell.revealWidget(FILE_NAVIGATOR_ID); + } + if (navigator instanceof FileNavigatorWidget) { + const model = navigator.model; + const node = await model.revealFile(new TheiaURI(resource)); + if (SelectableTreeNode.is(node)) { + model.selectNode(node); + } + } + } + }); } }