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:
Eike Ziller
2015-06-04 15:21:02 +02:00
parent be0aa40520
commit fef9d7ff94
22 changed files with 133 additions and 85 deletions

View File

@@ -70,23 +70,27 @@ FormWindowFile::FormWindowFile(QDesignerFormWindowInterface *form, QObject *pare
m_resourceHandler, &ResourceHandler::updateResources);
}
bool FormWindowFile::open(QString *errorString, const QString &fileName, const QString &realFileName)
Core::IDocument::OpenResult FormWindowFile::open(QString *errorString, const QString &fileName,
const QString &realFileName)
{
if (Designer::Constants::Internal::debug)
qDebug() << "FormWindowFile::open" << fileName;
QDesignerFormWindowInterface *form = formWindow();
QTC_ASSERT(form, return false);
QTC_ASSERT(form, return OpenResult::CannotHandle);
if (fileName.isEmpty())
return true;
return OpenResult::ReadError;
const QFileInfo fi(fileName);
const QString absfileName = fi.absoluteFilePath();
QString contents;
if (read(absfileName, &contents, errorString) != Utils::TextFileFormat::ReadSuccess)
return false;
Utils::TextFileFormat::ReadResult readResult = read(absfileName, &contents, errorString);
if (readResult == Utils::TextFileFormat::ReadEncodingError)
return OpenResult::CannotHandle;
else if (readResult != Utils::TextFileFormat::ReadSuccess)
return OpenResult::ReadError;
form->setFileName(absfileName);
const QByteArray contentsBA = contents.toUtf8();
@@ -94,7 +98,7 @@ bool FormWindowFile::open(QString *errorString, const QString &fileName, const Q
str.setData(contentsBA);
str.open(QIODevice::ReadOnly);
if (!form->setContents(&str, errorString))
return false;
return OpenResult::CannotHandle;
form->setDirty(fileName != realFileName);
syncXmlFromFormWindow();
@@ -102,7 +106,7 @@ bool FormWindowFile::open(QString *errorString, const QString &fileName, const Q
setShouldAutoSave(false);
resourceHandler()->updateProjectResources();
return true;
return OpenResult::Success;
}
bool FormWindowFile::save(QString *errorString, const QString &name, bool autoSave)
@@ -209,7 +213,8 @@ bool FormWindowFile::reload(QString *errorString, ReloadFlag flag, ChangeType ty
emit changed();
} else {
emit aboutToReload();
const bool success = open(errorString, filePath().toString(), filePath().toString());
const bool success
= (open(errorString, filePath().toString(), filePath().toString()) == OpenResult::Success);
emit reloadFinished(success);
return success;
}