diff --git a/packages/core/src/browser/common-frontend-contribution.ts b/packages/core/src/browser/common-frontend-contribution.ts index ed581ee9fa406..ed3eed5212e1b 100644 --- a/packages/core/src/browser/common-frontend-contribution.ts +++ b/packages/core/src/browser/common-frontend-contribution.ts @@ -85,8 +85,6 @@ export namespace CommonCommands { export const OPEN: Command = { id: 'core.open', - category: FILE_CATEGORY, - label: 'Open', }; export const CUT: Command = { diff --git a/packages/navigator/src/browser/navigator-contribution.ts b/packages/navigator/src/browser/navigator-contribution.ts index 5773f0c44e5eb..7f41fdbd9a51d 100644 --- a/packages/navigator/src/browser/navigator-contribution.ts +++ b/packages/navigator/src/browser/navigator-contribution.ts @@ -62,7 +62,7 @@ import { import { FileSystemCommands } from '@theia/filesystem/lib/browser/filesystem-frontend-contribution'; import { NavigatorDiff, NavigatorDiffCommands } from './navigator-diff'; import { UriSelection } from '@theia/core/lib/common/selection'; -import { DirNode } from '@theia/filesystem/lib/browser'; +import { DirNode, FileNode } from '@theia/filesystem/lib/browser'; import { FileNavigatorModel } from './navigator-model'; import { ClipboardService } from '@theia/core/lib/browser/clipboard-service'; import { SelectionService } from '@theia/core/lib/common/selection-service'; @@ -106,6 +106,11 @@ export namespace FileNavigatorCommands { export const COPY_RELATIVE_FILE_PATH: Command = { id: 'navigator.copyRelativeFilePath' }; + export const OPEN: Command = { + id: 'navigator.open', + category: 'File', + label: 'Open' + }; } /** @@ -330,6 +335,29 @@ export class FileNavigatorContribution extends AbstractViewContribution this.getResourceFileNodes().length > 0, + isVisible: () => this.getResourceFileNodes().length > 0, + execute: () => { + this.getResourceFileNodes().forEach(async node => { + const opener = await this.openerService.getOpener(node.uri); + opener.open(node.uri); + }); + } + }); + } + + /** + * Get the list of non-directory file nodes. + * + * @returns the list of non-directory file nodes. + */ + protected getResourceFileNodes(): FileNode[] { + const widget = this.tryGetWidget(); + if (!widget) { + return []; + } + return widget.model.selectedNodes.filter(node => FileNode.is(node) && !node.fileStat.isDirectory) as FileNode[]; } protected withWidget(widget: Widget | undefined = this.tryGetWidget(), cb: (navigator: FileNavigatorWidget) => T): T | false { @@ -348,7 +376,8 @@ export class FileNavigatorContribution extends AbstractViewContribution { diff --git a/packages/navigator/src/browser/navigator-widget.tsx b/packages/navigator/src/browser/navigator-widget.tsx index 0302dbfd20159..06b2717c921d8 100644 --- a/packages/navigator/src/browser/navigator-widget.tsx +++ b/packages/navigator/src/browser/navigator-widget.tsx @@ -18,7 +18,7 @@ import { injectable, inject, postConstruct } from 'inversify'; import { Message } from '@phosphor/messaging'; import URI from '@theia/core/lib/common/uri'; import { CommandService, SelectionService } from '@theia/core/lib/common'; -import { CommonCommands, CorePreferences, ViewContainerTitleOptions, Key } from '@theia/core/lib/browser'; +import { CorePreferences, ViewContainerTitleOptions, Key } from '@theia/core/lib/browser'; import { ContextMenuRenderer, ExpandableTreeNode, TreeProps, TreeModel, TreeNode @@ -32,6 +32,7 @@ import { FileSystem } from '@theia/filesystem/lib/common/filesystem'; import { isOSX, environment } from '@theia/core'; import * as React from 'react'; import { NavigatorContextKeyService } from './navigator-context-key-service'; +import { FileNavigatorCommands } from './navigator-contribution'; export const FILE_NAVIGATOR_ID = 'files'; export const EXPLORER_VIEW_CONTAINER_ID = 'explorer-view-container'; @@ -110,7 +111,7 @@ export class FileNavigatorWidget extends FileTreeWidget { const mainPanelNode = this.shell.mainPanel.node; this.addEventListener(mainPanelNode, 'drop', async ({ dataTransfer }) => { const treeNodes = dataTransfer && this.getSelectedTreeNodesFromData(dataTransfer) || []; - treeNodes.filter(FileNode.is).forEach(treeNode => this.commandService.executeCommand(CommonCommands.OPEN.id, treeNode.uri)); + treeNodes.filter(FileNode.is).forEach(treeNode => this.commandService.executeCommand(FileNavigatorCommands.OPEN.id, treeNode.uri)); }); const handler = (e: DragEvent) => { if (e.dataTransfer) {