Skip to content

Commit 47dfd87

Browse files
Open external files by DND into main panel (#9955)
Drag and dropping files from the file system into the main panel now opens their respective editors in the electron app. Previously, files that could not be matched to a navigator tree node were ignored. Signed-off-by: Alexandra Buzila <abuzila@eclipsesource.com>
1 parent 840490b commit 47dfd87

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
[1.17.0 Milestone](https://github.com/eclipse-theia/theia/milestone/23)
66

77
- [core] modified handling of toolbar items for `ViewContainer`s to handle `onDidChange` correctly. [#9798](https://github.com/eclipse-theia/theia/pull/9798)
8+
- [navigator] added support for opening external files by drag and dropping into the main panel [#9543](https://github.com/eclipse-theia/theia/issues/9543)
89

910
<a name="breaking_changes_1.17.0">[Breaking Changes:](#breaking_changes_1.17.0)</a>
1011

packages/navigator/src/browser/navigator-widget.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { injectable, inject, postConstruct } from '@theia/core/shared/inversify'
1818
import { Message } from '@theia/core/shared/@phosphor/messaging';
1919
import URI from '@theia/core/lib/common/uri';
2020
import { CommandService, SelectionService } from '@theia/core/lib/common';
21-
import { CorePreferences, Key, TreeModel, SelectableTreeNode } from '@theia/core/lib/browser';
21+
import { CorePreferences, Key, TreeModel, SelectableTreeNode, OpenerService } from '@theia/core/lib/browser';
2222
import {
2323
ContextMenuRenderer, ExpandableTreeNode,
2424
TreeProps, TreeNode
@@ -45,6 +45,8 @@ export class FileNavigatorWidget extends FileTreeWidget {
4545
@inject(NavigatorContextKeyService)
4646
protected readonly contextKeyService: NavigatorContextKeyService;
4747

48+
@inject(OpenerService) protected readonly openerService: OpenerService;
49+
4850
constructor(
4951
@inject(TreeProps) readonly props: TreeProps,
5052
@inject(FileNavigatorModel) readonly model: FileNavigatorModel,
@@ -106,13 +108,20 @@ export class FileNavigatorWidget extends FileTreeWidget {
106108
const mainPanelNode = this.shell.mainPanel.node;
107109
this.addEventListener(mainPanelNode, 'drop', async ({ dataTransfer }) => {
108110
const treeNodes = dataTransfer && this.getSelectedTreeNodesFromData(dataTransfer) || [];
109-
treeNodes.filter(FileNode.is).forEach(treeNode => {
110-
if (!SelectableTreeNode.isSelected(treeNode)) {
111-
this.model.toggleNode(treeNode);
112-
}
113-
});
114111
if (treeNodes.length > 0) {
112+
treeNodes.filter(FileNode.is).forEach(treeNode => {
113+
if (!SelectableTreeNode.isSelected(treeNode)) {
114+
this.model.toggleNode(treeNode);
115+
}
116+
});
115117
this.commandService.executeCommand(FileNavigatorCommands.OPEN.id);
118+
} else if (dataTransfer && dataTransfer.files?.length > 0) {
119+
// the files were dragged from the outside the workspace
120+
Array.from(dataTransfer.files).forEach(async file => {
121+
const fileUri = new URI(file.path);
122+
const opener = await this.openerService.getOpener(fileUri);
123+
opener.open(fileUri);
124+
});
116125
}
117126
});
118127
const handler = (e: DragEvent) => {

0 commit comments

Comments
 (0)