Fix reloading of patch files

(cherry picked from commit 37ddb4e9eb)
Change-Id: I06c41eb802b0a3318da3ddfa72bd3575c02867fa
Task-number: QTCREATORBUG-13241
Reviewed-by: Jarek Kobus <jaroslaw.kobus@digia.com>
This commit is contained in:
jkobus
2014-10-23 16:47:20 +02:00
committed by Eike Ziller
parent 4889239479
commit 2e364c1506
3 changed files with 32 additions and 38 deletions

View File

@@ -278,29 +278,10 @@ bool DiffEditor::open(QString *errorString,
{ {
Q_UNUSED(realFileName) Q_UNUSED(realFileName)
if (!m_controller) if (!m_document)
return false; return false;
QString patch; return m_document->open(errorString, fileName);
if (m_document->read(fileName, &patch, errorString) != Utils::TextFileFormat::ReadSuccess)
return false;
bool ok = false;
QList<FileData> fileDataList
= DiffUtils::readPatch(patch,
m_controller->isIgnoreWhitespace(),
&ok);
if (!ok) {
*errorString = tr("Could not parse patch file \"%1\". "
"The content is not of unified diff format.")
.arg(fileName);
return false;
}
const QFileInfo fi(fileName);
m_document->setFilePath(QDir::cleanPath(fi.absoluteFilePath()));
m_controller->setDiffFiles(fileDataList, fi.absolutePath());
return true;
} }
Core::IDocument *DiffEditor::document() Core::IDocument *DiffEditor::document()

View File

@@ -68,9 +68,6 @@ bool DiffEditorDocument::setContents(const QByteArray &contents)
QString DiffEditorDocument::defaultPath() const QString DiffEditorDocument::defaultPath() const
{ {
if (!m_controller)
return QString();
return m_controller->workingDirectory(); return m_controller->workingDirectory();
} }
@@ -79,9 +76,6 @@ bool DiffEditorDocument::save(QString *errorString, const QString &fileName, boo
Q_UNUSED(errorString) Q_UNUSED(errorString)
Q_UNUSED(autoSave) Q_UNUSED(autoSave)
if (!m_controller)
return false;
const QString contents = DiffUtils::makePatch(m_controller->diffFiles()); const QString contents = DiffUtils::makePatch(m_controller->diffFiles());
const bool ok = write(fileName, format(), contents, errorString); const bool ok = write(fileName, format(), contents, errorString);
@@ -90,24 +84,43 @@ bool DiffEditorDocument::save(QString *errorString, const QString &fileName, boo
return false; return false;
const QFileInfo fi(fileName); const QFileInfo fi(fileName);
setTemporary(false);
setFilePath(QDir::cleanPath(fi.absoluteFilePath())); setFilePath(QDir::cleanPath(fi.absoluteFilePath()));
setDisplayName(QString()); setDisplayName(QString());
return true; return true;
} }
Core::IDocument::ReloadBehavior DiffEditorDocument::reloadBehavior(ChangeTrigger state, ChangeType type) const
{
Q_UNUSED(state)
Q_UNUSED(type)
return BehaviorSilent;
}
bool DiffEditorDocument::reload(QString *errorString, ReloadFlag flag, ChangeType type) bool DiffEditorDocument::reload(QString *errorString, ReloadFlag flag, ChangeType type)
{ {
Q_UNUSED(errorString)
Q_UNUSED(flag)
Q_UNUSED(type) Q_UNUSED(type)
if (flag == FlagIgnore)
return true;
return open(errorString, filePath());
}
bool DiffEditorDocument::open(QString *errorString, const QString &fileName)
{
QString patch;
if (read(fileName, &patch, errorString) != Utils::TextFileFormat::ReadSuccess)
return false;
bool ok = false;
QList<FileData> fileDataList
= DiffUtils::readPatch(patch,
m_controller->isIgnoreWhitespace(),
&ok);
if (!ok) {
*errorString = tr("Could not parse patch file \"%1\". "
"The content is not of unified diff format.")
.arg(fileName);
return false; return false;
} }
const QFileInfo fi(fileName);
setTemporary(false);
setFilePath(QDir::cleanPath(fi.absoluteFilePath()));
m_controller->setDiffFiles(fileDataList, fi.absolutePath());
return true;
}
} // namespace DiffEditor } // namespace DiffEditor

View File

@@ -55,8 +55,8 @@ public:
bool isModified() const { return false; } bool isModified() const { return false; }
bool isSaveAsAllowed() const { return true; } bool isSaveAsAllowed() const { return true; }
bool save(QString *errorString, const QString &fileName, bool autoSave); bool save(QString *errorString, const QString &fileName, bool autoSave);
ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
bool reload(QString *errorString, ReloadFlag flag, ChangeType type); bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
bool open(QString *errorString, const QString &fileName);
private: private:
DiffEditorController *m_controller; DiffEditorController *m_controller;