mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
VerticalTabs: Close tree if middle clicking on collapsed item
BUG: 399217 FIXED-IN: 3.1.0
This commit is contained in:
parent
53d35dbdbd
commit
fe45d36cda
|
@ -203,7 +203,11 @@ bool TabTreeView::viewportEvent(QEvent *event)
|
|||
WebTab *tab = index.data(TabModel::WebTabRole).value<WebTab*>();
|
||||
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<WebTab*> tabs;
|
||||
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();
|
||||
}
|
||||
closeTree(pindex);
|
||||
});
|
||||
m->addAction(tr("Unload Tree"), this, [=]() {
|
||||
reverseTraverse(pindex, [&](const QModelIndex &index) {
|
||||
WebTab *tab = index.data(TabModel::WebTabRole).value<WebTab*>();
|
||||
if (tab && tab->isRestored()) {
|
||||
tab->unload();
|
||||
}
|
||||
});
|
||||
unloadTree(pindex);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -411,3 +401,27 @@ void TabTreeView::reverseTraverse(const QModelIndex &root, std::function<void(co
|
|||
}
|
||||
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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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<void(const QModelIndex&)> callback) const;
|
||||
|
||||
void closeTree(const QModelIndex &root);
|
||||
void unloadTree(const QModelIndex &root);
|
||||
|
||||
BrowserWindow *m_window;
|
||||
TabTreeDelegate *m_delegate;
|
||||
DelegateButton m_pressedButton = NoButton;
|
||||
|
|
Loading…
Reference in New Issue
Block a user