[images] Address review feedback for EditExternallyAction

GitOrigin-RevId: ca7b6df730a5aa8d27aa0333561d5f6ef8b97e84
This commit is contained in:
Konstantin Nisht
2025-07-16 12:16:35 +00:00
committed by intellij-monorepo-bot
parent 2efb146b95
commit 736d0eb2fc
2 changed files with 4 additions and 14 deletions
@@ -1,5 +1,5 @@
error.title.launching.external.editor=Problem Launching External Executable
error.cannot.edit.image.external.editor=Can't edit image in external editor
error.cannot.edit.image.external.editor=Cannot edit image in an external editor
select.external.executable.title=Select Editor
select.external.executable.message=Select external graphics editor
@@ -12,6 +12,7 @@ import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.actionSystem.PlatformCoreDataKeys
import com.intellij.openapi.application.EDT
import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.progress.currentThreadCoroutineScope
import com.intellij.openapi.project.DumbAwareAction
import com.intellij.openapi.ui.Messages
import com.intellij.openapi.util.Disposer
@@ -117,7 +118,7 @@ internal class EditExternallyAction : DumbAwareAction() {
private fun performActionWithBackingFile(e: AnActionEvent, imageFile: VirtualFile) {
try {
val disposable = e.getDisposable()
disposable.launch {
currentThreadCoroutineScope().launch {
try {
val backingFile = imageFile.copyToBackingFile(disposable)
actionPerformed(e, backingFile)
@@ -138,7 +139,7 @@ internal class EditExternallyAction : DumbAwareAction() {
}
private fun VirtualFile.copyToBackingFile(disposable: Disposable): VirtualFile {
val filePath = Files.createTempFile("EditExternallyAction", name)
val filePath = Files.createTempFile("EditExternallyAction (copy)", name)
Disposer.register(disposable, Disposable {
filePath.safeDelete()
})
@@ -162,17 +163,6 @@ private fun Path.safeDelete() {
}
}
private fun Disposable.launch(block: suspend CoroutineScope.() -> Unit) {
val job = SupervisorJob()
@Suppress("SSBasedInspection")
CoroutineScope(job + Dispatchers.IO).launch {
block()
}
Disposer.register(this, Disposable {
job.cancel()
})
}
/**
* Tries to get a Disposable from the event
*