[PyCharm] Jupyter (fix): Fixed suggestion to install Jupyter to view rich tables, added restart IDE. #PY-75914 Fixed

GitOrigin-RevId: 60ea3742324774979f6db883b0d2b2d63db3227d
This commit is contained in:
Nikita Pavlenko
2024-10-14 17:44:48 +02:00
committed by intellij-monorepo-bot
parent 996e62647d
commit ff567970a9
2 changed files with 43 additions and 19 deletions

View File

@@ -747,7 +747,7 @@ debugger.data.view.data=Data
debugger.data.view.close=Close
debugger.data.view.resize.automatically=Resize automatically
debugger.data.view.colored.cells=Colored cells
debugger.data.view.reach.view.suggestion=Reach table viewer could be enabled
debugger.data.view.reach.view.suggestion=Rich table viewer could be enabled
debugger.data.view.failed.to.evaluate.expression=Failed to evaluate the expression {0}
debugger.data.view.numpy.is.not.available=NumPy is not available. Install the module for proper data display.
debugger.data.view.type.is.not.supported={0} is not supported

View File

@@ -2,7 +2,6 @@
package com.jetbrains.python.debugger.containerview
import com.intellij.ide.IdeBundle
import com.intellij.ide.plugins.PluginManager
import com.intellij.ide.plugins.PluginManagerConfigurable
import com.intellij.ide.plugins.PluginManagerCore
import com.intellij.ide.util.PropertiesComponent
@@ -13,6 +12,7 @@ import com.intellij.openapi.updateSettings.impl.pluginsAdvertisement.installAndE
import com.intellij.openapi.util.NlsContexts
import com.intellij.ui.EditorNotificationPanel
import com.intellij.ui.components.JBCheckBox
import com.intellij.util.PlatformUtils
import com.intellij.util.ui.JBUI
import com.jetbrains.python.PyBundle
import com.jetbrains.python.debugger.PyDebugValue
@@ -44,14 +44,10 @@ class PyDataViewDialog(private val myProject: Project, value: PyDebugValue) : Di
mainPanel = JPanel(BorderLayout())
// If PythonPro installed and enabled.
val pythonPluginDescriptor = PluginManagerCore.getPlugin(PluginId.getId("Pythonid"))
if (isJupyterSuggestionEnabled(myProject) && pythonPluginDescriptor?.isEnabled == true) {
val jupyterPluginId = PluginId.findId("intellij.jupyter")
if (jupyterPluginId != null) {
val jupyterSuggestionPanel = createJupyterSuggestionPanel(jupyterPluginId)
this.jupyterSuggestionPanel = jupyterSuggestionPanel
mainPanel.add(jupyterSuggestionPanel, BorderLayout.NORTH)
}
val jupyterSuggestionPanel = createJupyterSuggestionPanel()
this.jupyterSuggestionPanel = jupyterSuggestionPanel
if (jupyterSuggestionPanel != null) {
mainPanel.add(jupyterSuggestionPanel, BorderLayout.NORTH)
}
mainPanel.add(dataViewerPanel, BorderLayout.CENTER)
@@ -99,24 +95,52 @@ class PyDataViewDialog(private val myProject: Project, value: PyDebugValue) : Di
override fun createCenterPanel() = mainPanel
private fun createJupyterSuggestionPanel(pluginId: PluginId): EditorNotificationPanel {
private fun createJupyterSuggestionPanel(): JPanel? {
if (PlatformUtils.isCommunityEdition()) return null
if (!isJupyterSuggestionEnabled(myProject)) return null
val requiredPluginIds = listOf(PluginId.getId("Pythonid"), PluginId.getId("intellij.jupyter"))
var needToInstallPlugin = false
val toInstallOrEnable = mutableSetOf<PluginId>().apply {
requiredPluginIds.forEach { pluginId ->
val pluginDescriptor = PluginManagerCore.findPlugin(pluginId)
if (pluginDescriptor == null) {
add(pluginId)
needToInstallPlugin = true
}
else {
if (!pluginDescriptor.isEnabled) {
add(pluginId)
}
}
}
}
if (toInstallOrEnable.isEmpty()) return null
val panel = EditorNotificationPanel()
panel.text = PyBundle.message("debugger.data.view.reach.view.suggestion")
if (!PluginManager.isPluginInstalled(pluginId)) {
fun supposeRestartIfFRequired() {
val requireRestart = toInstallOrEnable.firstOrNull { PluginManagerCore.getPlugin(it)?.isRequireRestart == true } != null
if (requireRestart) {
PluginManagerConfigurable.shutdownOrRestartApp()
}
}
if (needToInstallPlugin) {
panel.createActionLabel(IdeBundle.message("plugins.advertiser.action.install.plugin.name", "Jupyter")) {
installAndEnable(myProject, setOf(pluginId), true) {
installAndEnable(myProject, toInstallOrEnable, showDialog = false) {
hideJupyterSuggestionPanel()
supposeRestartIfFRequired()
}
}
}
else {
val jupyterPluginDescriptor = PluginManagerCore.getPlugin(PluginId.findId("com.intellij.grazie.pro"))
if (jupyterPluginDescriptor != null) {
panel.createActionLabel(IdeBundle.message("plugins.advertiser.action.enable.plugin", jupyterPluginDescriptor.name)) {
PluginManagerConfigurable.showPluginConfigurableAndEnable(myProject, setOf(jupyterPluginDescriptor))
hideJupyterSuggestionPanel()
}
panel.createActionLabel(IdeBundle.message("link.enable.required.plugin", "Jupyter")) {
toInstallOrEnable.forEach { PluginManagerCore.enablePlugin(it) }
hideJupyterSuggestionPanel()
supposeRestartIfFRequired()
}
}