Bug 235107

Summary: Add possibilty to define shortcuts for switching tabs
Product: [Unmaintained] rekonq Reporter: Sebastian Vahl <deadbabylon>
Component: generalAssignee: Andrea Diamantini <adjam7>
Status: RESOLVED FIXED    
Severity: wishlist CC: nsm.nikhil, pano_90
Priority: NOR    
Version: 0.4.0   
Target Milestone: ---   
Platform: Fedora RPMs   
OS: Unspecified   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Bug Depends on:    
Bug Blocks: 237890    

Description Sebastian Vahl 2010-04-22 21:36:38 UTC
Version:           0.4.0 (using KDE 4.4.2)
Installed from:    Fedora RPMs

I'm used to use ALT+1 for Tab1, Alt+2 for Tab2 and so on. This is currently not possible in rekonq. So it would be great to let the user define user base shortcuts for common tasks. Also the shortcuts from ALT+1 to ALT+9 should be pre-defined for switiching trough the Tabs 1 to 9.
Comment 1 Panagiotis Papadopoulos 2010-04-23 18:04:38 UTC
This feature was available in a very early version of rekonq (or at least a Merge Request with it). Don't know why it isn't there anymore.
Adjam: What do you think?
Comment 2 Andrea Diamantini 2010-04-23 18:39:16 UTC
On Friday 23 April 2010 18:04:39 Panagiotis Papadopoulos wrote:
> https://bugs.kde.org/show_bug.cgi?id=235107
> 
> 
> Panagiotis Papadopoulos <pano_90@gmx.net> changed:
> 
>            What    |Removed                     |Added
> ---------------------------------------------------------------------------
> - CC|                            |pano_90@gmx.net
> 
> 
> 
> 
> --- Comment #1 from Panagiotis Papadopoulos <pano_90 gmx net>  2010-04-23
> 18:04:38 --- This feature was available in a very early version of rekonq
> (or at least a Merge Request with it). Don't know why it isn't there
> anymore.
> Adjam: What do you think?

We probably removed in the "big switch" from TabWidget to MainView. I'll try 
to reimplement it ASAP.
Comment 3 Nikhil Marathe 2010-05-24 17:20:50 UTC
commit 9dc07f24c01c152d23c22cefab50db43fe517e95
Author: Nikhil Marathe <nsm.nikhil@gmail.com>
Date:   Mon May 24 16:48:49 2010 +0530

    Added actions to switch to Tab #n
    
    BUG: 235107

diff --git a/src/mainview.cpp b/src/mainview.cpp
index 1c36adc..01f0e1a 100644
--- a/src/mainview.cpp
+++ b/src/mainview.cpp
@@ -657,6 +657,17 @@ void MainView::openClosedTab()
     }
 }
 
+void MainView::switchToTab()
+{
+    // uses the sender to determine the tab index
+    QAction *sender = static_cast<QAction*>(QObject::sender());
+    int index = sender->data().toInt();
+    index -= 1; // to compensate for off by 1 presented to the user
+    if( index < 0 || index >= count() )
+        return;
+    setCurrentIndex( index );
+}
+
 QLabel *MainView::animatedLoading(int index, bool addMovie)
 {
     if (index == -1)
diff --git a/src/mainview.h b/src/mainview.h
index 0cff4c8..636d37a 100644
--- a/src/mainview.h
+++ b/src/mainview.h
@@ -135,6 +135,7 @@ public slots:
     void detachTab(int index = -1);
     void openClosedTabs();
     void openClosedTab();
+    void switchToTab();
 
     // WEB slot actions
     void webReload();
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index f5be73e..d14f225 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -398,6 +398,16 @@ void MainWindow::setupActions()
     closedTabsMenu->setDelayed(false);
     actionCollection()->addAction(QL1S("closed_tab_menu"), closedTabsMenu);
 
+    // shortcuts for quickly switching to a tab
+    for( int i = 1; i <= 9; i++ ) {
+        a = new KAction(i18n("Switch to Tab %1", i), this);
+        a->setShortcut(KShortcut( QString("Alt+%1").arg(i) ));
+        a->setData( QVariant(i) );
+        actionCollection()->addAction(QL1S(("switch_tab_" + QString::number(i)).toAscii()), a);
+        connect(a, SIGNAL(triggered(bool)), m_view, SLOT(switchToTab()));
+    }
+
+
     // ============================== Indexed Tab Actions ====================================
     a = new KAction(KIcon("tab-close"), i18n("&Close Tab"), this);
     actionCollection()->addAction(QL1S("close_tab"), a);