mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[DataSpell] Remove the hack to support png copy on macos
This hack was introduced due to JDK issue JBR-9044, but it was fixed in Java 21 JBR JBR-8952 GitOrigin-RevId: 14b7c7eac18540df913ffef18ccb251ed2602c5a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f99404d420
commit
170d39bc5c
+1
-34
@@ -1,19 +1,12 @@
|
||||
/*
|
||||
* Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
*/
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
|
||||
package com.intellij.notebooks.visualization.r.inlays
|
||||
|
||||
import com.intellij.openapi.ide.CopyPasteManager
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.util.system.OS
|
||||
import java.awt.Image
|
||||
import java.awt.datatransfer.DataFlavor
|
||||
import java.awt.datatransfer.Transferable
|
||||
import java.awt.datatransfer.UnsupportedFlavorException
|
||||
import java.awt.image.BufferedImage
|
||||
import java.io.File
|
||||
import javax.imageio.ImageIO
|
||||
|
||||
// TODO: Some problems with getting "event.isControlDown" on component placed on top of Idea Editor content.
|
||||
/** Clipboard utils to realize Ctrl+C functionality in Table and Plots. */
|
||||
@@ -23,32 +16,6 @@ object ClipboardUtils {
|
||||
CopyPasteManager.getInstance().setContents(ImageTransferable(image))
|
||||
}
|
||||
|
||||
// We have a situation that on some MacOS the image is copied as TIFF.
|
||||
// To avoid this situation on Mac, we have a special transferable which copies image as png.
|
||||
// https://bugs.openjdk.org/browse/JDK-8313706
|
||||
// https://youtrack.jetbrains.com/issue/PY-69919/Result-of-Copy-plot-command-results-in-Unsupported-image-type-in-Google-Slides
|
||||
fun copyPngImageToClipboard(image: BufferedImage) {
|
||||
val tempImage = FileUtil.createTempFile("clipboard", ".png")
|
||||
ImageIO.write(image, "png", tempImage)
|
||||
|
||||
CopyPasteManager.getInstance().setContents(FileTransferable(listOf(tempImage)))
|
||||
}
|
||||
|
||||
// Standard copy works incorrectly on Mac, see JBR-6788,
|
||||
// But it seemingly was fixed in the newer (15 and later) Mac versions
|
||||
fun isIntermediateFileWorkaroundNeeded(): Boolean = OS.CURRENT == OS.macOS && !OS.CURRENT.isAtLeast(15, 0)
|
||||
|
||||
private class FileTransferable(private val files: List<File>) : Transferable {
|
||||
override fun getTransferDataFlavors(): Array<DataFlavor> = arrayOf(DataFlavor.javaFileListFlavor)
|
||||
override fun isDataFlavorSupported(flavor: DataFlavor): Boolean = DataFlavor.javaFileListFlavor.equals(flavor)
|
||||
override fun getTransferData(flavor: DataFlavor): List<File> {
|
||||
if (!isDataFlavorSupported(flavor))
|
||||
throw UnsupportedFlavorException(flavor)
|
||||
|
||||
return files
|
||||
}
|
||||
}
|
||||
|
||||
private class ImageTransferable(private val image: Image) : Transferable {
|
||||
override fun getTransferDataFlavors(): Array<DataFlavor> {
|
||||
return arrayOf(DataFlavor.imageFlavor)
|
||||
|
||||
Reference in New Issue
Block a user