diff --git a/src/plugins/coreplugin/filemanager.cpp b/src/plugins/coreplugin/filemanager.cpp index c7ae13639ec8ff53789f30ec6f9bf3cc2a994319..e0525edbc8939e02355ea142bc9e180c845892d6 100644 --- a/src/plugins/coreplugin/filemanager.cpp +++ b/src/plugins/coreplugin/filemanager.cpp @@ -602,3 +602,33 @@ QList<IFile *> FileManager::managedFiles(const QString &fileName) const } return result; } + +FileChangeBlocker::FileChangeBlocker(const QString &fileName) + : m_reload(false) +{ + Core::FileManager *fm = Core::ICore::instance()->fileManager(); + m_files = fm->managedFiles(fileName); + foreach (Core::IFile *file, m_files) + fm->blockFileChange(file); +} + +FileChangeBlocker::~FileChangeBlocker() +{ + Core::IFile::ReloadBehavior tempBehavior = Core::IFile::ReloadAll; + Core::FileManager *fm = Core::ICore::instance()->fileManager(); + foreach (Core::IFile *file, m_files) { + if (m_reload) + file->modified(&tempBehavior); + fm->unblockFileChange(file); + } +} + +void FileChangeBlocker::setModifiedReload(bool b) +{ + m_reload = b; +} + +bool FileChangeBlocker::modifiedReload() const +{ + return m_reload; +} diff --git a/src/plugins/coreplugin/filemanager.h b/src/plugins/coreplugin/filemanager.h index e49541e19c4dade39bc014e3fb069d9b76222e41..558fac55b1e4e213de08d44af5fa2dc90414cefd 100644 --- a/src/plugins/coreplugin/filemanager.h +++ b/src/plugins/coreplugin/filemanager.h @@ -136,6 +136,25 @@ private: bool m_blockActivated; }; +/*! The FileChangeBlocker blocks all change notifications to all IFile * that + match the given filename. And unblocks in the destructor. + + To also reload the IFile in the destructor class set modifiedReload to true + + */ +class CORE_EXPORT FileChangeBlocker +{ +public: + FileChangeBlocker(const QString &fileName); + ~FileChangeBlocker(); + void setModifiedReload(bool reload); + bool modifiedReload() const; +private: + QList<IFile *> m_files; + bool m_reload; + Q_DISABLE_COPY(FileChangeBlocker); +}; + } // namespace Core #endif // FILEMANAGER_H diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp index b32f4e4653d0b53e24d5e7c976fa9f60d54cb0e8..74841b74b1b79d311973ab39a8dc74e7bc262f0c 100644 --- a/src/plugins/git/gitclient.cpp +++ b/src/plugins/git/gitclient.cpp @@ -42,6 +42,7 @@ #include <coreplugin/messagemanager.h> #include <coreplugin/progressmanager/progressmanager.h> #include <coreplugin/uniqueidmanager.h> +#include <coreplugin/filemanager.h> #include <texteditor/itexteditor.h> #include <utils/qtcassert.h> #include <vcsbase/vcsbaseeditor.h> diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp index 0c8729cd252692e40f06f06c1e8889ded30e83e6..595090085cb9613c94b7b392827e2d90c1ae6e11 100644 --- a/src/plugins/git/gitplugin.cpp +++ b/src/plugins/git/gitplugin.cpp @@ -553,7 +553,14 @@ void GitPlugin::undoFileChanges() QFileInfo fileInfo = currentFile(); QString fileName = fileInfo.fileName(); QString workingDirectory = fileInfo.absolutePath(); - m_gitClient->checkout(workingDirectory, fileName); + + Core::FileChangeBlocker fcb(fileInfo.filePath()); + fcb.setModifiedReload(true); + + QString errorMessage; + if (!m_gitClient->synchronousCheckout(workingDirectory, QStringList() << fileName, &errorMessage)) + m_outputWindow->append(errorMessage); + } void GitPlugin::undoProjectChanges() @@ -583,6 +590,9 @@ void GitPlugin::unstageFile() void GitPlugin::revertFile() { const QFileInfo fileInfo = currentFile(); + Core::FileChangeBlocker fcb(fileInfo.filePath()); + fcb.setModifiedReload(true); + m_gitClient->revert(QStringList(fileInfo.absoluteFilePath())); } diff --git a/src/plugins/perforce/perforceplugin.cpp b/src/plugins/perforce/perforceplugin.cpp index 789f56a60f51b04b948d17f19a850fff963ad450..92ac232b83295b907390a4c44354a9c32bd4d9d8 100644 --- a/src/plugins/perforce/perforceplugin.cpp +++ b/src/plugins/perforce/perforceplugin.cpp @@ -444,18 +444,9 @@ void PerforcePlugin::revertCurrentFile() return; } - Core::FileManager *fm = Core::ICore::instance()->fileManager(); - QList<Core::IFile *> files = fm->managedFiles(fileName); - foreach (Core::IFile *file, files) { - fm->blockFileChange(file); - } + Core::FileChangeBlocker fcb(fileName); + fcb.setModifiedReload(true); PerforceResponse result2 = runP4Cmd(QStringList() << QLatin1String("revert") << fileName, QStringList(), CommandToWindow|StdOutToWindow|StdErrToWindow|ErrorToWindow); - Core::IFile::ReloadBehavior tempBehavior = - Core::IFile::ReloadAll; - foreach (Core::IFile *file, files) { - file->modified(&tempBehavior); - fm->unblockFileChange(file); - } } void PerforcePlugin::diffCurrentFile() diff --git a/src/plugins/subversion/subversionplugin.cpp b/src/plugins/subversion/subversionplugin.cpp index 64488069912273d21d828fba8590a0d31909e87d..1c794e84a75cb9ea360e8f3e5f7099157d1f8de7 100644 --- a/src/plugins/subversion/subversionplugin.cpp +++ b/src/plugins/subversion/subversionplugin.cpp @@ -611,10 +611,8 @@ void SubversionPlugin::revertCurrentFile() QMessageBox::Yes, QMessageBox::No) == QMessageBox::No) return; - Core::FileManager *fm = Core::ICore::instance()->fileManager(); - QList<Core::IFile *> files = fm->managedFiles(file); - foreach (Core::IFile *file, files) - fm->blockFileChange(file); + + Core::FileChangeBlocker fcb(file); // revert args.clear(); @@ -622,16 +620,8 @@ void SubversionPlugin::revertCurrentFile() args.append(file); const SubversionResponse revertResponse = runSvn(args, subversionShortTimeOut, true); - if (revertResponse.error) { - foreach (Core::IFile *file, files) - fm->unblockFileChange(file); - return; - } - - Core::IFile::ReloadBehavior tempBehavior = Core::IFile::ReloadAll; - foreach (Core::IFile *file, files) { - file->modified(&tempBehavior); - fm->unblockFileChange(file); + if (!revertResponse.error) { + fcb.setModifiedReload(true); } }