Commit e97974fa authored by Kurt Hindenburg's avatar Kurt Hindenburg

Add ability to toggle/jump between two tabs

With this action, two tabs can be jumped back and forth.  This
somewhat abuses the stucture used for the "Last Used Tabs" action.
When the "Last Used Tabs" actions are used, the next "Toggle between
two tabs" will be incorrect for the first time.

Idea from https://phabricator.kde.org/D7068
parent d689ba54
......@@ -342,6 +342,18 @@ void TabbedViewContainer::activateLastUsedView(bool reverse)
setCurrentIndex(index);
}
// Jump to last view - this allows toggling between two views
// Using "Last Used Tabs" shortcut will cause "Toggle between two tabs"
// shortcut to be incorrect the first time.
void TabbedViewContainer::toggleLastUsedView()
{
if (_tabHistory.count() <= 1) {
return;
}
setCurrentIndex(indexOf(_tabHistory.at(1)));
}
void TabbedViewContainer::keyReleaseEvent(QKeyEvent* event)
{
if (_tabHistoryIndex != -1 && event->modifiers() == Qt::NoModifier) {
......
......@@ -98,6 +98,9 @@ public:
/** Changes the active view to the last used view */
void activateLastUsedView(bool reverse);
/** Toggle between last two views */
void toggleLastUsedView();
void setCss(const QString& styleSheet = QString());
void setCssFromFile(const QUrl& url);
/**
......
......@@ -138,6 +138,7 @@ void ViewManager::setupActions()
QAction *lastUsedViewAction = new QAction(i18nc("@action Shortcut entry", "Last Used Tabs"), this);
QAction *lastUsedViewReverseAction = new QAction(i18nc("@action Shortcut entry",
"Last Used Tabs (Reverse)"), this);
QAction *toggleTwoViewsAction = new QAction(i18nc("@action Shortcut entry", "Toggle Between Two Tabs"), this);
QAction *nextContainerAction = new QAction(i18nc("@action Shortcut entry",
"Next View Container"), this);
......@@ -226,6 +227,7 @@ void ViewManager::setupActions()
collection->addAction(QStringLiteral("last-tab"), lastViewAction);
collection->addAction(QStringLiteral("last-used-tab"), lastUsedViewAction);
collection->addAction(QStringLiteral("last-used-tab-reverse"), lastUsedViewReverseAction);
collection->addAction(QStringLiteral("toggle-two-tabs"), toggleTwoViewsAction);
collection->addAction(QStringLiteral("next-container"), nextContainerAction);
collection->addAction(QStringLiteral("move-view-left"), moveViewLeftAction);
collection->addAction(QStringLiteral("move-view-right"), moveViewRightAction);
......@@ -291,6 +293,9 @@ void ViewManager::setupActions()
collection->setDefaultShortcut(lastUsedViewReverseAction, Qt::CTRL + Qt::SHIFT + Qt::Key_Tab);
connect(lastUsedViewReverseAction, &QAction::triggered, this, &Konsole::ViewManager::lastUsedViewReverse);
_viewSplitter->addAction(lastUsedViewReverseAction);
connect(toggleTwoViewsAction, &QAction::triggered, this, &Konsole::ViewManager::toggleTwoViews);
_viewSplitter->addAction(toggleTwoViewsAction);
}
void ViewManager::switchToView(int index)
......@@ -372,6 +377,13 @@ void ViewManager::lastUsedViewReverse()
container->activateLastUsedView(true);
}
void ViewManager::toggleTwoViews()
{
TabbedViewContainer *container = _viewSplitter->activeContainer();
Q_ASSERT(container);
container->toggleLastUsedView();
}
void ViewManager::detachActiveView()
{
// find the currently active view and remove it from its container
......
......@@ -358,6 +358,9 @@ private Q_SLOTS:
// called when "Next View Container" shortcut is activated
void nextContainer();
// called when "Toggle Two tabs" shortcut is activated
void toggleTwoViews();
// called when the views in a container owned by this view manager
// changes
void containerViewsChanged(TabbedViewContainer *container);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment