From d109159408b166bfeac4fb19eaa3b2ffe6c21179 Mon Sep 17 00:00:00 2001 From: nowrep Date: Thu, 13 Mar 2014 11:11:15 +0100 Subject: [PATCH] [CloseOnLastTab] Instead of blocking closing tab, load new-tab-url --- src/lib/webview/tabwidget.cpp | 15 ++++++++++----- src/lib/webview/webview.h | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/lib/webview/tabwidget.cpp b/src/lib/webview/tabwidget.cpp index 22fe26eb2..c4fe1bd4f 100644 --- a/src/lib/webview/tabwidget.cpp +++ b/src/lib/webview/tabwidget.cpp @@ -481,10 +481,14 @@ void TabWidget::closeTab(int index, bool force) // This would close last tab, so we close the window instead if (!force && count() == 1) { - // But only if we can + // If we are not closing window upon closing last tab, let's just load new-tab-url if (m_dontCloseWithOneTab) { - // We won't actually close the tab - m_closedTabsManager->takeLastClosedTab(); + if (webView->url() == m_urlOnNewTab) { + // We don't want to accumulate more than one closed tab, if user tries + // to close the last tab multiple times + m_closedTabsManager->takeLastClosedTab(); + } + webView->load(m_urlOnNewTab); return; } m_window->close(); @@ -506,13 +510,14 @@ void TabWidget::closeTab(int index, bool force) webView->disconnectObjects(); webTab->disconnectObjects(); - webTab->deleteLater(); - if (!m_closedInsteadOpened && m_menuTabs->isVisible()) { QAction* labelAction = m_menuTabs->actions().last(); labelAction->setText(tr("Currently you have %n opened tab(s)", "", count() - 1)); } + removeTab(index); + delete webTab; + emit changed(); } diff --git a/src/lib/webview/webview.h b/src/lib/webview/webview.h index acb617435..6564669b8 100644 --- a/src/lib/webview/webview.h +++ b/src/lib/webview/webview.h @@ -38,6 +38,7 @@ public: WebPage* page() const; void setPage(QWebPage* page); + void load(const QUrl &url); void load(const QNetworkRequest &request, QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation, const QByteArray &body = QByteArray()); @@ -82,7 +83,6 @@ public slots: void editSelectAll(); void editDelete(); - void load(const QUrl &url); void reload(); void reloadBypassCache();