mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
save frame accessor inside panel (PY-22411)
This commit is contained in:
@@ -32,16 +32,11 @@ import com.intellij.ui.content.Content;
|
||||
import com.intellij.ui.content.ContentFactory;
|
||||
import com.intellij.ui.tabs.TabInfo;
|
||||
import com.intellij.ui.tabs.impl.JBEditorTabs;
|
||||
import com.intellij.xdebugger.XDebugProcess;
|
||||
import com.intellij.xdebugger.XDebugSession;
|
||||
import com.intellij.xdebugger.XDebugSessionListener;
|
||||
import com.jetbrains.python.debugger.PyDebugValue;
|
||||
import com.jetbrains.python.debugger.array.AsyncArrayTableModel;
|
||||
import com.jetbrains.python.debugger.PyFrameAccessor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class PyDataView implements DumbAware {
|
||||
public static final String DATA_VIEWER_ID = "Data View";
|
||||
public static final String COLORED_BY_DEFAULT = "python.debugger.dataview.coloredbydefault";
|
||||
@@ -62,7 +57,7 @@ public class PyDataView implements DumbAware {
|
||||
return;
|
||||
}
|
||||
window.getContentManager().getReady(this).doWhenDone(() -> {
|
||||
TabInfo selectedInfo = addTab();
|
||||
TabInfo selectedInfo = addTab(value.getFrameAccessor());
|
||||
PyDataViewerPanel dataViewerPanel = (PyDataViewerPanel)selectedInfo.getComponent();
|
||||
dataViewerPanel.apply(value);
|
||||
});
|
||||
@@ -73,14 +68,14 @@ public class PyDataView implements DumbAware {
|
||||
return ServiceManager.getService(project, PyDataView.class);
|
||||
}
|
||||
|
||||
public void init(@NotNull ToolWindow toolWindow, @NotNull XDebugProcess debugProcess) {
|
||||
public void init(@NotNull ToolWindow toolWindow, @NotNull PyFrameAccessor frameAccessor) {
|
||||
myTabs = new JBRunnerTabs(myProject, ActionManager.getInstance(), IdeFocusManager.findInstance(), myProject);
|
||||
myTabs.setPopupGroup(new DefaultActionGroup(new ColoredAction()), ActionPlaces.UNKNOWN, true);
|
||||
myTabs.setTabDraggingEnabled(true);
|
||||
final Content content = ContentFactory.SERVICE.getInstance().createContent(myTabs, "", false);
|
||||
content.setCloseable(true);
|
||||
toolWindow.getContentManager().addContent(content);
|
||||
addTab();
|
||||
addTab(frameAccessor);
|
||||
((ToolWindowManagerEx)ToolWindowManager.getInstance(myProject)).addToolWindowManagerListener(new ToolWindowManagerAdapter() {
|
||||
@Override
|
||||
public void stateChanged() {
|
||||
@@ -94,38 +89,18 @@ public class PyDataView implements DumbAware {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
XDebugSession currentSession = debugProcess.getSession();
|
||||
if (currentSession != null) {
|
||||
currentSession.addSessionListener(new XDebugSessionListener() {
|
||||
@Override
|
||||
public void stackFrameChanged() {
|
||||
TabInfo selectedInfo = myTabs.getSelectedInfo();
|
||||
for (TabInfo info : myTabs.getTabs()) {
|
||||
AsyncArrayTableModel model = ((PyDataViewerPanel)info.getComponent()).getModel();
|
||||
if (model == null) {
|
||||
continue;
|
||||
}
|
||||
model.invalidateCache();
|
||||
if (selectedInfo == info) {
|
||||
model.fireTableDataChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private TabInfo addTab() {
|
||||
private TabInfo addTab(@NotNull PyFrameAccessor frameAccessor) {
|
||||
if (hasOnlyEmptyTab()) {
|
||||
myTabs.removeAllTabs();
|
||||
}
|
||||
PyDataViewerPanel panel = new PyDataViewerPanel(myProject);
|
||||
PyDataViewerPanel panel = new PyDataViewerPanel(myProject, frameAccessor);
|
||||
TabInfo info = new TabInfo(panel);
|
||||
info.setText(EMPTY_TAB_NAME);
|
||||
info.setPreferredFocusableComponent(panel.getSliceTextField());
|
||||
info.setActions(new DefaultActionGroup(new NewViewerAction()), ActionPlaces.UNKNOWN);
|
||||
info.setTabLabelActions(new DefaultActionGroup(new CloseViewerAction(info)), ActionPlaces.UNKNOWN);
|
||||
info.setActions(new DefaultActionGroup(new NewViewerAction(frameAccessor)), ActionPlaces.UNKNOWN);
|
||||
info.setTabLabelActions(new DefaultActionGroup(new CloseViewerAction(info, frameAccessor)), ActionPlaces.UNKNOWN);
|
||||
panel.addListener(name -> info.setText(name));
|
||||
myTabs.addTab(info);
|
||||
myTabs.select(info, true);
|
||||
@@ -140,35 +115,40 @@ public class PyDataView implements DumbAware {
|
||||
if (info == null) {
|
||||
return false;
|
||||
}
|
||||
return ((PyDataViewerPanel)info.getComponent()).getSliceTextField().getText().isEmpty();
|
||||
return getPanel(info).getSliceTextField().getText().isEmpty();
|
||||
}
|
||||
|
||||
|
||||
private class NewViewerAction extends AnAction {
|
||||
public NewViewerAction() {
|
||||
private final PyFrameAccessor myFrameAccessor;
|
||||
|
||||
public NewViewerAction(PyFrameAccessor frameAccessor) {
|
||||
super("View New Container", "Open new container viewer", AllIcons.General.Add);
|
||||
myFrameAccessor = frameAccessor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
addTab();
|
||||
addTab(myFrameAccessor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class CloseViewerAction extends AnAction {
|
||||
private final TabInfo myInfo;
|
||||
private final PyFrameAccessor myFrameAccessor;
|
||||
|
||||
public CloseViewerAction(TabInfo info) {
|
||||
public CloseViewerAction(TabInfo info, PyFrameAccessor frameAccessor) {
|
||||
super("Close Viewer", "Close selected viewer", AllIcons.Actions.Close);
|
||||
myInfo = info;
|
||||
myFrameAccessor = frameAccessor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
myTabs.removeTab(myInfo);
|
||||
if (myTabs.getTabCount() == 0) {
|
||||
addTab();
|
||||
addTab(myFrameAccessor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -193,8 +173,7 @@ public class PyDataView implements DumbAware {
|
||||
if (info == null) {
|
||||
return null;
|
||||
}
|
||||
JComponent component = info.getComponent();
|
||||
return (PyDataViewerPanel)component;
|
||||
return PyDataView.getPanel(info);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -205,4 +184,8 @@ public class PyDataView implements DumbAware {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static PyDataViewerPanel getPanel(TabInfo tabInfo) {
|
||||
return ((PyDataViewerPanel)tabInfo.getComponent());
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -35,6 +35,7 @@ import com.intellij.xdebugger.XDebugSession;
|
||||
import com.intellij.xdebugger.XDebuggerManager;
|
||||
import com.intellij.xdebugger.XDebuggerManagerListener;
|
||||
import com.jetbrains.python.debugger.PyDebugProcess;
|
||||
import com.jetbrains.python.debugger.PyFrameAccessor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -50,7 +51,7 @@ public class PyDataViewToolWindowFactory implements ToolWindowFactory {
|
||||
createEmptyContent(toolWindow);
|
||||
}
|
||||
else {
|
||||
PyDataView.getInstance(project).init(toolWindow, session.getDebugProcess());
|
||||
PyDataView.getInstance(project).init(toolWindow, (PyFrameAccessor)session.getDebugProcess());
|
||||
}
|
||||
final MessageBusConnection connection = project.getMessageBus().connect(project);
|
||||
connection.subscribe(XDebuggerManager.TOPIC, new ChangeContentXDebuggerManagerListener(toolWindow, project));
|
||||
@@ -98,9 +99,9 @@ public class PyDataViewToolWindowFactory implements ToolWindowFactory {
|
||||
|
||||
@Override
|
||||
public void processStarted(@NotNull XDebugProcess debugProcess) {
|
||||
if (getProcesses().isEmpty()) {
|
||||
if (getProcesses().isEmpty() && debugProcess instanceof PyDebugProcess) {
|
||||
myToolWindow.getContentManager().removeAllContents(true);
|
||||
PyDataView.getInstance(myProject).init(myToolWindow, debugProcess);
|
||||
PyDataView.getInstance(myProject).init(myToolWindow, ((PyDebugProcess)debugProcess));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,16 +29,12 @@ import com.intellij.ui.components.JBLabel;
|
||||
import com.intellij.ui.table.JBTable;
|
||||
import com.intellij.util.TextFieldCompletionProvider;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import com.intellij.xdebugger.XDebugProcess;
|
||||
import com.intellij.xdebugger.XDebugSession;
|
||||
import com.intellij.xdebugger.XDebuggerManager;
|
||||
import com.intellij.xdebugger.XDebugSessionListener;
|
||||
import com.intellij.xdebugger.frame.XNamedValue;
|
||||
import com.intellij.xdebugger.frame.XValueChildrenList;
|
||||
import com.jetbrains.python.PythonFileType;
|
||||
import com.jetbrains.python.debugger.ArrayChunk;
|
||||
import com.jetbrains.python.debugger.PyDebugProcess;
|
||||
import com.jetbrains.python.debugger.PyDebugValue;
|
||||
import com.jetbrains.python.debugger.PyDebuggerException;
|
||||
import com.jetbrains.python.debugger.*;
|
||||
import com.jetbrains.python.debugger.array.AsyncArrayTableModel;
|
||||
import com.jetbrains.python.debugger.array.JBTableWithRowHeaders;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -61,6 +57,7 @@ public class PyDataViewerPanel extends JPanel {
|
||||
private final static int ROWS_IN_DEFAULT_VIEW = 1000;
|
||||
private static final Logger LOG = Logger.getInstance(PyDataViewerPanel.class);
|
||||
private final Project myProject;
|
||||
@NotNull private final PyFrameAccessor myFrameAccessor;
|
||||
private EditorTextField mySliceTextField;
|
||||
private JBTableWithRowHeaders myTable;
|
||||
private EditorTextField myFormatTextField;
|
||||
@@ -69,15 +66,35 @@ public class PyDataViewerPanel extends JPanel {
|
||||
private boolean myColored;
|
||||
List<Listener> myListeners;
|
||||
|
||||
public PyDataViewerPanel(@NotNull Project project) {
|
||||
public PyDataViewerPanel(@NotNull Project project, @NotNull PyFrameAccessor frameAccessor) {
|
||||
super(new BorderLayout());
|
||||
myProject = project;
|
||||
myFrameAccessor = frameAccessor;
|
||||
myErrorLabel.setVisible(false);
|
||||
myErrorLabel.setForeground(JBColor.RED);
|
||||
myMainPanel.setBorder(new EmptyBorder(20, 20, 20, 20));
|
||||
add(myMainPanel, BorderLayout.CENTER);
|
||||
myColored = PropertiesComponent.getInstance(myProject).getBoolean(PyDataView.COLORED_BY_DEFAULT, true);
|
||||
myListeners = new CopyOnWriteArrayList<>();
|
||||
setupChangeListener();
|
||||
}
|
||||
|
||||
private void setupChangeListener() {
|
||||
if (myFrameAccessor instanceof PyDebugProcess) {
|
||||
XDebugSession session = ((PyDebugProcess)myFrameAccessor).getSession();
|
||||
session.addSessionListener(new XDebugSessionListener() {
|
||||
@Override
|
||||
public void stackFrameChanged() {
|
||||
AsyncArrayTableModel model = getModel();
|
||||
if (model != null) {
|
||||
model.invalidateCache();
|
||||
if (isShowing()) {
|
||||
model.fireTableDataChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public JBTable getTable() {
|
||||
@@ -172,12 +189,8 @@ public class PyDataViewerPanel extends JPanel {
|
||||
}
|
||||
|
||||
private PyDebugValue getDebugValue(String expression) {
|
||||
PyDebugProcess process = getDebugProcess();
|
||||
if (process == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
PyDebugValue value = process.evaluate(expression, false, true);
|
||||
PyDebugValue value = myFrameAccessor.evaluate(expression, false, true);
|
||||
if (value.isErrorOnEval()) {
|
||||
setError(value.getValue());
|
||||
return null;
|
||||
@@ -199,16 +212,6 @@ public class PyDataViewerPanel extends JPanel {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private PyDebugProcess getDebugProcess() {
|
||||
XDebugSession session = XDebuggerManager.getInstance(myProject).getCurrentSession();
|
||||
if (session == null) {
|
||||
return null;
|
||||
}
|
||||
XDebugProcess process = session.getDebugProcess();
|
||||
return process instanceof PyDebugProcess ? ((PyDebugProcess)process) : null;
|
||||
}
|
||||
|
||||
public String getFormat() {
|
||||
String format = myFormatTextField.getText();
|
||||
return format.isEmpty() ? "%" : format;
|
||||
@@ -261,11 +264,7 @@ public class PyDataViewerPanel extends JPanel {
|
||||
private List<PyDebugValue> getAvailableValues() {
|
||||
List<PyDebugValue> values = new ArrayList<>();
|
||||
try {
|
||||
PyDebugProcess process = getDebugProcess();
|
||||
if (process == null) {
|
||||
return values;
|
||||
}
|
||||
XValueChildrenList list = process.loadFrame();
|
||||
XValueChildrenList list = myFrameAccessor.loadFrame();
|
||||
if (list == null) {
|
||||
return values;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user