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:
@@ -558,20 +558,21 @@ void TextDocument::checkPermissions()
|
||||
emit changed();
|
||||
}
|
||||
|
||||
bool TextDocument::open(QString *errorString, const QString &fileName, const QString &realFileName)
|
||||
Core::IDocument::OpenResult TextDocument::open(QString *errorString, const QString &fileName,
|
||||
const QString &realFileName)
|
||||
{
|
||||
emit aboutToOpen(fileName, realFileName);
|
||||
bool success = openImpl(errorString, fileName, realFileName);
|
||||
if (success) {
|
||||
OpenResult success = openImpl(errorString, fileName, realFileName);
|
||||
if (success == OpenResult::Success) {
|
||||
Utils::MimeDatabase mdb;
|
||||
setMimeType(mdb.mimeTypeForFile(fileName).name());
|
||||
emit openFinishedSuccessfully();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return success;
|
||||
}
|
||||
|
||||
bool TextDocument::openImpl(QString *errorString, const QString &fileName, const QString &realFileName)
|
||||
Core::IDocument::OpenResult TextDocument::openImpl(QString *errorString, const QString &fileName,
|
||||
const QString &realFileName)
|
||||
{
|
||||
QStringList content;
|
||||
|
||||
@@ -608,14 +609,15 @@ bool TextDocument::openImpl(QString *errorString, const QString &fileName, const
|
||||
}
|
||||
TextDocumentLayout *documentLayout =
|
||||
qobject_cast<TextDocumentLayout*>(d->m_document.documentLayout());
|
||||
QTC_ASSERT(documentLayout, return true);
|
||||
QTC_ASSERT(documentLayout, return OpenResult::CannotHandle);
|
||||
documentLayout->lastSaveRevision = d->m_autoSaveRevision = d->m_document.revision();
|
||||
d->updateRevisions();
|
||||
d->m_document.setModified(fileName != realFileName);
|
||||
setFilePath(Utils::FileName::fromUserInput(fi.absoluteFilePath()));
|
||||
}
|
||||
return readResult == Utils::TextFileFormat::ReadSuccess
|
||||
|| readResult == Utils::TextFileFormat::ReadEncodingError;
|
||||
if (readResult == Utils::TextFileFormat::ReadIOError)
|
||||
return OpenResult::ReadError;
|
||||
return OpenResult::Success;
|
||||
}
|
||||
|
||||
bool TextDocument::reload(QString *errorString, QTextCodec *codec)
|
||||
@@ -634,7 +636,7 @@ bool TextDocument::reload(QString *errorString)
|
||||
if (documentLayout)
|
||||
marks = documentLayout->documentClosing(); // removes text marks non-permanently
|
||||
|
||||
bool success = openImpl(errorString, filePath().toString(), filePath().toString());
|
||||
bool success = (openImpl(errorString, filePath().toString(), filePath().toString()) == OpenResult::Success);
|
||||
|
||||
if (documentLayout)
|
||||
documentLayout->documentReloaded(marks, this); // re-adds text marks
|
||||
|
||||
Reference in New Issue
Block a user