JBR-2736 provide writeObjects implementation for copying files/folders from Project Explorer to the Finder

(cherry picked from commit 33db034d49)
(cherry picked from commit d3ec3d899d)
This commit is contained in:
Andrey Starovoyt
2020-09-24 15:59:05 +03:00
committed by jbrbot
parent 4034e228c1
commit 1f76ef495f
2 changed files with 48 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)) {
writeObjects(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 writeObjects(byte[] data);
void checkPasteboardAndNotify() {
if (checkPasteboardWithoutNotification()) {

View File

@@ -175,6 +175,48 @@ JNI_COCOA_ENTER(env);
JNI_COCOA_EXIT(env);
}
/*
* Class: sun_lwawt_macosx_CClipboard
* Method: writeObjects
* Signature: ([BJ)V
*/
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CClipboard_writeObjects
(JNIEnv *env, jobject inObject, jbyteArray inBytes, jlong inFormat)
{
if (inBytes == NULL) {
return;
}
JNI_COCOA_ENTER(env);
jint nBytes = (*env)->GetArrayLength(env, inBytes);
jbyte *rawBytes = (*env)->GetPrimitiveArrayCritical(env, inBytes, NULL);
CHECK_NULL(rawBytes);
NSData *bytesAsData = [NSData dataWithBytes:rawBytes length:nBytes];
(*env)->ReleasePrimitiveArrayCritical(env, inBytes, rawBytes, JNI_ABORT);
NSString *format = formatForIndex(inFormat);
NSMutableArray *formatArray = [NSMutableArray arrayWithCapacity:2];
const char *bytes = [bytesAsData bytes];
BOOL isStart=YES;
for (int i = 0; i < [bytesAsData length]; i++) {
if ((unsigned char)bytes[i] == 0) {
isStart = YES;
} else {
if (isStart) {
isStart = NO;
NSString *path = [NSString stringWithUTF8String:(const char *)&bytes[i]];
NSURL *fileURL = [NSURL fileURLWithPath:path relativeToURL:nil];
[formatArray addObject:fileURL];
}
}
}
[ThreadUtilities performOnMainThreadWaiting:YES block:^() {
[[NSPasteboard generalPasteboard] writeObjects:formatArray];
}];
JNI_COCOA_EXIT(env);
}
/*
* Class: sun_lwawt_macosx_CClipboard
* Method: getClipboardFormats