From 65e5794dca6202af7a2b2a6aa4ab6334373e2560 Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 16 Apr 2025 13:51:29 +0200 Subject: [PATCH] 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 --- src/plugins/bineditor/bineditorplugin.cpp | 2 +- .../compilerexplorer/compilerexplorereditor.cpp | 6 +++--- .../coreplugin/editormanager/editormanager.cpp | 12 ------------ src/plugins/coreplugin/idocument.h | 1 - src/plugins/designer/formwindowfile.cpp | 4 ++-- src/plugins/diffeditor/diffeditordocument.cpp | 2 +- src/plugins/imageviewer/imageviewerfile.cpp | 2 +- src/plugins/modeleditor/modeldocument.cpp | 2 +- .../resourceeditor/qrceditor/resourcefile.cpp | 4 ++-- src/plugins/scxmleditor/scxmleditordocument.cpp | 6 +++--- src/plugins/squish/objectsmapdocument.cpp | 8 ++++---- src/plugins/texteditor/textdocument.cpp | 2 +- src/plugins/vcsbase/submiteditorfile.cpp | 4 ++-- 13 files changed, 21 insertions(+), 34 deletions(-) diff --git a/src/plugins/bineditor/bineditorplugin.cpp b/src/plugins/bineditor/bineditorplugin.cpp index ae0f5362ce4..1ec24de3986 100644 --- a/src/plugins/bineditor/bineditorplugin.cpp +++ b/src/plugins/bineditor/bineditorplugin.cpp @@ -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) { diff --git a/src/plugins/compilerexplorer/compilerexplorereditor.cpp b/src/plugins/compilerexplorer/compilerexplorereditor.cpp index 6020e1a65bb..544ef6a2e64 100644 --- a/src/plugins/compilerexplorer/compilerexplorereditor.cpp +++ b/src/plugins/compilerexplorer/compilerexplorereditor.cpp @@ -384,15 +384,15 @@ IDocument::OpenResult JsonSettingsDocument::open(const FilePath &filePath, const FilePath &realFilePath) { if (!filePath.isReadableFile()) - return OpenResult::ReadError; + return OpenResult::CannotHandle; Result contents = realFilePath.fileContents(); if (!contents) - return {OpenResult::ReadError, contents.error()}; + return {OpenResult::CannotHandle, contents.error()}; Result result = storeFromJson(*contents); if (!result) - return {OpenResult::ReadError, result.error()}; + return {OpenResult::CannotHandle, result.error()}; setFilePath(filePath); diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index 3985f1ac16f..c857ad8264c 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -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 { diff --git a/src/plugins/coreplugin/idocument.h b/src/plugins/coreplugin/idocument.h index 02e9e85ba3c..4d957360d97 100644 --- a/src/plugins/coreplugin/idocument.h +++ b/src/plugins/coreplugin/idocument.h @@ -31,7 +31,6 @@ public: public: enum Code { Success, - ReadError, CannotHandle }; diff --git a/src/plugins/designer/formwindowfile.cpp b/src/plugins/designer/formwindowfile.cpp index b3b1bf10c17..ac5fc3067b4 100644 --- a/src/plugins/designer/formwindowfile.cpp +++ b/src/plugins/designer/formwindowfile.cpp @@ -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(); diff --git a/src/plugins/diffeditor/diffeditordocument.cpp b/src/plugins/diffeditor/diffeditordocument.cpp index fa9fc47bcfa..db5614e8421 100644 --- a/src/plugins/diffeditor/diffeditordocument.cpp +++ b/src/plugins/diffeditor/diffeditordocument.cpp @@ -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> fileDataList = DiffUtils::readPatch(patch); diff --git a/src/plugins/imageviewer/imageviewerfile.cpp b/src/plugins/imageviewer/imageviewerfile.cpp index b11b6a1a992..5085f3552e5 100644 --- a/src/plugins/imageviewer/imageviewerfile.cpp +++ b/src/plugins/imageviewer/imageviewerfile.cpp @@ -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); diff --git a/src/plugins/modeleditor/modeldocument.cpp b/src/plugins/modeleditor/modeldocument.cpp index 980feff3fe3..501bf6e1a88 100644 --- a/src/plugins/modeleditor/modeldocument.cpp +++ b/src/plugins/modeleditor/modeldocument.cpp @@ -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.") diff --git a/src/plugins/resourceeditor/qrceditor/resourcefile.cpp b/src/plugins/resourceeditor/qrceditor/resourcefile.cpp index da5705475b7..1463c41750f 100644 --- a/src/plugins/resourceeditor/qrceditor/resourcefile.cpp +++ b/src/plugins/resourceeditor/qrceditor/resourcefile.cpp @@ -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 diff --git a/src/plugins/scxmleditor/scxmleditordocument.cpp b/src/plugins/scxmleditor/scxmleditordocument.cpp index 4eff969c391..339d440897f 100644 --- a/src/plugins/scxmleditor/scxmleditordocument.cpp +++ b/src/plugins/scxmleditor/scxmleditordocument.cpp @@ -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); diff --git a/src/plugins/squish/objectsmapdocument.cpp b/src/plugins/squish/objectsmapdocument.cpp index 7146e10bba0..51845e9cc80 100644 --- a/src/plugins/squish/objectsmapdocument.cpp +++ b/src/plugins/squish/objectsmapdocument.cpp @@ -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; } diff --git a/src/plugins/texteditor/textdocument.cpp b/src/plugins/texteditor/textdocument.cpp index 4e23e9a7512..bdd6781e97d 100644 --- a/src/plugins/texteditor/textdocument.cpp +++ b/src/plugins/texteditor/textdocument.cpp @@ -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; } diff --git a/src/plugins/vcsbase/submiteditorfile.cpp b/src/plugins/vcsbase/submiteditorfile.cpp index be85fed0cd9..996781b9ef5 100644 --- a/src/plugins/vcsbase/submiteditorfile.cpp +++ b/src/plugins/vcsbase/submiteditorfile.cpp @@ -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()))