Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

navigator: update open containing folder command #12076

Merged
merged 1 commit into from
Jan 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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