diff --git a/src/plugins/VerticalTabs/tabtreeview.cpp b/src/plugins/VerticalTabs/tabtreeview.cpp index 8bf143654..422ee3047 100644 --- a/src/plugins/VerticalTabs/tabtreeview.cpp +++ b/src/plugins/VerticalTabs/tabtreeview.cpp @@ -203,7 +203,11 @@ bool TabTreeView::viewportEvent(QEvent *event) WebTab *tab = index.data(TabModel::WebTabRole).value(); if (me->buttons() == Qt::MiddleButton) { if (tab) { - tab->closeTab(); + if (isExpanded(index)) { + tab->closeTab(); + } else { + closeTree(index); + } } else { m_window->addTab(); } @@ -363,7 +367,7 @@ TabTreeView::DelegateButton TabTreeView::buttonAt(const QPoint &pos, const QMode return NoButton; } -void TabTreeView::addMenuActions(QMenu *menu, const QModelIndex &index) const +void TabTreeView::addMenuActions(QMenu *menu, const QModelIndex &index) { if (!m_haveTreeModel) { return; @@ -375,24 +379,10 @@ void TabTreeView::addMenuActions(QMenu *menu, const QModelIndex &index) const if (index.isValid() && model()->rowCount(index) > 0) { QPersistentModelIndex pindex = index; m->addAction(tr("Close Tree"), this, [=]() { - QVector tabs; - reverseTraverse(pindex, [&](const QModelIndex &index) { - WebTab *tab = index.data(TabModel::WebTabRole).value(); - if (tab) { - tabs.append(tab); - } - }); - for (WebTab *tab : qAsConst(tabs)) { - tab->closeTab(); - } + closeTree(pindex); }); m->addAction(tr("Unload Tree"), this, [=]() { - reverseTraverse(pindex, [&](const QModelIndex &index) { - WebTab *tab = index.data(TabModel::WebTabRole).value(); - if (tab && tab->isRestored()) { - tab->unload(); - } - }); + unloadTree(pindex); }); } @@ -411,3 +401,27 @@ void TabTreeView::reverseTraverse(const QModelIndex &root, std::function tabs; + reverseTraverse(root, [&](const QModelIndex &index) { + WebTab *tab = index.data(TabModel::WebTabRole).value(); + 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(); + if (tab && tab->isRestored()) { + tab->unload(); + } + }); +} diff --git a/src/plugins/VerticalTabs/tabtreeview.h b/src/plugins/VerticalTabs/tabtreeview.h index 1be52519d..12db60e15 100644 --- a/src/plugins/VerticalTabs/tabtreeview.h +++ b/src/plugins/VerticalTabs/tabtreeview.h @@ -64,9 +64,12 @@ private: void initView(); 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 callback) const; + void closeTree(const QModelIndex &root); + void unloadTree(const QModelIndex &root); + BrowserWindow *m_window; TabTreeDelegate *m_delegate; DelegateButton m_pressedButton = NoButton;