Skip to content
Snippets Groups Projects
Commit 4637d562 authored by dt's avatar dt
Browse files

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

Simply do it.

Task-Nr: 254558
parent 69d04bc0
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
......@@ -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
......@@ -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>
......
......@@ -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()));
}
......
......@@ -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()
......
......@@ -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);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment