introduce frame listeners (PY-22535)

This commit is contained in:
Liana.Bakradze
2017-02-14 11:04:15 +03:00
parent d508a6d17e
commit fb5a64686d
5 changed files with 26 additions and 22 deletions
@@ -33,5 +33,5 @@ public interface PyFrameAccessor {
default void showNumericContainer(PyDebugValue value) {}
default void setDataChangedCallback(@NotNull Runnable runnable) {}
default void addFrameListener(@NotNull PyFrameListener listener) {}
}
@@ -0,0 +1,5 @@
package com.jetbrains.python.debugger;
public interface PyFrameListener {
void frameChanged();
}
@@ -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<PyFrameListener> 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);
}
}
@@ -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<PyFrameListener> 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
@@ -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() {