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

Cannot drag/drop file from VS Code to other apps due to invalid data object #91132

Open
davkean opened this issue Feb 21, 2020 · 13 comments
Open
Assignees
Labels
feature-request Request for new features or functionality file-explorer Explorer widget issues
Milestone

Comments

@davkean
Copy link
Member

davkean commented Feb 21, 2020

Version: 1.42.1 (user setup)
Commit: c47d83b
Date: 2020-02-11T14:45:59.656Z
Electron: 6.1.6
Chrome: 76.0.3809.146
Node.js: 12.4.0
V8: 7.6.303.31-electron.0
OS: Windows_NT x64 10.0.18363

Steps to Reproduce:

Drag a file from Explorer tool window and drop it onto:

Visual Studio

  1. Visual Studio's main window (with no editors open)

Expected: For VS to open the file
Actual: Get stop icon indicating the drag is not supported

  1. C# project in Solution Explorer

Expected: For the file to be copied to the project
Actual: Get an drag icon indicating that a Copy will occur, but after dropping nothing happens --

Outlook

  1. Onto Outlook

Expected: New Email with file as attachment
Actual : Message Box with Cannot copy the items

Excel

  1. Drop it on Excel

Expected: File to be opened as text
Actual: Just the file name is pasted into cell

Does this issue occur when all extensions are disabled?: Yes

Background

I work on Visual Studio and debugged this from our side, and this is what I've found. We are expecting a format of CF_HDROP and doing the following pseudo code:

var format = new FORMATETC
{
    cfFormat = CF_HDROP,
    ptd = IntPtr.Zero,
    dwAspect = (uint)DVASPECT.DVASPECT_CONTENT,
    lindex = -1,
    tymed = (uint)TYMED.TYMED_HGLOBAL
};

var storage = default(STGMEDIUM);

if (dataObject.QueryGetData(format) == S_OK)
{
     dataObject.GetData(format, storage) // "Invalid FORMATETC structure (0x80040064 - DV_E_FORMATETC)
}

QueryGetData is saying "I support this format", yet GetData is returning a HRESULT saying the format we just passed to QueryGetData is invalid. I suspect this is happening similarly in other applications. We have 4 or 5 places we look CF_HDROP and everyone of them fails.

I spent a little bit of time trying to figure out how VS Code produces CF_HDROP but to no avail. Could not find any code that looks like it puts a data object into the clipboard other than text.

@isidorn
Copy link
Contributor

isidorn commented Feb 21, 2020

@davkean hi. Thanks for trying this out and for providing feedback.
The only custom data transfer we set from the explorer is a file transfer to be able to DND between multiple code file explorers across windows. We also apply some datatransfer types to allow for dragging the element outside of the application.

Feel free to experiment with the code here

If you can make this work to be able to drop in Visual Studio while still working with our current use cases of dropping between VS Code instances and native explorer / finders then we would be open to accept a PR.

fyi @bpasero

@isidorn isidorn added feature-request Request for new features or functionality file-explorer Explorer widget issues labels Feb 21, 2020
@isidorn isidorn added this to the Backlog milestone Feb 21, 2020
@davkean
Copy link
Member Author

davkean commented Feb 21, 2020

That's fine, but the Window's Shell IDataObject that VS Code is providing says it supports "CF_HDROP". If it indeed does not provide that format, then QueryGetData should be returning DV_E_FORMATETC, so that the drop operation is blocked.

@isidorn
Copy link
Contributor

isidorn commented Feb 21, 2020

Not sure how much of this behavior we can control since that is probably just done by Chrome (since VS Code is built on top of Electron that uses Chrome). Anyways just try changing the code at the pointer I provided, not sure if possible to achieve what you would like. Thanks

@bpasero
Copy link
Member

bpasero commented Feb 21, 2020

Duplicate of #164

Electron does not give us any data to control the contents of the operation as far as I know.

@bpasero bpasero marked this as a duplicate of #164 Feb 21, 2020
@davkean
Copy link
Member Author

davkean commented Feb 21, 2020

@bpasero A quick search through the Chromium source, I can find code that pulls CF_HDROP from the clipboard, but can't find the actual implementation of the IDataObject that we're seeing as the target or anything pushing CF_HDROP on the clipboard. It's the one that has a broken QueryGetData.

@bpasero
Copy link
Member

bpasero commented Feb 21, 2020

There is actually API: https://github.com/electron/electron/blob/7-0-x/docs/api/clipboard.md

Related: electron/electron#11838

I am open for help here, be it Electron, Chrome itself or VSCode side if we can improve this.

//cc @deepak1556

@davkean
Copy link
Member Author

davkean commented Feb 24, 2020

There's two things here;

  1. A bug where VS Code is saying it provides "CF_HDROP/FileDrop" when it actually doesn't
  2. A feature to support "CF_HDROP/FileDrop".

@jrlanglois
Copy link

jrlanglois commented Dec 17, 2020

Can confirm this still happens in the latest vscode.

@mjbvz
Copy link
Collaborator

mjbvz commented May 4, 2023

With #181373, we now set the standard text/uri-list mime when dragging resources in VS Code (this is done using the standard drag and drop API, not anything electron specific)

I've confirmed that this works correctly when dropping from VS Code into the Chrome address bar

@davkean Does VS handle drops of text/uri-list from browsers (not sure what the internal id of this type is)? I tried but I don't think it does?

@davkean
Copy link
Member Author

davkean commented May 4, 2023

No we don't, but will file a bug to accept it.

@mjbvz The intention here is to only support dragging to another app and have it open the file? You are not adding support for copy/move? For copy/move (say to Solution Exporer in Visual Studio or File Explorer in Windows), you should be using CF_HDROP/FileDrop.

@davkean
Copy link
Member Author

davkean commented May 4, 2023

I should state, this particular bug was that VS Code's data object was saying that supported "CF_HDROP/FileDrop" but it didn't actually when it came to pulling the data.

@mjbvz
Copy link
Collaborator

mjbvz commented May 5, 2023

You are not adding support for copy/move?

With this change, drops from VS Code should look like drops from any webpage that sets text/uri-list on a drag event. Again not sure about the OS types but we don't say anything about copy vs move

@satnam888
Copy link

I wish...

Eg: I am using VSC and would like to be able to drag a file from the Explorer side bar to say a different application just like i might do from a (MacOs) Finder window or a windows 11 Explorer window.

The drag shouldn't move a file - just allows a file to be handled just like it would be if I was doing it from an OS File Explorer window.

At the moment I have to say something like Reveal in Finder and the drag from there (ie a 2 stage process).

Even if user was required to press CTRL or ALT as part of the DRAG would be better to make it a single step and easier process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality file-explorer Explorer widget issues
Projects
None yet
Development

No branches or pull requests

8 participants