Skip to content

Commit

Permalink
navigator: fix 'open' command
Browse files Browse the repository at this point in the history
the following commit fixes the `open` command for the navigator
to only display the command for file nodes and not directories (since
directories cannot be opened).

Signed-off-by: vince-fugnitto <[email protected]>
  • Loading branch information
vince-fugnitto committed Aug 3, 2020
1 parent b80ac33 commit 8ac1e5f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
2 changes: 0 additions & 2 deletions packages/core/src/browser/common-frontend-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ export namespace CommonCommands {

export const OPEN: Command = {
id: 'core.open',
category: FILE_CATEGORY,
label: 'Open',
};

export const CUT: Command = {
Expand Down
24 changes: 22 additions & 2 deletions packages/navigator/src/browser/navigator-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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'
};
}

/**
Expand Down Expand Up @@ -330,6 +335,20 @@ export class FileNavigatorContribution extends AbstractViewContribution<FileNavi
await this.clipboardService.writeText(text);
}
}, { multi: true }));
registry.registerCommand(FileNavigatorCommands.OPEN, {
isEnabled: () => this.getSelectedFileNodes().length > 0,
isVisible: () => this.getSelectedFileNodes().length > 0,
execute: () => {
this.getSelectedFileNodes().forEach(async node => {
const opener = await this.openerService.getOpener(node.uri);
opener.open(node.uri);
});
}
});
}

protected getSelectedFileNodes(): FileNode[] {
return this.tryGetWidget()?.model.selectedNodes.filter(FileNode.is) || [];
}

protected withWidget<T>(widget: Widget | undefined = this.tryGetWidget(), cb: (navigator: FileNavigatorWidget) => T): T | false {
Expand All @@ -348,7 +367,8 @@ export class FileNavigatorContribution extends AbstractViewContribution<FileNavi
});

registry.registerMenuAction(NavigatorContextMenu.NAVIGATION, {
commandId: CommonCommands.OPEN.id
commandId: FileNavigatorCommands.OPEN.id,
label: 'Open'
});
registry.registerSubmenu(NavigatorContextMenu.OPEN_WITH, 'Open With');
this.openerService.getOpeners().then(openers => {
Expand Down
5 changes: 3 additions & 2 deletions packages/navigator/src/browser/navigator-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,6 +31,7 @@ import { FileNavigatorModel } from './navigator-model';
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';
Expand Down Expand Up @@ -108,7 +109,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) {
Expand Down

0 comments on commit 8ac1e5f

Please sign in to comment.