-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
[PTRun] Drag and drop files #22409
[PTRun] Drag and drop files #22409
Conversation
Is this feature only for folder plugin? It might make sense to have it in the indexer plugin too. |
As already stated above, this feature is available for the following plugins:
|
But is it correct that the everything plugin needs to be updated to implement the new interface? |
Yes. But I can't do it without having this changes in PTRun first. :-) |
Do we have a check if the access to the path is denied. We should prevent a crash in this case. |
Hm, not sure what to do... The Drag&Drop does not process "the file" in any way but only passes the path (string) as data to the shell. So Open questions:
|
Regarding the error check: If we can't crash or hang I see no reason to handle something in our code.
Not sure. But it shouldn't be to complicated.
Regarding the thumbnail: Do you have a screenshot of what you mean? |
This comment has been minimized.
This comment has been minimized.
Done. Changed _viewModel.Hide();
try
{
// DoDragDrop with file thumbnail as drag image
var dataObject = DragDataObject.FromFile(fileDropResult.Path);
IntPtr hBitmap = Image.WindowsThumbnailProvider.GetHBitmap(Path.GetFullPath(fileDropResult.Path), Constant.ThumbnailSize, Constant.ThumbnailSize, Image.ThumbnailOptions.None);
try
{
dataObject.SetDragImage(hBitmap, Constant.ThumbnailSize, Constant.ThumbnailSize);
DragDrop.DoDragDrop(ListBox.SuggestionsList, dataObject, DragDropEffects.Copy);
}
finally
{
Image.NativeMethods.DeleteObject(hBitmap);
}
}
catch
{
// DoDragDrop without drag image
IDataObject dataObject = new DataObject(DataFormats.FileDrop, new[] { fileDropResult.Path });
DragDrop.DoDragDrop(ListBox.SuggestionsList, dataObject, DragDropEffects.Copy);
} I added src/modules/launcher/PowerLauncher/Helper/DragDataObject.cs with helper methods to deal with shell data objects (and drag images) and had to make |
@daniel-richter |
It's done before starting the drag&drop action (after clicking one result item and dragging the mouse the minumum drag distance). So drag&drop function won't affect searching in any way. Creating the hBitmap could be slow, but the Folder and Indexer plugins will set the The thumbnails for search results will be cached ( |
This comment has been minimized.
This comment has been minimized.
Okay, found a solution in https://stackoverflow.com/a/2897325 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty nice feature, and it's working very well!
Thanks a lot for the contribution!
Summary of the Pull Request
Support drag&drop to other application for files in result list.
PR Checklist
Detailed Description of the Pull Request / Additional comments
To implement this behaviour, I added the following things:
detect dragging an item from the suggestions list
extend src/modules/launcher/PowerLauncher/MainWindow.xaml.cs
Save mouse position on mouse down and check aggainst system drag distance
check whether this item represents a file/folder (something path-related)
Since all plugins that return files/folders put their data objects containing the path information into
Result.ContextData
, I decided to introduce an interfaceIFileDropResult
to indicate that a result contains a file/folder to be draggable.src/modules/launcher/Wox.Plugin/Interfaces/IFileDropResult.cs
So we can check whether the result connected to the view model of the clicked result item implements this interface.
perform a DragDrop with path as FileDrop
If so, the PTRun window will be hidden and the corresponding path of the dragged item will be made available for dragging as FileDrop:
make related plugins (that return files/folders) mark their results as draggable file/folder
The search result types of the following plugins now implement
IFileDropResult
:For unification, I had to rename Folder/SearchResult's
FullPath
toPath
.Validation Steps Performed
(See screen recording)