From a32b1a830acaaeda5caa070d046e5676fa8e9734 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 11 May 2010 11:20:24 +0200 Subject: (Re)-open closed tabs tabbar actions & CTRL + SHIFT + T shortcut for the last Johannes Zellner's patch. Thanks :) --- src/mainview.cpp | 16 ++++++++++++++++ src/mainview.h | 2 ++ src/mainwindow.cpp | 31 +++++++++++++++++++++++++++++++ src/tabbar.cpp | 5 ++++- 4 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/mainview.cpp b/src/mainview.cpp index 6179af80..e703976d 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -637,6 +637,22 @@ void MainView::previousTab() setCurrentIndex(next); } +void MainView::openClosedTabs() +{ + foreach (const HistoryItem &item, recentlyClosedTabs()) + { + Application::instance()->loadUrl( KUrl(item.url), Rekonq::SettingOpenTab); + } +} + +void MainView::openClosedTab() +{ + KAction *action = qobject_cast(sender()); + if (action) + { + Application::instance()->loadUrl(action->data().toUrl(), Rekonq::SettingOpenTab); + } +} QLabel *MainView::animatedLoading(int index, bool addMovie) { diff --git a/src/mainview.h b/src/mainview.h index eb5b3e02..6edccc15 100644 --- a/src/mainview.h +++ b/src/mainview.h @@ -132,6 +132,8 @@ public slots: void nextTab(); void previousTab(); void detachTab(int index = -1); + void openClosedTabs(); + void openClosedTab(); // WEB slot actions void webReload(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index ef665cc7..128648bf 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -393,6 +393,16 @@ void MainWindow::setupActions() a->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() : KStandardShortcut::tabPrev()); actionCollection()->addAction(QL1S("show_prev_tab"), a); connect(a, SIGNAL(triggered(bool)), m_view, SLOT(previousTab())); + + a = new KAction(KIcon("tab-new"), i18n("Open Closed Tabs"), this); + a->setShortcut(KShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_T)); + actionCollection()->addAction(QL1S("open_closed_tabs"), a); + connect(a, SIGNAL(triggered(bool)), m_view, SLOT(openClosedTabs())); + + // Closed Tabs Menu + KActionMenu *closedTabsMenu = new KActionMenu(KIcon("tab-new"), i18n("Closed Tabs"), this); + closedTabsMenu->setDelayed(false); + actionCollection()->addAction(QL1S("closed_tab_menu"), closedTabsMenu); // ============================== Indexed Tab Actions ==================================== a = new KAction(KIcon("tab-close"), i18n("&Close Tab"), this); @@ -634,6 +644,27 @@ void MainWindow::updateActions() QAction *historyForwardAction = actionByName(KStandardAction::name(KStandardAction::Forward)); historyForwardAction->setEnabled(currentTab()->view()->history()->canGoForward()); + + QAction *openClosedTabsAction = actionByName(QLatin1String("open_closed_tabs")); + openClosedTabsAction->setEnabled(mainView()->recentlyClosedTabs().size() > 0); + + // update closed tabs menu + KActionMenu *am = dynamic_cast(actionByName(QLatin1String("closed_tab_menu"))); + if (!am) + return; + + am->setEnabled(mainView()->recentlyClosedTabs().size() > 0); + + if (am->menu()) + am->menu()->clear(); + + foreach (HistoryItem item, mainView()->recentlyClosedTabs()) + { + KAction *a = new KAction(Application::icon(item.url), item.title, this); + a->setData(item.url); + connect(a, SIGNAL(triggered()), m_view, SLOT(openClosedTab())); + am->addAction(a); + } } diff --git a/src/tabbar.cpp b/src/tabbar.cpp index 27835892..1274d813 100644 --- a/src/tabbar.cpp +++ b/src/tabbar.cpp @@ -279,9 +279,10 @@ void TabBar::contextMenu(int tab, const QPoint &pos) menu.addAction(mainWindow->actionByName( QL1S("new_tab") )); menu.addAction(mainWindow->actionByName( QL1S("clone_tab") )); - if (count() > 1) menu.addAction(mainWindow->actionByName( QL1S("detach_tab") )); + menu.addAction(mainWindow->actionByName( QL1S("open_closed_tabs") )); + menu.addAction(mainWindow->actionByName( QL1S("closed_tab_menu") )); menu.addSeparator(); menu.addAction(mainWindow->actionByName( QL1S("close_tab") )); menu.addAction(mainWindow->actionByName( QL1S("close_other_tabs") )); @@ -299,6 +300,8 @@ void TabBar::emptyAreaContextMenu(const QPoint &pos) MainWindow *mainWindow = Application::instance()->mainWindow(); menu.addAction(mainWindow->actionByName( QL1S("new_tab") )); + menu.addAction(mainWindow->actionByName( QL1S("open_closed_tabs") )); + menu.addAction(mainWindow->actionByName( QL1S("closed_tab_menu") )); menu.addSeparator(); menu.addAction(mainWindow->actionByName( QL1S("reload_all_tabs") )); -- cgit v1.2.1