diff --git a/python/pydevSrc/com/jetbrains/python/debugger/PyFrameAccessor.java b/python/pydevSrc/com/jetbrains/python/debugger/PyFrameAccessor.java index 28b10a3c4c2f..b75e2d374eff 100644 --- a/python/pydevSrc/com/jetbrains/python/debugger/PyFrameAccessor.java +++ b/python/pydevSrc/com/jetbrains/python/debugger/PyFrameAccessor.java @@ -33,5 +33,5 @@ public interface PyFrameAccessor { default void showNumericContainer(PyDebugValue value) {} - default void setDataChangedCallback(@NotNull Runnable runnable) {} + default void addFrameListener(@NotNull PyFrameListener listener) {} } diff --git a/python/pydevSrc/com/jetbrains/python/debugger/PyFrameListener.java b/python/pydevSrc/com/jetbrains/python/debugger/PyFrameListener.java new file mode 100644 index 000000000000..224801650d12 --- /dev/null +++ b/python/pydevSrc/com/jetbrains/python/debugger/PyFrameListener.java @@ -0,0 +1,5 @@ +package com.jetbrains.python.debugger; + +public interface PyFrameListener { + void frameChanged(); +} diff --git a/python/src/com/jetbrains/python/console/PydevConsoleCommunication.java b/python/src/com/jetbrains/python/console/PydevConsoleCommunication.java index 4a39d4da021c..8ca8de1b2534 100644 --- a/python/src/com/jetbrains/python/console/PydevConsoleCommunication.java +++ b/python/src/com/jetbrains/python/console/PydevConsoleCommunication.java @@ -29,6 +29,7 @@ import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.Function; import com.intellij.util.WaitFor; +import com.intellij.util.containers.ContainerUtil; import com.intellij.xdebugger.XSourcePosition; import com.intellij.xdebugger.frame.XValueChildrenList; import com.jetbrains.python.console.parsing.PythonConsoleData; @@ -105,6 +106,7 @@ public class PydevConsoleCommunication extends AbstractConsoleCommunication impl private boolean myNeedsMore = false; private PythonConsoleView myConsoleView; + private List myFrameListeners = ContainerUtil.createLockFreeCopyOnWriteList(); /** * Initializes the xml-rpc communication. @@ -630,6 +632,14 @@ public class PydevConsoleCommunication extends AbstractConsoleCommunication impl throw new PyDebuggerException("pydevconsole failed to execute connectToDebugger", exception); } + @Override + public void notifyCommandExecuted(boolean more) { + super.notifyCommandExecuted(more); + for (PyFrameListener listener : myFrameListeners) { + listener.frameChanged(); + } + } + private static void checkError(Object ret) throws PyDebuggerException { if (ret instanceof Object[] && ((Object[])ret).length == 1) { throw new PyDebuggerException(((Object[])ret)[0].toString()); @@ -694,17 +704,7 @@ public class PydevConsoleCommunication extends AbstractConsoleCommunication impl } @Override - public void setDataChangedCallback(@NotNull Runnable runnable) { - addCommunicationListener(new ConsoleCommunicationListener() { - @Override - public void commandExecuted(boolean more) { - runnable.run(); - } - - @Override - public void inputRequested() { - - } - }); + public void addFrameListener(@NotNull PyFrameListener listener) { + myFrameListeners.add(listener); } } diff --git a/python/src/com/jetbrains/python/debugger/PyDebugProcess.java b/python/src/com/jetbrains/python/debugger/PyDebugProcess.java index 4c53823770f6..cb8baa0d16e9 100644 --- a/python/src/com/jetbrains/python/debugger/PyDebugProcess.java +++ b/python/src/com/jetbrains/python/debugger/PyDebugProcess.java @@ -52,6 +52,7 @@ import com.intellij.psi.ResolveState; import com.intellij.psi.scope.PsiScopeProcessor; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.remote.RemoteProcessControl; +import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.UIUtil; import com.intellij.xdebugger.*; import com.intellij.xdebugger.breakpoints.*; @@ -117,6 +118,7 @@ public class PyDebugProcess extends XDebugProcess implements IPyDebugProcess, Pr private boolean myWaitingForConnection = false; private PyStackFrame myConsoleContextFrame = null; private PyReferrersLoader myReferrersProvider; + private final List myFrameListeners = ContainerUtil.createLockFreeCopyOnWriteList(); public PyDebugProcess(@NotNull XDebugSession session, @NotNull ServerSocket serverSocket, @@ -212,6 +214,9 @@ public class PyDebugProcess extends XDebugProcess implements IPyDebugProcess, Pr getSession().positionReached(createSuspendContext(threadInfo)); } } + for (PyFrameListener listener : myFrameListeners) { + listener.frameChanged(); + } } }); } @@ -1150,13 +1155,8 @@ public class PyDebugProcess extends XDebugProcess implements IPyDebugProcess, Pr } @Override - public void setDataChangedCallback(@NotNull Runnable runnable) { - getSession().addSessionListener(new XDebugSessionListener() { - @Override - public void stackFrameChanged() { - runnable.run(); - } - }); + public void addFrameListener(@NotNull PyFrameListener listener) { + myFrameListeners.add(listener); } @Nullable diff --git a/python/src/com/jetbrains/python/debugger/containerview/PyDataViewerPanel.java b/python/src/com/jetbrains/python/debugger/containerview/PyDataViewerPanel.java index 21003577c907..188df3004300 100644 --- a/python/src/com/jetbrains/python/debugger/containerview/PyDataViewerPanel.java +++ b/python/src/com/jetbrains/python/debugger/containerview/PyDataViewerPanel.java @@ -19,7 +19,6 @@ import com.intellij.codeInsight.completion.CompletionResultSet; import com.intellij.codeInsight.completion.PrioritizedLookupElement; import com.intellij.codeInsight.lookup.LookupElementBuilder; import com.intellij.ide.util.PropertiesComponent; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.EditorFactory; import com.intellij.openapi.editor.ex.EditorEx; @@ -82,7 +81,7 @@ public class PyDataViewerPanel extends JPanel { } private void setupChangeListener() { - myFrameAccessor.setDataChangedCallback(() -> ApplicationManager.getApplication().invokeLater(() -> updateModel())); + myFrameAccessor.addFrameListener(() -> UIUtil.invokeLaterIfNeeded(() -> updateModel())); } private void updateModel() {