From ff567970a96939b2293fb553492423c1a41ad67c Mon Sep 17 00:00:00 2001 From: Nikita Pavlenko Date: Mon, 14 Oct 2024 17:44:48 +0200 Subject: [PATCH] [PyCharm] Jupyter (fix): Fixed suggestion to install Jupyter to view rich tables, added restart IDE. #PY-75914 Fixed GitOrigin-RevId: 60ea3742324774979f6db883b0d2b2d63db3227d --- .../messages/PyBundle.properties | 2 +- .../containerview/PyDataViewDialog.kt | 60 +++++++++++++------ 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/python/pluginResources/messages/PyBundle.properties b/python/pluginResources/messages/PyBundle.properties index 2071594b28ab..a0f0ab3f827a 100644 --- a/python/pluginResources/messages/PyBundle.properties +++ b/python/pluginResources/messages/PyBundle.properties @@ -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 diff --git a/python/src/com/jetbrains/python/debugger/containerview/PyDataViewDialog.kt b/python/src/com/jetbrains/python/debugger/containerview/PyDataViewDialog.kt index 5d692ebc73bb..6fe62fd35d55 100644 --- a/python/src/com/jetbrains/python/debugger/containerview/PyDataViewDialog.kt +++ b/python/src/com/jetbrains/python/debugger/containerview/PyDataViewDialog.kt @@ -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().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() } }