diff --git a/python/src/META-INF/python-plugin-common.xml b/python/src/META-INF/python-plugin-common.xml
index e73a6786eb40..db7cab5a6e86 100644
--- a/python/src/META-INF/python-plugin-common.xml
+++ b/python/src/META-INF/python-plugin-common.xml
@@ -984,6 +984,12 @@
+
+
+
+
consumer) {
Collection consoles = getConsoles(project);
- ExecutionHelper.selectContentDescriptor(editor, consoles, "Select console to execute in", new Consumer() {
+ ExecutionHelper.selectContentDescriptor(dataContext, project, consoles, "Select console to execute in", new Consumer() {
@Override
public void consume(RunContentDescriptor descriptor) {
if (descriptor != null && descriptor.getExecutionConsole() instanceof PyCodeExecutor) {
@@ -193,7 +192,7 @@ public class ExecuteInConsoleAction extends AnAction {
Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext());
if (project != null && editor != null) {
if (canFindConsole(e)) {
- selectConsole(project, editor, consumer);
+ selectConsole(e.getDataContext(), project, consumer);
}
else {
startConsole(project, consumer, e.getData(LangDataKeys.MODULE));
diff --git a/python/src/com/jetbrains/python/console/PyOpenDebugConsoleAction.java b/python/src/com/jetbrains/python/console/PyOpenDebugConsoleAction.java
new file mode 100644
index 000000000000..ee90b7e35c92
--- /dev/null
+++ b/python/src/com/jetbrains/python/console/PyOpenDebugConsoleAction.java
@@ -0,0 +1,83 @@
+package com.jetbrains.python.console;
+
+import com.intellij.execution.ExecutionHelper;
+import com.intellij.execution.process.ProcessHandler;
+import com.intellij.execution.ui.RunContentDescriptor;
+import com.intellij.openapi.actionSystem.AnAction;
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.actionSystem.DataContext;
+import com.intellij.openapi.actionSystem.PlatformDataKeys;
+import com.intellij.openapi.project.DumbAware;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.wm.IdeFocusManager;
+import com.intellij.util.Consumer;
+import com.intellij.util.NotNullFunction;
+import icons.PythonIcons;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.Collection;
+
+/**
+ * @author traff
+ */
+public class PyOpenDebugConsoleAction extends AnAction implements DumbAware {
+
+ public PyOpenDebugConsoleAction() {
+ super();
+ getTemplatePresentation().setIcon(PythonIcons.Python.Debug.CommandLine);
+ }
+
+ @Override
+ public void update(final AnActionEvent e) {
+ e.getPresentation().setVisible(false);
+ e.getPresentation().setEnabled(true);
+ final Project project = e.getData(PlatformDataKeys.PROJECT);
+ if (project != null) {
+ e.getPresentation().setVisible(getConsoles(project).size() > 0);
+ }
+ }
+
+ public void actionPerformed(final AnActionEvent e) {
+ final Project project = e.getData(PlatformDataKeys.PROJECT);
+ if (project != null) {
+ selectRunningProcess(e.getDataContext(), project, new Consumer() {
+ @Override
+ public void consume(PythonDebugLanguageConsoleView view) {
+ view.showDebugConsole(true);
+ IdeFocusManager.getInstance(project).requestFocus(view.getPydevConsoleView().getComponent(), true);
+ }
+ });
+ }
+ }
+
+
+ private static void selectRunningProcess(@NotNull DataContext dataContext, @NotNull Project project,
+ final Consumer consumer) {
+ Collection consoles = getConsoles(project);
+
+ ExecutionHelper
+ .selectContentDescriptor(dataContext, project, consoles, "Select running python process", new Consumer() {
+ @Override
+ public void consume(RunContentDescriptor descriptor) {
+ if (descriptor != null && descriptor.getExecutionConsole() instanceof PythonDebugLanguageConsoleView) {
+ consumer.consume((PythonDebugLanguageConsoleView)descriptor.getExecutionConsole());
+ }
+ }
+ });
+ }
+
+ private static Collection getConsoles(Project project) {
+ return ExecutionHelper.findRunningConsole(project, new NotNullFunction() {
+ @NotNull
+ @Override
+ public Boolean fun(RunContentDescriptor dom) {
+ return dom.getExecutionConsole() instanceof PyCodeExecutor && isAlive(dom);
+ }
+ });
+ }
+
+ private static boolean isAlive(RunContentDescriptor dom) {
+ ProcessHandler processHandler = dom.getProcessHandler();
+ return processHandler != null && !processHandler.isProcessTerminated();
+ }
+}