From 869ec0b322b6f85c663e3b05e60f53cb23ceaca0 Mon Sep 17 00:00:00 2001 From: Elizaveta Shashkova Date: Thu, 30 Nov 2017 20:10:34 +0300 Subject: [PATCH] "Jump To Cursor" action isn't visible, when non-Python configuration selected (PY-27227) --- .../python/debugger/PyDebugSupportUtils.java | 19 ++++++------------- .../debugger/PySetNextStatementAction.kt | 4 ++-- .../debugger/PyStepIntoMyCodeAction.java | 4 ++-- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/python/src/com/jetbrains/python/debugger/PyDebugSupportUtils.java b/python/src/com/jetbrains/python/debugger/PyDebugSupportUtils.java index 3d0d31d4f47c..e107e8707979 100644 --- a/python/src/com/jetbrains/python/debugger/PyDebugSupportUtils.java +++ b/python/src/com/jetbrains/python/debugger/PyDebugSupportUtils.java @@ -15,9 +15,6 @@ */ package com.jetbrains.python.debugger; -import com.intellij.execution.RunManager; -import com.intellij.execution.RunnerAndConfigurationSettings; -import com.intellij.execution.configurations.RunConfiguration; import com.intellij.openapi.application.ReadAction; import com.intellij.openapi.editor.Document; import com.intellij.openapi.project.Project; @@ -26,9 +23,10 @@ import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.xdebugger.XDebugSession; +import com.intellij.xdebugger.XDebuggerManager; import com.jetbrains.python.PyTokenTypes; import com.jetbrains.python.psi.*; -import com.jetbrains.python.run.AbstractPythonRunConfiguration; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -118,15 +116,10 @@ public class PyDebugSupportUtils { return false; } - public static boolean isPythonConfigurationSelected(Project project) { - if (project != null) { - RunnerAndConfigurationSettings settings = RunManager.getInstance(project).getSelectedConfiguration(); - if (settings != null) { - RunConfiguration runConfiguration = settings.getConfiguration(); - if (runConfiguration instanceof AbstractPythonRunConfiguration) { - return true; - } - } + public static boolean isCurrentPythonDebugProcess(Project project) { + XDebugSession session = XDebuggerManager.getInstance(project).getCurrentSession(); + if (session != null && session.getDebugProcess() instanceof PyDebugProcess) { + return true; } return false; } diff --git a/python/src/com/jetbrains/python/debugger/PySetNextStatementAction.kt b/python/src/com/jetbrains/python/debugger/PySetNextStatementAction.kt index f62b56c9f596..7da663cbba60 100644 --- a/python/src/com/jetbrains/python/debugger/PySetNextStatementAction.kt +++ b/python/src/com/jetbrains/python/debugger/PySetNextStatementAction.kt @@ -63,7 +63,7 @@ class PySetNextStatementAction : XDebuggerActionBase(true) { } override fun isEnabled(project: Project, event: AnActionEvent): Boolean { - return super.isEnabled(project, event) && PyDebugSupportUtils.isPythonConfigurationSelected(project) + return super.isEnabled(project, event) && PyDebugSupportUtils.isCurrentPythonDebugProcess(project) } } } @@ -71,7 +71,7 @@ class PySetNextStatementAction : XDebuggerActionBase(true) { override fun getHandler(debuggerSupport: DebuggerSupport) = setNextStatementActionHandler override fun isHidden(event: AnActionEvent): Boolean { - return !PyDebugSupportUtils.isPythonConfigurationSelected(event.getData(CommonDataKeys.PROJECT)) + return !PyDebugSupportUtils.isCurrentPythonDebugProcess(event.getData(CommonDataKeys.PROJECT)) } companion object { diff --git a/python/src/com/jetbrains/python/debugger/PyStepIntoMyCodeAction.java b/python/src/com/jetbrains/python/debugger/PyStepIntoMyCodeAction.java index a521b5016a51..5ddd3e0b8a3b 100644 --- a/python/src/com/jetbrains/python/debugger/PyStepIntoMyCodeAction.java +++ b/python/src/com/jetbrains/python/debugger/PyStepIntoMyCodeAction.java @@ -45,7 +45,7 @@ public class PyStepIntoMyCodeAction extends XDebuggerActionBase { @Override public boolean isEnabled(@NotNull Project project, AnActionEvent event) { - return super.isEnabled(project, event) && PyDebugSupportUtils.isPythonConfigurationSelected(project); + return super.isEnabled(project, event) && PyDebugSupportUtils.isCurrentPythonDebugProcess(project); } }; } @@ -58,6 +58,6 @@ public class PyStepIntoMyCodeAction extends XDebuggerActionBase { @Override protected boolean isHidden(AnActionEvent event) { - return !PyDebugSupportUtils.isPythonConfigurationSelected(event.getData(CommonDataKeys.PROJECT)); + return !PyDebugSupportUtils.isCurrentPythonDebugProcess(event.getData(CommonDataKeys.PROJECT)); } }