Core: Merge OpenResult::Code ReadError into CannotHandle

The only use was to pop up two different error dialogs, and the
usage was not consistent.

Merging them means only one case of error is used, so this is
semantically a Utils::Result<> now.

Change-Id: I44c9bd1f547720e7792208dccd2c7e9038ef7a77
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2025-04-16 13:51:29 +02:00
parent a122b22dab
commit 65e5794dca
13 changed files with 21 additions and 34 deletions

View File

@@ -2125,7 +2125,7 @@ IDocument::OpenResult BinEditorDocument::openImpl(const FilePath &filePath, quin
QString msg = Tr::tr("Cannot open %1: %2").arg(filePath.toUserOutput(), Tr::tr("File Error"));
// FIXME: Was: file.errorString(), but we don't have a file anymore.
QMessageBox::critical(ICore::dialogParent(), Tr::tr("File Error"), msg);
return {OpenResult::ReadError, msg};
return {OpenResult::CannotHandle, msg};
}
if (size == 0) {

View File

@@ -384,15 +384,15 @@ IDocument::OpenResult JsonSettingsDocument::open(const FilePath &filePath,
const FilePath &realFilePath)
{
if (!filePath.isReadableFile())
return OpenResult::ReadError;
return OpenResult::CannotHandle;
Result<QByteArray> contents = realFilePath.fileContents();
if (!contents)
return {OpenResult::ReadError, contents.error()};
return {OpenResult::CannotHandle, contents.error()};
Result<Store> result = storeFromJson(*contents);
if (!result)
return {OpenResult::ReadError, result.error()};
return {OpenResult::CannotHandle, result.error()};
setFilePath(filePath);

View File

@@ -910,18 +910,6 @@ IEditor *EditorManagerPrivate::openEditor(EditorView *view, const FilePath &file
overrideCursor.reset();
delete editor;
editor = nullptr;
if (openResult.code == IDocument::OpenResult::ReadError) {
QMessageBox msgbox(QMessageBox::Critical,
::Core::Tr::tr("File Error"),
::Core::Tr::tr("Could not open \"%1\" for reading. "
"Either the file does not exist or you do not have "
"the permissions to open it.")
.arg(realFp.toUserOutput()),
QMessageBox::Ok,
ICore::dialogParent());
msgbox.exec();
return nullptr;
}
// can happen e.g. when trying to open an completely empty .qrc file
QTC_CHECK(openResult.code == IDocument::OpenResult::CannotHandle);
} else {

View File

@@ -31,7 +31,6 @@ public:
public:
enum Code {
Success,
ReadError,
CannotHandle
};

View File

@@ -53,7 +53,7 @@ IDocument::OpenResult FormWindowFile::open(const FilePath &filePath,
QTC_ASSERT(form, return OpenResult::CannotHandle);
if (filePath.isEmpty())
return OpenResult::ReadError;
return OpenResult::CannotHandle;
QString contents;
QString errorString;
@@ -63,7 +63,7 @@ IDocument::OpenResult FormWindowFile::open(const FilePath &filePath,
if (readResult == Utils::TextFileFormat::ReadEncodingError)
return {OpenResult::CannotHandle, errorString};
if (readResult != Utils::TextFileFormat::ReadSuccess)
return {OpenResult::ReadError, errorString};
return {OpenResult::CannotHandle, errorString};
form->setFileName(filePath.absoluteFilePath().toUrlishString());
const QByteArray contentsBA = contents.toUtf8();

View File

@@ -274,7 +274,7 @@ IDocument::OpenResult DiffEditorDocument::open(const FilePath &filePath, const F
ReadResult readResult = read(filePath, &patch, &errorString);
if (readResult == TextFileFormat::ReadIOError
|| readResult == TextFileFormat::ReadMemoryAllocationError) {
return {OpenResult::ReadError, errorString};
return {OpenResult::CannotHandle, errorString};
}
const std::optional<QList<FileData>> fileDataList = DiffUtils::readPatch(patch);

View File

@@ -77,7 +77,7 @@ IDocument::OpenResult ImageViewerFile::openImpl(const FilePath &filePath)
cleanUp();
if (!filePath.isReadableFile())
return OpenResult::ReadError;
return OpenResult::CannotHandle;
const QString &fileName = filePath.toUrlishString();
QByteArray format = QImageReader::imageFormat(fileName);

View File

@@ -120,7 +120,7 @@ Core::IDocument::OpenResult ModelDocument::load(const FilePath &fileName)
d->documentController->loadProject(fileName);
setFilePath(d->documentController->projectController()->project()->fileName());
} catch (const qmt::FileNotFoundException &ex) {
return {OpenResult::ReadError, ex.errorMessage()};
return {OpenResult::CannotHandle, ex.errorMessage()};
} catch (const qmt::Exception &ex) {
return {OpenResult::CannotHandle,
Tr::tr("Could not open \"%1\" for reading: %2.")

View File

@@ -95,7 +95,7 @@ Core::IDocument::OpenResult ResourceFile::load()
if (m_filePath.isEmpty()) {
m_error_message = Tr::tr("The file name is empty.");
return Core::IDocument::OpenResult::ReadError;
return Core::IDocument::OpenResult::CannotHandle;
}
clearPrefixList();
@@ -108,7 +108,7 @@ Core::IDocument::OpenResult ResourceFile::load()
QFile file(m_filePath.toUrlishString());
if (!file.open(QIODevice::ReadOnly)) {
m_error_message = file.errorString();
return Core::IDocument::OpenResult::ReadError;
return Core::IDocument::OpenResult::CannotHandle;
}
QByteArray data = file.readAll();
// Detect line ending style

View File

@@ -41,14 +41,14 @@ Core::IDocument::OpenResult ScxmlEditorDocument::open(const FilePath &filePath,
Q_UNUSED(realFilePath)
if (filePath.isEmpty())
return OpenResult::ReadError;
return OpenResult::CannotHandle;
if (!m_designWidget)
return OpenResult::ReadError;
return OpenResult::CannotHandle;
const FilePath &absoluteFilePath = filePath.absoluteFilePath();
if (!m_designWidget->load(absoluteFilePath.toUrlishString()))
return {OpenResult::ReadError, m_designWidget->errorMessage()};
return {OpenResult::CannotHandle, m_designWidget->errorMessage()};
setFilePath(absoluteFilePath);

View File

@@ -183,18 +183,18 @@ IDocument::OpenResult ObjectsMapDocument::openImpl(const FilePath &fileName,
if (realFileName.fileName() == "objects.map") {
FileReader reader;
if (const Result<> res = reader.fetch(realFileName); !res)
return {OpenResult::ReadError, res.error()};
return {OpenResult::CannotHandle, res.error()};
text = reader.text();
} else {
const FilePath base = settings().squishPath();
if (base.isEmpty()) {
return {OpenResult::ReadError, Tr::tr("Incomplete Squish settings. "
return {OpenResult::CannotHandle, Tr::tr("Incomplete Squish settings. "
"Missing Squish installation path.")};
}
const FilePath exe = base.pathAppended("lib/exec/objectmaptool").withExecutableSuffix();
if (!exe.isExecutableFile())
return {OpenResult::ReadError, Tr::tr("objectmaptool not found.")};
return {OpenResult::CannotHandle, Tr::tr("objectmaptool not found.")};
Process objectMapReader;
@@ -206,7 +206,7 @@ IDocument::OpenResult ObjectsMapDocument::openImpl(const FilePath &fileName,
text = objectMapReader.cleanedStdOut().toUtf8();
}
if (!setContents(text))
return {OpenResult::ReadError, Tr::tr("Failure while parsing objects.map content.")};
return {OpenResult::CannotHandle, Tr::tr("Failure while parsing objects.map content.")};
return OpenResult::Success;
}

View File

@@ -827,7 +827,7 @@ IDocument::OpenResult TextDocument::openImpl(const FilePath &filePath,
setFilePath(filePath);
}
if (readResult == Utils::TextFileFormat::ReadIOError)
return {OpenResult::ReadError, errorString};
return {OpenResult::CannotHandle, errorString};
return OpenResult::Success;
}

View File

@@ -30,11 +30,11 @@ SubmitEditorFile::SubmitEditorFile(VcsBaseSubmitEditor *editor) :
IDocument::OpenResult SubmitEditorFile::open(const FilePath &filePath, const FilePath &realFilePath)
{
if (filePath.isEmpty())
return OpenResult::ReadError;
return OpenResult::CannotHandle;
FileReader reader;
if (const Result<> res = reader.fetch(realFilePath); !res)
return {OpenResult::ReadError, res.error()};
return {OpenResult::CannotHandle, res.error()};
const QString text = QString::fromLocal8Bit(reader.text());
if (!m_editor->setFileContents(text.toUtf8()))