Commit ffd16c47 authored by Christoph Cullmann's avatar Christoph Cullmann

allow to collect all files from git ;)

parent 41882f19
......@@ -4,22 +4,37 @@
"groups": [
{
"name": "KTextEditor",
"files": [ { "directory": "ktexteditor", "filters": ["*.cpp", "*.h", "*.ui", "CMakeLists.txt", "Find*.cmake"] } ]
"files": [ { "directory": "ktexteditor", "git": 1 } ]
},
{
"name": "KatePart",
"files": [ { "directory": "part", "filters": ["*.cpp", "*.h", "*.ui", "CMakeLists.txt", "Find*.cmake"], "recursive": 1 } ]
"files": [ { "directory": "part", "git": 1 } ]
},
{
"name": "Kate",
"files": [ { "directory": "kate", "filters": ["*.cpp", "*.h", "*.ui", "CMakeLists.txt", "Find*.cmake"], "recursive": 1 } ]
"files": [ { "directory": "kate", "git": 1 } ]
},
{
"name": "KWrite",
"files": [ { "directory": "kwrite", "filters": ["*.cpp", "*.h", "*.ui", "CMakeLists.txt", "Find*.cmake"] } ]
"files": [ { "directory": "kwrite", "git": 1 } ]
},
{
"name": "Documentation",
"files": [ { "directory": "doc", "git": 1 } ]
},
{
"name": "Includes",
"files": [ { "directory": "includes", "git": 1 } ]
},
{
"name": "Test Suite",
"files": [ { "directory": "testdata", "git": 1 } ]
}
],
......
......@@ -24,6 +24,7 @@
#include <QDirIterator>
#include <QFile>
#include <QFileInfo>
#include <QProcess>
#include <KMimeType>
#include <KIconLoader>
......@@ -218,32 +219,66 @@ void KateProject::loadDirectory (QStandardItem *parent, const QVariantMap &direc
return;
/**
* default filter: only files!
* now: choose between different methodes to get files in the directory
*/
dir.setFilter (QDir::Files);
QStringList files;
/**
* set name filters, if any
* use GIT
*/
QStringList filters = directory["filters"].toStringList();
if (!filters.isEmpty())
dir.setNameFilters (filters);
if (directory["git"].toBool()) {
/**
* try to run git with ls-files for this directory
*/
QProcess git;
git.setWorkingDirectory (dir.absolutePath());
git.start("git", QStringList() << "ls-files" << ".");
if (!git.waitForStarted() || !git.waitForFinished())
return;
/**
* get output and split up into files
*/
QStringList relFiles = QString::fromLocal8Bit (git.readAllStandardOutput ()).split (QRegExp("[\n\r]"), QString::SkipEmptyParts);
/**
* prepend the directory path
*/
foreach (QString relFile, relFiles)
files.append (dir.absolutePath() + "/" + relFile);
}
/**
* construct flags for iterator
* fallback to use QDirIterator and search files ourself!
*/
QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags;
if (directory["recursive"].toBool())
flags = flags | QDirIterator::Subdirectories;
else {
/**
* default filter: only files!
*/
dir.setFilter (QDir::Files);
/**
* create iterator and collect all files
*/
QDirIterator dirIterator (dir, flags);
QStringList files;
while (dirIterator.hasNext()) {
dirIterator.next();
files.append (dirIterator.filePath());
/**
* set name filters, if any
*/
QStringList filters = directory["filters"].toStringList();
if (!filters.isEmpty())
dir.setNameFilters (filters);
/**
* construct flags for iterator
*/
QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags;
if (directory["recursive"].toBool())
flags = flags | QDirIterator::Subdirectories;
/**
* create iterator and collect all files
*/
QDirIterator dirIterator (dir, flags);
while (dirIterator.hasNext()) {
dirIterator.next();
files.append (dirIterator.filePath());
}
}
/**
......
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