diff --git a/src/plugins/qmlprojectmanager/fileformat/filefilteritems.cpp b/src/plugins/qmlprojectmanager/fileformat/filefilteritems.cpp index d2726f9872ddb84c18e0bf0b9ea0afdd5759c895..5a595cf2751f5324dbba834417589bb6da529079 100644 --- a/src/plugins/qmlprojectmanager/fileformat/filefilteritems.cpp +++ b/src/plugins/qmlprojectmanager/fileformat/filefilteritems.cpp @@ -6,7 +6,7 @@ namespace QmlProjectManager { FileFilterBaseItem::FileFilterBaseItem(QObject *parent) : QmlProjectContentItem(parent), - m_recursive(false) + m_recurse(RecurseDefault) { connect(&m_fsWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(updateFileList())); connect(&m_fsWatcher, SIGNAL(fileChanged(QString)), this, SLOT(updateFileList())); @@ -58,15 +58,33 @@ void FileFilterBaseItem::setFilter(const QString &filter) 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) - return; - m_recursive = recursive; - updateFileList(); + bool oldRecursive = recursive(); + + if (recurse) { + m_recurse = Recurse; + } else { + m_recurse = DoNotRecurse; + } + + if (recurse != oldRecursive) + updateFileList(); } QStringList FileFilterBaseItem::pathsProperty() const @@ -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)) { fileSet += filesInSubTree(rootDir, QDir(subDir.absoluteFilePath()), parsedDirs); } diff --git a/src/plugins/qmlprojectmanager/fileformat/filefilteritems.h b/src/plugins/qmlprojectmanager/fileformat/filefilteritems.h index ef85d58b8546999083e4dd74522f2634f3825aa6..dc27c3d563fb92142d45c9d619fba9539db30290 100644 --- a/src/plugins/qmlprojectmanager/fileformat/filefilteritems.h +++ b/src/plugins/qmlprojectmanager/fileformat/filefilteritems.h @@ -61,7 +61,15 @@ private: QString m_filter; QList<QRegExp> m_regExpList; - bool m_recursive; + + enum RecursiveOption { + Recurse, + DoNotRecurse, + RecurseDefault // not set explicitly + }; + + RecursiveOption m_recurse; + QStringList m_explicitFiles; QFileSystemWatcher m_fsWatcher; diff --git a/src/plugins/qmlprojectmanager/qmlprojectapplicationwizard.cpp b/src/plugins/qmlprojectmanager/qmlprojectapplicationwizard.cpp index 444ed4659ceb9a507cca970fa03775f9db7ca76f..8ba918c7fe7eb6c28b66807029a227bc65353de6 100644 --- a/src/plugins/qmlprojectmanager/qmlprojectapplicationwizard.cpp +++ b/src/plugins/qmlprojectmanager/qmlprojectapplicationwizard.cpp @@ -127,13 +127,13 @@ Core::GeneratedFiles QmlProjectApplicationWizard::generateFiles(const QWizard *w out //: Comment added to generated .qmlproject file - << "// " << tr("File generated by QtCreator", "qmlproject Template") << endl + << "/* " << tr("File generated by QtCreator", "qmlproject Template") << " */" << endl << endl << "import QmlProject 1.0" << endl << endl << "Project {" << endl //: 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 << " directory: \".\"" << endl << " }" << endl @@ -144,13 +144,11 @@ Core::GeneratedFiles QmlProjectApplicationWizard::generateFiles(const QWizard *w << " directory: \".\"" << endl << " }" << endl //: Comment added to generated .qmlproject file - << " // List of plugin directories passed to QML runtime" << endl - //: Comment added to generated .qmlproject file + << " /* " << tr("List of plugin directories passed to QML runtime", "qmlproject Template") << " */" << endl << " // importPaths: [ \" ../exampleplugin \" ]" << endl << "}" << endl; } Core::GeneratedFile generatedCreatorFile(creatorFileName); - generatedCreatorFile.setContents(projectContents); Core::GeneratedFiles files; diff --git a/src/plugins/qmlprojectmanager/qmlprojectimportwizard.cpp b/src/plugins/qmlprojectmanager/qmlprojectimportwizard.cpp index 01526cc4aef879827dfcd7043ea61035d28fb700..8b927dc744b66cac8a3f8f15f17aa3d11305a229 100644 --- a/src/plugins/qmlprojectmanager/qmlprojectimportwizard.cpp +++ b/src/plugins/qmlprojectmanager/qmlprojectimportwizard.cpp @@ -142,24 +142,25 @@ Core::GeneratedFiles QmlProjectImportWizard::generateFiles(const QWizard *w, out //: Comment added to generated .qmlproject file - << "// " << tr("File generated by QtCreator", "qmlproject Template") << endl + << "/* " << tr("File generated by QtCreator", "qmlproject Template") << " */" << endl << endl << "import QmlProject 1.0" << endl << 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 << " directory: \".\"" << endl - << " recursive: true" << endl << " }" << endl << " JavaScriptFiles {" << endl << " directory: \".\"" << endl - << " recursive: true" << endl << " }" << endl << " ImageFiles {" << endl << " directory: \".\"" << endl - << " recursive: true" << endl << " }" << endl + //: Comment added to generated .qmlproject file + << " /* " << tr("List of plugin directories passed to QML runtime", "qmlproject Template") << " */" << endl + << " // importPaths: [ \" ../exampleplugin \" ]" << endl << "}" << endl; } Core::GeneratedFile generatedCreatorFile(creatorFileName); diff --git a/tests/auto/qml/qmlprojectmanager/fileformat/tst_fileformat.cpp b/tests/auto/qml/qmlprojectmanager/fileformat/tst_fileformat.cpp index a5f7598b83068047ee16ed2b2660cda74c2cbf96..107bfc02c40f240613e2a6d26759f6a99a152ded 100644 --- a/tests/auto/qml/qmlprojectmanager/fileformat/tst_fileformat.cpp +++ b/tests/auto/qml/qmlprojectmanager/fileformat/tst_fileformat.cpp @@ -30,7 +30,7 @@ QString testDataDir = QLatin1String(SRCDIR "/data"); void TestProject::testFileFilter() { // - // search for qml files in local directory + // Search for qml files in directory + subdirectories // QString projectFile = QLatin1String( "import QmlProject 1.0\n" @@ -53,18 +53,19 @@ void TestProject::testFileFilter() project->setSourceDirectory(testDataDir); QStringList expectedFiles(QStringList() << testDataDir + "/file1.qml" - << testDataDir + "/file2.qml"); + << testDataDir + "/file2.qml" + << testDataDir + "/subdir/file3.qml"); QCOMPARE(project->files().toSet(), expectedFiles.toSet()); } // - // search for all qml files in all subdirectories + // search for all qml files in directory // projectFile = QLatin1String( "import QmlProject 1.0\n" "Project {\n" " QmlFiles {\n" - " recursive: true\n" + " recursive: false\n" " }\n" "}\n"); @@ -82,8 +83,7 @@ void TestProject::testFileFilter() project->setSourceDirectory(testDataDir); QStringList expectedFiles(QStringList() << testDataDir + "/file1.qml" - << testDataDir + "/file2.qml" - << testDataDir + "/subdir/file3.qml"); + << testDataDir + "/file2.qml"); QCOMPARE(project->files().toSet(), expectedFiles.toSet()); } @@ -121,6 +121,7 @@ void TestProject::testFileFilter() "Project {\n" " QmlFiles {\n" " directory: \".\"\n" + " recursive: false\n" " }" " QmlFiles {\n" " directory: \"subdir\"\n"