Commit ef66bc98 authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

Fixed QTCREATORBUG-1397.

When adding a new file, refreshing semantic errors in the open editor should
have worked. It now also works for removing existing files.

Done-with: Christian Kamm
parent 62141475
......@@ -254,9 +254,7 @@ void Snapshot::insert(const Document::Ptr &document)
const QString fileName = document->fileName();
const QString path = document->path();
Document::Ptr old = _documents.value(fileName);
if (old)
_documentsByPath.remove(path, old);
remove(fileName);
_documentsByPath.insert(path, document);
_documents.insert(fileName, document);
}
......@@ -267,6 +265,15 @@ void Snapshot::insertLibraryInfo(const QString &path, const LibraryInfo &info)
_libraries.insert(QDir::cleanPath(path), info);
}
void Snapshot::remove(const QString &fileName)
{
Document::Ptr doc = _documents.value(fileName);
if (!doc.isNull()) {
_documentsByPath.remove(doc->path(), doc);
_documents.remove(fileName);
}
}
Document::Ptr Snapshot::documentFromSource(const QString &code,
const QString &fileName) const
{
......
......@@ -148,6 +148,7 @@ public:
void insert(const Document::Ptr &document);
void insertLibraryInfo(const QString &path, const LibraryInfo &info);
void remove(const QString &fileName);
Document::Ptr document(const QString &fileName) const;
QList<Document::Ptr> documentsInDirectory(const QString &path) const;
......
......@@ -164,6 +164,16 @@ void ModelManager::fileChangedOnDisk(const QString &path)
this, true);
}
void ModelManager::removeFiles(const QStringList &files)
{
emit aboutToRemoveFiles(files);
QMutexLocker locker(&m_mutex);
foreach (const QString &file, files)
_snapshot.remove(file);
}
void ModelManager::emitDocumentChangedOnDisk(Document::Ptr doc)
{ emit documentChangedOnDisk(doc); }
......
......@@ -57,6 +57,7 @@ public:
virtual void updateSourceFiles(const QStringList &files,
bool emitDocumentOnDiskChanged);
virtual void fileChangedOnDisk(const QString &path);
virtual void removeFiles(const QStringList &files);
void emitDocumentUpdated(QmlJS::Document::Ptr doc);
void emitLibraryInfoUpdated(const QString &path, const QmlJS::LibraryInfo &info);
......@@ -69,7 +70,6 @@ Q_SIGNALS:
void projectPathChanged(const QString &projectPath);
void libraryInfoUpdated(const QString &path, const QmlJS::LibraryInfo &info);
private Q_SLOTS:
// this should be executed in the GUI thread.
void onDocumentUpdated(QmlJS::Document::Ptr doc);
......
......@@ -56,6 +56,7 @@ public:
virtual void updateSourceFiles(const QStringList &files,
bool emitDocumentOnDiskChanged) = 0;
virtual void fileChangedOnDisk(const QString &path) = 0;
virtual void removeFiles(const QStringList &files) = 0;
virtual void setProjectImportPaths(const QStringList &importPaths) = 0;
virtual QStringList importPaths() const = 0;
......
......@@ -169,8 +169,15 @@ void FileFilterBaseItem::updateFileList()
newFiles += filesInSubTree(QDir(m_defaultDir), QDir(projectDir), &dirsToBeWatched);
if (newFiles != m_files) {
QSet<QString> addedFiles = newFiles;
QSet<QString> removedFiles = m_files;
QSet<QString> unchanged = newFiles;
unchanged.intersect(m_files);
addedFiles.subtract(unchanged);
removedFiles.subtract(unchanged);
m_files = newFiles;
emit filesChanged();
emit filesChanged(addedFiles, removedFiles);
}
// update watched directories
......
......@@ -45,7 +45,7 @@ signals:
void directoryChanged();
void recursiveChanged();
void pathsChanged();
void filesChanged();
void filesChanged(const QSet<QString> &added, const QSet<QString> &removed);
void filterChanged();
private slots:
......
......@@ -72,7 +72,8 @@ void QmlProjectItem::setSourceDirectory(const QString &directoryPath)
FileFilterBaseItem *fileFilter = qobject_cast<FileFilterBaseItem*>(contentElement);
if (fileFilter) {
fileFilter->setDefaultDirectory(directoryPath);
connect(fileFilter, SIGNAL(filesChanged()), this, SIGNAL(qmlFilesChanged()));
connect(fileFilter, SIGNAL(filesChanged(QSet<QString>, QSet<QString>)),
this, SIGNAL(qmlFilesChanged(QSet<QString>, QSet<QString>)));
}
}
......
......@@ -44,7 +44,7 @@ public:
bool matchesFile(const QString &filePath) const;
signals:
void qmlFilesChanged();
void qmlFilesChanged(const QSet<QString> &, const QSet<QString> &);
void sourceDirectoryChanged();
void importPathsChanged();
......
......@@ -94,7 +94,8 @@ void QmlProject::parseProject(RefreshOptions options)
if (component->isReady()
&& qobject_cast<QmlProjectItem*>(component->create())) {
m_projectItem = qobject_cast<QmlProjectItem*>(component->create());
connect(m_projectItem.data(), SIGNAL(qmlFilesChanged()), this, SLOT(refreshFiles()));
connect(m_projectItem.data(), SIGNAL(qmlFilesChanged(QSet<QString>, QSet<QString>)),
this, SLOT(refreshFiles(QSet<QString>, QSet<QString>)));
connect(m_projectItem.data(), SIGNAL(importPathsChanged()), this, SLOT(refreshImportPaths()));
refreshImportPaths();
} else {
......@@ -121,20 +122,10 @@ void QmlProject::parseProject(RefreshOptions options)
void QmlProject::refresh(RefreshOptions options)
{
const QSet<QString> oldFiles = m_files.toSet();
parseProject(options);
if (options & Files)
m_rootNode->refresh();
const QSet<QString> newFiles = m_files.toSet();
QStringList removedPaths;
foreach (const QString &oldFile, oldFiles)
if (!newFiles.contains(oldFile))
removedPaths.append(oldFile);
if (!removedPaths.isEmpty())
emit filesRemovedFromProject(removedPaths);
}
QStringList QmlProject::convertToAbsoluteFiles(const QStringList &paths) const
......@@ -188,9 +179,11 @@ void QmlProject::refreshProjectFile()
refresh(QmlProject::ProjectFile | Files);
}
void QmlProject::refreshFiles()
void QmlProject::refreshFiles(const QSet<QString> &/*added*/, const QSet<QString> &removed)
{
refresh(Files);
if (!removed.isEmpty())
m_modelManager->removeFiles(removed.toList());
}
void QmlProject::refreshImportPaths()
......
......@@ -101,12 +101,9 @@ public:
bool addFiles(const QStringList &filePaths);
signals:
void filesRemovedFromProject(const QStringList removedPaths);
private slots:
void refreshProjectFile();
void refreshFiles();
void refreshFiles(const QSet<QString> &added, const QSet<QString> &removed);
void refreshImportPaths();
protected:
......
......@@ -79,14 +79,8 @@ ProjectExplorer::Project *Manager::openProject(const QString &fileName)
}
}
if (fileInfo.isFile()) {
QmlProject *project = new QmlProject(this, fileName);
QmlTaskManager *taskManager = QmlTaskManager::instance();
if (taskManager)
connect(project, SIGNAL(filesRemovedFromProject(QStringList)),
taskManager, SLOT(documentsRemoved(const QStringList)));
return project;
}
if (fileInfo.isFile())
return new QmlProject(this, fileName);
return 0;
}
......
......@@ -103,6 +103,8 @@ void QmlProjectPlugin::extensionsInitialized()
Q_ASSERT(modelManager);
connect(modelManager, SIGNAL(documentChangedOnDisk(QmlJS::Document::Ptr)),
m_qmlTaskManager, SLOT(documentChangedOnDisk(QmlJS::Document::Ptr)));
connect(modelManager, SIGNAL(aboutToRemoveFiles(QStringList)),
m_qmlTaskManager, SLOT(documentsRemoved(QStringList)));
}
} // namespace Internal
......
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