Dragging a wxFileDataObject to an external macOS application does not
provide valid file URLs. Cocoa recipients expect public.file-url pasteboard
data, but wx currently exposes the internal newline-separated filename data.
CFURL-backed public.file-url payloads.NSDraggingItem for every dragged file.External Cocoa targets, such as Finder, receive valid file URLs for single-
and multi-file drags.
https://github.com/wxWidgets/wxWidgets/pull/27047
(1 file)
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
@vadz commented on this pull request.
Thanks, I didn't test this but if it solves the problem with dragging files (does this work when dragging them from the dnd sample now?), it should be merged, of course, but I'm not sure about the NSDragOperationDelete removal.
@csomor Do you see anything wrong here?
> size_t size = m_data->GetDataSize(format); - CFMutableDataRef data = CFDataCreateMutable(kCFAllocatorDefault,size ); + CFMutableDataRef data = CFDataCreateMutable(kCFAllocatorDefault, size);
Minor, but please try to avoid making whitespace-only changes in the same commits as the actual changes, this is distracting and results in wrong results from git-blame later.
> wxCFMutableArrayRef<NSDraggingItem*> items;
- NSDraggingItem* item = [[NSDraggingItem alloc] initWithPasteboardWriter:writer];
- [item setDraggingFrame:NSMakeRect(p.x, p.y, 16, 16) contents:image];
- items.push_back(item);
+ wxPasteBoardWriter* writer = nil;
+
+ wxArrayString files = GetFilenamesFromDataObject(m_data);
+ if ( files.GetCount() > 1 )
+ {
+ for ( size_t i = 0; i < files.GetCount(); ++i )
+ {
+ wxCFRef<CFURLRef> url(wxOSXCreateURLFromFileSystemPath(files[i]));
+ if ( !url )
+ continue;
+
+ CFDataRef data = CFURLCreateData(nullptr, url, kCFStringEncodingUTF8, true);
Should also use wxCFRef<CFDataRef> here (and remove the explicit CFRelease() below).
> wxCFMutableArrayRef<NSDraggingItem*> items; - NSDraggingItem* item = [[NSDraggingItem alloc] initWithPasteboardWriter:writer]; - [item setDraggingFrame:NSMakeRect(p.x, p.y, 16, 16) contents:image]; - items.push_back(item); + wxPasteBoardWriter* writer = nil; + + wxArrayString files = GetFilenamesFromDataObject(m_data); + if ( files.GetCount() > 1 )
Why do we have to handle the case of a single file differently from multiple ones?
> + + if ( items.empty() )
This could/should be just
⬇️ Suggested change- - if ( items.empty() ) + else
, right?
> @@ -555,8 +623,11 @@ - (nullable id)pasteboardPropertyListForType:(nonnull NSPasteboardType)type
result = NSDragOperationToWxDragResult([delegate code]);
[delegate release];
[image release];
- [writer clearDataObject];
- [writer release];
+ if ( writer )
AFAIK this is not really needed, sending events to a nil object doesn't do anything anyhow.
> - // NSDragOperationGeneric also makes a drag to the trash possible - // resulting in something we don't support (NSDragOperationDelete)
I don't quite understand why is this code not correct any more, I think we still don't support NSDragOperationDelete and so dragging to the trash should remain forbidden.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
@exkrexpexfex commented on this pull request.
> wxCFMutableArrayRef<NSDraggingItem*> items; - NSDraggingItem* item = [[NSDraggingItem alloc] initWithPasteboardWriter:writer]; - [item setDraggingFrame:NSMakeRect(p.x, p.y, 16, 16) contents:image]; - items.push_back(item); + wxPasteBoardWriter* writer = nil; + + wxArrayString files = GetFilenamesFromDataObject(m_data); + if ( files.GetCount() > 1 )
It turns out the single-file case is not equivalent in practice. Using an explicit NSPasteboardItem containing only public.file-url makes Finder create an alias, while the existing wxPasteBoardWriter path preserves the additional pasteboard representations Finder needs to accept it as the actual file.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
@vadz commented on this pull request.
> wxCFMutableArrayRef<NSDraggingItem*> items; - NSDraggingItem* item = [[NSDraggingItem alloc] initWithPasteboardWriter:writer]; - [item setDraggingFrame:NSMakeRect(p.x, p.y, 16, 16) contents:image]; - items.push_back(item); + wxPasteBoardWriter* writer = nil; + + wxArrayString files = GetFilenamesFromDataObject(m_data); + if ( files.GetCount() > 1 )
Thanks, but it would be nice to explain this in a comment as it certainly doesn't seem obvious (at least to me).
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
@exkrexpexfex commented on this pull request.
> wxCFMutableArrayRef<NSDraggingItem*> items; - NSDraggingItem* item = [[NSDraggingItem alloc] initWithPasteboardWriter:writer]; - [item setDraggingFrame:NSMakeRect(p.x, p.y, 16, 16) contents:image]; - items.push_back(item); + wxPasteBoardWriter* writer = nil; + + wxArrayString files = GetFilenamesFromDataObject(m_data); + if ( files.GetCount() > 1 )
Checked again, it's fine here to handle both single and multiple files same way, the issue with links is due to the other suggestion, see answer on Trash denial thread
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
> - // NSDragOperationGeneric also makes a drag to the trash possible - // resulting in something we don't support (NSDragOperationDelete)
The problem I observed was Finder creating an alias instead of copying the file. The old NSDragOperationEvery mask still advertised NSDragOperationLink, although wxDropSource::DoDragDrop() has no flag for allowing link operations: its contract is Copy only, or Copy and Move when wxDrag_AllowMove/wxDrag_DefaultMove is supplied. Finder can select Link and create an alias.
The new code is therefore an explicit whitelist of the operations wx actually supports: Copy always, plus Move when requested. It still forbids Delete and Generic, and no longer offers unsupported Link.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
@exkrexpexfex pushed 1 commit.
—
View it on GitHub or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
> size_t size = m_data->GetDataSize(format); - CFMutableDataRef data = CFDataCreateMutable(kCFAllocatorDefault,size ); + CFMutableDataRef data = CFDataCreateMutable(kCFAllocatorDefault, size);
ok
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
> wxCFMutableArrayRef<NSDraggingItem*> items;
- NSDraggingItem* item = [[NSDraggingItem alloc] initWithPasteboardWriter:writer];
- [item setDraggingFrame:NSMakeRect(p.x, p.y, 16, 16) contents:image];
- items.push_back(item);
+ wxPasteBoardWriter* writer = nil;
+
+ wxArrayString files = GetFilenamesFromDataObject(m_data);
+ if ( files.GetCount() > 1 )
+ {
+ for ( size_t i = 0; i < files.GetCount(); ++i )
+ {
+ wxCFRef<CFURLRef> url(wxOSXCreateURLFromFileSystemPath(files[i]));
+ if ( !url )
+ continue;
+
+ CFDataRef data = CFURLCreateData(nullptr, url, kCFStringEncodingUTF8, true);
done
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
@exkrexpexfex commented on this pull request.
> wxCFMutableArrayRef<NSDraggingItem*> items; - NSDraggingItem* item = [[NSDraggingItem alloc] initWithPasteboardWriter:writer]; - [item setDraggingFrame:NSMakeRect(p.x, p.y, 16, 16) contents:image]; - items.push_back(item); + wxPasteBoardWriter* writer = nil; + + wxArrayString files = GetFilenamesFromDataObject(m_data); + if ( files.GetCount() > 1 )
so, done as suggested
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
> + + if ( items.empty() )
Yes, that's better, done
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
> @@ -555,8 +623,11 @@ - (nullable id)pasteboardPropertyListForType:(nonnull NSPasteboardType)type
result = NSDragOperationToWxDragResult([delegate code]);
[delegate release];
[image release];
- [writer clearDataObject];
- [writer release];
+ if ( writer )
ok
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
@vadz thanks for review! Files are dragging out of WX with these changes for me. NSDragOperationDelete is still denied, I have switched from blacklisting to whitelisting to explicitly allow Copy and Move while denying not only Delete but also Link
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
Thanks, I didn't test this but if it solves the problem with dragging files (does this work when dragging them from the
dndsample now?), it should be merged, of course, but I'm not sure about theNSDragOperationDeleteremoval.@csomor Do you see anything wrong here?
thanks @exkrexpexfex
I have to go through the changes, as I wasn't even aware this was not working properly under Cocoa (anymore ?), as I've been separating the Windows inspired files-data for decades before ...
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()