mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
terminal: restore tabs only once at startup, restore tab selection
This commit is contained in:
@@ -3,6 +3,7 @@ package org.jetbrains.plugins.terminal;
|
||||
|
||||
import com.intellij.openapi.components.*;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -31,7 +32,7 @@ public class TerminalArrangementManager implements PersistentStateComponent<Term
|
||||
|
||||
@Nullable
|
||||
TerminalArrangementState getArrangementState() {
|
||||
return myState;
|
||||
return Registry.is("terminal.persistant.tabs") ? myState : null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -30,6 +30,6 @@ public class TerminalToolWindowFactory implements ToolWindowFactory, DumbAware {
|
||||
@Override
|
||||
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
|
||||
TerminalView terminalView = TerminalView.getInstance(project);
|
||||
terminalView.initTerminal(toolWindow);
|
||||
terminalView.initTerminal(toolWindow, TerminalArrangementManager.getInstance(project).getArrangementState());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.wm.ToolWindow;
|
||||
import com.intellij.openapi.wm.ToolWindowManager;
|
||||
import com.intellij.openapi.wm.ex.ToolWindowEx;
|
||||
import com.intellij.openapi.wm.ex.ToolWindowManagerListener;
|
||||
import com.intellij.openapi.wm.impl.InternalDecorator;
|
||||
@@ -80,7 +79,7 @@ public class TerminalView {
|
||||
return project.getComponent(TerminalView.class);
|
||||
}
|
||||
|
||||
public void initTerminal(final ToolWindow toolWindow) {
|
||||
public void initTerminal(@NotNull ToolWindow toolWindow, @Nullable TerminalArrangementState arrangementState) {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
return;
|
||||
}
|
||||
@@ -94,8 +93,7 @@ public class TerminalView {
|
||||
});
|
||||
|
||||
myToolWindow.setToHideOnEmptyContent(true);
|
||||
TerminalArrangementState state = Registry.get("terminal.persistant.tabs").asBoolean() ? TerminalArrangementManager.getInstance(myProject).getArrangementState() : null;
|
||||
List<TerminalTabState> states = state != null ? state.myTabStates : null;
|
||||
List<TerminalTabState> states = arrangementState != null ? arrangementState.myTabStates : null;
|
||||
if (ContainerUtil.isEmpty(states)) {
|
||||
newTab(null);
|
||||
}
|
||||
@@ -103,23 +101,21 @@ public class TerminalView {
|
||||
for (TerminalTabState tabState : states) {
|
||||
createNewSession(myTerminalRunner, tabState);
|
||||
}
|
||||
ContentManager contentManager = toolWindow.getContentManager();
|
||||
Content content = contentManager.getContent(arrangementState.mySelectedTabIndex);
|
||||
if (content != null) {
|
||||
contentManager.setSelectedContent(content);
|
||||
}
|
||||
}
|
||||
|
||||
myProject.getMessageBus().connect().subscribe(ToolWindowManagerListener.TOPIC, new ToolWindowManagerListener() {
|
||||
@Override
|
||||
public void stateChanged() {
|
||||
ToolWindow window = ToolWindowManager.getInstance(myProject).getToolWindow(TerminalToolWindowFactory.TOOL_WINDOW_ID);
|
||||
if (window != null) {
|
||||
boolean visible = window.isVisible();
|
||||
if (visible) {
|
||||
if (myToolWindow.getContentManager().getContentCount() == 0) {
|
||||
initTerminal(window);
|
||||
}
|
||||
else if (myFileToOpen != null) {
|
||||
//myTerminalRunner.openSessionForFile(myTerminalWidget, myFileToOpen);
|
||||
}
|
||||
myFileToOpen = null;
|
||||
if (toolWindow.isVisible()) {
|
||||
if (myToolWindow.getContentManager().getContentCount() == 0) {
|
||||
initTerminal(toolWindow, null);
|
||||
}
|
||||
myFileToOpen = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user