forked from qt-creator/qt-creator
QmlProject file format: Let filters recurse by default
E.g. "QmlFiles {}" now also monitors subdirectories by default, while
"QmlFiles { paths : ["bla.qml"] } does not.
Task-number: BAUHAUS-503
This commit is contained in:
@@ -6,7 +6,7 @@ namespace QmlProjectManager {
|
|||||||
|
|
||||||
FileFilterBaseItem::FileFilterBaseItem(QObject *parent) :
|
FileFilterBaseItem::FileFilterBaseItem(QObject *parent) :
|
||||||
QmlProjectContentItem(parent),
|
QmlProjectContentItem(parent),
|
||||||
m_recursive(false)
|
m_recurse(RecurseDefault)
|
||||||
{
|
{
|
||||||
connect(&m_fsWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(updateFileList()));
|
connect(&m_fsWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(updateFileList()));
|
||||||
connect(&m_fsWatcher, SIGNAL(fileChanged(QString)), this, SLOT(updateFileList()));
|
connect(&m_fsWatcher, SIGNAL(fileChanged(QString)), this, SLOT(updateFileList()));
|
||||||
@@ -58,14 +58,32 @@ void FileFilterBaseItem::setFilter(const QString &filter)
|
|||||||
|
|
||||||
bool FileFilterBaseItem::recursive() const
|
bool FileFilterBaseItem::recursive() const
|
||||||
{
|
{
|
||||||
return m_recursive;
|
bool recursive;
|
||||||
|
if (m_recurse == Recurse) {
|
||||||
|
recursive = true;
|
||||||
|
} else if (m_recurse == DoNotRecurse) {
|
||||||
|
recursive = false;
|
||||||
|
} else { // RecurseDefault
|
||||||
|
if (m_explicitFiles.isEmpty()) {
|
||||||
|
recursive = true;
|
||||||
|
} else {
|
||||||
|
recursive = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return recursive;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileFilterBaseItem::setRecursive(bool recursive)
|
void FileFilterBaseItem::setRecursive(bool recurse)
|
||||||
{
|
{
|
||||||
if (recursive == m_recursive)
|
bool oldRecursive = recursive();
|
||||||
return;
|
|
||||||
m_recursive = recursive;
|
if (recurse) {
|
||||||
|
m_recurse = Recurse;
|
||||||
|
} else {
|
||||||
|
m_recurse = DoNotRecurse;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (recurse != oldRecursive)
|
||||||
updateFileList();
|
updateFileList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,7 +212,7 @@ QSet<QString> FileFilterBaseItem::filesInSubTree(const QDir &rootDir, const QDir
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_recursive) {
|
if (recursive()) {
|
||||||
foreach (const QFileInfo &subDir, dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot)) {
|
foreach (const QFileInfo &subDir, dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot)) {
|
||||||
fileSet += filesInSubTree(rootDir, QDir(subDir.absoluteFilePath()), parsedDirs);
|
fileSet += filesInSubTree(rootDir, QDir(subDir.absoluteFilePath()), parsedDirs);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,15 @@ private:
|
|||||||
|
|
||||||
QString m_filter;
|
QString m_filter;
|
||||||
QList<QRegExp> m_regExpList;
|
QList<QRegExp> m_regExpList;
|
||||||
bool m_recursive;
|
|
||||||
|
enum RecursiveOption {
|
||||||
|
Recurse,
|
||||||
|
DoNotRecurse,
|
||||||
|
RecurseDefault // not set explicitly
|
||||||
|
};
|
||||||
|
|
||||||
|
RecursiveOption m_recurse;
|
||||||
|
|
||||||
QStringList m_explicitFiles;
|
QStringList m_explicitFiles;
|
||||||
|
|
||||||
QFileSystemWatcher m_fsWatcher;
|
QFileSystemWatcher m_fsWatcher;
|
||||||
|
|||||||
@@ -127,13 +127,13 @@ Core::GeneratedFiles QmlProjectApplicationWizard::generateFiles(const QWizard *w
|
|||||||
|
|
||||||
out
|
out
|
||||||
//: Comment added to generated .qmlproject file
|
//: Comment added to generated .qmlproject file
|
||||||
<< "// " << tr("File generated by QtCreator", "qmlproject Template") << endl
|
<< "/* " << tr("File generated by QtCreator", "qmlproject Template") << " */" << endl
|
||||||
<< endl
|
<< endl
|
||||||
<< "import QmlProject 1.0" << endl
|
<< "import QmlProject 1.0" << endl
|
||||||
<< endl
|
<< endl
|
||||||
<< "Project {" << endl
|
<< "Project {" << endl
|
||||||
//: Comment added to generated .qmlproject file
|
//: Comment added to generated .qmlproject file
|
||||||
<< " // " << tr("Scan current directory for .qml, .js, and image files", "qmlproject Template") << endl
|
<< " /* " << tr("Include .qml, .js, and image files from current directory and subdirectories", "qmlproject Template") << " */" << endl
|
||||||
<< " QmlFiles {" << endl
|
<< " QmlFiles {" << endl
|
||||||
<< " directory: \".\"" << endl
|
<< " directory: \".\"" << endl
|
||||||
<< " }" << endl
|
<< " }" << endl
|
||||||
@@ -144,13 +144,11 @@ Core::GeneratedFiles QmlProjectApplicationWizard::generateFiles(const QWizard *w
|
|||||||
<< " directory: \".\"" << endl
|
<< " directory: \".\"" << endl
|
||||||
<< " }" << endl
|
<< " }" << endl
|
||||||
//: Comment added to generated .qmlproject file
|
//: Comment added to generated .qmlproject file
|
||||||
<< " // List of plugin directories passed to QML runtime" << endl
|
<< " /* " << tr("List of plugin directories passed to QML runtime", "qmlproject Template") << " */" << endl
|
||||||
//: Comment added to generated .qmlproject file
|
|
||||||
<< " // importPaths: [ \" ../exampleplugin \" ]" << endl
|
<< " // importPaths: [ \" ../exampleplugin \" ]" << endl
|
||||||
<< "}" << endl;
|
<< "}" << endl;
|
||||||
}
|
}
|
||||||
Core::GeneratedFile generatedCreatorFile(creatorFileName);
|
Core::GeneratedFile generatedCreatorFile(creatorFileName);
|
||||||
|
|
||||||
generatedCreatorFile.setContents(projectContents);
|
generatedCreatorFile.setContents(projectContents);
|
||||||
|
|
||||||
Core::GeneratedFiles files;
|
Core::GeneratedFiles files;
|
||||||
|
|||||||
@@ -142,24 +142,25 @@ Core::GeneratedFiles QmlProjectImportWizard::generateFiles(const QWizard *w,
|
|||||||
|
|
||||||
out
|
out
|
||||||
//: Comment added to generated .qmlproject file
|
//: Comment added to generated .qmlproject file
|
||||||
<< "// " << tr("File generated by QtCreator", "qmlproject Template") << endl
|
<< "/* " << tr("File generated by QtCreator", "qmlproject Template") << " */" << endl
|
||||||
<< endl
|
<< endl
|
||||||
<< "import QmlProject 1.0" << endl
|
<< "import QmlProject 1.0" << endl
|
||||||
<< endl
|
<< endl
|
||||||
<< "Project {" << endl
|
<< "Project {" << endl
|
||||||
<< " // " << tr("Scan current directory and subdirectories for .qml, .js, and image files", "qmlproject Template") << endl
|
//: Comment added to generated .qmlproject file
|
||||||
|
<< " /* " << tr("Include .qml, .js, and image files from current directory and subdirectories", "qmlproject Template") << " */" << endl
|
||||||
<< " QmlFiles {" << endl
|
<< " QmlFiles {" << endl
|
||||||
<< " directory: \".\"" << endl
|
<< " directory: \".\"" << endl
|
||||||
<< " recursive: true" << endl
|
|
||||||
<< " }" << endl
|
<< " }" << endl
|
||||||
<< " JavaScriptFiles {" << endl
|
<< " JavaScriptFiles {" << endl
|
||||||
<< " directory: \".\"" << endl
|
<< " directory: \".\"" << endl
|
||||||
<< " recursive: true" << endl
|
|
||||||
<< " }" << endl
|
<< " }" << endl
|
||||||
<< " ImageFiles {" << endl
|
<< " ImageFiles {" << endl
|
||||||
<< " directory: \".\"" << endl
|
<< " directory: \".\"" << endl
|
||||||
<< " recursive: true" << endl
|
|
||||||
<< " }" << endl
|
<< " }" << endl
|
||||||
|
//: Comment added to generated .qmlproject file
|
||||||
|
<< " /* " << tr("List of plugin directories passed to QML runtime", "qmlproject Template") << " */" << endl
|
||||||
|
<< " // importPaths: [ \" ../exampleplugin \" ]" << endl
|
||||||
<< "}" << endl;
|
<< "}" << endl;
|
||||||
}
|
}
|
||||||
Core::GeneratedFile generatedCreatorFile(creatorFileName);
|
Core::GeneratedFile generatedCreatorFile(creatorFileName);
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ QString testDataDir = QLatin1String(SRCDIR "/data");
|
|||||||
void TestProject::testFileFilter()
|
void TestProject::testFileFilter()
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// search for qml files in local directory
|
// Search for qml files in directory + subdirectories
|
||||||
//
|
//
|
||||||
QString projectFile = QLatin1String(
|
QString projectFile = QLatin1String(
|
||||||
"import QmlProject 1.0\n"
|
"import QmlProject 1.0\n"
|
||||||
@@ -53,18 +53,19 @@ void TestProject::testFileFilter()
|
|||||||
project->setSourceDirectory(testDataDir);
|
project->setSourceDirectory(testDataDir);
|
||||||
|
|
||||||
QStringList expectedFiles(QStringList() << testDataDir + "/file1.qml"
|
QStringList expectedFiles(QStringList() << testDataDir + "/file1.qml"
|
||||||
<< testDataDir + "/file2.qml");
|
<< testDataDir + "/file2.qml"
|
||||||
|
<< testDataDir + "/subdir/file3.qml");
|
||||||
QCOMPARE(project->files().toSet(), expectedFiles.toSet());
|
QCOMPARE(project->files().toSet(), expectedFiles.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// search for all qml files in all subdirectories
|
// search for all qml files in directory
|
||||||
//
|
//
|
||||||
projectFile = QLatin1String(
|
projectFile = QLatin1String(
|
||||||
"import QmlProject 1.0\n"
|
"import QmlProject 1.0\n"
|
||||||
"Project {\n"
|
"Project {\n"
|
||||||
" QmlFiles {\n"
|
" QmlFiles {\n"
|
||||||
" recursive: true\n"
|
" recursive: false\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
|
|
||||||
@@ -82,8 +83,7 @@ void TestProject::testFileFilter()
|
|||||||
project->setSourceDirectory(testDataDir);
|
project->setSourceDirectory(testDataDir);
|
||||||
|
|
||||||
QStringList expectedFiles(QStringList() << testDataDir + "/file1.qml"
|
QStringList expectedFiles(QStringList() << testDataDir + "/file1.qml"
|
||||||
<< testDataDir + "/file2.qml"
|
<< testDataDir + "/file2.qml");
|
||||||
<< testDataDir + "/subdir/file3.qml");
|
|
||||||
QCOMPARE(project->files().toSet(), expectedFiles.toSet());
|
QCOMPARE(project->files().toSet(), expectedFiles.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,6 +121,7 @@ void TestProject::testFileFilter()
|
|||||||
"Project {\n"
|
"Project {\n"
|
||||||
" QmlFiles {\n"
|
" QmlFiles {\n"
|
||||||
" directory: \".\"\n"
|
" directory: \".\"\n"
|
||||||
|
" recursive: false\n"
|
||||||
" }"
|
" }"
|
||||||
" QmlFiles {\n"
|
" QmlFiles {\n"
|
||||||
" directory: \"subdir\"\n"
|
" directory: \"subdir\"\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user