diff --git a/src/ViewManager.h b/src/ViewManager.h --- a/src/ViewManager.h +++ b/src/ViewManager.h @@ -86,6 +86,7 @@ */ void applyProfileToView(TerminalDisplay *view, const Profile::Ptr &profile); + void toggleActionsBasedOnState(); /** * Return the main widget for the view manager which * holds all of the views managed by this ViewManager instance. @@ -309,7 +310,6 @@ // called when the "Detach View" menu item is selected void detachActiveView(); void detachActiveTab(); - void updateDetachViewState(); // called when a session terminates - the view manager will delete any // views associated with the session diff --git a/src/ViewManager.cpp b/src/ViewManager.cpp --- a/src/ViewManager.cpp +++ b/src/ViewManager.cpp @@ -262,20 +262,31 @@ collection->addAction(QStringLiteral("switch-to-tab-%1").arg(i), action); } - auto handleMultiTabActionsLambda = [=]{ - const int count = _viewContainer->count(); - foreach(QAction *tabOnlyAction, _multiTabOnlyActions) { - tabOnlyAction->setEnabled(count > 1); - } - }; - connect(_viewContainer, &TabbedViewContainer::viewAdded, this, handleMultiTabActionsLambda); - connect(_viewContainer, &TabbedViewContainer::viewRemoved, this, handleMultiTabActionsLambda); - connect(_viewContainer, &QTabWidget::currentChanged, this, &ViewManager::updateDetachViewState); + connect(_viewContainer, &TabbedViewContainer::viewAdded, this, &ViewManager::toggleActionsBasedOnState); + connect(_viewContainer, &TabbedViewContainer::viewRemoved, this, &ViewManager::toggleActionsBasedOnState); + connect(_viewContainer, &QTabWidget::currentChanged, this, &ViewManager::toggleActionsBasedOnState); - // Initial state - handleMultiTabActionsLambda(); - updateDetachViewState(); + toggleActionsBasedOnState(); +} + +void ViewManager::toggleActionsBasedOnState() { + const int count = _viewContainer->count(); + foreach(QAction *tabOnlyAction, _multiTabOnlyActions) { + tabOnlyAction->setEnabled(count > 1); + } + + if (_viewContainer && _viewContainer->activeViewSplitter()) { + const int splitCount = _viewContainer + ->activeViewSplitter() + ->getToplevelSplitter() + ->findChildren() + .count(); + + foreach (QAction *action, _multiSplitterOnlyActions) { + action->setEnabled(splitCount > 1); + } + } } void ViewManager::switchToView(int index) @@ -297,21 +308,6 @@ } } -void ViewManager::updateDetachViewState() -{ - if (_viewContainer && _viewContainer->activeViewSplitter()) { - const int splitCount = _viewContainer - ->activeViewSplitter() - ->getToplevelSplitter() - ->findChildren() - .count(); - - foreach (QAction *action, _multiSplitterOnlyActions) { - action->setEnabled(splitCount > 1); - } - } -} - void ViewManager::focusUp() { _viewContainer->activeViewSplitter()->focusUp(); @@ -417,7 +413,7 @@ QHash detachedSessions = forgetAll(newSplitter); emit terminalsDetached(newSplitter, detachedSessions); focusAnotherTerminal(activeSplitter->getToplevelSplitter()); - updateDetachViewState(); + toggleActionsBasedOnState(); } } @@ -498,7 +494,7 @@ if (_sessionMap.size() > 0) { updateTerminalDisplayHistory(view, true); focusAnotherTerminal(toplevelSplitter); - updateDetachViewState(); + toggleActionsBasedOnState(); } } @@ -561,7 +557,7 @@ _viewContainer->splitView(terminalDisplay, orientation); - updateDetachViewState(); + toggleActionsBasedOnState(); // focus the new container terminalDisplay->setFocus(); @@ -635,7 +631,7 @@ Qt::UniqueConnection); _sessionMap[terminal] = session; createController(session, terminal); - updateDetachViewState(); + toggleActionsBasedOnState(); _terminalDisplayHistory.append(terminal); } @@ -768,7 +764,7 @@ } //we only update the focus if the splitter is still alive - updateDetachViewState(); + toggleActionsBasedOnState(); // The below causes the menus to be messed up // Only happens when using the tab bar close button diff --git a/src/main.cpp b/src/main.cpp --- a/src/main.cpp +++ b/src/main.cpp @@ -22,6 +22,7 @@ #include "MainWindow.h" #include "config-konsole.h" //krazy:exclude=includes #include "KonsoleSettings.h" +#include "ViewManager.h" // OS specific #include @@ -369,7 +370,10 @@ void restoreSession(Application &app) { int n = 1; + while (KMainWindow::canBeRestored(n)) { - app.newMainWindow()->restore(n++); + auto mainWindow = app.newMainWindow(); + mainWindow->restore(n++); + mainWindow->viewManager()->toggleActionsBasedOnState(); } }