1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

VerticalTabs: Close tree if middle clicking on collapsed item

BUG: 399217
FIXED-IN: 3.1.0
This commit is contained in:
David Rosca 2018-12-24 15:18:40 +01:00
parent 53d35dbdbd
commit fe45d36cda
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
2 changed files with 36 additions and 19 deletions

View File

@ -203,7 +203,11 @@ bool TabTreeView::viewportEvent(QEvent *event)
WebTab *tab = index.data(TabModel::WebTabRole).value<WebTab*>(); WebTab *tab = index.data(TabModel::WebTabRole).value<WebTab*>();
if (me->buttons() == Qt::MiddleButton) { if (me->buttons() == Qt::MiddleButton) {
if (tab) { if (tab) {
tab->closeTab(); if (isExpanded(index)) {
tab->closeTab();
} else {
closeTree(index);
}
} else { } else {
m_window->addTab(); m_window->addTab();
} }
@ -363,7 +367,7 @@ TabTreeView::DelegateButton TabTreeView::buttonAt(const QPoint &pos, const QMode
return NoButton; return NoButton;
} }
void TabTreeView::addMenuActions(QMenu *menu, const QModelIndex &index) const void TabTreeView::addMenuActions(QMenu *menu, const QModelIndex &index)
{ {
if (!m_haveTreeModel) { if (!m_haveTreeModel) {
return; return;
@ -375,24 +379,10 @@ void TabTreeView::addMenuActions(QMenu *menu, const QModelIndex &index) const
if (index.isValid() && model()->rowCount(index) > 0) { if (index.isValid() && model()->rowCount(index) > 0) {
QPersistentModelIndex pindex = index; QPersistentModelIndex pindex = index;
m->addAction(tr("Close Tree"), this, [=]() { m->addAction(tr("Close Tree"), this, [=]() {
QVector<WebTab*> tabs; closeTree(pindex);
reverseTraverse(pindex, [&](const QModelIndex &index) {
WebTab *tab = index.data(TabModel::WebTabRole).value<WebTab*>();
if (tab) {
tabs.append(tab);
}
});
for (WebTab *tab : qAsConst(tabs)) {
tab->closeTab();
}
}); });
m->addAction(tr("Unload Tree"), this, [=]() { m->addAction(tr("Unload Tree"), this, [=]() {
reverseTraverse(pindex, [&](const QModelIndex &index) { unloadTree(pindex);
WebTab *tab = index.data(TabModel::WebTabRole).value<WebTab*>();
if (tab && tab->isRestored()) {
tab->unload();
}
});
}); });
} }
@ -411,3 +401,27 @@ void TabTreeView::reverseTraverse(const QModelIndex &root, std::function<void(co
} }
callback(root); callback(root);
} }
void TabTreeView::closeTree(const QModelIndex &root)
{
QVector<WebTab*> tabs;
reverseTraverse(root, [&](const QModelIndex &index) {
WebTab *tab = index.data(TabModel::WebTabRole).value<WebTab*>();
if (tab) {
tabs.append(tab);
}
});
for (WebTab *tab : qAsConst(tabs)) {
tab->closeTab();
}
}
void TabTreeView::unloadTree(const QModelIndex &root)
{
reverseTraverse(root, [&](const QModelIndex &index) {
WebTab *tab = index.data(TabModel::WebTabRole).value<WebTab*>();
if (tab && tab->isRestored()) {
tab->unload();
}
});
}

View File

@ -64,9 +64,12 @@ private:
void initView(); void initView();
DelegateButton buttonAt(const QPoint &pos, const QModelIndex &index) const; DelegateButton buttonAt(const QPoint &pos, const QModelIndex &index) const;
void addMenuActions(QMenu *menu, const QModelIndex &index) const; void addMenuActions(QMenu *menu, const QModelIndex &index);
void reverseTraverse(const QModelIndex &root, std::function<void(const QModelIndex&)> callback) const; void reverseTraverse(const QModelIndex &root, std::function<void(const QModelIndex&)> callback) const;
void closeTree(const QModelIndex &root);
void unloadTree(const QModelIndex &root);
BrowserWindow *m_window; BrowserWindow *m_window;
TabTreeDelegate *m_delegate; TabTreeDelegate *m_delegate;
DelegateButton m_pressedButton = NoButton; DelegateButton m_pressedButton = NoButton;