diff options
| author | Alex Miranda <[email protected]> | 2019-10-13 16:37:00 +0200 |
|---|---|---|
| committer | Elvis Angelaccio <[email protected]> | 2019-10-13 16:41:00 +0200 |
| commit | e04ec8601f3771aa7ce98d9d1de34e332f26c103 (patch) | |
| tree | f11990490628100944e5d57b00dd0042b51c8098 | |
| parent | e7de9862022a08e1dd9204f0acd6329ac7bf5353 (diff) | |
Add actions for switching to a specific tab
Summary:
Add actions to switch to each of the first 9 tabs and another action to
switch to the last tab.
This feature makes it much easier to quickly switch between tabs just
like you normally would be able to when using a web browser or other
applications.
Reviewers: #vdg, #dolphin, ngraham, elvisangelaccio
Reviewed By: #vdg, #dolphin, ngraham
Subscribers: meven, ngraham, elvisangelaccio, kfm-devel
Tags: #dolphin
Differential Revision: https://phabricator.kde.org/D24353
| -rw-r--r-- | src/dolphinmainwindow.cpp | 24 | ||||
| -rw-r--r-- | src/dolphintabwidget.cpp | 12 | ||||
| -rw-r--r-- | src/dolphintabwidget.h | 10 |
3 files changed, 46 insertions, 0 deletions
diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index ce2013798..ce1746d2b 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -93,6 +93,8 @@ namespace { const int CurrentDolphinVersion = 200; // The maximum number of entries in the back/forward popup menu const int MaxNumberOfNavigationentries = 12; + // The maximum number of "Activate Tab" shortcuts + const int MaxActivateTabShortcuts = 9; } DolphinMainWindow::DolphinMainWindow() : @@ -1178,6 +1180,10 @@ void DolphinMainWindow::activeViewChanged(DolphinViewContainer* viewContainer) void DolphinMainWindow::tabCountChanged(int count) { const bool enableTabActions = (count > 1); + for (int i = 0; i < MaxActivateTabShortcuts; ++i) { + actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i))->setEnabled(enableTabActions); + } + actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions); actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions); actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions); } @@ -1503,6 +1509,24 @@ void DolphinMainWindow::setupActions() QList<QKeySequence> prevTabKeys = KStandardShortcut::tabPrev(); prevTabKeys.append(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Tab)); + for (int i = 0; i < MaxActivateTabShortcuts; ++i) { + QAction* activateTab = actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i)); + activateTab->setText(i18nc("@action:inmenu", "Activate Tab %1", i + 1)); + activateTab->setEnabled(false); + connect(activateTab, &QAction::triggered, this, [this, i]() { m_tabWidget->activateTab(i); }); + + // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts + if (i < 9) { + actionCollection()->setDefaultShortcut(activateTab, QStringLiteral("Alt+%1").arg(i + 1)); + } + } + + QAction* activateLastTab = actionCollection()->addAction(QStringLiteral("activate_last_tab")); + activateLastTab->setText(i18nc("@action:inmenu", "Activate Last Tab")); + activateLastTab->setEnabled(false); + connect(activateLastTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activateLastTab); + actionCollection()->setDefaultShortcut(activateLastTab, Qt::ALT + Qt::Key_0); + QAction* activateNextTab = actionCollection()->addAction(QStringLiteral("activate_next_tab")); activateNextTab->setIconText(i18nc("@action:inmenu", "Next Tab")); activateNextTab->setText(i18nc("@action:inmenu", "Activate Next Tab")); diff --git a/src/dolphintabwidget.cpp b/src/dolphintabwidget.cpp index ec0c783bc..0408d7ed4 100644 --- a/src/dolphintabwidget.cpp +++ b/src/dolphintabwidget.cpp @@ -266,6 +266,18 @@ void DolphinTabWidget::closeTab(const int index) tabPage->deleteLater(); } +void DolphinTabWidget::activateTab(const int index) +{ + if (index < count()) { + setCurrentIndex(index); + } +} + +void DolphinTabWidget::activateLastTab() +{ + setCurrentIndex(count() - 1); +} + void DolphinTabWidget::activateNextTab() { const int index = currentIndex() + 1; diff --git a/src/dolphintabwidget.h b/src/dolphintabwidget.h index 4351a40a8..746aec6c6 100644 --- a/src/dolphintabwidget.h +++ b/src/dolphintabwidget.h @@ -155,6 +155,16 @@ public slots: void closeTab(const int index); /** + * Activates the tab with the index \a index. + */ + void activateTab(const int index); + + /** + * Activates the last tab in the tab bar. + */ + void activateLastTab(); + + /** * Activates the next tab in the tab bar. * If the current active tab is the last tab, it activates the first tab. */ |
