Skip to content

Commit

Permalink
Support dragging files in browser
Browse files Browse the repository at this point in the history
  • Loading branch information
msujew committed Jan 22, 2025
1 parent ecf65d3 commit 6e24f8d
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions packages/core/src/browser/shell/application-shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from '@phosphor/widgets';
import { Message } from '@phosphor/messaging';
import { IDragEvent } from '@phosphor/dragdrop';
import { RecursivePartial, Event as CommonEvent, DisposableCollection, Disposable, environment, isObject } from '../../common';
import { RecursivePartial, Event as CommonEvent, DisposableCollection, Disposable, environment, isObject, UntitledResourceResolver, UNTITLED_SCHEME } from '../../common';
import { animationFrame } from '../browser';
import { Saveable, SaveableWidget, SaveOptions } from '../saveable';
import { StatusBarImpl, StatusBarEntry, StatusBarAlignment } from '../status-bar/status-bar';
Expand Down Expand Up @@ -232,6 +232,9 @@ export class ApplicationShell extends Widget {
@inject(OpenerService)
protected readonly openerService: OpenerService;

@inject(UntitledResourceResolver)
protected readonly untitledResourceResolver: UntitledResourceResolver;

protected readonly onDidAddWidgetEmitter = new Emitter<Widget>();
readonly onDidAddWidget = this.onDidAddWidgetEmitter.event;
protected fireDidAddWidget(widget: Widget): void {
Expand Down Expand Up @@ -572,10 +575,21 @@ export class ApplicationShell extends Widget {
uris.forEach(openUri);
} else if (event.dataTransfer.files?.length > 0) {
// the files were dragged from the outside the workspace
Array.from(event.dataTransfer.files).forEach(file => {
if (file.path) {
const fileUri = URI.fromFilePath(file.path);
openUri(fileUri);
Array.from(event.dataTransfer.files).forEach(async file => {
if (environment.electron.is()) {
if (file.path) {
const fileUri = URI.fromFilePath(file.path);
openUri(fileUri);
}
} else {
const fileContent = await file.text();
const fileName = file.name;
const untitledResource = await this.untitledResourceResolver.createUntitledResource(
fileContent,
undefined,
new URI(`${UNTITLED_SCHEME}:/${fileName}`)
);
openUri(untitledResource.uri);
}
});
}
Expand Down

0 comments on commit 6e24f8d

Please sign in to comment.