IDEA-342398 Fix modality in ImageFileService

When invoked from a modal dialog, the previous implementation
would never be invoked until the dialog is closed. If the image editor
is in the dialog, it would never show an image.

This service was initially supposed to work in any modal context.
It's because it used to be completely synchronous code before,
so it's really supposed to be invoked as soon as possible,
just without blocking the EDT anymore.

GitOrigin-RevId: 778f870a70a6078fdab893b91e1ea8ab42265ee2
This commit is contained in:
Sergei Tachenov
2024-01-08 14:51:47 +02:00
committed by intellij-monorepo-bot
parent 6ca3373c89
commit 5934649315

View File

@@ -2,6 +2,8 @@
package org.intellij.images.editor.impl
import com.intellij.openapi.application.EDT
import com.intellij.openapi.application.ModalityState
import com.intellij.openapi.application.asContextElement
import com.intellij.openapi.components.Service
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.project.Project
@@ -35,7 +37,7 @@ internal class ImageFileService(
try {
val imageProvider = withContext(Dispatchers.IO) { IfsUtil.getImageProvider(file) }
val format = withContext(Dispatchers.IO) { IfsUtil.getFormat(file) }
withContext(Dispatchers.EDT) {
withContext(Dispatchers.EDT + ModalityState.any().asContextElement()) {
target.setImageProvider(imageProvider, format)
}
}