]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Add actions for switching to a specific tab
authorAlex Miranda <amdev1@yandex.com>
Sun, 13 Oct 2019 14:37:00 +0000 (16:37 +0200)
committerElvis Angelaccio <elvis.angelaccio@kde.org>
Sun, 13 Oct 2019 14:41:00 +0000 (16:41 +0200)
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

src/dolphinmainwindow.cpp
src/dolphintabwidget.cpp
src/dolphintabwidget.h

index ce2013798ddca711f321658ec1f7ab035cd2aafd..ce1746d2b78c8ecbcae90db4b4819a00ef00bc66 100644 (file)
@@ -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"));
index ec0c783bc34a491426dadda1d5ce4656dbbf4f01..0408d7ed47304dfead6ad8a9f35b58124bc20972 100644 (file)
@@ -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;
index 4351a40a837ded13f4e41347dd611f54be93d81f..746aec6c64ec347fdb2611c22d8e01a115374958 100644 (file)
@@ -154,6 +154,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.