Repository navigation
feat(desktop): drag files out of the app from a view - #2837
Merged
Merged
Conversation
Add core.View.Desktop.DragFiles, DragFilesMove and OnDragFilesEnd: a drag on the view past the platform's drag distance carries the files to Finder, Explorer, a Linux file manager or another app, through an NSDraggingSession on macOS, SHDoDragDrop with the shell's data object on Windows and a GtkDragSource with a GdkFileList on Linux. nsgotest's DragFilesOut returns the paths offered and ends the drag with an operation. Fixes #2829
…t press Reuse the existing g_file_new_for_path binding on Linux instead of declaring it twice, build the core test's file list with NewSignalFunc, and clear the view a press would drag files from on every press and release, so a press a scroll bar, selection, braked touch or hosted widget takes cannot start a drag of an earlier press's files. Add mapping tests for the macOS and Windows end operations and a Linux native test of the drag source.
|
This pull request has no valid
Run the checks on the head commit, fill the block in the template, then push or edit the body: this label and comment update on their own. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
An app can now drag files it names out of a view to Finder, Explorer, a Linux file manager or any other app that takes files, the outgoing twin of
OnFileDrop.core.View.Desktop.DragFilesreturns absolute paths; the drag starts once the press moves past the platform's drag distance, so a shorter press stays a press.DragFilesMovelets the destination move the files instead of copying them, andOnDragFilesEndreceives acore.DragOperation(copied, moved, linked or cancelled).nsgotest'sApp.DragFilesOut(selector, op)(andSurface.DragFilesOut) returns the paths a view offers and ends the drag with the given operation, andView.Props.DragFileList()shows what a view offers.ViewProps.DragFilesand sets the view'sEventDragFilesEndbit.EventMaskhas no free bit, so it sharesEventOpenURL's, an answer that names no view; one with an ID is a drag's end.NSDraggingSessionfrom the view'sNSView(itsNSDraggingSource), oneNSDraggingItemper file with anNSURLfile URL and its Finder icon.BHID_DataObject(CF_HDROP and shell ID lists), run withSHDoDragDrop; an optimized move is read fromPerformed DropEffect.GtkDragSourceon the surface whoseprepareanswers only for the view the current press went down on, with aGdkFileList. Every press and release clears that view first, so a press a scroll bar, a text selection, a braked touch or a hosted widget takes, or a press released short of GTK's threshold, cannot later start a drag of another view's files.nsgotestmodels, the macOS end-operation mapping and source mask, the WindowsDROPEFFECTmapping, and a Linux native test that drivesprepare/drag-endby hand: a press on the view released short of the threshold firesOnPressand leaves nothing to drag, a following press the text selection takes prepares no drag, and a press on the view prepares one whose cancellation reachesOnDragFilesEnd.docs/roadmap.md.Fixes #2829
Targets
core,base,ui,tsx, thensgotool)Screenshots
None
Verification
375b833fc03dfbadbfc59016149caeb9a72af6cda10710d3c89cd6b94c4131684d10ffc0fe7385c3(main)go tool nsgo check -target macos,windows,linux -jobs 6→ exit code 0 (vets linux, macos and windows on arm64 and x64, test files included)go tool nsgo test ./core ./nsgotest ./internal/driver→ exit code 0 (1545 passed, 0 failed, 1 skipped)go tool nsgo test -run 'TestDragOperation|TestFileDragMask' ./internal/platform/macos→ exit code 0 (2 passed)passedTestFileDragOutAnswersOnlyThePressOnItsView) and the Windows test (TestDropOperationMapsTheDragsEnd) were compiled by the vet above but not run, since no Linux or Windows host was available; the macOS run was on x64 only. The below-threshold press path on macOS and Windows has no backend test (it goes through each backend's existing pan activation). Real drags to Finder, Explorer and a Linux file manager were not checked by hand on any desktop.Checklist
fix(linux): keep the caret after a paste; a squash merge uses it as the commit subject.changelog.d/fragment, not inCHANGELOG.md.