From 9d5c82f458c78fb7ae9507cb09dbf83b0f270d3c Mon Sep 17 00:00:00 2001 From: Louis Vignier Date: Mon, 26 May 2025 12:40:31 +0200 Subject: [PATCH] [codeInspection.ui] Make InspectionResultsExportActionProvider stateless IJ-CR-163402 GitOrigin-RevId: 89b5fa8e84e5a196c80e8e240dc02dbdeb7b1987 --- platform/lang-impl/api-dump-unreviewed.txt | 7 ++-- .../ui/actions/ExportToHTMLAction.kt | 20 +++++------ .../InspectionResultsExportActionProvider.kt | 35 +++++++++++-------- 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/platform/lang-impl/api-dump-unreviewed.txt b/platform/lang-impl/api-dump-unreviewed.txt index 7e70afcb9a77..e32af2582c6a 100644 --- a/platform/lang-impl/api-dump-unreviewed.txt +++ b/platform/lang-impl/api-dump-unreviewed.txt @@ -5991,13 +5991,12 @@ c:com.intellij.codeInspection.ui.RefElementNode a:com.intellij.codeInspection.ui.actions.InspectionResultsExportActionProvider - com.intellij.codeInspection.ui.actions.InspectionViewActionBase - sf:Companion:com.intellij.codeInspection.ui.actions.InspectionResultsExportActionProvider$Companion -- sf:LOCATION_KEY:java.lang.String +- sf:LOCATION_PROPERTY_NAME:java.lang.String - (java.util.function.Supplier,java.util.function.Supplier,javax.swing.Icon):V - actionPerformed(com.intellij.openapi.actionSystem.AnActionEvent):V -- additionalSettings():javax.swing.JPanel +- additionalSettings(com.intellij.openapi.util.UserDataHolderEx):javax.swing.JPanel - a:getProgressTitle():java.lang.String -- f:getPropertyGraph():com.intellij.openapi.observable.properties.PropertyGraph -- onExportSuccessful():V +- onExportSuccessful(com.intellij.openapi.util.UserDataHolderEx):V - a:writeResults(com.intellij.codeInspection.ui.InspectionTree,com.intellij.codeInspection.ex.InspectionProfileImpl,com.intellij.codeInspection.ex.GlobalInspectionContextImpl,com.intellij.openapi.project.Project,java.nio.file.Path):V f:com.intellij.codeInspection.ui.actions.InspectionResultsExportActionProvider$Companion - f:getEP_NAME():com.intellij.openapi.extensions.ExtensionPointName diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/actions/ExportToHTMLAction.kt b/platform/lang-impl/src/com/intellij/codeInspection/ui/actions/ExportToHTMLAction.kt index 3edc0962a064..83ac86c8520f 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/actions/ExportToHTMLAction.kt +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/actions/ExportToHTMLAction.kt @@ -9,6 +9,8 @@ import com.intellij.codeInspection.ui.InspectionTree import com.intellij.icons.AllIcons import com.intellij.ide.BrowserUtil import com.intellij.openapi.project.Project +import com.intellij.openapi.util.Key +import com.intellij.openapi.util.UserDataHolderEx import com.intellij.ui.dsl.builder.panel import org.jetbrains.annotations.ApiStatus import java.nio.file.Path @@ -22,32 +24,30 @@ class ExportToHTMLAction : InspectionResultsExportActionProvider(Supplier { "HTM AllIcons.FileTypes.Html) { override val progressTitle: String = InspectionsBundle.message("inspection.generating.html.progress.title") - var open: Boolean = false - var outputPath: Path? = null - override fun writeResults(tree: InspectionTree, profile: InspectionProfileImpl, globalInspectionContext: GlobalInspectionContextImpl, project: Project, outputPath: Path) { - this.outputPath = outputPath InspectionTreeHtmlWriter(tree, profile, globalInspectionContext.refManager, outputPath) } - override fun onExportSuccessful() { - if (open) { - val path = outputPath ?: return - BrowserUtil.browse(path.resolve("index.html")) + override fun onExportSuccessful(data: UserDataHolderEx) { + if (data.getUserData(openKey) == true) { + val path = data.getUserData(ExportDialog.LOCATION_KEY) ?: return + BrowserUtil.browse(Path.of(path, "index.html")) } } - override fun additionalSettings(): JPanel { + override fun additionalSettings(data: UserDataHolderEx): JPanel { return panel { row { checkBox(InspectionsBundle.message("inspection.export.open.option")).applyToComponent { - addChangeListener { open = isSelected } + addChangeListener { data.putUserData(openKey, isSelected) } } } } } } + +private val openKey: Key = Key.create("export.to.html.action.open") \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/actions/InspectionResultsExportActionProvider.kt b/platform/lang-impl/src/com/intellij/codeInspection/ui/actions/InspectionResultsExportActionProvider.kt index 1523bb056b13..15a11eb21b51 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/actions/InspectionResultsExportActionProvider.kt +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/actions/InspectionResultsExportActionProvider.kt @@ -6,7 +6,7 @@ import com.intellij.codeInspection.ex.GlobalInspectionContextImpl import com.intellij.codeInspection.ex.InspectionProfileImpl import com.intellij.codeInspection.ui.InspectionResultsView import com.intellij.codeInspection.ui.InspectionTree -import com.intellij.codeInspection.ui.actions.InspectionResultsExportActionProvider.Companion.LOCATION_KEY +import com.intellij.codeInspection.ui.actions.InspectionResultsExportActionProvider.Companion.LOCATION_PROPERTY_NAME import com.intellij.ide.util.PropertiesComponent import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.application.invokeLater @@ -15,7 +15,6 @@ import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.editor.EditorBundle import com.intellij.openapi.extensions.ExtensionPointName import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory -import com.intellij.openapi.observable.properties.PropertyGraph import com.intellij.openapi.progress.ProcessCanceledException import com.intellij.openapi.progress.ProgressIndicator import com.intellij.openapi.progress.ProgressManager @@ -24,7 +23,10 @@ import com.intellij.openapi.project.Project import com.intellij.openapi.project.guessProjectDir import com.intellij.openapi.ui.DialogWrapper import com.intellij.openapi.ui.Messages +import com.intellij.openapi.util.Key import com.intellij.openapi.util.NlsContexts.ProgressTitle +import com.intellij.openapi.util.UserDataHolderBase +import com.intellij.openapi.util.UserDataHolderEx import com.intellij.ui.dsl.builder.* import com.intellij.util.concurrency.annotations.RequiresBackgroundThread import com.intellij.util.concurrency.annotations.RequiresEdt @@ -45,17 +47,16 @@ abstract class InspectionResultsExportActionProvider(text: Supplier, companion object { val EP_NAME: ExtensionPointName = ExtensionPointName.create("com.intellij.inspectionResultsExportActionProvider") - const val LOCATION_KEY: String = "com.intellij.codeInspection.ui.actions.InspectionResultsExportActionProvider.location" + const val LOCATION_PROPERTY_NAME: String = "com.intellij.codeInspection.ui.actions.InspectionResultsExportActionProvider.location" } - val propertyGraph: PropertyGraph = PropertyGraph() - abstract val progressTitle: @ProgressTitle String override fun actionPerformed(e: AnActionEvent) { val view: InspectionResultsView = getView(e) ?: return - val dialog = ExportDialog(this, view) + val dataHolder = UserDataHolderBase() + val dialog = ExportDialog(this, view, dataHolder) if (!dialog.showAndGet()) return val path = dialog.path @@ -83,7 +84,7 @@ abstract class InspectionResultsExportActionProvider(text: Supplier, } invokeLater { - onExportSuccessful() + onExportSuccessful(dataHolder) } } }) @@ -100,18 +101,22 @@ abstract class InspectionResultsExportActionProvider(text: Supplier, outputPath: Path) @RequiresEdt - open fun onExportSuccessful() {} + open fun onExportSuccessful(data: UserDataHolderEx) {} /** * Additional configuration to be added in [ExportDialog]. */ - open fun additionalSettings(): JPanel? = null + open fun additionalSettings(data: UserDataHolderEx): JPanel? = null } -private class ExportDialog(private val actionProvider: InspectionResultsExportActionProvider, val view: InspectionResultsView) : DialogWrapper(view.project, true) { +internal class ExportDialog(private val actionProvider: InspectionResultsExportActionProvider, val view: InspectionResultsView, val dataHolder: UserDataHolderEx) : DialogWrapper(view.project, true) { var location: String = "" + companion object { + val LOCATION_KEY: Key = Key.create(LOCATION_PROPERTY_NAME) + } + init { setOKButtonText(InspectionsBundle.message("inspection.export.save.button")) title = InspectionsBundle.message("inspection.export.results.title") @@ -119,7 +124,8 @@ private class ExportDialog(private val actionProvider: InspectionResultsExportAc location = PropertiesComponent .getInstance(view.project) - .getValue(LOCATION_KEY, view.project.guessProjectDir()?.path ?: "") + .getValue(LOCATION_PROPERTY_NAME, view.project.guessProjectDir()?.path ?: "") + LOCATION_KEY.set(dataHolder, location) init() } @@ -137,7 +143,7 @@ private class ExportDialog(private val actionProvider: InspectionResultsExportAc .bottomGap(BottomGap.SMALL) row(EditorBundle.message("export.to.html.output.directory.label")) { textFieldWithBrowseButton( - FileChooserDescriptorFactory.createSingleFolderDescriptor().withTitle(EditorBundle.message("export.to.html.select.output.directory.title")), + FileChooserDescriptorFactory.singleDir().withTitle(EditorBundle.message("export.to.html.select.output.directory.title")), view.project ) .columns(COLUMNS_LARGE) @@ -147,7 +153,7 @@ private class ExportDialog(private val actionProvider: InspectionResultsExportAc else null } } - actionProvider.additionalSettings()?.let { + actionProvider.additionalSettings(dataHolder)?.let { row { cell(it) } } } @@ -156,7 +162,8 @@ private class ExportDialog(private val actionProvider: InspectionResultsExportAc override fun doOKAction() { PropertiesComponent .getInstance(view.project) - .setValue(LOCATION_KEY, location) + .setValue(LOCATION_PROPERTY_NAME, location) + LOCATION_KEY.set(dataHolder, location) super.doOKAction() } } \ No newline at end of file