Skip to content

Commit 83be22a

Browse files
Add command for opening the containing folder of a file
A new 'OPEN_CONTAINING_FOLDER' command was added for the electron application. It opens the native file explorer at the path where the selected resource (or resources) from the file navigator is located. Signed-off-by: Alexandra Buzila <abuzila@eclipsesource.com>
1 parent 7f954ac commit 83be22a

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- [scripts] added Electron frontend start-up performance measurement script [#10442](https://github.com/eclipse-theia/theia/pull/10442) - Contributed on behalf of STMicroelectronics
88
- [core, editor, editor-preview] additional commands added to tabbar context menu for editor widgets. [#10394](https://github.com/eclipse-theia/theia/pull/10394)
99
- [preferences] Updated `AbstractResourcePreferenceProvider` to handle multiple preference settings in the same tick and handle open preference files. It will save the file exactly once, and prompt the user if the file is dirty when a programmatic setting is attempted. [#7775](https://github.com/eclipse-theia/theia/pull/7775)
10+
- [navigator] added `Open Containing Folder` command [#10523](https://github.com/eclipse-theia/theia/pull/10523)
1011

1112
<a name="breaking_changes_1.21.0">[Breaking Changes:](#breaking_changes_1.21.0)</a>
1213

packages/navigator/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
"theiaExtensions": [
1515
{
1616
"frontend": "lib/browser/navigator-frontend-module"
17+
},
18+
{
19+
"frontendElectron": "lib/electron-browser/electron-navigator-module"
1720
}
1821
],
1922
"keywords": [
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/********************************************************************************
2+
* Copyright (C) 2021 EclipseSource and others.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the Eclipse
10+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
11+
* with the GNU Classpath Exception which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
********************************************************************************/
16+
17+
import { Command, CommandContribution, CommandRegistry, MenuContribution, MenuModelRegistry } from '@theia/core';
18+
import { CommonCommands } from '@theia/core/lib/browser';
19+
import { WidgetManager } from '@theia/core/lib/browser/widget-manager';
20+
import * as electron from '@theia/core/shared/electron';
21+
import { inject, injectable } from '@theia/core/shared/inversify';
22+
import { FileStatNode } from '@theia/filesystem/lib/browser';
23+
import { FileNavigatorWidget, FILE_NAVIGATOR_ID } from '../browser';
24+
import { NavigatorContextMenu } from '../browser/navigator-contribution';
25+
26+
export const OPEN_CONTAINING_FOLDER = Command.toDefaultLocalizedCommand({
27+
id: 'navigator.openContainingFolder',
28+
category: CommonCommands.FILE_CATEGORY,
29+
label: 'Open Containing Folder'
30+
});
31+
32+
@injectable()
33+
export class ElectronNavigatorMenuContribution implements MenuContribution, CommandContribution {
34+
@inject(WidgetManager)
35+
protected readonly widgetManager: WidgetManager;
36+
37+
registerCommands(commands: CommandRegistry): void {
38+
commands.registerCommand(OPEN_CONTAINING_FOLDER, {
39+
isEnabled: () => this.getSelectedFileStatNodes().length > 0,
40+
isVisible: () => this.getSelectedFileStatNodes().length > 0,
41+
execute: () => {
42+
this.getSelectedFileStatNodes().forEach(async node => {
43+
electron.shell.showItemInFolder(node.uri.path.toString());
44+
});
45+
}
46+
});
47+
}
48+
registerMenus(menus: MenuModelRegistry): void {
49+
menus.registerMenuAction(NavigatorContextMenu.NAVIGATION, {
50+
commandId: OPEN_CONTAINING_FOLDER.id,
51+
label: OPEN_CONTAINING_FOLDER.label
52+
});
53+
}
54+
55+
protected getSelectedFileStatNodes(): FileStatNode[] {
56+
return this.tryGetNavigatorWidget()?.model.selectedNodes.filter(FileStatNode.is) || [];
57+
}
58+
59+
tryGetNavigatorWidget(): FileNavigatorWidget | undefined {
60+
return this.widgetManager.tryGetWidget(FILE_NAVIGATOR_ID);
61+
}
62+
63+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/********************************************************************************
2+
* Copyright (C) 2021 EclipseSource and others.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the Eclipse
10+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
11+
* with the GNU Classpath Exception which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
********************************************************************************/
16+
17+
import { CommandContribution, MenuContribution } from '@theia/core';
18+
import { ContainerModule } from '@theia/core/shared/inversify';
19+
import { ElectronNavigatorMenuContribution } from './electron-navigator-menu-contribution';
20+
21+
export default new ContainerModule(bind => {
22+
bind(MenuContribution).to(ElectronNavigatorMenuContribution).inSingletonScope();
23+
bind(CommandContribution).to(ElectronNavigatorMenuContribution).inSingletonScope();
24+
});

0 commit comments

Comments
 (0)