PY-27257 Reuse Console tool window in Python plugin and add action to make Python Console available before tool window registered

If Console tool window was created once, it's available as action in Python plugin. But before creation it's impossible to start Python Console during debug session.

GitOrigin-RevId: cfb9ac4450246f067d70626b139d8830166d68f1
This commit is contained in:
Elizaveta Shashkova
2019-12-10 18:27:53 +03:00
committed by intellij-monorepo-bot
parent 4cc56ef3cf
commit 9670bc3457
7 changed files with 58 additions and 23 deletions

View File

@@ -7,12 +7,6 @@
</component>
</project-components>
<project-components>
<component>
<implementation-class>com.jetbrains.python.console.PythonConsoleToolWindow</implementation-class>
</component>
</project-components>
<application-components>
<component>
<implementation-class>com.jetbrains.python.PythonSdkConfigurator</implementation-class>

View File

@@ -11,6 +11,8 @@
<action id="PyManagePackages" class="com.jetbrains.python.packaging.PyManagePackagesAction" text="Manage Python Packages...">
<add-to-group group-id="ToolsMenu" anchor="last"/>
</action>
<action id="RunPythonToolwindowAction" class="com.jetbrains.python.console.RunPythonToolwindowAction" text="Python Console">
</action>
</actions>
<application-components>

View File

@@ -719,9 +719,9 @@
icon="PlatformDebuggerImplIcons.Actions.Force_step_into" description="Step into, ignore stepping filters for libraries, constructors, etc."/>
<!-- Console -->
<action id="com.jetbrains.python.console.RunPythonConsoleAction"
class="com.jetbrains.python.console.RunPythonConsoleAction"
text="Python Console..." description="Allows to quickly run Python console">
<action id="com.jetbrains.python.console.RunPythonOrDebugConsoleAction"
class="com.jetbrains.python.console.RunPythonOrDebugConsoleAction"
text="Python or Debug Console" description="Allows to quickly run Python Console or Debug Console if debug session is running">
<add-to-group group-id="ToolsMenu" anchor="last"/>
</action>
@@ -825,4 +825,10 @@
<implementation-class>com.jetbrains.python.sdk.pipenv.PipEnvPipFileWatcherComponent</implementation-class>
</component>
</project-components>
<project-components>
<component>
<implementation-class>com.jetbrains.python.console.PythonConsoleToolWindow</implementation-class>
</component>
</project-components>
</idea-plugin>

View File

@@ -11,11 +11,13 @@ import com.intellij.openapi.ui.SimpleToolWindowPanel;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowAnchor;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.openapi.wm.ex.ToolWindowManagerListener;
import com.intellij.openapi.wm.impl.content.ToolWindowContentUi;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;
import icons.PythonIcons;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -73,12 +75,9 @@ public class PythonConsoleToolWindow {
@Override
public void stateChanged(@NotNull ToolWindowManager toolWindowManager) {
ToolWindow window = getToolWindow(myProject);
if (window != null) {
boolean visible = window.isVisible();
if (visible && toolWindow.getContentManager().getContentCount() == 0) {
PydevConsoleRunner runner = PythonConsoleRunnerFactory.getInstance().createConsoleRunner(myProject, null);
runner.run(true);
}
if (window.isVisible() && toolWindow.getContentManager().getContentCount() == 0) {
PydevConsoleRunner runner = PythonConsoleRunnerFactory.getInstance().createConsoleRunner(myProject, null);
runner.run(true);
}
}
});
@@ -105,7 +104,13 @@ public class PythonConsoleToolWindow {
}
public static ToolWindow getToolWindow(Project project) {
return ToolWindowManager.getInstance(project).getToolWindow(PythonConsoleToolWindowFactory.ID);
final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
ToolWindow consoleToolWindow = toolWindowManager.getToolWindow(PythonConsoleToolWindowFactory.ID);
if (consoleToolWindow == null) {
consoleToolWindow = toolWindowManager.registerToolWindow(PythonConsoleToolWindowFactory.ID, true, ToolWindowAnchor.BOTTOM);
consoleToolWindow.setIcon(PythonIcons.Python.PythonConsoleToolWindow);
}
return consoleToolWindow;
}
public void setContent(RunContentDescriptor contentDescriptor) {

View File

@@ -17,9 +17,9 @@ import org.jetbrains.annotations.NotNull;
/**
* @author oleg
*/
public class RunPythonConsoleAction extends AnAction implements DumbAware {
public class RunPythonOrDebugConsoleAction extends AnAction implements DumbAware {
public RunPythonConsoleAction() {
public RunPythonOrDebugConsoleAction() {
super();
getTemplatePresentation().setIcon(PythonIcons.Python.PythonConsole);
}

View File

@@ -0,0 +1,28 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.python.console
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.DumbAware
import com.intellij.openapi.wm.ToolWindowManager
import com.jetbrains.python.actions.PyExecuteSelectionAction
import icons.PythonIcons
class RunPythonToolwindowAction : AnAction(PythonIcons.Python.PythonConsoleToolWindow), DumbAware {
override fun actionPerformed(e: AnActionEvent) {
val project = e.project
if (project == null) return
PyExecuteSelectionAction.startNewConsoleInstance(project, {}, null, null)
}
/*
* This action should be available only when Python Console tool window isn't registered yet
* It's used only in Python plugin, because Console tool window is available by default in PyCharm
*/
override fun update(e: AnActionEvent) {
val project = e.project
if (project == null) return
e.presentation.isEnabledAndVisible = ToolWindowManager.getInstance(project).getToolWindow(PythonConsoleToolWindowFactory.ID) == null
}
}

View File

@@ -4,23 +4,23 @@ package com.jetbrains.python.run.runAnything
import com.intellij.ide.actions.runAnything.activity.RunAnythingAnActionProvider
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.DataContext
import com.jetbrains.python.console.RunPythonConsoleAction
import com.jetbrains.python.console.RunPythonOrDebugConsoleAction
import icons.PythonIcons
import javax.swing.Icon
/**
* @author vlan
*/
class PyConsoleRunAnythingProvider : RunAnythingAnActionProvider<RunPythonConsoleAction>() {
override fun getCommand(value: RunPythonConsoleAction) = helpCommand
class PyConsoleRunAnythingProvider : RunAnythingAnActionProvider<RunPythonOrDebugConsoleAction>() {
override fun getCommand(value: RunPythonOrDebugConsoleAction) = helpCommand
override fun getHelpCommand() = "python"
override fun getHelpGroupTitle(): String? = "Python"
override fun getValues(dataContext: DataContext, pattern: String): Collection<RunPythonConsoleAction> {
override fun getValues(dataContext: DataContext, pattern: String): Collection<RunPythonOrDebugConsoleAction> {
val action = ActionManager.getInstance().getAction("com.jetbrains.python.console.RunPythonConsoleAction")
return listOfNotNull(action as? RunPythonConsoleAction)
return listOfNotNull(action as? RunPythonOrDebugConsoleAction)
}
override fun getHelpIcon(): Icon = PythonIcons.Python.PythonConsole