Core: Return expected_str<void> from IDocument::reload()

... and adjust callers.

Change-Id: Iee41f06e8f6e0019aecff67ce06a6f22ec1a45ee
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2024-09-20 12:49:55 +02:00
parent c66185ce04
commit 779fcdb18b
29 changed files with 138 additions and 122 deletions

View File

@@ -120,7 +120,7 @@ public:
bool isSaveAsAllowed() const final { return true; }
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) final;
Utils::expected_str<void> reload(ReloadFlag flag, ChangeType type) final;
Utils::expected_str<void> saveImpl(const Utils::FilePath &filePath, bool autoSave) final;
void fetchData(quint64 address) const { if (m_fetchDataHandler) m_fetchDataHandler(address); }
@@ -2182,16 +2182,19 @@ bool BinEditorDocument::isModified() const
return m_undoStack.size() != m_unmodifiedState;
}
bool BinEditorDocument::reload(QString *errorString, ReloadFlag flag, ChangeType type)
expected_str<void> BinEditorDocument::reload(ReloadFlag flag, ChangeType type)
{
Q_UNUSED(type)
if (flag == FlagIgnore)
return true;
return {};
emit aboutToReload();
clear();
const bool success = (openImpl(errorString, filePath()) == OpenResult::Success);
QString errorString;
const bool success = (openImpl(&errorString, filePath()) == OpenResult::Success);
emit reloadFinished(success);
return success;
if (!success)
return make_unexpected(errorString);
return {};
}
expected_str<void> BinEditorDocument::saveImpl(const FilePath &filePath, bool autoSave)

View File

@@ -1188,19 +1188,18 @@ void DocumentManager::checkForReload()
removeFileInfo(document);
addFileInfos({document});
bool success = true;
QString errorString;
expected_str<void> success;
// we've got some modification
document->checkPermissions();
// check if it's contents or permissions:
if (!type) {
// Only permission change
success = true;
success = {};
// now we know it's a content change or file was removed
} else if (defaultBehavior == IDocument::ReloadUnmodified && type == IDocument::TypeContents
&& !document->isModified()) {
// content change, but unmodified (and settings say to reload in this case)
success = document->reload(&errorString, IDocument::FlagReload, *type);
success = document->reload(IDocument::FlagReload, *type);
// file was removed or it's a content change and the default behavior for
// unmodified files didn't kick in
} else if (defaultBehavior == IDocument::ReloadUnmodified && type == IDocument::TypeRemoved
@@ -1210,7 +1209,7 @@ void DocumentManager::checkForReload()
documentsToClose << document;
} else if (defaultBehavior == IDocument::IgnoreAll) {
// content change or removed, but settings say ignore
success = document->reload(&errorString, IDocument::FlagIgnore, *type);
success = document->reload(IDocument::FlagIgnore, *type);
// either the default behavior is to always ask,
// or the ReloadUnmodified default behavior didn't kick in,
// so do whatever the IDocument wants us to do
@@ -1221,16 +1220,16 @@ void DocumentManager::checkForReload()
if (type == IDocument::TypeRemoved)
documentsToClose << document;
else
success = document->reload(&errorString, IDocument::FlagReload, *type);
success = document->reload(IDocument::FlagReload, *type);
// IDocument wants us to ask
} else if (type == IDocument::TypeContents) {
// content change, IDocument wants to ask user
if (previousReloadAnswer == ReloadNone || previousReloadAnswer == ReloadNoneAndDiff) {
// answer already given, ignore
success = document->reload(&errorString, IDocument::FlagIgnore, IDocument::TypeContents);
success = document->reload(IDocument::FlagIgnore, IDocument::TypeContents);
} else if (previousReloadAnswer == ReloadAll) {
// answer already given, reload
success = document->reload(&errorString, IDocument::FlagReload, IDocument::TypeContents);
success = document->reload(IDocument::FlagReload, IDocument::TypeContents);
} else {
// Ask about content change
previousReloadAnswer = reloadPrompt(document->filePath(), document->isModified(),
@@ -1239,12 +1238,12 @@ void DocumentManager::checkForReload()
switch (previousReloadAnswer) {
case ReloadAll:
case ReloadCurrent:
success = document->reload(&errorString, IDocument::FlagReload, IDocument::TypeContents);
success = document->reload(IDocument::FlagReload, IDocument::TypeContents);
break;
case ReloadSkipCurrent:
case ReloadNone:
case ReloadNoneAndDiff:
success = document->reload(&errorString, IDocument::FlagIgnore, IDocument::TypeContents);
success = document->reload(IDocument::FlagIgnore, IDocument::TypeContents);
break;
case CloseCurrent:
documentsToClose << document;
@@ -1288,9 +1287,9 @@ void DocumentManager::checkForReload()
}
}
if (!success) {
QString errorString = success.error();
if (errorString.isEmpty())
errorStrings << Tr::tr("Cannot reload %1").arg(document->filePath().toUserOutput());
else
errorString = Tr::tr("Cannot reload %1").arg(document->filePath().toUserOutput());
errorStrings << errorString;
}

View File

@@ -2630,9 +2630,10 @@ void EditorManagerPrivate::revertToSaved(IDocument *document)
return;
}
}
QString errorString;
if (!document->reload(&errorString, IDocument::FlagReload, IDocument::TypeContents))
QMessageBox::critical(ICore::dialogParent(), ::Core::Tr::tr("File Error"), errorString);
const expected_str<void> res = document->reload(IDocument::FlagReload, IDocument::TypeContents);
if (!res)
QMessageBox::critical(ICore::dialogParent(), ::Core::Tr::tr("File Error"), res.error());
}
void EditorManagerPrivate::autoSuspendDocuments()

View File

@@ -467,12 +467,11 @@ IDocument::ReloadBehavior IDocument::reloadBehavior(ChangeTrigger trigger, Chang
\sa reloadFinished()
\sa changed()
*/
bool IDocument::reload(QString *errorString, ReloadFlag flag, ChangeType type)
Utils::expected_str<void> IDocument::reload(ReloadFlag flag, ChangeType type)
{
Q_UNUSED(errorString)
Q_UNUSED(flag)
Q_UNUSED(type)
return true;
return {};
}
/*!

View File

@@ -100,7 +100,7 @@ public:
void setSuspendAllowed(bool value);
virtual ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
virtual bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
virtual Utils::expected_str<void> reload(ReloadFlag flag, ChangeType type);
void checkPermissions();

View File

@@ -189,11 +189,11 @@ bool FormWindowFile::isSaveAsAllowed() const
return true;
}
bool FormWindowFile::reload(QString *errorString, ReloadFlag flag, ChangeType type)
expected_str<void> FormWindowFile::reload(ReloadFlag flag, ChangeType type)
{
if (flag == FlagIgnore) {
if (!m_formWindow || type != TypeContents)
return true;
return {};
const bool wasModified = m_formWindow->isDirty();
{
Utils::GuardLocker locker(m_modificationChangedGuard);
@@ -203,13 +203,16 @@ bool FormWindowFile::reload(QString *errorString, ReloadFlag flag, ChangeType ty
}
if (!wasModified)
updateIsModified();
return true;
return {};
} else {
emit aboutToReload();
QString errorString;
const bool success
= (open(errorString, filePath(), filePath()) == OpenResult::Success);
= (open(&errorString, filePath(), filePath()) == OpenResult::Success);
emit reloadFinished(success);
return success;
if (!success)
return make_unexpected(errorString);
return {};
}
}

View File

@@ -33,7 +33,7 @@ public:
bool shouldAutoSave() const override;
bool isModified() const override;
bool isSaveAsAllowed() const override;
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override;
Utils::expected_str<void> reload(ReloadFlag flag, ChangeType type) override;
QString fallbackSaveAsFileName() const override;
bool supportsCodec(const QTextCodec *codec) const override;

View File

@@ -261,20 +261,22 @@ expected_str<void> DiffEditorDocument::saveImpl(const FilePath &filePath, bool a
void DiffEditorDocument::reload()
{
if (m_controller) {
if (m_controller)
m_controller->requestReload();
} else {
QString errorMessage;
reload(&errorMessage, Core::IDocument::FlagReload, Core::IDocument::TypeContents);
}
else
reload(Core::IDocument::FlagReload, Core::IDocument::TypeContents);
}
bool DiffEditorDocument::reload(QString *errorString, ReloadFlag flag, ChangeType type)
expected_str<void> DiffEditorDocument::reload(ReloadFlag flag, ChangeType type)
{
Q_UNUSED(type)
if (flag == FlagIgnore)
return true;
return open(errorString, filePath(), filePath()) == OpenResult::Success;
return {};
QString errorString;
bool success = open(&errorString, filePath(), filePath()) == OpenResult::Success;
if (!success)
return make_unexpected(errorString);
return {};
}
Core::IDocument::OpenResult DiffEditorDocument::open(QString *errorString, const FilePath &filePath,
@@ -314,8 +316,7 @@ bool DiffEditorDocument::selectEncoding()
switch (result.action) {
case CodecSelectorResult::Reload: {
setCodec(result.codec);
QString errorMessage;
return reload(&errorMessage, Core::IDocument::FlagReload, Core::IDocument::TypeContents);
return bool(reload(Core::IDocument::FlagReload, Core::IDocument::TypeContents));
}
case CodecSelectorResult::Save:
setCodec(result.codec);

View File

@@ -61,7 +61,7 @@ public:
bool isSaveAsAllowed() const override;
void reload();
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override;
Utils::expected_str<void> reload(ReloadFlag flag, ChangeType type) override;
OpenResult open(QString *errorString, const Utils::FilePath &filePath,
const Utils::FilePath &realFilePath) override;
bool selectEncoding();

View File

@@ -191,8 +191,7 @@ void DiffEditorWidgetController::patch(PatchAction patchAction, int fileIndex, i
if (PatchTool::runPatch(EditorManager::defaultTextCodec()->fromUnicode(patch),
FilePath::fromString(contentsCopyDir), 0, patchAction)) {
QString errorString;
if (textDocument->reload(&errorString, FilePath::fromString(contentsCopyFileName)))
if (textDocument->reload(FilePath::fromString(contentsCopyFileName)))
m_document->reload();
}
}

View File

@@ -84,7 +84,7 @@ public:
return BehaviorSilent;
}
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) final;
expected_str<void> reload(ReloadFlag flag, ChangeType type) final;
private:
GenericProject *m_project = nullptr;
@@ -695,15 +695,14 @@ void GenericProject::configureAsExampleProject(Kit *kit)
setup(infoList);
}
bool GenericProjectFile::reload(QString *errorString, IDocument::ReloadFlag flag, IDocument::ChangeType type)
expected_str<void> GenericProjectFile::reload(IDocument::ReloadFlag flag, IDocument::ChangeType type)
{
Q_UNUSED(errorString)
Q_UNUSED(flag)
Q_UNUSED(type)
if (Target *t = m_project->activeTarget())
static_cast<GenericBuildSystem *>(t->buildSystem())->refresh(m_options);
return true;
return {};
}
void GenericProject::editFilesTriggered()

View File

@@ -25,6 +25,8 @@
#include <QGraphicsSvgItem>
#endif
using namespace Utils;
namespace ImageViewer::Internal {
class MovieItem : public QObject, public QGraphicsPixmapItem
@@ -144,17 +146,19 @@ Core::IDocument::ReloadBehavior ImageViewerFile::reloadBehavior(ChangeTrigger st
return BehaviorAsk;
}
bool ImageViewerFile::reload(QString *errorString,
Core::IDocument::ReloadFlag flag,
expected_str<void> ImageViewerFile::reload(Core::IDocument::ReloadFlag flag,
Core::IDocument::ChangeType type)
{
Q_UNUSED(type)
if (flag == FlagIgnore)
return true;
return {};
emit aboutToReload();
bool success = (openImpl(errorString, filePath()) == OpenResult::Success);
QString errorString;
bool success = (openImpl(&errorString, filePath()) == OpenResult::Success);
emit reloadFinished(success);
return success;
if (!success)
return make_unexpected(errorString);
return {};
}
QMovie *ImageViewerFile::movie() const

View File

@@ -39,7 +39,7 @@ public:
const Utils::FilePath &realFilePath) override;
ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const override;
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override;
Utils::expected_str<void> reload(ReloadFlag flag, ChangeType type) override;
QMovie *movie() const;

View File

@@ -11,8 +11,6 @@
#include "qmt/config/configcontroller.h"
#include "qmt/infrastructure/ioexceptions.h"
#include "qmt/model_controller/modelcontroller.h"
#include "qmt/model/mdiagram.h"
#include "qmt/project_controller/projectcontroller.h"
#include "qmt/project/project.h"
@@ -91,24 +89,22 @@ bool ModelDocument::isSaveAsAllowed() const
return true;
}
bool ModelDocument::reload(QString *errorString, Core::IDocument::ReloadFlag flag,
Utils::expected_str<void> ModelDocument::reload(Core::IDocument::ReloadFlag flag,
Core::IDocument::ChangeType type)
{
Q_UNUSED(type)
if (flag == FlagIgnore)
return true;
return {};
try {
d->documentController->loadProject(filePath());
} catch (const qmt::FileNotFoundException &ex) {
*errorString = ex.errorMessage();
return false;
return make_unexpected(ex.errorMessage());
} catch (const qmt::Exception &ex) {
*errorString = Tr::tr("Could not open \"%1\" for reading: %2.")
.arg(filePath().toUserOutput(), ex.errorMessage());
return false;
return make_unexpected(Tr::tr("Could not open \"%1\" for reading: %2.")
.arg(filePath().toUserOutput(), ex.errorMessage()));
}
emit contentSet();
return true;
return {};
}
ExtDocumentController *ModelDocument::documentController() const

View File

@@ -33,7 +33,7 @@ public:
bool shouldAutoSave() const override;
bool isModified() const override;
bool isSaveAsAllowed() const override;
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override;
Utils::expected_str<void> reload(ReloadFlag flag, ChangeType type) override;
ExtDocumentController *documentController() const;

View File

@@ -145,14 +145,13 @@ public:
return BehaviorSilent;
}
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) final
expected_str<void> reload(ReloadFlag flag, ChangeType type) final
{
Q_UNUSED(errorString)
Q_UNUSED(flag)
Q_UNUSED(type)
emit m_project->projectFileIsDirty(filePath());
return true;
return {};
}
private:

View File

@@ -45,15 +45,19 @@ Core::IDocument::ReloadBehavior TaskFile::reloadBehavior(ChangeTrigger state, Ch
return BehaviorSilent;
}
bool TaskFile::reload(QString *errorString, ReloadFlag flag, ChangeType type)
expected_str<void> TaskFile::reload(ReloadFlag flag, ChangeType type)
{
Q_UNUSED(flag)
if (type == TypeRemoved) {
deleteLater();
return true;
return {};
}
return load(errorString, filePath());
QString errorString;
bool success = load(&errorString, filePath());
if (!success)
return make_unexpected(errorString);
return {};
}
static Task::TaskType typeFrom(const QString &typeName)

View File

@@ -24,7 +24,7 @@ public:
TaskFile(QObject *parent);
ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const override;
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override;
Utils::expected_str<void> reload(ReloadFlag flag, ChangeType type) override;
bool load(QString *errorString, const Utils::FilePath &fileName);

View File

@@ -929,9 +929,10 @@ void QmakePriFile::save(const QStringList &lines)
QStringList errorStrings;
Core::IDocument *document = Core::DocumentModel::documentForFilePath(filePath());
if (document) {
QString errorString;
if (!document->reload(&errorString, Core::IDocument::FlagReload, Core::IDocument::TypeContents))
errorStrings << errorString;
expected_str<void> res =
document->reload(Core::IDocument::FlagReload, Core::IDocument::TypeContents);
if (!res)
errorStrings << res.error();
}
if (!errorStrings.isEmpty())
QMessageBox::warning(Core::ICore::dialogParent(), Tr::tr("File Error"),

View File

@@ -101,14 +101,13 @@ public:
Q_UNUSED(type)
return BehaviorSilent;
}
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override
expected_str<void> reload(ReloadFlag flag, ChangeType type) override
{
Q_UNUSED(errorString)
Q_UNUSED(flag)
Q_UNUSED(type)
if (m_priFile)
m_priFile->scheduleUpdate();
return true;
return {};
}
void setPriFile(QmakePriFile *priFile) { m_priFile = priFile; }

View File

@@ -56,7 +56,7 @@ public:
bool shouldAutoSave() const final { return m_shouldAutoSave; }
bool isModified() const final { return m_model.dirty(); }
bool isSaveAsAllowed() const final { return true; }
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) final;
expected_str<void> reload(ReloadFlag flag, ChangeType type) final;
void setFilePath(const FilePath &newName) final;
void setBlockDirtyChanged(bool value) { m_blockDirtyChanged = value; }
@@ -280,15 +280,18 @@ void ResourceEditorImpl::restoreState(const QByteArray &state)
m_resourceEditor->restoreState(splitterState);
}
bool ResourceEditorDocument::reload(QString *errorString, ReloadFlag flag, ChangeType type)
expected_str<void> ResourceEditorDocument::reload(ReloadFlag flag, ChangeType type)
{
Q_UNUSED(type)
if (flag == FlagIgnore)
return true;
return {};
emit aboutToReload();
const bool success = (open(errorString, filePath(), filePath()) == OpenResult::Success);
QString errorString;
const bool success = (open(&errorString, filePath(), filePath()) == OpenResult::Success);
emit reloadFinished(success);
return success;
if (!success)
return make_unexpected(errorString);
return {};
}
void ResourceEditorDocument::dirtyChanged(bool dirty)

View File

@@ -47,14 +47,13 @@ public:
return BehaviorSilent;
}
bool reload(QString *, ReloadFlag, ChangeType type) final
expected_str<void> reload(ReloadFlag, ChangeType) final
{
Q_UNUSED(type)
FolderNode *parent = m_node->parentFolderNode();
QTC_ASSERT(parent, return false);
QTC_ASSERT(parent, return make_unexpected(QString()));
parent->replaceSubtree(m_node, std::make_unique<ResourceTopLevelNode>(
m_node->filePath(), parent->filePath(), m_node->contents()));
return true;
return {};
}
private:

View File

@@ -110,16 +110,19 @@ bool ScxmlEditorDocument::isModified() const
return m_designWidget && m_designWidget->isDirty();
}
bool ScxmlEditorDocument::reload(QString *errorString, ReloadFlag flag, ChangeType type)
Utils::expected_str<void> ScxmlEditorDocument::reload(ReloadFlag flag, ChangeType type)
{
Q_UNUSED(type)
if (flag == FlagIgnore)
return true;
return {};
emit aboutToReload();
emit reloadRequested(errorString, filePath().toString());
const bool success = errorString->isEmpty();
QString errorString;
emit reloadRequested(&errorString, filePath().toString());
const bool success = errorString.isEmpty();
emit reloadFinished(success);
return success;
if (!success)
return make_unexpected(errorString);
return {};
}
bool ScxmlEditorDocument::supportsCodec(const QTextCodec *codec) const

View File

@@ -33,7 +33,7 @@ public:
bool shouldAutoSave() const override;
bool isSaveAsAllowed() const override;
bool isModified() const override;
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override;
Utils::expected_str<void> reload(ReloadFlag flag, ChangeType type) override;
bool supportsCodec(const QTextCodec *codec) const override;
// Internal

View File

@@ -74,19 +74,21 @@ void ObjectsMapDocument::setModified(bool modified)
emit changed();
}
bool ObjectsMapDocument::reload(QString *errorString,
Core::IDocument::ReloadFlag flag,
expected_str<void> ObjectsMapDocument::reload(Core::IDocument::ReloadFlag flag,
Core::IDocument::ChangeType type)
{
Q_UNUSED(type);
if (flag == FlagIgnore)
return true;
return {};
emit aboutToReload();
const bool success = (openImpl(errorString, filePath(), filePath()) == OpenResult::Success);
QString errorString;
const bool success = (openImpl(&errorString, filePath(), filePath()) == OpenResult::Success);
if (success)
setModified(false);
emit reloadFinished(success);
return success;
if (!success)
return make_unexpected(errorString);
return {};
}
bool ObjectsMapDocument::buildObjectsMapTree(const QByteArray &contents)

View File

@@ -26,7 +26,7 @@ public:
bool isModified() const override { return m_isModified; }
void setModified(bool modified);
bool isSaveAsAllowed() const override { return true; }
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override;
Utils::expected_str<void> reload(ReloadFlag flag, ChangeType type) override;
bool shouldAutoSave() const override { return true; }
bool setContents(const QByteArray &contents) override;

View File

@@ -791,19 +791,19 @@ Core::IDocument::OpenResult TextDocument::openImpl(QString *errorString,
return OpenResult::Success;
}
bool TextDocument::reload(QString *errorString, QTextCodec *codec)
expected_str<void> TextDocument::reload(QTextCodec *codec)
{
QTC_ASSERT(codec, return false);
QTC_ASSERT(codec, return make_unexpected(QString("No codec given")));
setCodec(codec);
return reload(errorString);
return reload();
}
bool TextDocument::reload(QString *errorString)
expected_str<void> TextDocument::reload()
{
return reload(errorString, filePath());
return reload(filePath());
}
bool TextDocument::reload(QString *errorString, const FilePath &realFilePath)
expected_str<void> TextDocument::reload(const FilePath &realFilePath)
{
emit aboutToReload();
auto documentLayout =
@@ -811,13 +811,16 @@ bool TextDocument::reload(QString *errorString, const FilePath &realFilePath)
if (documentLayout)
documentLayout->documentAboutToReload(this); // removes text marks non-permanently
bool success = openImpl(errorString, filePath(), realFilePath, /*reload =*/true)
QString errorString;
bool success = openImpl(&errorString, filePath(), realFilePath, /*reload =*/true)
== OpenResult::Success;
if (documentLayout)
documentLayout->documentReloaded(this); // re-adds text marks
emit reloadFinished(success);
return success;
if (!success)
return make_unexpected(errorString);
return {};
}
bool TextDocument::setPlainText(const QString &text)
@@ -834,24 +837,24 @@ bool TextDocument::setPlainText(const QString &text)
return true;
}
bool TextDocument::reload(QString *errorString, ReloadFlag flag, ChangeType type)
expected_str<void> TextDocument::reload(ReloadFlag flag, ChangeType type)
{
if (flag == FlagIgnore) {
if (type != TypeContents)
return true;
return {};
const bool wasModified = document()->isModified();
{
Utils::GuardLocker locker(d->m_modificationChangedGuard);
GuardLocker locker(d->m_modificationChangedGuard);
// hack to ensure we clean the clear state in QTextDocument
document()->setModified(false);
document()->setModified(true);
}
if (!wasModified)
modificationChanged(true);
return true;
return {};
}
return reload(errorString);
return reload();
}
void TextDocument::resetSyntaxHighlighter(const std::function<SyntaxHighlighter *()> &creator)

View File

@@ -105,7 +105,7 @@ public:
bool shouldAutoSave() const override;
bool isModified() const override;
bool isSaveAsAllowed() const override;
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override;
Utils::expected_str<void> reload(ReloadFlag flag, ChangeType type) override;
void setFilePath(const Utils::FilePath &newName) override;
ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const override;
@@ -117,8 +117,8 @@ public:
OpenResult open(QString *errorString, const Utils::FilePath &filePath,
const Utils::FilePath &realFilePath) override;
virtual bool reload(QString *errorString);
bool reload(QString *errorString, const Utils::FilePath &realFilePath);
virtual Utils::expected_str<void> reload();
Utils::expected_str<void> reload(const Utils::FilePath &realFilePath);
bool setPlainText(const QString &text);
QTextDocument *document() const;
@@ -127,7 +127,7 @@ public:
void resetSyntaxHighlighter(const SyntaxHighLighterCreator &creator);
SyntaxHighlighter *syntaxHighlighter() const;
bool reload(QString *errorString, QTextCodec *codec);
Utils::expected_str<void> reload(QTextCodec *codec);
void cleanWhitespace(const QTextCursor &cursor);
virtual void triggerPendingUpdates();

View File

@@ -1862,9 +1862,8 @@ void TextEditorWidget::selectEncoding()
const CodecSelectorResult result = Core::askForCodec(Core::ICore::dialogParent(), doc);
switch (result.action) {
case Core::CodecSelectorResult::Reload: {
QString errorString;
if (!doc->reload(&errorString, result.codec)) {
QMessageBox::critical(this, Tr::tr("File Error"), errorString);
if (expected_str<void> res = doc->reload(result.codec); !res) {
QMessageBox::critical(this, Tr::tr("File Error"), res.error());
break;
}
break;