Commit 4637d562 authored by dt's avatar dt

Don't ask to reload the file, if the user uses git/undo or git/revert.

Simply do it.

Task-Nr: 254558
parent 69d04bc0
...@@ -602,3 +602,33 @@ QList<IFile *> FileManager::managedFiles(const QString &fileName) const ...@@ -602,3 +602,33 @@ QList<IFile *> FileManager::managedFiles(const QString &fileName) const
} }
return result; 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;
}
...@@ -136,6 +136,25 @@ private: ...@@ -136,6 +136,25 @@ private:
bool m_blockActivated; 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 } // namespace Core
#endif // FILEMANAGER_H #endif // FILEMANAGER_H
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include <coreplugin/messagemanager.h> #include <coreplugin/messagemanager.h>
#include <coreplugin/progressmanager/progressmanager.h> #include <coreplugin/progressmanager/progressmanager.h>
#include <coreplugin/uniqueidmanager.h> #include <coreplugin/uniqueidmanager.h>
#include <coreplugin/filemanager.h>
#include <texteditor/itexteditor.h> #include <texteditor/itexteditor.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <vcsbase/vcsbaseeditor.h> #include <vcsbase/vcsbaseeditor.h>
......
...@@ -553,7 +553,14 @@ void GitPlugin::undoFileChanges() ...@@ -553,7 +553,14 @@ void GitPlugin::undoFileChanges()
QFileInfo fileInfo = currentFile(); QFileInfo fileInfo = currentFile();
QString fileName = fileInfo.fileName(); QString fileName = fileInfo.fileName();
QString workingDirectory = fileInfo.absolutePath(); 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() void GitPlugin::undoProjectChanges()
...@@ -583,6 +590,9 @@ void GitPlugin::unstageFile() ...@@ -583,6 +590,9 @@ void GitPlugin::unstageFile()
void GitPlugin::revertFile() void GitPlugin::revertFile()
{ {
const QFileInfo fileInfo = currentFile(); const QFileInfo fileInfo = currentFile();
Core::FileChangeBlocker fcb(fileInfo.filePath());
fcb.setModifiedReload(true);
m_gitClient->revert(QStringList(fileInfo.absoluteFilePath())); m_gitClient->revert(QStringList(fileInfo.absoluteFilePath()));
} }
......
...@@ -444,18 +444,9 @@ void PerforcePlugin::revertCurrentFile() ...@@ -444,18 +444,9 @@ void PerforcePlugin::revertCurrentFile()
return; return;
} }
Core::FileManager *fm = Core::ICore::instance()->fileManager(); Core::FileChangeBlocker fcb(fileName);
QList<Core::IFile *> files = fm->managedFiles(fileName); fcb.setModifiedReload(true);
foreach (Core::IFile *file, files) {
fm->blockFileChange(file);
}
PerforceResponse result2 = runP4Cmd(QStringList() << QLatin1String("revert") << fileName, QStringList(), CommandToWindow|StdOutToWindow|StdErrToWindow|ErrorToWindow); 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() void PerforcePlugin::diffCurrentFile()
......
...@@ -611,10 +611,8 @@ void SubversionPlugin::revertCurrentFile() ...@@ -611,10 +611,8 @@ void SubversionPlugin::revertCurrentFile()
QMessageBox::Yes, QMessageBox::No) == QMessageBox::No) QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
return; return;
Core::FileManager *fm = Core::ICore::instance()->fileManager();
QList<Core::IFile *> files = fm->managedFiles(file); Core::FileChangeBlocker fcb(file);
foreach (Core::IFile *file, files)
fm->blockFileChange(file);
// revert // revert
args.clear(); args.clear();
...@@ -622,16 +620,8 @@ void SubversionPlugin::revertCurrentFile() ...@@ -622,16 +620,8 @@ void SubversionPlugin::revertCurrentFile()
args.append(file); args.append(file);
const SubversionResponse revertResponse = runSvn(args, subversionShortTimeOut, true); const SubversionResponse revertResponse = runSvn(args, subversionShortTimeOut, true);
if (revertResponse.error) { if (!revertResponse.error) {
foreach (Core::IFile *file, files) fcb.setModifiedReload(true);
fm->unblockFileChange(file);
return;
}
Core::IFile::ReloadBehavior tempBehavior = Core::IFile::ReloadAll;
foreach (Core::IFile *file, files) {
file->modified(&tempBehavior);
fm->unblockFileChange(file);
} }
} }
......
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