Commit 6d56c513 authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

Allow closing all widgets at once

parent 9202a58b
......@@ -325,12 +325,22 @@ void KateFileTree::mouseClicked(const QModelIndex &index)
{
const bool closeButtonClicked = m_hasCloseButton && index.column() == 1;
if (m_proxyModel->isDir(index)) {
if (closeButtonClicked) {
const QList<KTextEditor::Document *> list = m_proxyModel->docTreeFromIndex(index);
closeDocs(list);
}
if (m_proxyModel->isDir(index) && closeButtonClicked) {
const QList<KTextEditor::Document *> list = m_proxyModel->docTreeFromIndex(index);
closeDocs(list);
return;
} else if (m_proxyModel->isWidgetDir(index) && closeButtonClicked) {
const auto idx = index.siblingAtColumn(0);
const auto count = m_proxyModel->rowCount(idx);
QWidgetList widgets;
widgets.reserve(count);
for (int i = 0; i < count; ++i) {
widgets << m_proxyModel->index(i, 0, idx).data(KateFileTreeModel::WidgetRole).value<QWidget *>();
}
for (const auto &w : widgets) {
closeWidget(w);
}
}
if (auto *doc = m_proxyModel->docFromIndex(index)) {
......
......@@ -836,18 +836,33 @@ bool KateFileTreeModel::hasChildren(const QModelIndex &parent) const
return item->childCount() > 0;
}
bool KateFileTreeModel::isDir(const QModelIndex &index)
ProxyItem *KateFileTreeModel::itemForIndex(const QModelIndex &index) const
{
if (!index.isValid()) {
return true;
return m_root;
}
const ProxyItem *item = static_cast<ProxyItem *>(index.internalPointer());
ProxyItem *item = static_cast<ProxyItem *>(index.internalPointer());
if (!item) {
return false;
return nullptr;
}
return item;
}
return item->flag(ProxyItem::Dir);
bool KateFileTreeModel::isDir(const QModelIndex &index) const
{
if (auto item = itemForIndex(index)) {
return item->flag(ProxyItem::Dir) && !item->flag(ProxyItem::Widget);
}
return false;
}
bool KateFileTreeModel::isWidgetDir(const QModelIndex &index) const
{
if (auto item = itemForIndex(index)) {
return item->flag(ProxyItem::Dir) && item->flag(ProxyItem::Widget);
}
return false;
}
bool KateFileTreeModel::listMode() const
......
......@@ -61,7 +61,8 @@ public:
QModelIndex widgetIndex(QWidget *) const;
static bool isDir(const QModelIndex &index);
bool isDir(const QModelIndex &index) const;
bool isWidgetDir(const QModelIndex &index) const;
bool listMode() const;
void setListMode(bool);
......@@ -113,6 +114,7 @@ private:
void initModel();
void clearModel();
void connectDocument(const KTextEditor::Document *);
ProxyItem *itemForIndex(const QModelIndex &index) const;
private:
ProxyItemDir *m_root;
......
......@@ -86,3 +86,8 @@ QModelIndex KateFileTreeProxyModel::widgetIndex(QWidget *w) const
{
return mapFromSource(static_cast<KateFileTreeModel *>(sourceModel())->widgetIndex(w));
}
bool KateFileTreeProxyModel::isWidgetDir(const QModelIndex &i) const
{
return static_cast<KateFileTreeModel *>(sourceModel())->isWidgetDir(mapToSource(i));
}
......@@ -25,6 +25,7 @@ public:
QModelIndex docIndex(const KTextEditor::Document *) const;
QModelIndex widgetIndex(QWidget *) const;
bool isDir(const QModelIndex &i) const;
bool isWidgetDir(const QModelIndex &i) const;
void setSourceModel(QAbstractItemModel *model) override;
KTextEditor::Document *docFromIndex(const QModelIndex &index);
QList<KTextEditor::Document *> docTreeFromIndex(const QModelIndex &index);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment