Skip to content

Commit

Permalink
navigator: update open containing folder command (#12076)
Browse files Browse the repository at this point in the history
The commit updates the `open containing folder` (known under different
names depending on the OS), so it can be used in the shell tabbar, and
it ultimately opens the resource in the user's fs explorer.

Signed-off-by: vince-fugnitto <vincent.fugnitto@ericsson.com>
  • Loading branch information
vince-fugnitto authored Jan 23, 2023
1 parent ca59f1d commit 339de2d
Showing 1 changed file with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
// *****************************************************************************

import { Command, CommandContribution, CommandRegistry, MenuContribution, MenuModelRegistry } from '@theia/core';
import { Command, CommandContribution, CommandRegistry, MenuContribution, MenuModelRegistry, SelectionService } from '@theia/core';
import { CommonCommands, KeybindingContribution, KeybindingRegistry } from '@theia/core/lib/browser';
import { WidgetManager } from '@theia/core/lib/browser/widget-manager';
import * as electron from '@theia/core/electron-shared/electron';
import * as electronRemote from '@theia/core/electron-shared/@electron/remote';
import { inject, injectable } from '@theia/core/shared/inversify';
import { FileStatNode } from '@theia/filesystem/lib/browser';
import { FileNavigatorWidget, FILE_NAVIGATOR_ID } from '../browser';
import { NavigatorContextMenu } from '../browser/navigator-contribution';
import { NavigatorContextMenu, SHELL_TABBAR_CONTEXT_REVEAL } from '../browser/navigator-contribution';
import { isWindows, isOSX } from '@theia/core/lib/common/os';
import { UriAwareCommandHandler } from '@theia/core/lib/common/uri-command-handler';
import { WorkspaceService } from '@theia/workspace/lib/browser';

export const OPEN_CONTAINING_FOLDER = Command.toDefaultLocalizedCommand({
id: 'revealFileInOS',
Expand All @@ -36,29 +38,38 @@ export const OPEN_CONTAINING_FOLDER = Command.toDefaultLocalizedCommand({
@injectable()
export class ElectronNavigatorMenuContribution implements MenuContribution, CommandContribution, KeybindingContribution {

@inject(SelectionService)
protected readonly selectionService: SelectionService;

@inject(WidgetManager)
protected readonly widgetManager: WidgetManager;

@inject(WorkspaceService)
protected readonly workspaceService: WorkspaceService;

registerCommands(commands: CommandRegistry): void {
commands.registerCommand(OPEN_CONTAINING_FOLDER, {
isEnabled: () => this.getSelectedFileStatNodes().length > 0,
isVisible: () => this.getSelectedFileStatNodes().length > 0,
execute: () => {
commands.registerCommand(OPEN_CONTAINING_FOLDER, UriAwareCommandHandler.MonoSelect(this.selectionService, {
execute: async uri => {
// workaround for https://github.com/electron/electron/issues/4349:
// use electron.remote.shell to open the window in the foreground on Windows
const shell = isWindows ? electronRemote.shell : electron.shell;
this.getSelectedFileStatNodes().forEach(node => {
shell.showItemInFolder(node.uri['codeUri'].fsPath);
});
}
});
shell.showItemInFolder(uri['codeUri'].fsPath);
},
isEnabled: uri => !!this.workspaceService.getWorkspaceRootUri(uri),
isVisible: uri => !!this.workspaceService.getWorkspaceRootUri(uri),
}));
}

registerMenus(menus: MenuModelRegistry): void {
menus.registerMenuAction(NavigatorContextMenu.NAVIGATION, {
commandId: OPEN_CONTAINING_FOLDER.id,
label: OPEN_CONTAINING_FOLDER.label
});
menus.registerMenuAction(SHELL_TABBAR_CONTEXT_REVEAL, {
commandId: OPEN_CONTAINING_FOLDER.id,
label: OPEN_CONTAINING_FOLDER.label,
order: '4'
});
}

registerKeybindings(keybindings: KeybindingRegistry): void {
Expand Down

0 comments on commit 339de2d

Please sign in to comment.