1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

TabContextMenu: Add Unload Tab action

Closes #2563
This commit is contained in:
David Rosca 2018-01-23 17:02:51 +01:00
parent 4e39cad310
commit ba75905134
6 changed files with 45 additions and 19 deletions

View File

@ -44,6 +44,7 @@ TabContextMenu::TabContextMenu(int index, Qt::Orientation orientation, BrowserWi
connect(this, SIGNAL(closeToRight(int)), m_tabWidget, SLOT(closeToRight(int)));
connect(this, SIGNAL(closeToLeft(int)), m_tabWidget, SLOT(closeToLeft(int)));
connect(this, SIGNAL(duplicateTab(int)), m_tabWidget, SLOT(duplicateTab(int)));
connect(this, SIGNAL(unloadTab(int)), m_tabWidget, SLOT(unloadTab(int)));
init();
}
@ -121,6 +122,11 @@ void TabContextMenu::init()
addAction(webTab->isPinned() ? tr("Un&pin Tab") : tr("&Pin Tab"), this, SLOT(pinTab()));
addAction(webTab->isMuted() ? tr("Un&mute Tab") : tr("&Mute Tab"), this, SLOT(muteTab()));
if (webTab->isRestored()) {
addAction(tr("Unload Tab"), this, SLOT(unloadTab()));
}
addSeparator();
addAction(tr("Re&load All Tabs"), m_tabWidget, SLOT(reloadAllTabs()));
addAction(tr("Bookmark &All Tabs"), m_window, SLOT(bookmarkAllTabs()));

View File

@ -39,12 +39,14 @@ signals:
void closeToRight(int index);
void closeToLeft(int index);
void duplicateTab(int index);
void unloadTab(int index);
private slots:
void reloadTab() { emit reloadTab(m_clickedTab); }
void stopTab() { emit stopTab(m_clickedTab); }
void closeTab() { emit tabCloseRequested(m_clickedTab); }
void duplicateTab() { emit duplicateTab(m_clickedTab); }
void unloadTab() { emit unloadTab(m_clickedTab); }
void pinTab();
void muteTab();

View File

@ -672,6 +672,15 @@ int TabWidget::duplicateTab(int index)
return id;
}
void TabWidget::unloadTab(int index)
{
if (!validIndex(index)) {
return;
}
weTab(index)->unload();
}
void TabWidget::restoreClosedTab(QObject* obj)
{
if (!obj) {

View File

@ -116,6 +116,7 @@ public slots:
void closeToRight(int index);
void closeToLeft(int index);
void detachTab(int index);
void unloadTab(int index);
void restoreClosedTab(QObject* obj = 0);
void restoreAllClosedTabs();
void clearClosedTabsList();

View File

@ -311,14 +311,21 @@ QByteArray WebTab::historyData() const
}
}
void WebTab::stop()
{
m_webView->stop();
}
void WebTab::reload()
{
m_webView->reload();
}
void WebTab::stop()
void WebTab::unload()
{
m_webView->stop();
m_savedTab = SavedTab(this);
m_webView->history()->clear();
m_webView->setUrl(QUrl(QSL("about:blank")));
}
bool WebTab::isLoading() const
@ -426,6 +433,10 @@ void WebTab::showNotification(QWidget* notif)
void WebTab::loadStarted()
{
if (!isRestored()) {
return;
}
if (m_tabBar && m_webView->title(/*allowEmpty*/true).isEmpty()) {
m_tabBar->setTabText(tabIndex(), tr("Loading..."));
}
@ -433,12 +444,16 @@ void WebTab::loadStarted()
void WebTab::loadFinished()
{
titleChanged(m_webView->title());
if (isRestored()) {
titleChanged(m_webView->title());
} else if (m_webView->url().toString() == QL1S("about:blank")) {
m_webView->history()->clear();
}
}
void WebTab::titleChanged(const QString &title)
{
if (!m_tabBar || !m_window || title.isEmpty()) {
if (!m_tabBar || !m_window || title.isEmpty() || !isRestored()) {
return;
}
@ -449,25 +464,19 @@ void WebTab::titleChanged(const QString &title)
m_tabBar->setTabText(tabIndex(), title);
}
void WebTab::slotRestore()
{
Q_ASSERT(m_tabBar);
if (isRestored()) {
return;
}
p_restoreTab(m_savedTab);
m_savedTab.clear();
}
void WebTab::tabActivated()
{
if (isRestored()) {
return;
}
QTimer::singleShot(0, this, SLOT(slotRestore()));
QTimer::singleShot(0, this, [this]() {
if (isRestored()) {
return;
}
p_restoreTab(m_savedTab);
m_savedTab.clear();
});
}
void WebTab::resizeEvent(QResizeEvent *event)

View File

@ -77,6 +77,7 @@ public:
void stop();
void reload();
void unload();
bool isLoading() const;
bool isPinned() const;
@ -110,8 +111,6 @@ private slots:
void loadFinished();
void titleChanged(const QString &title);
void slotRestore();
private:
void resizeEvent(QResizeEvent *event) override;