From 4b363ed35e880a6a74ac7784fcad713c62902f3a Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 3 Jan 2012 18:31:13 +0100 Subject: improve closed tabs management - remove reopened tabs from the closed tabs list. - limit them to MAX 8 elements (it seems enough to me) - save history also when there is just one tab closed - DON'T save history when you opened a "rekonq" page BUG:271224 --- src/mainview.cpp | 112 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 57 insertions(+), 55 deletions(-) (limited to 'src/mainview.cpp') diff --git a/src/mainview.cpp b/src/mainview.cpp index 50fff2ac..62851590 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -2,7 +2,7 @@ * * This file is a part of the rekonq project * -* Copyright (C) 2008-2011 by Andrea Diamantini +* Copyright (C) 2008-2012 by Andrea Diamantini * Copyright (C) 2009 by Paweł Prażak * Copyright (C) 2009-2011 by Lionel Chauvin * Copyright (C) 2010 by Matthieu Gicquel @@ -421,14 +421,45 @@ void MainView::closeTab(int index, bool del) if (index < 0 || index >= count()) return; + WebTab *tabToClose = webTab(index); + if (!tabToClose) + return; + + if (tabToClose->view()->isModified()) + { + int risp = KMessageBox::warningContinueCancel(this, + i18n("This tab contains changes that have not been submitted.\n" + "Closing the tab will discard these changes.\n" + "Do you really want to close this tab?\n"), + i18n("Closing Modified Tab"), KGuiItem(i18n("Close &Tab"), "tab-close"), KStandardGuiItem::cancel()); + if (risp != KMessageBox::Continue) + return; + } + + kDebug() << "URL: " << tabToClose->url(); + kDebug() << "rekonq page: " << tabToClose->page()->isOnRekonqPage(); + + if (!tabToClose->url().isEmpty() + && tabToClose->url().scheme() != QL1S("about") + && !tabToClose->page()->isOnRekonqPage() + && !QWebSettings::globalSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled) + ) + { + const int recentlyClosedTabsLimit = 8; + TabHistory history(tabToClose->view()->history()); + + m_recentlyClosedTabs.removeAll(history); + if (m_recentlyClosedTabs.count() == recentlyClosedTabsLimit) + m_recentlyClosedTabs.removeLast(); + m_recentlyClosedTabs.prepend(history); + } + + // what to do if there is just one tab... if (count() == 1) { if (ReKonfig::lastTabClosesWindow()) { emit closeWindow(); -// // closing window... -// MainWindow *w = qobject_cast(parent()); -// w->close(); return; } @@ -453,34 +484,7 @@ void MainView::closeTab(int index, bool del) } return; } - - WebTab *tabToClose = webTab(index); - if (!tabToClose) - return; - - if (tabToClose->view()->isModified()) - { - int risp = KMessageBox::warningContinueCancel(this, - i18n("This tab contains changes that have not been submitted.\n" - "Closing the tab will discard these changes.\n" - "Do you really want to close this tab?\n"), - i18n("Closing Modified Tab"), KGuiItem(i18n("Close &Tab"), "tab-close"), KStandardGuiItem::cancel()); - if (risp != KMessageBox::Continue) - return; - } - - if (!tabToClose->url().isEmpty() - && !QWebSettings::globalSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled) - ) - { - const int recentlyClosedTabsLimit = 10; - TabHistory history(tabToClose->view()->history()); - - m_recentlyClosedTabs.removeAll(history); - if (m_recentlyClosedTabs.count() == recentlyClosedTabsLimit) - m_recentlyClosedTabs.removeLast(); - m_recentlyClosedTabs.prepend(history); - } + // else... removeTab(index); updateTabBar(); // UI operation: do it ASAP!! @@ -494,6 +498,7 @@ void MainView::closeTab(int index, bool del) } } + void MainView::webViewLoadStarted() { WebView *view = qobject_cast(sender()); @@ -623,37 +628,34 @@ void MainView::previousTab() } -void MainView::openLastClosedTab() +void MainView::openClosedTab() { - if (m_recentlyClosedTabs.isEmpty()) + KAction *action = qobject_cast(sender()); + if (!action) return; - TabHistory history = m_recentlyClosedTabs.takeFirst(); - WebView *view = rApp->mainWindow()->mainView()->newWebTab()->view(); - - history.applyHistory(view->history()); + int index = action->data().toInt(); + kDebug() << "TAB INDEX TO RESTORE:" << index; + restoreClosedTab(index); } -void MainView::openClosedTab() +void MainView::restoreClosedTab(int i, bool inNewTab) { - KAction *action = qobject_cast(sender()); - if (action) - { - WebView *view = rApp->mainWindow()->mainView()->newWebTab()->view(); - TabHistory history; - Q_FOREACH(const TabHistory & item, m_recentlyClosedTabs) - { - if (item.history == action->data().toByteArray()) - { - history = item; - break; - } - } - history.applyHistory(view->history()); + if (m_recentlyClosedTabs.isEmpty()) + return; - m_recentlyClosedTabs.removeAll(history); - } + TabHistory history = m_recentlyClosedTabs.takeAt(i); + + WebView *view = inNewTab + ? newWebTab()->view() + : currentWebTab()->view() + ; + + history.applyHistory(view->history()); + + // just to get sure... + m_recentlyClosedTabs.removeAll(history); } -- cgit v1.2.1