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

Support dragging files in browser #14756

Merged
merged 1 commit into from
Jan 30, 2025
Merged

Support dragging files in browser #14756

merged 1 commit into from
Jan 30, 2025

Conversation

msujew
Copy link
Member

@msujew msujew commented Jan 22, 2025

What it does

Adds a feature that wasn't originally included in #12065. We currently support dragging files from the OS explorer to the main area of Theia, which results in opening the exact file (via its original URI) that was dropped into the application.

This won't work in browser based Theia apps for obvious reasons. Instead, this PRs adjusts the behavior for non-Electron apps. We now simply read the file name and text data of the dropped file into an untitled resource that we then attempt to open. Reusing untitled resources has a few benefits, mainly that it automatically handles disposal in case the editor is closed and also that it has special behavior when it comes to saving the file (it will automatically open the "Save As..." dialog).

How to test

  1. Open the browser example app
  2. Drag & drop a text (!) file into the main area. Dropping a non-text file (like an image) into the editor will usually result in unexpected behavior. However, it seems like vscode.dev also struggles with that, so it's at least as good as VS Code.
  3. The file should open, contain the expected file name and otherwise behave as any other untitled resource.

Follow-ups

We could potentially also support non-text files later on.

Review checklist

Reminder for reviewers

@msujew msujew added dnd issues related to drag & drop browser issues specific to the browser use-case labels Jan 22, 2025
@msujew msujew requested a review from tsmaeder January 22, 2025 16:35
@msujew msujew force-pushed the msujew/dnd-browser branch from 6e24f8d to f111561 Compare January 22, 2025 16:39
@tsmaeder
Copy link
Contributor

@msujew I have a strange behavior: when I drag a file into the editor area, it opens in a dirty text editor, as expected. But when I click on the close box, I only get two options: "Save" and "Cancel". I should have "Don't save", as well.

@msujew
Copy link
Member Author

msujew commented Jan 29, 2025

@tsmaeder Cannot reproduce :/

Screen.Recording.2025-01-29.181928.mp4

@msujew
Copy link
Member Author

msujew commented Jan 29, 2025

The Don't save button isn't even conditional; it should always appear on the dialog. Perhaps something in your build broke for some reason?

constructor(widget: Widget) {
super({
title: nls.localizeByDefault('Do you want to save the changes you made to {0}?', widget.title.label || widget.title.caption)
}, {
node: widget.node.ownerDocument.createElement('div')
});
const messageNode = this.node.ownerDocument.createElement('div');
messageNode.textContent = nls.localizeByDefault("Your changes will be lost if you don't save them.");
messageNode.setAttribute('style', 'flex: 1 100%; padding-bottom: calc(var(--theia-ui-padding)*3);');
this.contentNode.appendChild(messageNode);
this.appendCloseButton();
this.dontSaveButton = this.appendDontSaveButton();
this.appendAcceptButton(nls.localizeByDefault('Save'));
}

@tsmaeder
Copy link
Contributor

Here's what I do...looks like the untitled resource causes a "save as..." dialog. This is firefox on windows.

2025-01-29.20-38-23.mp4

Copy link
Contributor

@tsmaeder tsmaeder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had "autosave" on for some reason 🤷

@msujew msujew merged commit ec39f83 into master Jan 30, 2025
11 checks passed
@github-actions github-actions bot added this to the 1.58.0 milestone Jan 30, 2025
@msujew msujew deleted the msujew/dnd-browser branch January 30, 2025 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
browser issues specific to the browser use-case dnd issues related to drag & drop
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants