diff --git a/src/plugins/projectexplorer/projectmodels.cpp b/src/plugins/projectexplorer/projectmodels.cpp index 9a47d1d0473..833643197de 100644 --- a/src/plugins/projectexplorer/projectmodels.cpp +++ b/src/plugins/projectexplorer/projectmodels.cpp @@ -471,12 +471,16 @@ void FlatModel::handleProjectAdded(Project *project) void FlatModel::updateVCStatusFor(const Utils::FilePath root, const QStringList &files) { std::for_each(std::begin(files), std::end(files), [root, this](const QString &file) { - const Node *node = ProjectTree::nodeForFile(root.pathAppended(file)); - + const FilePath filePath = root.pathAppended(file); + Node *node = ProjectTree::nodeForFile(filePath); if (!node) return; + FileNode *fileNode = node->asFileNode(); + if (!fileNode) + return; - const QModelIndex index = indexForNode(node); + fileNode->resetModificationState(); + const QModelIndex index = indexForNode(fileNode); emit dataChanged(index, index, {Qt::ForegroundRole}); }); } diff --git a/src/plugins/projectexplorer/projectnodes.cpp b/src/plugins/projectexplorer/projectnodes.cpp index 2ac4859eabb..42e1d604741 100644 --- a/src/plugins/projectexplorer/projectnodes.cpp +++ b/src/plugins/projectexplorer/projectnodes.cpp @@ -266,12 +266,14 @@ Core::IVersionControl::FileState FileNode::modificationState() const if (isGenerated()) return Core::IVersionControl::FileState::NoModification; - const FilePath file = filePath(); - const FilePath dir = file.absolutePath(); - if (Core::IVersionControl *vc = Core::VcsManager::findVersionControlForDirectory(dir)) - return vc->modificationState(file); - - return Core::IVersionControl::FileState::NoModification; + if (!m_modificationState) { + const FilePath dir = filePath().absolutePath(); + if (Core::IVersionControl *vc = Core::VcsManager::findVersionControlForDirectory(dir)) + m_modificationState = vc->modificationState(filePath()); + else + m_modificationState = Core::IVersionControl::FileState::NoModification; + } + return *m_modificationState; } bool FileNode::useUnavailableMarker() const @@ -284,6 +286,11 @@ void FileNode::setUseUnavailableMarker(bool useUnavailableMarker) m_useUnavailableMarker = useUnavailableMarker; } +void FileNode::resetModificationState() +{ + m_modificationState.reset(); +} + /*! Returns \c true if the file is automatically generated by a compile step. */ diff --git a/src/plugins/projectexplorer/projectnodes.h b/src/plugins/projectexplorer/projectnodes.h index 623dea202dc..1e2e0ff4d3f 100644 --- a/src/plugins/projectexplorer/projectnodes.h +++ b/src/plugins/projectexplorer/projectnodes.h @@ -204,6 +204,7 @@ public: void setHasError(const bool error) const; Core::IVersionControl::FileState modificationState() const; + void resetModificationState(); QIcon icon() const; void setIcon(const QIcon icon); @@ -213,6 +214,7 @@ public: private: FileType m_fileType; + mutable std::optional m_modificationState; mutable QIcon m_icon; mutable bool m_hasError = false; bool m_useUnavailableMarker = false;