Core: Return expected_str<void> from IDocumnet::autoSave()

... and adapt caller.

Change-Id: Ib139069a1a44116d661979e115e1a3daebf9b136
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2024-09-20 13:13:46 +02:00
parent 9e3925de87
commit bf8cfeb153
3 changed files with 8 additions and 11 deletions

View File

@@ -2382,9 +2382,8 @@ void EditorManagerPrivate::autoSave()
if (document->filePath().isEmpty() if (document->filePath().isEmpty()
|| !savePath.isWritableDir()) // FIXME: save them to a dedicated directory || !savePath.isWritableDir()) // FIXME: save them to a dedicated directory
continue; continue;
QString errorString; if (expected_str<void> res = document->autoSave(saveName); !res)
if (!document->autoSave(&errorString, saveName)) errors << res.error();
errors << errorString;
} }
if (!errors.isEmpty()) if (!errors.isEmpty())
QMessageBox::critical(ICore::dialogParent(), QMessageBox::critical(ICore::dialogParent(),

View File

@@ -647,15 +647,13 @@ void IDocument::setMimeType(const QString &mimeType)
/*! /*!
\internal \internal
*/ */
bool IDocument::autoSave(QString *errorString, const FilePath &filePath) expected_str<void> IDocument::autoSave(const FilePath &filePath)
{ {
const expected_str<void> res = save(filePath, true); if (const expected_str<void> res = save(filePath, true); !res)
if (!res) { return res;
*errorString = res.error();
return false;
}
d->autoSavePath = filePath; d->autoSavePath = filePath;
return true; return {};
} }
static const char kRestoredAutoSave[] = "RestoredAutoSave"; static const char kRestoredAutoSave[] = "RestoredAutoSave";

View File

@@ -104,7 +104,7 @@ public:
void checkPermissions(); void checkPermissions();
bool autoSave(QString *errorString, const Utils::FilePath &filePath); Utils::expected_str<void> autoSave(const Utils::FilePath &filePath);
void setRestoredFrom(const Utils::FilePath &path); void setRestoredFrom(const Utils::FilePath &path);
void removeAutoSaveFile(); void removeAutoSaveFile();