ryanmcgrath / cacao

Rust bindings for AppKit (macOS) and UIKit (iOS/tvOS). Experimental, but working!
MIT License
1.86k stars 69 forks source link

Implement `writeObjects` for Pasteboard #22

Open jdmremi opened 2 years ago

jdmremi commented 2 years ago

Referencing this Stack Overflow article, the following code allows the user to copy some object (in this case, a file) to the clipboard:

NSURL *object = [[NSURL alloc] initFileURLWithPath:@"/Users/username/Desktop/main.png"];
NSPasteboard *pb = [NSPasteboard generalPasteboard];
[pb clearContents];

NSArray *objectsToCopy = [[NSArray alloc] initWithObjects:object, nil];
BOOL pasted = [pb writeObjects:objectsToCopy];

if(pasted) // paste was successful
    NSLog(@"pasted");

[object release];
[objectsToCopy release];
[pb release];

However, after reading through the documentation/the Pasteboard implementation, it does not appear that there is a straightforward way to do this by using Cacao, as there is only support for writing text to the Pasteboard (clipboard).

ryanmcgrath commented 2 years ago

This should actually be easier in the 0.3 branch, which I need to land. Will revisit it then - hopefully within the next week or two.

jdmremi commented 2 years ago

Hey! Any update on this request?