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

@@ -265,13 +265,13 @@ public:
}
}
bool open(QString *errorString, const QString &fileName, const QString &realFileName)
OpenResult open(QString *errorString, const QString &fileName, const QString &realFileName)
{
QTC_CHECK(fileName == realFileName); // The bineditor can do no autosaving
return openImpl(errorString, fileName);
}
bool openImpl(QString *errorString, const QString &fileName, quint64 offset = 0)
OpenResult openImpl(QString *errorString, const QString &fileName, quint64 offset = 0)
{
QFile file(fileName);
if (file.open(QIODevice::ReadOnly)) {
@@ -283,7 +283,7 @@ public:
*errorString = msg;
else
QMessageBox::critical(ICore::mainWindow(), tr("File Error"), msg);
return false;
return OpenResult::CannotHandle;
}
if (size > INT_MAX) {
QString msg = tr("The file is too big for the Binary Editor (max. 2GB).");
@@ -291,13 +291,13 @@ public:
*errorString = msg;
else
QMessageBox::critical(ICore::mainWindow(), tr("File Error"), msg);
return false;
return OpenResult::CannotHandle;
}
if (offset >= size)
return false;
return OpenResult::CannotHandle;
setFilePath(FileName::fromString(fileName));
m_widget->setSizes(offset, file.size());
return true;
return OpenResult::Success;
}
QString errStr = tr("Cannot open %1: %2").arg(
QDir::toNativeSeparators(fileName), file.errorString());
@@ -305,7 +305,7 @@ public:
*errorString = errStr;
else
QMessageBox::critical(ICore::mainWindow(), tr("File Error"), errStr);
return false;
return OpenResult::ReadError;
}
private slots:
@@ -363,7 +363,7 @@ public:
emit aboutToReload();
int cPos = m_widget->cursorPosition();
m_widget->clear();
const bool success = openImpl(errorString, filePath().toString());
const bool success = (openImpl(errorString, filePath().toString()) == OpenResult::Success);
m_widget->setCursorPosition(cPos);
emit reloadFinished(success);
return success;