mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Open debug console action in Tools menu (PY-5449).
This commit is contained in:
@@ -984,6 +984,12 @@
|
||||
<add-to-group group-id="ToolsMenu" anchor="last"/>
|
||||
</group>
|
||||
|
||||
<action id="com.jetbrains.python.console.PyOpenDebugConsoleAction"
|
||||
class="com.jetbrains.python.console.PyOpenDebugConsoleAction"
|
||||
text="Open Debug Command Line" description="Opens debug command line for running process">
|
||||
<add-to-group group-id="ToolsMenu" anchor="last"/>
|
||||
</action>
|
||||
|
||||
|
||||
<action id="ExecuteInPyConsoleAction"
|
||||
class="com.jetbrains.python.actions.ExecuteInConsoleAction"
|
||||
|
||||
@@ -158,12 +158,11 @@ public class ExecuteInConsoleAction extends AnAction {
|
||||
return psi instanceof PyFile;
|
||||
}
|
||||
|
||||
private static void selectConsole(@NotNull Project project,
|
||||
@NotNull Editor editor,
|
||||
private static void selectConsole(@NotNull DataContext dataContext, @NotNull Project project,
|
||||
final Consumer<PyCodeExecutor> consumer) {
|
||||
Collection<RunContentDescriptor> consoles = getConsoles(project);
|
||||
|
||||
ExecutionHelper.selectContentDescriptor(editor, consoles, "Select console to execute in", new Consumer<RunContentDescriptor>() {
|
||||
ExecutionHelper.selectContentDescriptor(dataContext, project, consoles, "Select console to execute in", new Consumer<RunContentDescriptor>() {
|
||||
@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));
|
||||
|
||||
@@ -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<PythonDebugLanguageConsoleView>() {
|
||||
@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<PythonDebugLanguageConsoleView> consumer) {
|
||||
Collection<RunContentDescriptor> consoles = getConsoles(project);
|
||||
|
||||
ExecutionHelper
|
||||
.selectContentDescriptor(dataContext, project, consoles, "Select running python process", new Consumer<RunContentDescriptor>() {
|
||||
@Override
|
||||
public void consume(RunContentDescriptor descriptor) {
|
||||
if (descriptor != null && descriptor.getExecutionConsole() instanceof PythonDebugLanguageConsoleView) {
|
||||
consumer.consume((PythonDebugLanguageConsoleView)descriptor.getExecutionConsole());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static Collection<RunContentDescriptor> getConsoles(Project project) {
|
||||
return ExecutionHelper.findRunningConsole(project, new NotNullFunction<RunContentDescriptor, Boolean>() {
|
||||
@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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user