Commit 3e4551da authored by Christoph Cullmann's avatar Christoph Cullmann 🐮
Browse files

sort per directory level, this is MUCH faster

parent 73b34c0d
......@@ -81,6 +81,19 @@ QVariant KateProjectItem::data(int role) const
return QStandardItem::data(role);
}
bool KateProjectItem::operator<(const QStandardItem &other) const
{
// let directories stay first
const bool isDirectory = data(Qt::ToolTipRole).isNull();
const bool otherIsDirectory = other.data(Qt::ToolTipRole).isNull();
if (isDirectory != otherIsDirectory) {
return isDirectory > otherIsDirectory;
}
// case-insensitive compare of the filename
return data(Qt::DisplayRole).toString().compare(other.data(Qt::DisplayRole).toString(), Qt::CaseInsensitive) < 0;
}
QIcon *KateProjectItem::icon() const
{
if (m_icon) {
......
......@@ -48,6 +48,13 @@ public:
*/
QVariant data(int role = Qt::UserRole + 1) const override;
/**
* We want case-insensitive sorting and directories first!
* @param other other element to compare with
* @return is this element less than?
*/
bool operator<(const QStandardItem &other) const override;
public:
void slotModifiedChanged(KTextEditor::Document *);
void slotModifiedOnDisk(KTextEditor::Document *document, bool isModified, KTextEditor::ModificationInterface::ModifiedOnDiskReason reason);
......
......@@ -167,12 +167,13 @@ void KateProjectWorker::loadFilesEntry(QStandardItem *parent, const QVariantMap
}),
files.end());
/**
* we might end up with nothing to add at all
*/
if (files.isEmpty()) {
return;
}
files.sort(Qt::CaseInsensitive);
/**
* construct paths first in tree and items in a map
*/
......@@ -213,6 +214,12 @@ void KateProjectWorker::loadFilesEntry(QStandardItem *parent, const QVariantMap
for (const auto &item : qAsConst(item2ParentPath)) {
item.second->appendRow(item.first);
}
/**
* sort the stuff once recursively, this is a LOT faster than once sorting the list
* as we have normally not all stuff in on level of directory
*/
parent->sortChildren(0);
}
QStringList KateProjectWorker::findFiles(const QDir &dir, const QVariantMap &filesEntry)
......
Markdown is supported
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