TerminalArrangementState (@NotNull ToolWindow terminalToolWindow) { TerminalArrangementState arrangementState = new TerminalArrangementState(); ContentManager contentManager = terminalToolWindow.getContentManager(); for (Content content : contentManager.getContents()) { AbstractTerminalRunner<?> runner = TerminalToolWindowManager.getRunnerByContent(content); if (runner == null || !runner.isTerminalSessionPersistent()) { continue; } JBTerminalWidget terminalWidget = TerminalToolWindowManager.getWidgetByContent(content); if (terminalWidget == null) continue; ShellTerminalWidget shellTerminalWidget = ObjectUtils.tryCast(terminalWidget, ShellTerminalWidget.class); TerminalTabState tabState = new TerminalTabState(); tabState.myTabName = content.getTabName(); tabState.myShellCommand = shellTerminalWidget != null ? shellTerminalWidget.getShellCommand() : null; tabState.myIsUserDefinedTabTitle = tabState.myTabName.equals(terminalWidget.getTerminalTitle().getUserDefinedTitle()); tabState.myWorkingDirectory = myWorkingDirectoryManager.getWorkingDirectory(content); tabState.myCommandHistoryFileName = TerminalCommandHistoryManager.getFilename( shellTerminalWidget != null ? shellTerminalWidget.getCommandHistoryFilePath() : null ); arrangementState.myTabStates.add(tabState); } Content selectedContent = contentManager.getSelectedContent(); arrangementState.mySelectedTabIndex = selectedContent == null ? -1 : contentManager.getIndexOfContent(selectedContent); return arrangementState; }