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: fix explorer 'open' command #8228

Merged
merged 1 commit into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
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
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 @@ -85,8 +85,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 @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down