forked from qt-creator/qt-creator
Editor manager: Abort with a single message if file is not readable.
We show a dialog that offers opening a file in a different editor type if opening a file fails, but we should not do that if opening the file fails because it is not readable. With this change, documents now specify if they failed to open a file because reading failed, or because they could not handle the file contents. Task-number: QTCREATORBUG-14495 Change-Id: I5d4b7cfa74b87ef21b9b55bc30b3ebe2f8238dfa Reviewed-by: Daniel Teske <daniel.teske@theqtcompany.com> Reviewed-by: Leena Miettinen <riitta-leena.miettinen@theqtcompany.com>
This commit is contained in:
@@ -235,18 +235,20 @@ bool DiffEditorDocument::reload(QString *errorString, ReloadFlag flag, ChangeTyp
|
||||
Q_UNUSED(type)
|
||||
if (flag == FlagIgnore)
|
||||
return true;
|
||||
return open(errorString, filePath().toString(), filePath().toString());
|
||||
return open(errorString, filePath().toString(), filePath().toString()) == OpenResult::Success;
|
||||
}
|
||||
|
||||
bool DiffEditorDocument::open(QString *errorString, const QString &fileName,
|
||||
Core::IDocument::OpenResult DiffEditorDocument::open(QString *errorString, const QString &fileName,
|
||||
const QString &realFileName)
|
||||
{
|
||||
QTC_ASSERT(errorString, return false);
|
||||
QTC_ASSERT(fileName == realFileName, return false); // does not support autosave
|
||||
QTC_CHECK(fileName == realFileName); // does not support autosave
|
||||
beginReload();
|
||||
QString patch;
|
||||
if (read(fileName, &patch, errorString) != TextFileFormat::ReadSuccess)
|
||||
return false;
|
||||
ReadResult readResult = read(fileName, &patch, errorString);
|
||||
if (readResult == TextFileFormat::ReadEncodingError)
|
||||
return OpenResult::CannotHandle;
|
||||
else if (readResult != TextFileFormat::ReadSuccess)
|
||||
return OpenResult::ReadError;
|
||||
|
||||
bool ok = false;
|
||||
QList<FileData> fileDataList = DiffUtils::readPatch(patch, &ok);
|
||||
@@ -262,7 +264,7 @@ bool DiffEditorDocument::open(QString *errorString, const QString &fileName,
|
||||
setDiffFiles(fileDataList, fi.absolutePath());
|
||||
}
|
||||
endReload(ok);
|
||||
return ok;
|
||||
return ok ? OpenResult::Success : OpenResult::CannotHandle;
|
||||
}
|
||||
|
||||
QString DiffEditorDocument::suggestedFileName() const
|
||||
|
||||
Reference in New Issue
Block a user