mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-22572 Data View: close corresponding tabs when Python Console session removed
This commit is contained in:
@@ -39,6 +39,7 @@ import com.jetbrains.python.debugger.PyDebugProcess;
|
||||
import com.jetbrains.python.debugger.PyDebugValue;
|
||||
import com.jetbrains.python.debugger.PyFrameAccessor;
|
||||
import icons.PythonIcons;
|
||||
import org.apache.xmlrpc.XmlRpcException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -46,6 +47,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PyDataView implements DumbAware {
|
||||
@@ -76,14 +78,11 @@ public class PyDataView implements DumbAware {
|
||||
window.show(null);
|
||||
}
|
||||
|
||||
public void closeRelatedTabs(@NotNull PyDebugProcess process) {
|
||||
public void closeTabs(Predicate<PyFrameAccessor> ifClose) {
|
||||
List<TabInfo> tabsToRemove = new ArrayList<>();
|
||||
for (TabInfo info : myTabs.getTabs()) {
|
||||
PyFrameAccessor frameAccessor = getPanel(info).getFrameAccessor();
|
||||
if (frameAccessor instanceof PyDebugProcess) {
|
||||
if (frameAccessor == process) {
|
||||
tabsToRemove.add(info);
|
||||
}
|
||||
if (ifClose.test(getPanel(info).getFrameAccessor())) {
|
||||
tabsToRemove.add(info);
|
||||
}
|
||||
}
|
||||
ApplicationManager.getApplication().invokeLater(() -> {
|
||||
@@ -141,6 +140,19 @@ public class PyDataView implements DumbAware {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void closeDisconnectedFromConsoleTabs() {
|
||||
closeTabs(frameAccessor -> frameAccessor instanceof PydevConsoleCommunication && !isConnected(((PydevConsoleCommunication)frameAccessor)));
|
||||
}
|
||||
|
||||
private static boolean isConnected(PydevConsoleCommunication accessor){
|
||||
try {
|
||||
return accessor.handshake();
|
||||
}
|
||||
catch (XmlRpcException ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static PyDataView getInstance(@NotNull final Project project) {
|
||||
return ServiceManager.getService(project, PyDataView.class);
|
||||
}
|
||||
|
||||
+22
-5
@@ -25,22 +25,24 @@ import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DefaultActionGroup;
|
||||
import com.intellij.openapi.actionSystem.ToggleAction;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.wm.ToolWindow;
|
||||
import com.intellij.openapi.wm.ToolWindowAnchor;
|
||||
import com.intellij.openapi.wm.ToolWindowFactory;
|
||||
import com.intellij.openapi.wm.ToolWindowType;
|
||||
import com.intellij.openapi.wm.*;
|
||||
import com.intellij.openapi.wm.ex.ToolWindowEx;
|
||||
import com.intellij.ui.content.ContentManagerAdapter;
|
||||
import com.intellij.ui.content.ContentManagerEvent;
|
||||
import com.intellij.util.messages.MessageBusConnection;
|
||||
import com.intellij.xdebugger.XDebugProcess;
|
||||
import com.intellij.xdebugger.XDebuggerManager;
|
||||
import com.intellij.xdebugger.XDebuggerManagerListener;
|
||||
import com.jetbrains.python.console.PythonConsoleToolWindowFactory;
|
||||
import com.jetbrains.python.debugger.PyDebugProcess;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class PyDataViewToolWindowFactory implements ToolWindowFactory {
|
||||
public static final String EMPTY_TEXT = "Run debugger to view available data ";
|
||||
private static final Logger LOG = Logger.getInstance(PyDataViewToolWindowFactory.class);
|
||||
|
||||
@Override
|
||||
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
|
||||
@@ -70,9 +72,24 @@ public class PyDataViewToolWindowFactory implements ToolWindowFactory {
|
||||
}
|
||||
});
|
||||
|
||||
addPythonConsoleListener(project);
|
||||
((ToolWindowEx)toolWindow).setAdditionalGearActions(new DefaultActionGroup(new ColoredByDefaultAction()));
|
||||
}
|
||||
|
||||
private static void addPythonConsoleListener(@NotNull Project project) {
|
||||
final ToolWindow pythonConsole = ToolWindowManager.getInstance(project).getToolWindow(PythonConsoleToolWindowFactory.Companion.getID());
|
||||
if (pythonConsole == null) {
|
||||
LOG.error("No Python Console tool window");
|
||||
return;
|
||||
}
|
||||
pythonConsole.getContentManager().addContentManagerListener(new ContentManagerAdapter() {
|
||||
@Override
|
||||
public void contentRemoved(ContentManagerEvent event) {
|
||||
PyDataView.getInstance(project).closeDisconnectedFromConsoleTabs();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(ToolWindow window) {
|
||||
window.setDefaultState(ToolWindowAnchor.RIGHT, ToolWindowType.FLOATING, null);
|
||||
@@ -109,7 +126,7 @@ public class PyDataViewToolWindowFactory implements ToolWindowFactory {
|
||||
@Override
|
||||
public void processStopped(@NotNull XDebugProcess debugProcess) {
|
||||
if (debugProcess instanceof PyDebugProcess) {
|
||||
PyDataView.getInstance(myProject).closeRelatedTabs(((PyDebugProcess)debugProcess));
|
||||
PyDataView.getInstance(myProject).closeTabs(frameAccessor -> frameAccessor instanceof PyDebugProcess && frameAccessor == debugProcess);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user