mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2025-12-06 09:29:38 +01:00
JBR-2736 provide writeObjects implementation for copying files/folders from Project Explorer to the Finder
(cherry picked from commit33db034d49) (cherry picked from commitd3ec3d899d)
This commit is contained in:
@@ -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()) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user