8314498: [macos] Transferring File objects to Finder fails

Co-authored-by: Andrey Starovoyt <Andrey.Starovoyt@jetbrains.com>
Reviewed-by: prr
This commit is contained in:
Alexey Ushakov 2024-07-15 23:25:11 +00:00
parent c8a95a763c
commit bc7cd42d11
2 changed files with 39 additions and 1 deletions

View File

@ -89,7 +89,11 @@ final class CClipboard extends SunClipboard {
try {
byte[] bytes = DataTransferer.getInstance().translateTransferable(contents, flavor, format);
setData(bytes, format);
if (DataFlavor.javaFileListFlavor.equals(flavor)) {
writeFileObjects(bytes);
} else {
setData(bytes, format);
}
} catch (IOException e) {
// Fix 4696186: don't print exception if data with
// javaJVMLocalObjectMimeType failed to serialize.
@ -127,6 +131,7 @@ final class CClipboard extends SunClipboard {
private native void declareTypes(long[] formats, SunClipboard newOwner);
private native void setData(byte[] data, long format);
private native void writeFileObjects(byte[] data);
void checkPasteboardAndNotify() {
if (checkPasteboardWithoutNotification()) {

View File

@ -174,6 +174,39 @@ JNI_COCOA_ENTER(env);
JNI_COCOA_EXIT(env);
}
/*
* Class: sun_lwawt_macosx_CClipboard
* Method: writeFileObjects
* Signature: ([B)V
*/
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CClipboard_writeFileObjects
(JNIEnv *env, jobject inObject, jbyteArray inBytes)
{
CHECK_NULL(inBytes);
JNI_COCOA_ENTER(env);
jint nBytes = (*env)->GetArrayLength(env, inBytes);
jbyte *rawBytes = (*env)->GetPrimitiveArrayCritical(env, inBytes, NULL);
CHECK_NULL(rawBytes);
NSMutableArray *formatArray = [NSMutableArray arrayWithCapacity:2];
int i = 0;
for (int j = 0; j < nBytes; j++) {
if (rawBytes[j] == 0) {
NSString *path = [NSString stringWithUTF8String:(const char*)(rawBytes + i)];
NSURL *fileURL = [NSURL fileURLWithPath:path];
[formatArray addObject:fileURL.absoluteURL];
i = j + 1;
}
}
(*env)->ReleasePrimitiveArrayCritical(env, inBytes, rawBytes, JNI_ABORT);
[ThreadUtilities performOnMainThreadWaiting:YES block:^() {
[[NSPasteboard generalPasteboard] writeObjects:formatArray];
}];
JNI_COCOA_EXIT(env);
}
/*
* Class: sun_lwawt_macosx_CClipboard
* Method: getClipboardFormats