diff --git a/python/src/com/jetbrains/python/sdk/add/PyAddSdkDialog.kt b/python/src/com/jetbrains/python/sdk/add/PyAddSdkDialog.kt index c7702ff257fc4b14b929cb2efaa4b648dbe1d67d..d9dd53e04a1396c72b114bb6fba207f704191152 100644 --- a/python/src/com/jetbrains/python/sdk/add/PyAddSdkDialog.kt +++ b/python/src/com/jetbrains/python/sdk/add/PyAddSdkDialog.kt @@ -285,7 +285,7 @@ class PyAddSdkDialog private constructor(private val project: Project?, Messages.showErrorDialog(e.localizedMessage, "Error") } else { - showExecutionErrorDialog(project, cause) + showProcessExecutionErrorDialog(project, cause) } return } diff --git a/python/src/com/jetbrains/python/sdk/add/wizardUIUtil.kt b/python/src/com/jetbrains/python/sdk/add/wizardUIUtil.kt index 3bcf1117f1ab93c0168f6dbfec68ebc1951c365d..8b6900a7101c8afc66a617751bfe33c38e98ae72 100644 --- a/python/src/com/jetbrains/python/sdk/add/wizardUIUtil.kt +++ b/python/src/com/jetbrains/python/sdk/add/wizardUIUtil.kt @@ -72,35 +72,28 @@ internal fun show(panel: JPanel, stepContent: Component) { (panel.layout as CardLayout).show(panel, stepContentName) } -fun showExecutionErrorDialog(project: Project?, e: PyExecutionException) { - val errorMessage = JBLabel("<html>${e.command} could not complete successfully. " + - "Please see the command's output for information about resolving this problem.</html>", - Messages.getErrorIcon(), SwingConstants.LEFT) - val formBuilder = FormBuilder().addComponent(errorMessage) - - val commandOutputTextField = JTextPane().apply { - val stdoutStyle = addStyle("stdoutStyle", null) - StyleConstants.setFontFamily(stdoutStyle, Font.MONOSPACED) - val stderrStyle = addStyle("stderrStyle", stdoutStyle) - StyleConstants.setForeground(stderrStyle, JBColor.RED) - document.apply { - e.stdout.let { - if (it.isNotEmpty()) insertString(length, it + "\n", stdoutStyle) - } - e.stderr.let { - if (it.isNotEmpty()) insertString(length, it + "\n", stderrStyle) - } - insertString(length, "Process finished with exit code ${e.exitCode}", stdoutStyle) - } +internal fun showProcessExecutionErrorDialog(project: Project?, e: PyExecutionException) { + val errorMessageText = "${e.command} could not complete successfully. " + + "Please see the command's output for information about resolving this problem." + // HTML format for text in `JBLabel` enables text wrapping + val errorMessageLabel = JBLabel(UIUtil.toHtml(errorMessageText), Messages.getErrorIcon(), SwingConstants.LEFT) + + val commandOutputTextPane = JTextPane().apply { + appendProcessOutput(e.stdout, e.stderr, e.exitCode) + background = JBColor.WHITE isEditable = false } - formBuilder.addComponentFillVertically(BorderLayoutPanel().apply { + val commandOutputPanel = BorderLayoutPanel().apply { border = IdeBorderFactory.createTitledBorder("Command output", false) - addToCenter(JBScrollPane(commandOutputTextField, VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_NEVER)) - }, UIUtil.DEFAULT_VGAP) + addToCenter(JBScrollPane(commandOutputTextPane, VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_NEVER)) + } + + val formBuilder = FormBuilder() + .addComponent(errorMessageLabel) + .addComponentFillVertically(commandOutputPanel, UIUtil.DEFAULT_VGAP) object : DialogWrapper(project) { init { @@ -110,8 +103,21 @@ fun showExecutionErrorDialog(project: Project?, e: PyExecutionException) { override fun createActions(): Array<Action> = arrayOf(okAction) - override fun createCenterPanel(): JComponent { - return formBuilder.panel.apply { preferredSize = Dimension(600, 300) } + override fun createCenterPanel(): JComponent = formBuilder.panel.apply { + preferredSize = Dimension(600, 300) } }.showAndGet() +} + +private fun JTextPane.appendProcessOutput(stdout: String, stderr: String, exitCode: Int) { + val stdoutStyle = addStyle(null, null) + StyleConstants.setFontFamily(stdoutStyle, Font.MONOSPACED) + val stderrStyle = addStyle(null, stdoutStyle) + StyleConstants.setForeground(stderrStyle, JBColor.RED) + document.apply { + arrayOf(stdout to stdoutStyle, stderr to stderrStyle).forEach { (std, style) -> + if (std.isNotEmpty()) insertString(length, std + "\n", style) + } + insertString(length, "Process finished with exit code $exitCode", stdoutStyle) + } } \ No newline at end of file