forked from qt-creator/qt-creator
Don't show error message if file added to qmlproject is picked up
Check for the case that a new file to be added to a .qmlproject is also automatically covered e.g. by a wildcard filter. In this case we don't have to do anything.
This commit is contained in:
@@ -89,6 +89,47 @@ QStringList FileFilterBaseItem::files() const
|
|||||||
return m_files.toList();
|
return m_files.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Check whether filter matches a file path - regardless whether the file already exists or not.
|
||||||
|
|
||||||
|
@param filePath: absolute file path
|
||||||
|
*/
|
||||||
|
bool FileFilterBaseItem::matchesFile(const QString &filePath) const
|
||||||
|
{
|
||||||
|
foreach (const QString &explicitFile, m_explicitFiles) {
|
||||||
|
if (absolutePath(explicitFile) == filePath)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool regexMatches = false;
|
||||||
|
const QString &fileName = QFileInfo(filePath).fileName();
|
||||||
|
foreach (const QRegExp &exp, m_regExpList) {
|
||||||
|
if (exp.exactMatch(fileName)) {
|
||||||
|
regexMatches = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!regexMatches)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const QStringList watchedDirectories = m_fsWatcher.directories();
|
||||||
|
const QDir fileDir = QFileInfo(filePath).absoluteDir();
|
||||||
|
foreach (const QString &watchedDirectory, watchedDirectories) {
|
||||||
|
if (QDir(watchedDirectory) == fileDir)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString FileFilterBaseItem::absolutePath(const QString &path) const
|
||||||
|
{
|
||||||
|
if (QFileInfo(path).isAbsolute())
|
||||||
|
return path;
|
||||||
|
return QDir(absoluteDir()).absoluteFilePath(path);
|
||||||
|
}
|
||||||
|
|
||||||
QString FileFilterBaseItem::absoluteDir() const
|
QString FileFilterBaseItem::absoluteDir() const
|
||||||
{
|
{
|
||||||
QString absoluteDir;
|
QString absoluteDir;
|
||||||
@@ -110,11 +151,7 @@ void FileFilterBaseItem::updateFileList()
|
|||||||
QSet<QString> dirsToBeWatched;
|
QSet<QString> dirsToBeWatched;
|
||||||
QSet<QString> newFiles;
|
QSet<QString> newFiles;
|
||||||
foreach (const QString &explicitPath, m_explicitFiles) {
|
foreach (const QString &explicitPath, m_explicitFiles) {
|
||||||
if (QFileInfo(explicitPath).isAbsolute()) {
|
newFiles << absolutePath(explicitPath);
|
||||||
newFiles << explicitPath;
|
|
||||||
} else {
|
|
||||||
newFiles << QDir(projectDir).absoluteFilePath(explicitPath);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!m_regExpList.isEmpty() && m_explicitFiles.isEmpty())
|
if (!m_regExpList.isEmpty() && m_explicitFiles.isEmpty())
|
||||||
newFiles += filesInSubTree(QDir(m_defaultDir), QDir(projectDir), &dirsToBeWatched);
|
newFiles += filesInSubTree(QDir(m_defaultDir), QDir(projectDir), &dirsToBeWatched);
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ public:
|
|||||||
void setPathsProperty(const QString &path);
|
void setPathsProperty(const QString &path);
|
||||||
|
|
||||||
virtual QStringList files() const;
|
virtual QStringList files() const;
|
||||||
|
bool matchesFile(const QString &filePath) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void directoryChanged();
|
void directoryChanged();
|
||||||
@@ -50,6 +51,7 @@ private slots:
|
|||||||
void updateFileList();
|
void updateFileList();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QString absolutePath(const QString &path) const;
|
||||||
QString absoluteDir() const;
|
QString absoluteDir() const;
|
||||||
|
|
||||||
QSet<QString> filesInSubTree(const QDir &rootDir, const QDir &dir, QSet<QString> *parsedDirs = 0);
|
QSet<QString> filesInSubTree(const QDir &rootDir, const QDir &dir, QSet<QString> *parsedDirs = 0);
|
||||||
|
|||||||
@@ -115,6 +115,26 @@ QStringList QmlProjectItem::files() const
|
|||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Check whether the project would include a file path
|
||||||
|
- regardless whether the file already exists or not.
|
||||||
|
|
||||||
|
@param filePath: absolute file path to check
|
||||||
|
*/
|
||||||
|
bool QmlProjectItem::matchesFile(const QString &filePath) const
|
||||||
|
{
|
||||||
|
const Q_D(QmlProjectItem);
|
||||||
|
for (int i = 0; i < d->content.size(); ++i) {
|
||||||
|
QmlProjectContentItem *contentElement = d->content.at(i);
|
||||||
|
FileFilterBaseItem *fileFilter = qobject_cast<FileFilterBaseItem*>(contentElement);
|
||||||
|
if (fileFilter) {
|
||||||
|
if (fileFilter->matchesFile(filePath))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace QmlProjectManager
|
} // namespace QmlProjectManager
|
||||||
|
|
||||||
QML_DEFINE_NOCREATE_TYPE(QmlProjectManager::QmlProjectContentItem)
|
QML_DEFINE_NOCREATE_TYPE(QmlProjectManager::QmlProjectContentItem)
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ public:
|
|||||||
void setLibraryPaths(const QStringList &paths);
|
void setLibraryPaths(const QStringList &paths);
|
||||||
|
|
||||||
QStringList files() const;
|
QStringList files() const;
|
||||||
|
bool matchesFile(const QString &filePath) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void qmlFilesChanged();
|
void qmlFilesChanged();
|
||||||
|
|||||||
@@ -242,6 +242,16 @@ QStringList QmlProject::libraryPaths() const
|
|||||||
return libraryPaths;
|
return libraryPaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool QmlProject::addFiles(const QStringList &filePaths)
|
||||||
|
{
|
||||||
|
QStringList toAdd;
|
||||||
|
foreach (const QString &filePath, filePaths) {
|
||||||
|
if (!m_projectItem.data()->matchesFile(filePath))
|
||||||
|
toAdd << filePaths;
|
||||||
|
}
|
||||||
|
return toAdd.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
void QmlProject::refreshProjectFile()
|
void QmlProject::refreshProjectFile()
|
||||||
{
|
{
|
||||||
refresh(QmlProject::ProjectFile | Files);
|
refresh(QmlProject::ProjectFile | Files);
|
||||||
|
|||||||
@@ -99,6 +99,8 @@ public:
|
|||||||
QStringList files() const;
|
QStringList files() const;
|
||||||
QStringList libraryPaths() const;
|
QStringList libraryPaths() const;
|
||||||
|
|
||||||
|
bool addFiles(const QStringList &filePaths);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void refreshProjectFile();
|
void refreshProjectFile();
|
||||||
void refreshFiles();
|
void refreshFiles();
|
||||||
|
|||||||
@@ -183,9 +183,9 @@ bool QmlProjectNode::removeSubProjects(const QStringList &proFilePaths)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool QmlProjectNode::addFiles(const ProjectExplorer::FileType /*fileType*/,
|
bool QmlProjectNode::addFiles(const ProjectExplorer::FileType /*fileType*/,
|
||||||
const QStringList & /*filePaths*/, QStringList * /*notAdded*/)
|
const QStringList &filePaths, QStringList * /*notAdded*/)
|
||||||
{
|
{
|
||||||
return false;
|
return m_project->addFiles(filePaths);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QmlProjectNode::removeFiles(const ProjectExplorer::FileType /*fileType*/,
|
bool QmlProjectNode::removeFiles(const ProjectExplorer::FileType /*fileType*/,
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ public:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void testFileFilter();
|
void testFileFilter();
|
||||||
|
void testMatchesFile();
|
||||||
void testLibraryPaths();
|
void testLibraryPaths();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -205,6 +206,41 @@ void TestProject::testFileFilter()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestProject::testMatchesFile()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// search for qml files in local directory
|
||||||
|
//
|
||||||
|
QString projectFile = QLatin1String(
|
||||||
|
"import QmlProject 1.0\n"
|
||||||
|
"Project {\n"
|
||||||
|
" QmlFiles {"
|
||||||
|
" recursive: true"
|
||||||
|
" }"
|
||||||
|
" JavaScriptFiles {"
|
||||||
|
" paths: [\"script.js\"]"
|
||||||
|
" }"
|
||||||
|
"}\n");
|
||||||
|
|
||||||
|
QmlEngine engine;
|
||||||
|
QmlComponent component(&engine);
|
||||||
|
component.setData(projectFile.toUtf8(), QUrl());
|
||||||
|
if (!component.isReady())
|
||||||
|
qDebug() << component.errorsString();
|
||||||
|
QVERIFY(component.isReady());
|
||||||
|
|
||||||
|
QmlProjectItem *project = qobject_cast<QmlProjectItem*>(component.create());
|
||||||
|
QVERIFY(project);
|
||||||
|
|
||||||
|
project->setSourceDirectory(testDataDir);
|
||||||
|
|
||||||
|
QVERIFY(project->matchesFile(testDataDir + "/file1.qml"));
|
||||||
|
QVERIFY(project->matchesFile(testDataDir + "/notyetexistingfile.qml"));
|
||||||
|
QVERIFY(project->matchesFile(testDataDir + "/subdir/notyetexistingfile.qml"));
|
||||||
|
QVERIFY(project->matchesFile(testDataDir + "/script.js"));
|
||||||
|
QVERIFY(!project->matchesFile(testDataDir + "/script.css"));
|
||||||
|
}
|
||||||
|
|
||||||
void TestProject::testLibraryPaths()
|
void TestProject::testLibraryPaths()
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user