Commit cff4edd3 authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

project: Add ability to exclude folders

Sometimes we have folder around in the project that don't need to be
shown in the project tree. For git projects, you can just gitignore them
but for non-git folder based projects there is no way to do this.

With this commit, you can now specify a "exclude_folder_patterns" in the
.kateproject file like:

{
   "exclude_patterns": ["node_modules", "blah"]
}

and any file/folder that matches this pattern is ignored
parent b2d93536
......@@ -290,6 +290,13 @@ void KateProjectWorker::loadFilesEntry(QStandardItem *parent,
*/
QVector<QString> files = findFiles(dir, filesEntry);
QStringList excludeFolderPatterns = m_projectMap.value(QStringLiteral("exclude_patterns")).toStringList();
std::vector<QRegularExpression> excludeRegexps;
excludeRegexps.reserve(excludeFolderPatterns.size());
for (const auto &pattern : excludeFolderPatterns) {
excludeRegexps.push_back(QRegularExpression(pattern, QRegularExpression::DontCaptureOption));
}
/**
* sort out non-files
* even for git, that just reports non-directories, we need to filter out e.g. sym-links to directories
......@@ -302,7 +309,7 @@ void KateProjectWorker::loadFilesEntry(QStandardItem *parent,
preparedItems.reserve(files.size());
for (const auto &item : files)
preparedItems.emplace_back(item, QString(), nullptr);
QtConcurrent::blockingMap(preparedItems, [dirPath](std::tuple<QString, QString, KateProjectItem *> &item) {
QtConcurrent::blockingMap(preparedItems, [excludeFolderPatterns, dirPath, excludeRegexps](std::tuple<QString, QString, KateProjectItem *> &item) {
/**
* cheap file name computation
* we do this A LOT, QFileInfo is very expensive just for this operation
......@@ -310,6 +317,13 @@ void KateProjectWorker::loadFilesEntry(QStandardItem *parent,
*/
auto &[filePath, fullFilePath, projectItem] = item;
fullFilePath = dirPath + filePath;
for (const auto &excludePattern : excludeRegexps) {
if (excludePattern.match(fullFilePath).hasMatch()) {
return;
}
}
const int slashIndex = filePath.lastIndexOf(QLatin1Char('/'));
const QString fileName = (slashIndex < 0) ? filePath : filePath.mid(slashIndex + 1);
filePath = (slashIndex < 0) ? QString() : filePath.left(slashIndex);
......
......@@ -48,7 +48,7 @@ private:
* @param project variant map for this group
* @param file2Item mapping file => item, will be filled
*/
static void loadProject(QStandardItem *parent, const QVariantMap &project, QHash<QString, KateProjectItem *> *file2Item, const QString &baseDir);
void loadProject(QStandardItem *parent, const QVariantMap &project, QHash<QString, KateProjectItem *> *file2Item, const QString &baseDir);
/**
* Load one files entry in the current parent item.
......@@ -56,7 +56,7 @@ private:
* @param filesEntry one files entry specification to load
* @param file2Item mapping file => item, will be filled
*/
static void loadFilesEntry(QStandardItem *parent, const QVariantMap &filesEntry, QHash<QString, KateProjectItem *> *file2Item, const QString &baseDir);
void loadFilesEntry(QStandardItem *parent, const QVariantMap &filesEntry, QHash<QString, KateProjectItem *> *file2Item, const QString &baseDir);
static QVector<QString> findFiles(const QDir &dir, const QVariantMap &filesEntry);
......
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