Commit 84f1466b authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Use FileChangeBlocker



Use FileChangeBlocker over expecting/unexpecting file changes manually.

Change-Id: I8428841f966d81be477260416c75e91dee795425
Reviewed-by: Eike Ziller's avatarEike Ziller <eike.ziller@qt.io>
parent 2ec82a2a
......@@ -158,7 +158,7 @@ bool GenericProject::saveRawFileList(const QStringList &rawFileList)
bool GenericProject::saveRawList(const QStringList &rawList, const QString &fileName)
{
DocumentManager::expectFileChange(fileName);
FileChangeBlocker changeGuard(fileName);
// Make sure we can open the file for writing
Utils::FileSaver saver(fileName, QIODevice::Text);
if (!saver.hasError()) {
......@@ -168,7 +168,6 @@ bool GenericProject::saveRawList(const QStringList &rawList, const QString &file
saver.setResult(&stream);
}
bool result = saver.finalize(ICore::mainWindow());
DocumentManager::unexpectFileChange(fileName);
return result;
}
......
......@@ -3194,9 +3194,8 @@ void ProjectExplorerPluginPrivate::removeFile()
return;
}
DocumentManager::expectFileChange(filePath);
FileChangeBlocker changeGuard(filePath);
FileUtils::removeFile(filePath, deleteFile);
DocumentManager::unexpectFileChange(filePath);
}
}
......@@ -3253,7 +3252,7 @@ void ProjectExplorerPluginPrivate::deleteFile()
folderNode->deleteFiles(QStringList(filePath));
DocumentManager::expectFileChange(filePath);
FileChangeBlocker changeGuard(filePath);
if (IVersionControl *vc =
VcsManager::findVersionControlForDirectory(QFileInfo(filePath).absolutePath())) {
vc->vcsDelete(filePath);
......@@ -3265,7 +3264,6 @@ void ProjectExplorerPluginPrivate::deleteFile()
tr("Could not delete file %1.")
.arg(QDir::toNativeSeparators(filePath)));
}
DocumentManager::unexpectFileChange(filePath);
}
void ProjectExplorerPluginPrivate::handleRenameFile()
......
......@@ -649,7 +649,7 @@ bool PythonProject::saveRawFileList(const QStringList &rawFileList)
bool PythonProject::saveRawList(const QStringList &rawList, const QString &fileName)
{
DocumentManager::expectFileChange(fileName);
FileChangeBlocker changeGuarg(fileName);
// Make sure we can open the file for writing
FileSaver saver(fileName, QIODevice::Text);
if (!saver.hasError()) {
......@@ -659,7 +659,6 @@ bool PythonProject::saveRawList(const QStringList &rawList, const QString &fileN
saver.setResult(&stream);
}
bool result = saver.finalize(ICore::mainWindow());
DocumentManager::unexpectFileChange(fileName);
return result;
}
......
......@@ -1335,13 +1335,15 @@ bool QmakePriFileNode::setProVariable(const QString &var, const QStringList &val
void QmakePriFileNode::save(const QStringList &lines)
{
Core::DocumentManager::expectFileChange(m_projectFilePath.toString());
FileSaver saver(m_projectFilePath.toString(), QIODevice::Text);
saver.write(lines.join(QLatin1Char('\n')).toLocal8Bit());
saver.finalize(Core::ICore::mainWindow());
{
FileChangeBlocker changeGuard(m_projectFilePath.toString());
FileSaver saver(m_projectFilePath.toString(), QIODevice::Text);
saver.write(lines.join(QLatin1Char('\n')).toLocal8Bit());
saver.finalize(Core::ICore::mainWindow());
m_project->projectManager()->notifyChanged(m_projectFilePath);
}
m_project->projectManager()->notifyChanged(m_projectFilePath);
Core::DocumentManager::unexpectFileChange(m_projectFilePath.toString());
// This is a hack.
// We are saving twice in a very short timeframe, once the editor and once the ProFile.
// So the modification time might not change between those two saves.
......
......@@ -85,9 +85,8 @@ static bool addFilesToResource(const Utils::FileName &resourceFile,
}
}
Core::DocumentManager::expectFileChange(resourceFile.toString());
Core::FileChangeBlocker changeGuard(resourceFile.toString());
file.save();
Core::DocumentManager::unexpectFileChange(resourceFile.toString());
return true;
}
......@@ -282,9 +281,8 @@ bool ResourceTopLevelNode::addPrefix(const QString &prefix, const QString &lang)
int index = file.addPrefix(prefix, lang);
if (index == -1)
return false;
Core::DocumentManager::expectFileChange(filePath().toString());
Core::FileChangeBlocker changeGuard(filePath().toString());
file.save();
Core::DocumentManager::unexpectFileChange(filePath().toString());
return true;
}
......@@ -298,9 +296,8 @@ bool ResourceTopLevelNode::removePrefix(const QString &prefix, const QString &la
if (file.prefix(i) == prefix
&& file.lang(i) == lang) {
file.removePrefix(i);
Core::DocumentManager::expectFileChange(filePath().toString());
Core::FileChangeBlocker changeGuard(filePath().toString());
file.save();
Core::DocumentManager::unexpectFileChange(filePath().toString());
return true;
}
}
......@@ -324,9 +321,8 @@ bool ResourceTopLevelNode::removeNonExistingFiles()
}
}
Core::DocumentManager::expectFileChange(filePath().toString());
Core::FileChangeBlocker changeGuard(filePath().toString());
file.save();
Core::DocumentManager::unexpectFileChange(filePath().toString());
return true;
}
......@@ -421,9 +417,8 @@ bool ResourceFolderNode::removeFiles(const QStringList &filePaths, QStringList *
file.removeFile(index, j);
--j;
}
Core::DocumentManager::expectFileChange(m_topLevelNode->filePath().toString());
Core::FileChangeBlocker changeGuard(m_topLevelNode->filePath().toString());
file.save();
Core::DocumentManager::unexpectFileChange(m_topLevelNode->filePath().toString());
return true;
}
......@@ -461,9 +456,8 @@ bool ResourceFolderNode::renameFile(const QString &filePath, const QString &newF
for (int j = 0; j < file.fileCount(index); ++j) {
if (file.file(index, j) == filePath) {
file.replaceFile(index, j, newFilePath);
Core::DocumentManager::expectFileChange(m_topLevelNode->filePath().toString());
Core::FileChangeBlocker changeGuard(m_topLevelNode->filePath().toString());
file.save();
Core::DocumentManager::unexpectFileChange(m_topLevelNode->filePath().toString());
return true;
}
}
......@@ -483,9 +477,8 @@ bool ResourceFolderNode::renamePrefix(const QString &prefix, const QString &lang
if (!file.replacePrefixAndLang(index, prefix, lang))
return false;
Core::DocumentManager::expectFileChange(m_topLevelNode->filePath().toString());
Core::FileChangeBlocker changeGuard(m_topLevelNode->filePath().toString());
file.save();
Core::DocumentManager::unexpectFileChange(m_topLevelNode->filePath().toString());
return true;
}
......@@ -675,9 +668,8 @@ bool SimpleResourceFolderNode::removeFiles(const QStringList &filePaths, QString
file.removeFile(index, j);
--j;
}
Core::DocumentManager::expectFileChange(m_topLevelNode->filePath().toString());
Core::FileChangeBlocker changeGuard(m_topLevelNode->filePath().toString());
file.save();
Core::DocumentManager::unexpectFileChange(m_topLevelNode->filePath().toString());
return true;
}
......@@ -694,9 +686,8 @@ bool SimpleResourceFolderNode::renameFile(const QString &filePath, const QString
for (int j = 0; j < file.fileCount(index); ++j) {
if (file.file(index, j) == filePath) {
file.replaceFile(index, j, newFilePath);
Core::DocumentManager::expectFileChange(m_topLevelNode->filePath().toString());
Core::FileChangeBlocker changeGuard(m_topLevelNode->filePath().toString());
file.save();
Core::DocumentManager::unexpectFileChange(m_topLevelNode->filePath().toString());
return true;
}
}
......
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