diff --git a/src/ViewContainer.h b/src/ViewContainer.h --- a/src/ViewContainer.h +++ b/src/ViewContainer.h @@ -211,6 +211,9 @@ /** Changes the active view to the last view */ void activateLastView(); + /** Changes the active view to the alternate view */ + void activateAlternateView(); + /** * This enum describes the directions * in which views can be re-arranged within the container @@ -346,6 +349,9 @@ */ virtual void moveViewWidget(int fromIndex, int toIndex); + /** Holds the alternate tab */ + QWidget *_alternateView; + private Q_SLOTS: void viewDestroyed(QObject *view); void searchBarDestroyed(); diff --git a/src/ViewContainer.cpp b/src/ViewContainer.cpp --- a/src/ViewContainer.cpp +++ b/src/ViewContainer.cpp @@ -52,6 +52,7 @@ ViewContainer::ViewContainer(NavigationPosition position, QObject *parent) : QObject(parent), + _alternateView(nullptr), _navigationVisibility(AlwaysShowNavigation), _navigationPosition(position), _searchBar(nullptr) @@ -231,6 +232,13 @@ setActiveView(_views.at(_views.count() - 1)); } +void ViewContainer::activateAlternateView() +{ + if (_alternateView != nullptr) { + setActiveView(_alternateView); + } +} + void ViewContainer::activatePreviousView() { QWidget *active = activeView(); @@ -645,6 +653,8 @@ void TabbedViewContainer::currentTabChanged(int index) { + _alternateView = activeView(); + _stackWidget->setCurrentIndex(index); if (_stackWidget->widget(index) != nullptr) { emit activeViewChanged(_stackWidget->widget(index)); @@ -679,7 +689,7 @@ Q_ASSERT(index != -1); - _stackWidget->setCurrentWidget(view); + // let the tab bar be the unique item setting the active view _tabBar->setCurrentIndex(index); } @@ -809,6 +819,8 @@ void StackedViewContainer::setActiveView(QWidget *view) { + _alternateView = activeView(); + _stackWidget->setCurrentWidget(view); } diff --git a/src/ViewManager.h b/src/ViewManager.h --- a/src/ViewManager.h +++ b/src/ViewManager.h @@ -318,6 +318,9 @@ // called when "Switch to last tab" shortcut is activated void lastView(); + // called when "Switch to alternate tab" shortcut is activated + void alternateView(); + // called when "Next View Container" shortcut is activated void nextContainer(); diff --git a/src/ViewManager.cpp b/src/ViewManager.cpp --- a/src/ViewManager.cpp +++ b/src/ViewManager.cpp @@ -139,6 +139,8 @@ QAction *previousViewAction = new QAction(i18nc("@action Shortcut entry", "Previous Tab"), this); QAction *lastViewAction = new QAction(i18nc("@action Shortcut entry", "Switch to Last Tab"), this); + QAction *alternateViewAction = new QAction(i18nc("@action Shortcut entry", + "Switch to Alternate Tab"), this); QAction *nextContainerAction = new QAction(i18nc("@action Shortcut entry", "Next View Container"), this); @@ -223,6 +225,7 @@ collection->addAction(QStringLiteral("next-view"), nextViewAction); collection->addAction(QStringLiteral("previous-view"), previousViewAction); collection->addAction(QStringLiteral("last-tab"), lastViewAction); + collection->addAction(QStringLiteral("alternate-tab"), alternateViewAction); collection->addAction(QStringLiteral("next-container"), nextContainerAction); collection->addAction(QStringLiteral("move-view-left"), moveViewLeftAction); collection->addAction(QStringLiteral("move-view-right"), moveViewRightAction); @@ -279,6 +282,9 @@ connect(lastViewAction, &QAction::triggered, this, &Konsole::ViewManager::lastView); _viewSplitter->addAction(lastViewAction); + + connect(alternateViewAction, &QAction::triggered, this, &Konsole::ViewManager::alternateView); + _viewSplitter->addAction(alternateViewAction); } void ViewManager::switchToView(int index) @@ -359,6 +365,15 @@ container->activateLastView(); } +void ViewManager::alternateView() +{ + ViewContainer *container = _viewSplitter->activeContainer(); + + Q_ASSERT(container); + + container->activateAlternateView(); +} + void ViewManager::detachActiveView() { // find the currently active view and remove it from its container @@ -773,6 +788,11 @@ action->setEnabled(enable); } + action = collection->action(QStringLiteral("alternate-tab")); + if (action != nullptr) { + action->setEnabled(enable); + } + action = collection->action(QStringLiteral("split-view-left-right")); if (action != nullptr) { action->setEnabled(enable);