forked from qt-creator/qt-creator
Utils: Use the new Result class in some FilePath functions
Change-Id: I3ebabbc7dbf690b3e134993d5a2aa3e89a7be277 Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -5,9 +5,9 @@
|
||||
|
||||
#include "utils_global.h"
|
||||
|
||||
#include "expected.h"
|
||||
#include "filepathinfo.h"
|
||||
#include "osspecificaspects.h"
|
||||
#include "result.h"
|
||||
#include "utiltypes.h"
|
||||
|
||||
#include <QDir>
|
||||
|
@@ -1517,10 +1517,10 @@ private:
|
||||
|
||||
bool isSaveAsAllowed() const override { return false; }
|
||||
|
||||
expected_str<void> saveImpl(const FilePath &filePath, bool autoSave) override
|
||||
Result saveImpl(const FilePath &filePath, bool autoSave) override
|
||||
{
|
||||
m_editorWidget->preSave();
|
||||
expected_str<void> result = TextDocument::saveImpl(filePath, autoSave);
|
||||
Result result = TextDocument::saveImpl(filePath, autoSave);
|
||||
m_editorWidget->postSave();
|
||||
return result;
|
||||
}
|
||||
|
@@ -119,8 +119,8 @@ public:
|
||||
|
||||
bool isSaveAsAllowed() const final { return true; }
|
||||
|
||||
Utils::expected_str<void> reload(ReloadFlag flag, ChangeType type) final;
|
||||
Utils::expected_str<void> saveImpl(const Utils::FilePath &filePath, bool autoSave) final;
|
||||
Utils::Result reload(ReloadFlag flag, ChangeType type) final;
|
||||
Utils::Result saveImpl(const Utils::FilePath &filePath, bool autoSave) final;
|
||||
|
||||
void fetchData(quint64 address) const { if (m_fetchDataHandler) m_fetchDataHandler(address); }
|
||||
void requestNewWindow(quint64 address) { if (m_newWindowRequestHandler) m_newWindowRequestHandler(address); }
|
||||
@@ -156,7 +156,7 @@ public:
|
||||
void addData(quint64 addr, const QByteArray &data);
|
||||
void updateContents();
|
||||
|
||||
expected_str<void> save(const FilePath &oldFilePath, const FilePath &newFilePath);
|
||||
Result save(const FilePath &oldFilePath, const FilePath &newFilePath);
|
||||
void clear();
|
||||
|
||||
void undo();
|
||||
@@ -614,7 +614,7 @@ void BinEditorDocument::setModified(bool modified)
|
||||
emit changed();
|
||||
}
|
||||
|
||||
expected_str<void> BinEditorDocument::save(const FilePath &oldFilePath, const FilePath &newFilePath)
|
||||
Result BinEditorDocument::save(const FilePath &oldFilePath, const FilePath &newFilePath)
|
||||
{
|
||||
if (oldFilePath != newFilePath) {
|
||||
// Get a unique temporary file name
|
||||
@@ -623,19 +623,19 @@ expected_str<void> BinEditorDocument::save(const FilePath &oldFilePath, const Fi
|
||||
const auto result = TemporaryFilePath::create(
|
||||
newFilePath.stringAppended("_XXXXXX.new"));
|
||||
if (!result)
|
||||
return make_unexpected(result.error());
|
||||
return Result::Error(result.error());
|
||||
tmpName = (*result)->filePath();
|
||||
}
|
||||
|
||||
if (expected_str<void> res = oldFilePath.copyFile(tmpName); !res)
|
||||
if (Result res = oldFilePath.copyFile(tmpName); !res)
|
||||
return res;
|
||||
|
||||
if (newFilePath.exists()) {
|
||||
if (expected_str<void> res = newFilePath.removeFile(); !res)
|
||||
if (Result res = newFilePath.removeFile(); !res)
|
||||
return res;
|
||||
}
|
||||
|
||||
if (expected_str<void> res = tmpName.renameFile(newFilePath); !res)
|
||||
if (Result res = tmpName.renameFile(newFilePath); !res)
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -661,10 +661,10 @@ expected_str<void> BinEditorDocument::save(const FilePath &oldFilePath, const Fi
|
||||
|
||||
QString errorString;
|
||||
if (!saver.finalize(&errorString))
|
||||
return make_unexpected(errorString);
|
||||
return Result::Error(errorString);
|
||||
|
||||
setModified(false);
|
||||
return {};
|
||||
return Result::Ok;
|
||||
}
|
||||
|
||||
void BinEditorDocument::setSizes(quint64 startAddr, qint64 range, int blockSize)
|
||||
@@ -2181,28 +2181,26 @@ bool BinEditorDocument::isModified() const
|
||||
return m_undoStack.size() != m_unmodifiedState;
|
||||
}
|
||||
|
||||
expected_str<void> BinEditorDocument::reload(ReloadFlag flag, ChangeType type)
|
||||
Result BinEditorDocument::reload(ReloadFlag flag, ChangeType type)
|
||||
{
|
||||
Q_UNUSED(type)
|
||||
if (flag == FlagIgnore)
|
||||
return {};
|
||||
return Result::Ok;
|
||||
emit aboutToReload();
|
||||
clear();
|
||||
QString errorString;
|
||||
const bool success = (openImpl(&errorString, filePath()) == OpenResult::Success);
|
||||
emit reloadFinished(success);
|
||||
if (!success)
|
||||
return make_unexpected(errorString);
|
||||
return {};
|
||||
return Result(success, errorString);
|
||||
}
|
||||
|
||||
expected_str<void> BinEditorDocument::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
Result BinEditorDocument::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
{
|
||||
QTC_ASSERT(!autoSave, return {}); // bineditor does not support autosave - it would be a bit expensive
|
||||
if (expected_str<void> res = save(this->filePath(), filePath); !res)
|
||||
QTC_ASSERT(!autoSave, return Result::Ok); // bineditor does not support autosave - it would be a bit expensive
|
||||
if (Result res = save(this->filePath(), filePath); !res)
|
||||
return res;
|
||||
setFilePath(filePath);
|
||||
return {};
|
||||
return Result::Ok;
|
||||
}
|
||||
|
||||
class BinEditorImpl final : public IEditor, public EditorService
|
||||
|
@@ -1994,7 +1994,7 @@ void ClangdTestCompletion::testCompleteAfterProjectChange()
|
||||
EditorManager::openEditor(project()->projectFilePath()));
|
||||
QVERIFY(proFileEditor);
|
||||
proFileEditor->insert("DEFINES += PROJECT_CONFIGURATION_1\n");
|
||||
const expected_str<void> res = proFileEditor->document()->save();
|
||||
const Result res = proFileEditor->document()->save();
|
||||
QVERIFY2(res, qPrintable(res.error()));
|
||||
QVERIFY(waitForSignalOrTimeout(project(), &Project::anyParsingFinished, timeOutInMs()));
|
||||
QVERIFY(waitForSignalOrTimeout(LanguageClientManager::instance(),
|
||||
|
@@ -41,7 +41,7 @@ void VirtualFileSystemOverlay::update()
|
||||
saved.path = m_root.filePath(doc->filePath().fileName() + ".auto");
|
||||
while (saved.path.exists())
|
||||
saved.path = saved.path.stringAppended(".1");
|
||||
if (Utils::expected_str<void> res = doc->save(saved.path, true); !res) {
|
||||
if (Utils::Result res = doc->save(saved.path, true); !res) {
|
||||
qCDebug(LOG) << res.error();
|
||||
continue;
|
||||
}
|
||||
|
@@ -154,7 +154,7 @@ public:
|
||||
const Utils::FilePath &filePath,
|
||||
const Utils::FilePath &realFilePath) override;
|
||||
|
||||
Utils::expected_str<void> saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
|
||||
Result saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
|
||||
|
||||
bool setContents(const QByteArray &contents) override;
|
||||
|
||||
@@ -409,7 +409,7 @@ Core::IDocument::OpenResult JsonSettingsDocument::open(QString *errorString,
|
||||
return OpenResult::Success;
|
||||
}
|
||||
|
||||
expected_str<void> JsonSettingsDocument::saveImpl(const FilePath &newFilePath, bool autoSave)
|
||||
Result JsonSettingsDocument::saveImpl(const FilePath &newFilePath, bool autoSave)
|
||||
{
|
||||
Store store;
|
||||
|
||||
@@ -435,10 +435,10 @@ expected_str<void> JsonSettingsDocument::saveImpl(const FilePath &newFilePath, b
|
||||
|
||||
expected_str<qint64> result = path.writeFileContents(jsonFromStore(store));
|
||||
if (!result)
|
||||
return make_unexpected(result.error());
|
||||
return Result::Error(result.error());
|
||||
|
||||
emit changed();
|
||||
return {};
|
||||
return Result::Ok;
|
||||
}
|
||||
|
||||
bool JsonSettingsDocument::isModified() const
|
||||
|
@@ -715,7 +715,7 @@ bool DocumentManager::saveDocument(IDocument *document,
|
||||
expectFileChange(savePath); // This only matters to other IDocuments which refer to this file
|
||||
bool addWatcher = removeDocument(document); // So that our own IDocument gets no notification at all
|
||||
|
||||
if (const expected_str<void> res = document->save(savePath, false); !res) {
|
||||
if (const Result res = document->save(savePath, false); !res) {
|
||||
if (isReadOnly) {
|
||||
QFile ofi(savePath.toString());
|
||||
// Check whether the existing file is writable
|
||||
@@ -1188,13 +1188,12 @@ void DocumentManager::checkForReload()
|
||||
removeFileInfo(document);
|
||||
addFileInfos({document});
|
||||
|
||||
expected_str<void> success;
|
||||
Result success = Result::Ok;
|
||||
// we've got some modification
|
||||
document->checkPermissions();
|
||||
// check if it's contents or permissions:
|
||||
if (!type) {
|
||||
// Only permission change
|
||||
success = {};
|
||||
// now we know it's a content change or file was removed
|
||||
} else if (defaultBehavior == IDocument::ReloadUnmodified && type == IDocument::TypeContents
|
||||
&& !document->isModified()) {
|
||||
|
@@ -2382,7 +2382,7 @@ void EditorManagerPrivate::autoSave()
|
||||
if (document->filePath().isEmpty()
|
||||
|| !savePath.isWritableDir()) // FIXME: save them to a dedicated directory
|
||||
continue;
|
||||
if (expected_str<void> res = document->autoSave(saveName); !res)
|
||||
if (Result res = document->autoSave(saveName); !res)
|
||||
errors << res.error();
|
||||
}
|
||||
if (!errors.isEmpty())
|
||||
@@ -2610,8 +2610,7 @@ void EditorManagerPrivate::revertToSaved(IDocument *document)
|
||||
}
|
||||
}
|
||||
|
||||
const expected_str<void> res = document->reload(IDocument::FlagReload, IDocument::TypeContents);
|
||||
if (!res)
|
||||
if (Result res = document->reload(IDocument::FlagReload, IDocument::TypeContents); !res)
|
||||
QMessageBox::critical(ICore::dialogParent(), ::Core::Tr::tr("File Error"), res.error());
|
||||
}
|
||||
|
||||
|
@@ -343,11 +343,11 @@ IDocument::OpenResult IDocument::open(QString *errorString, const Utils::FilePat
|
||||
\sa saved()
|
||||
\sa filePath()
|
||||
*/
|
||||
expected_str<void> IDocument::save(const FilePath &filePath, bool autoSave)
|
||||
Result IDocument::save(const FilePath &filePath, bool autoSave)
|
||||
{
|
||||
const FilePath savePath = filePath.isEmpty() ? this->filePath() : filePath;
|
||||
emit aboutToSave(savePath, autoSave);
|
||||
const expected_str<void> res = saveImpl(savePath, autoSave);
|
||||
const Result res = saveImpl(savePath, autoSave);
|
||||
if (res)
|
||||
emit saved(savePath, autoSave);
|
||||
return res;
|
||||
@@ -364,11 +364,11 @@ expected_str<void> IDocument::save(const FilePath &filePath, bool autoSave)
|
||||
|
||||
The default implementation does nothing and returns \c false.
|
||||
*/
|
||||
expected_str<void> IDocument::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
Result IDocument::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
{
|
||||
Q_UNUSED(filePath)
|
||||
Q_UNUSED(autoSave)
|
||||
return make_unexpected(Tr::tr("Not implemented"));
|
||||
return Result::Error(Tr::tr("Not implemented"));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -467,11 +467,11 @@ IDocument::ReloadBehavior IDocument::reloadBehavior(ChangeTrigger trigger, Chang
|
||||
\sa reloadFinished()
|
||||
\sa changed()
|
||||
*/
|
||||
Utils::expected_str<void> IDocument::reload(ReloadFlag flag, ChangeType type)
|
||||
Result IDocument::reload(ReloadFlag flag, ChangeType type)
|
||||
{
|
||||
Q_UNUSED(flag)
|
||||
Q_UNUSED(type)
|
||||
return {};
|
||||
return Result::Ok;
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -647,13 +647,13 @@ void IDocument::setMimeType(const QString &mimeType)
|
||||
/*!
|
||||
\internal
|
||||
*/
|
||||
expected_str<void> IDocument::autoSave(const FilePath &filePath)
|
||||
Result IDocument::autoSave(const FilePath &filePath)
|
||||
{
|
||||
if (const expected_str<void> res = save(filePath, true); !res)
|
||||
if (const Result res = save(filePath, true); !res)
|
||||
return res;
|
||||
|
||||
d->autoSavePath = filePath;
|
||||
return {};
|
||||
return Result::Ok;
|
||||
}
|
||||
|
||||
static const char kRestoredAutoSave[] = "RestoredAutoSave";
|
||||
|
@@ -68,7 +68,7 @@ public:
|
||||
|
||||
virtual OpenResult open(QString *errorString, const Utils::FilePath &filePath, const Utils::FilePath &realFilePath);
|
||||
|
||||
Utils::expected_str<void> save(const Utils::FilePath &filePath = {}, bool autoSave = false);
|
||||
Utils::Result save(const Utils::FilePath &filePath = {}, bool autoSave = false);
|
||||
|
||||
virtual QByteArray contents() const;
|
||||
virtual bool setContents(const QByteArray &contents);
|
||||
@@ -100,11 +100,11 @@ public:
|
||||
void setSuspendAllowed(bool value);
|
||||
|
||||
virtual ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
|
||||
virtual Utils::expected_str<void> reload(ReloadFlag flag, ChangeType type);
|
||||
virtual Utils::Result reload(ReloadFlag flag, ChangeType type);
|
||||
|
||||
void checkPermissions();
|
||||
|
||||
Utils::expected_str<void> autoSave(const Utils::FilePath &filePath);
|
||||
Utils::Result autoSave(const Utils::FilePath &filePath);
|
||||
void setRestoredFrom(const Utils::FilePath &path);
|
||||
void removeAutoSaveFile();
|
||||
|
||||
@@ -131,8 +131,7 @@ signals:
|
||||
void filePathChanged(const Utils::FilePath &oldName, const Utils::FilePath &newName);
|
||||
|
||||
protected:
|
||||
virtual Utils::expected_str<void>
|
||||
saveImpl(const Utils::FilePath &filePath = {}, bool autoSave = false);
|
||||
virtual Utils::Result saveImpl(const Utils::FilePath &filePath = {}, bool autoSave = false);
|
||||
|
||||
private:
|
||||
Internal::IDocumentPrivate *d;
|
||||
|
@@ -489,7 +489,7 @@ TextEditor::TabSettings CppEditorDocument::tabSettings() const
|
||||
return indenter()->tabSettings().value_or(TextEditor::TextDocument::tabSettings());
|
||||
}
|
||||
|
||||
expected_str<void> CppEditorDocument::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
Result CppEditorDocument::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
{
|
||||
if (!indenter()->formatOnSave() || autoSave)
|
||||
return TextEditor::TextDocument::saveImpl(filePath, autoSave);
|
||||
|
@@ -67,7 +67,7 @@ signals:
|
||||
|
||||
protected:
|
||||
void applyFontSettings() override;
|
||||
Utils::expected_str<void> saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
|
||||
Utils::Result saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
|
||||
|
||||
private:
|
||||
void invalidateFormatterCache();
|
||||
|
@@ -11,8 +11,6 @@
|
||||
|
||||
#include <QtTest>
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
namespace {
|
||||
|
||||
class FindFirstFunctionDefinition: protected CPlusPlus::ASTVisitor
|
||||
@@ -150,7 +148,7 @@ void LocalSymbolsTest::test()
|
||||
QFETCH(QList<Result>, expectedUses);
|
||||
|
||||
CPlusPlus::Document::Ptr document =
|
||||
CPlusPlus::Document::create(FilePath::fromPathPart(u"test.cpp"));
|
||||
CPlusPlus::Document::create(Utils::FilePath::fromPathPart(u"test.cpp"));
|
||||
document->setUtf8Source(source);
|
||||
document->check();
|
||||
QVERIFY(document->diagnosticMessages().isEmpty());
|
||||
|
@@ -84,12 +84,12 @@ Core::IDocument::OpenResult FormWindowFile::open(QString *errorString,
|
||||
return OpenResult::Success;
|
||||
}
|
||||
|
||||
expected_str<void> FormWindowFile::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
Result FormWindowFile::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
{
|
||||
QTC_ASSERT(m_formWindow, return make_unexpected(QString()));
|
||||
|
||||
if (!m_formWindow)
|
||||
return Result::Error("ASSERT: FormWindoFile: !m_formWindow");
|
||||
if (filePath.isEmpty())
|
||||
return make_unexpected(QString());
|
||||
return Result::Error("ASSERT: FormWindowFile: filePath.isEmpty()");
|
||||
|
||||
const QString oldFormName = m_formWindow->fileName();
|
||||
if (!autoSave)
|
||||
@@ -97,22 +97,19 @@ expected_str<void> FormWindowFile::saveImpl(const FilePath &filePath, bool autoS
|
||||
QString errorString;
|
||||
const bool writeOK = writeFile(filePath, &errorString);
|
||||
m_shouldAutoSave = false;
|
||||
if (autoSave) {
|
||||
if (writeOK)
|
||||
return {};
|
||||
return make_unexpected(errorString);
|
||||
}
|
||||
if (autoSave)
|
||||
return Result(writeOK, errorString);
|
||||
|
||||
if (!writeOK) {
|
||||
m_formWindow->setFileName(oldFormName);
|
||||
return make_unexpected(errorString);
|
||||
return Result::Error(errorString);
|
||||
}
|
||||
|
||||
m_formWindow->setDirty(false);
|
||||
setFilePath(filePath);
|
||||
updateIsModified();
|
||||
|
||||
return {};
|
||||
return Result::Ok;
|
||||
}
|
||||
|
||||
QByteArray FormWindowFile::contents() const
|
||||
@@ -189,11 +186,11 @@ bool FormWindowFile::isSaveAsAllowed() const
|
||||
return true;
|
||||
}
|
||||
|
||||
expected_str<void> FormWindowFile::reload(ReloadFlag flag, ChangeType type)
|
||||
Result FormWindowFile::reload(ReloadFlag flag, ChangeType type)
|
||||
{
|
||||
if (flag == FlagIgnore) {
|
||||
if (!m_formWindow || type != TypeContents)
|
||||
return {};
|
||||
return Result::Ok;
|
||||
const bool wasModified = m_formWindow->isDirty();
|
||||
{
|
||||
Utils::GuardLocker locker(m_modificationChangedGuard);
|
||||
@@ -203,16 +200,14 @@ expected_str<void> FormWindowFile::reload(ReloadFlag flag, ChangeType type)
|
||||
}
|
||||
if (!wasModified)
|
||||
updateIsModified();
|
||||
return {};
|
||||
return Result::Ok;
|
||||
} else {
|
||||
emit aboutToReload();
|
||||
QString errorString;
|
||||
const bool success
|
||||
= (open(&errorString, filePath(), filePath()) == OpenResult::Success);
|
||||
emit reloadFinished(success);
|
||||
if (!success)
|
||||
return make_unexpected(errorString);
|
||||
return {};
|
||||
return Result(success, errorString);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -33,7 +33,7 @@ public:
|
||||
bool shouldAutoSave() const override;
|
||||
bool isModified() const override;
|
||||
bool isSaveAsAllowed() const override;
|
||||
Utils::expected_str<void> reload(ReloadFlag flag, ChangeType type) override;
|
||||
Utils::Result reload(ReloadFlag flag, ChangeType type) override;
|
||||
QString fallbackSaveAsFileName() const override;
|
||||
bool supportsCodec(const QTextCodec *codec) const override;
|
||||
|
||||
@@ -52,7 +52,7 @@ public:
|
||||
void updateIsModified();
|
||||
|
||||
protected:
|
||||
Utils::expected_str<void> saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
|
||||
Utils::Result saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
|
||||
|
||||
private:
|
||||
void slotFormWindowRemoved(QDesignerFormWindowInterface *w);
|
||||
|
@@ -234,18 +234,18 @@ bool DiffEditorDocument::isSaveAsAllowed() const
|
||||
return state() == LoadOK;
|
||||
}
|
||||
|
||||
expected_str<void> DiffEditorDocument::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
Result DiffEditorDocument::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
{
|
||||
Q_UNUSED(autoSave)
|
||||
|
||||
QString errorString;
|
||||
if (state() != LoadOK)
|
||||
return make_unexpected(errorString);
|
||||
return Result::Error(errorString);
|
||||
|
||||
const bool ok = write(filePath, format(), plainText(), &errorString);
|
||||
|
||||
if (!ok)
|
||||
return make_unexpected(errorString);
|
||||
return Result::Error(errorString);
|
||||
|
||||
setController(nullptr);
|
||||
setDescription({});
|
||||
@@ -256,7 +256,7 @@ expected_str<void> DiffEditorDocument::saveImpl(const FilePath &filePath, bool a
|
||||
setPreferredDisplayName({});
|
||||
emit temporaryStateChanged();
|
||||
|
||||
return {};
|
||||
return Result::Ok;
|
||||
}
|
||||
|
||||
void DiffEditorDocument::reload()
|
||||
@@ -267,16 +267,14 @@ void DiffEditorDocument::reload()
|
||||
reload(Core::IDocument::FlagReload, Core::IDocument::TypeContents);
|
||||
}
|
||||
|
||||
expected_str<void> DiffEditorDocument::reload(ReloadFlag flag, ChangeType type)
|
||||
Result DiffEditorDocument::reload(ReloadFlag flag, ChangeType type)
|
||||
{
|
||||
Q_UNUSED(type)
|
||||
if (flag == FlagIgnore)
|
||||
return {};
|
||||
return Result::Ok;
|
||||
QString errorString;
|
||||
bool success = open(&errorString, filePath(), filePath()) == OpenResult::Success;
|
||||
if (!success)
|
||||
return make_unexpected(errorString);
|
||||
return {};
|
||||
return Result(success, errorString);
|
||||
}
|
||||
|
||||
Core::IDocument::OpenResult DiffEditorDocument::open(QString *errorString, const FilePath &filePath,
|
||||
|
@@ -61,7 +61,7 @@ public:
|
||||
|
||||
bool isSaveAsAllowed() const override;
|
||||
void reload();
|
||||
Utils::expected_str<void> reload(ReloadFlag flag, ChangeType type) override;
|
||||
Utils::Result reload(ReloadFlag flag, ChangeType type) override;
|
||||
OpenResult open(QString *errorString, const Utils::FilePath &filePath,
|
||||
const Utils::FilePath &realFilePath) override;
|
||||
bool selectEncoding();
|
||||
@@ -75,7 +75,7 @@ signals:
|
||||
void descriptionChanged();
|
||||
|
||||
protected:
|
||||
Utils::expected_str<void> saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
|
||||
Utils::Result saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
|
||||
|
||||
private:
|
||||
void beginReload();
|
||||
|
@@ -84,7 +84,7 @@ public:
|
||||
return BehaviorSilent;
|
||||
}
|
||||
|
||||
expected_str<void> reload(ReloadFlag flag, ChangeType type) final;
|
||||
Result reload(ReloadFlag flag, ChangeType type) final;
|
||||
|
||||
private:
|
||||
GenericProject *m_project = nullptr;
|
||||
@@ -695,14 +695,14 @@ void GenericProject::configureAsExampleProject(Kit *kit)
|
||||
setup(infoList);
|
||||
}
|
||||
|
||||
expected_str<void> GenericProjectFile::reload(IDocument::ReloadFlag flag, IDocument::ChangeType type)
|
||||
Result GenericProjectFile::reload(IDocument::ReloadFlag flag, IDocument::ChangeType type)
|
||||
{
|
||||
Q_UNUSED(flag)
|
||||
Q_UNUSED(type)
|
||||
if (Target *t = m_project->activeTarget())
|
||||
static_cast<GenericBuildSystem *>(t->buildSystem())->refresh(m_options);
|
||||
|
||||
return {};
|
||||
return Result::Ok;
|
||||
}
|
||||
|
||||
void GenericProject::editFilesTriggered()
|
||||
|
@@ -146,19 +146,17 @@ Core::IDocument::ReloadBehavior ImageViewerFile::reloadBehavior(ChangeTrigger st
|
||||
return BehaviorAsk;
|
||||
}
|
||||
|
||||
expected_str<void> ImageViewerFile::reload(Core::IDocument::ReloadFlag flag,
|
||||
Core::IDocument::ChangeType type)
|
||||
Result ImageViewerFile::reload(Core::IDocument::ReloadFlag flag,
|
||||
Core::IDocument::ChangeType type)
|
||||
{
|
||||
Q_UNUSED(type)
|
||||
if (flag == FlagIgnore)
|
||||
return {};
|
||||
return Result::Ok;
|
||||
emit aboutToReload();
|
||||
QString errorString;
|
||||
bool success = (openImpl(&errorString, filePath()) == OpenResult::Success);
|
||||
emit reloadFinished(success);
|
||||
if (!success)
|
||||
return make_unexpected(errorString);
|
||||
return {};
|
||||
return Result(success, errorString);
|
||||
}
|
||||
|
||||
QMovie *ImageViewerFile::movie() const
|
||||
|
@@ -39,7 +39,7 @@ public:
|
||||
const Utils::FilePath &realFilePath) override;
|
||||
|
||||
ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const override;
|
||||
Utils::expected_str<void> reload(ReloadFlag flag, ChangeType type) override;
|
||||
Utils::Result reload(ReloadFlag flag, ChangeType type) override;
|
||||
|
||||
QMovie *movie() const;
|
||||
|
||||
|
@@ -52,16 +52,16 @@ Core::IDocument::OpenResult ModelDocument::open(QString *errorString,
|
||||
return result;
|
||||
}
|
||||
|
||||
expected_str<void> ModelDocument::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
Result ModelDocument::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
{
|
||||
if (!d->documentController)
|
||||
return make_unexpected(Tr::tr("No model loaded. Cannot save."));
|
||||
return Result::Error(Tr::tr("No model loaded. Cannot save."));
|
||||
|
||||
d->documentController->projectController()->setFileName(filePath);
|
||||
try {
|
||||
d->documentController->projectController()->save();
|
||||
} catch (const qmt::Exception &ex) {
|
||||
return make_unexpected(ex.errorMessage());
|
||||
return Result::Error(ex.errorMessage());
|
||||
}
|
||||
|
||||
if (autoSave) {
|
||||
@@ -71,7 +71,7 @@ expected_str<void> ModelDocument::saveImpl(const FilePath &filePath, bool autoSa
|
||||
emit changed();
|
||||
}
|
||||
|
||||
return {};
|
||||
return Result::Ok;
|
||||
}
|
||||
|
||||
bool ModelDocument::shouldAutoSave() const
|
||||
@@ -89,22 +89,22 @@ bool ModelDocument::isSaveAsAllowed() const
|
||||
return true;
|
||||
}
|
||||
|
||||
Utils::expected_str<void> ModelDocument::reload(Core::IDocument::ReloadFlag flag,
|
||||
Core::IDocument::ChangeType type)
|
||||
Result ModelDocument::reload(Core::IDocument::ReloadFlag flag,
|
||||
Core::IDocument::ChangeType type)
|
||||
{
|
||||
Q_UNUSED(type)
|
||||
if (flag == FlagIgnore)
|
||||
return {};
|
||||
return Result::Ok;
|
||||
try {
|
||||
d->documentController->loadProject(filePath());
|
||||
} catch (const qmt::FileNotFoundException &ex) {
|
||||
return make_unexpected(ex.errorMessage());
|
||||
return Result::Error(ex.errorMessage());
|
||||
} catch (const qmt::Exception &ex) {
|
||||
return make_unexpected(Tr::tr("Could not open \"%1\" for reading: %2.")
|
||||
return Result::Error(Tr::tr("Could not open \"%1\" for reading: %2.")
|
||||
.arg(filePath().toUserOutput(), ex.errorMessage()));
|
||||
}
|
||||
emit contentSet();
|
||||
return {};
|
||||
return Result::Ok;
|
||||
}
|
||||
|
||||
ExtDocumentController *ModelDocument::documentController() const
|
||||
|
@@ -33,14 +33,14 @@ public:
|
||||
bool shouldAutoSave() const override;
|
||||
bool isModified() const override;
|
||||
bool isSaveAsAllowed() const override;
|
||||
Utils::expected_str<void> reload(ReloadFlag flag, ChangeType type) override;
|
||||
Utils::Result reload(ReloadFlag flag, ChangeType type) override;
|
||||
|
||||
ExtDocumentController *documentController() const;
|
||||
|
||||
OpenResult load(QString *errorString, const Utils::FilePath &fileName);
|
||||
|
||||
protected:
|
||||
Utils::expected_str<void> saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
|
||||
Utils::Result saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
|
||||
|
||||
private:
|
||||
ModelDocumentPrivate *d;
|
||||
|
@@ -145,13 +145,13 @@ public:
|
||||
return BehaviorSilent;
|
||||
}
|
||||
|
||||
expected_str<void> reload(ReloadFlag flag, ChangeType type) final
|
||||
Result reload(ReloadFlag flag, ChangeType type) final
|
||||
{
|
||||
Q_UNUSED(flag)
|
||||
Q_UNUSED(type)
|
||||
|
||||
emit m_project->projectFileIsDirty(filePath());
|
||||
return {};
|
||||
return Result::Ok;
|
||||
}
|
||||
|
||||
private:
|
||||
|
@@ -45,19 +45,17 @@ Core::IDocument::ReloadBehavior TaskFile::reloadBehavior(ChangeTrigger state, Ch
|
||||
return BehaviorSilent;
|
||||
}
|
||||
|
||||
expected_str<void> TaskFile::reload(ReloadFlag flag, ChangeType type)
|
||||
Result TaskFile::reload(ReloadFlag flag, ChangeType type)
|
||||
{
|
||||
Q_UNUSED(flag)
|
||||
|
||||
if (type == TypeRemoved) {
|
||||
deleteLater();
|
||||
return {};
|
||||
return Result::Ok;
|
||||
}
|
||||
QString errorString;
|
||||
bool success = load(&errorString, filePath());
|
||||
if (!success)
|
||||
return make_unexpected(errorString);
|
||||
return {};
|
||||
return Result(success, errorString);
|
||||
}
|
||||
|
||||
static Task::TaskType typeFrom(const QString &typeName)
|
||||
|
@@ -24,7 +24,7 @@ public:
|
||||
TaskFile(QObject *parent);
|
||||
|
||||
ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const override;
|
||||
Utils::expected_str<void> reload(ReloadFlag flag, ChangeType type) override;
|
||||
Utils::Result reload(ReloadFlag flag, ChangeType type) override;
|
||||
|
||||
bool load(QString *errorString, const Utils::FilePath &fileName);
|
||||
|
||||
|
@@ -929,8 +929,7 @@ void QmakePriFile::save(const QStringList &lines)
|
||||
QStringList errorStrings;
|
||||
Core::IDocument *document = Core::DocumentModel::documentForFilePath(filePath());
|
||||
if (document) {
|
||||
expected_str<void> res =
|
||||
document->reload(Core::IDocument::FlagReload, Core::IDocument::TypeContents);
|
||||
Result res = document->reload(Core::IDocument::FlagReload, Core::IDocument::TypeContents);
|
||||
if (!res)
|
||||
errorStrings << res.error();
|
||||
}
|
||||
|
@@ -101,13 +101,13 @@ public:
|
||||
Q_UNUSED(type)
|
||||
return BehaviorSilent;
|
||||
}
|
||||
expected_str<void> reload(ReloadFlag flag, ChangeType type) override
|
||||
Result reload(ReloadFlag flag, ChangeType type) override
|
||||
{
|
||||
Q_UNUSED(flag)
|
||||
Q_UNUSED(type)
|
||||
if (m_priFile)
|
||||
m_priFile->scheduleUpdate();
|
||||
return {};
|
||||
return Result::Ok;
|
||||
}
|
||||
|
||||
void setPriFile(QmakePriFile *priFile) { m_priFile = priFile; }
|
||||
|
@@ -242,7 +242,7 @@ void AssetExporter::onQmlFileLoaded()
|
||||
.arg(designDocument->displayName()));
|
||||
} else {
|
||||
exportComponent(m_view->rootModelNode());
|
||||
if (Utils::expected_str<void> res = m_view->saveQmlFile(); !res) {
|
||||
if (Utils::Result res = m_view->saveQmlFile(); !res) {
|
||||
ExportNotification::addError(tr("Error saving component file. %1")
|
||||
.arg(res.error().isEmpty()? tr("Unknown") : res.error()));
|
||||
}
|
||||
|
@@ -49,11 +49,11 @@ bool AssetExporterView::loadQmlFile(const Utils::FilePath &path, uint timeoutSec
|
||||
return true;
|
||||
}
|
||||
|
||||
Utils::expected_str<void> AssetExporterView::saveQmlFile() const
|
||||
Utils::Result AssetExporterView::saveQmlFile() const
|
||||
{
|
||||
if (!m_currentEditor) {
|
||||
qCDebug(loggerWarn) << "Saving QML file failed. No editor.";
|
||||
return Utils::make_unexpected(QString("Saving QML file failed. No editor."));
|
||||
return Utils::Result::Error("Saving QML file failed. No editor.");
|
||||
}
|
||||
|
||||
return m_currentEditor->document()->save();
|
||||
|
@@ -28,7 +28,7 @@ public:
|
||||
AssetExporterView(ExternalDependenciesInterface &externalDependencies);
|
||||
|
||||
bool loadQmlFile(const Utils::FilePath &path, uint timeoutSecs = 10);
|
||||
Utils::expected_str<void> saveQmlFile() const;
|
||||
Utils::Result saveQmlFile() const;
|
||||
|
||||
void modelAttached(Model *model) override;
|
||||
void instanceInformationsChanged(const QMultiHash<ModelNode, InformationName> &informationChangeHash) override;
|
||||
|
@@ -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; }
|
||||
expected_str<void> reload(ReloadFlag flag, ChangeType type) final;
|
||||
Result reload(ReloadFlag flag, ChangeType type) final;
|
||||
void setFilePath(const FilePath &newName) final;
|
||||
void setBlockDirtyChanged(bool value) { m_blockDirtyChanged = value; }
|
||||
|
||||
@@ -67,7 +67,7 @@ signals:
|
||||
void loaded(bool success);
|
||||
|
||||
private:
|
||||
Utils::expected_str<void> saveImpl(const FilePath &filePath, bool autoSave) final;
|
||||
Result saveImpl(const FilePath &filePath, bool autoSave) final;
|
||||
void dirtyChanged(bool);
|
||||
|
||||
RelativeResourceModel m_model;
|
||||
@@ -209,20 +209,20 @@ IDocument::OpenResult ResourceEditorDocument::open(QString *errorString,
|
||||
return OpenResult::Success;
|
||||
}
|
||||
|
||||
expected_str<void> ResourceEditorDocument::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
Result ResourceEditorDocument::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
{
|
||||
if (debugResourceEditorW)
|
||||
qDebug() << ">ResourceEditorW::saveImpl: " << filePath;
|
||||
|
||||
if (filePath.isEmpty())
|
||||
return make_unexpected(QString()); // FIXME: better message
|
||||
return Result::Error("ASSERT: ResourceEditorDocument: filePath.isEmpty()");
|
||||
|
||||
m_blockDirtyChanged = true;
|
||||
m_model.setFilePath(filePath);
|
||||
if (!m_model.save()) {
|
||||
m_model.setFilePath(this->filePath());
|
||||
m_blockDirtyChanged = false;
|
||||
return make_unexpected(m_model.errorMessage());
|
||||
return Result::Error(m_model.errorMessage());
|
||||
}
|
||||
|
||||
m_shouldAutoSave = false;
|
||||
@@ -230,14 +230,14 @@ expected_str<void> ResourceEditorDocument::saveImpl(const FilePath &filePath, bo
|
||||
m_model.setFilePath(this->filePath());
|
||||
m_model.setDirty(true);
|
||||
m_blockDirtyChanged = false;
|
||||
return {};
|
||||
return Result::Ok;
|
||||
}
|
||||
|
||||
setFilePath(filePath);
|
||||
m_blockDirtyChanged = false;
|
||||
|
||||
emit changed();
|
||||
return {};
|
||||
return Result::Ok;
|
||||
}
|
||||
|
||||
bool ResourceEditorDocument::setContents(const QByteArray &contents)
|
||||
@@ -280,18 +280,16 @@ void ResourceEditorImpl::restoreState(const QByteArray &state)
|
||||
m_resourceEditor->restoreState(splitterState);
|
||||
}
|
||||
|
||||
expected_str<void> ResourceEditorDocument::reload(ReloadFlag flag, ChangeType type)
|
||||
Result ResourceEditorDocument::reload(ReloadFlag flag, ChangeType type)
|
||||
{
|
||||
Q_UNUSED(type)
|
||||
if (flag == FlagIgnore)
|
||||
return {};
|
||||
return Result::Ok;
|
||||
emit aboutToReload();
|
||||
QString errorString;
|
||||
const bool success = (open(&errorString, filePath(), filePath()) == OpenResult::Success);
|
||||
emit reloadFinished(success);
|
||||
if (!success)
|
||||
return make_unexpected(errorString);
|
||||
return {};
|
||||
return Result(success, errorString);
|
||||
}
|
||||
|
||||
void ResourceEditorDocument::dirtyChanged(bool dirty)
|
||||
|
@@ -47,13 +47,14 @@ public:
|
||||
return BehaviorSilent;
|
||||
}
|
||||
|
||||
expected_str<void> reload(ReloadFlag, ChangeType) final
|
||||
Result reload(ReloadFlag, ChangeType) final
|
||||
{
|
||||
FolderNode *parent = m_node->parentFolderNode();
|
||||
QTC_ASSERT(parent, return make_unexpected(QString()));
|
||||
if (!parent)
|
||||
return Result::Error("ASSERT: !parent");
|
||||
parent->replaceSubtree(m_node, std::make_unique<ResourceTopLevelNode>(
|
||||
m_node->filePath(), parent->filePath(), m_node->contents()));
|
||||
return {};
|
||||
return Result::Ok;
|
||||
}
|
||||
|
||||
private:
|
||||
|
@@ -58,22 +58,23 @@ Core::IDocument::OpenResult ScxmlEditorDocument::open(QString *errorString,
|
||||
return OpenResult::Success;
|
||||
}
|
||||
|
||||
Utils::expected_str<void> ScxmlEditorDocument::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
Result ScxmlEditorDocument::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
{
|
||||
if (filePath.isEmpty())
|
||||
return make_unexpected(QString());
|
||||
return Result::Error("ASSERT: ScxmlEditorDocument: filePath.isEmpty()");
|
||||
|
||||
bool dirty = m_designWidget->isDirty();
|
||||
|
||||
m_designWidget->setFileName(filePath.toString());
|
||||
if (!m_designWidget->save()) {
|
||||
m_designWidget->setFileName(this->filePath().toString());
|
||||
return make_unexpected(m_designWidget->errorMessage());
|
||||
return Result::Error(m_designWidget->errorMessage());
|
||||
}
|
||||
|
||||
if (autoSave) {
|
||||
m_designWidget->setFileName(this->filePath().toString());
|
||||
m_designWidget->save();
|
||||
return {};
|
||||
return Result::Ok;
|
||||
}
|
||||
|
||||
setFilePath(filePath);
|
||||
@@ -81,7 +82,7 @@ Utils::expected_str<void> ScxmlEditorDocument::saveImpl(const FilePath &filePath
|
||||
if (dirty != m_designWidget->isDirty())
|
||||
emit changed();
|
||||
|
||||
return {};
|
||||
return Result::Ok;
|
||||
}
|
||||
|
||||
void ScxmlEditorDocument::setFilePath(const FilePath &newName)
|
||||
@@ -110,19 +111,17 @@ bool ScxmlEditorDocument::isModified() const
|
||||
return m_designWidget && m_designWidget->isDirty();
|
||||
}
|
||||
|
||||
Utils::expected_str<void> ScxmlEditorDocument::reload(ReloadFlag flag, ChangeType type)
|
||||
Result ScxmlEditorDocument::reload(ReloadFlag flag, ChangeType type)
|
||||
{
|
||||
Q_UNUSED(type)
|
||||
if (flag == FlagIgnore)
|
||||
return {};
|
||||
return Result::Ok;
|
||||
emit aboutToReload();
|
||||
QString errorString;
|
||||
emit reloadRequested(&errorString, filePath().toString());
|
||||
const bool success = errorString.isEmpty();
|
||||
emit reloadFinished(success);
|
||||
if (!success)
|
||||
return make_unexpected(errorString);
|
||||
return {};
|
||||
return Result(success, errorString);
|
||||
}
|
||||
|
||||
bool ScxmlEditorDocument::supportsCodec(const QTextCodec *codec) const
|
||||
|
@@ -33,7 +33,7 @@ public:
|
||||
bool shouldAutoSave() const override;
|
||||
bool isSaveAsAllowed() const override;
|
||||
bool isModified() const override;
|
||||
Utils::expected_str<void> reload(ReloadFlag flag, ChangeType type) override;
|
||||
Utils::Result reload(ReloadFlag flag, ChangeType type) override;
|
||||
bool supportsCodec(const QTextCodec *codec) const override;
|
||||
|
||||
// Internal
|
||||
@@ -46,7 +46,7 @@ signals:
|
||||
void reloadRequested(QString *errorString, const QString &);
|
||||
|
||||
protected:
|
||||
Utils::expected_str<void> saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
|
||||
Utils::Result saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
|
||||
|
||||
private:
|
||||
QPointer<Common::MainWidget> m_designWidget;
|
||||
|
@@ -42,20 +42,20 @@ Core::IDocument::OpenResult ObjectsMapDocument::open(QString *errorString,
|
||||
return result;
|
||||
}
|
||||
|
||||
expected_str<void> ObjectsMapDocument::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
Result ObjectsMapDocument::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
{
|
||||
if (filePath.isEmpty())
|
||||
return make_unexpected(QString());
|
||||
return Result::Error("ASSERT: ObjectsMapDocument: filePath.isEmpty()");
|
||||
|
||||
const bool writeOk = writeFile(filePath);
|
||||
if (!writeOk)
|
||||
return make_unexpected(Tr::tr("Failed to write \"%1\"").arg(filePath.toUserOutput()));
|
||||
return Result::Error(Tr::tr("Failed to write \"%1\"").arg(filePath.toUserOutput()));
|
||||
|
||||
if (!autoSave) {
|
||||
setModified(false);
|
||||
setFilePath(filePath);
|
||||
}
|
||||
return {};
|
||||
return Result::Ok;
|
||||
}
|
||||
|
||||
Utils::FilePath ObjectsMapDocument::fallbackSaveAsPath() const
|
||||
@@ -74,21 +74,19 @@ void ObjectsMapDocument::setModified(bool modified)
|
||||
emit changed();
|
||||
}
|
||||
|
||||
expected_str<void> ObjectsMapDocument::reload(Core::IDocument::ReloadFlag flag,
|
||||
Core::IDocument::ChangeType type)
|
||||
Result ObjectsMapDocument::reload(Core::IDocument::ReloadFlag flag,
|
||||
Core::IDocument::ChangeType type)
|
||||
{
|
||||
Q_UNUSED(type);
|
||||
if (flag == FlagIgnore)
|
||||
return {};
|
||||
return Result::Ok;
|
||||
emit aboutToReload();
|
||||
QString errorString;
|
||||
const bool success = (openImpl(&errorString, filePath(), filePath()) == OpenResult::Success);
|
||||
if (success)
|
||||
setModified(false);
|
||||
emit reloadFinished(success);
|
||||
if (!success)
|
||||
return make_unexpected(errorString);
|
||||
return {};
|
||||
return Result(success, errorString);
|
||||
}
|
||||
|
||||
bool ObjectsMapDocument::buildObjectsMapTree(const QByteArray &contents)
|
||||
|
@@ -26,7 +26,7 @@ public:
|
||||
bool isModified() const override { return m_isModified; }
|
||||
void setModified(bool modified);
|
||||
bool isSaveAsAllowed() const override { return true; }
|
||||
Utils::expected_str<void> reload(ReloadFlag flag, ChangeType type) override;
|
||||
Utils::Result reload(ReloadFlag flag, ChangeType type) override;
|
||||
|
||||
bool shouldAutoSave() const override { return true; }
|
||||
bool setContents(const QByteArray &contents) override;
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
ObjectsMapModel *model() const { return m_contentModel; }
|
||||
|
||||
protected:
|
||||
Utils::expected_str<void> saveImpl(const Utils::FilePath &fileName, bool autoSave) override;
|
||||
Utils::Result saveImpl(const Utils::FilePath &fileName, bool autoSave) override;
|
||||
|
||||
private:
|
||||
OpenResult openImpl(QString *error,
|
||||
|
@@ -589,7 +589,7 @@ QTextDocument *TextDocument::document() const
|
||||
* If \a autoSave is true, the cursor will be restored and some signals suppressed
|
||||
* and we do not clean up the text file (cleanWhitespace(), ensureFinalNewLine()).
|
||||
*/
|
||||
Utils::expected_str<void> TextDocument::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
Result TextDocument::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
{
|
||||
QTextCursor cursor(&d->m_document);
|
||||
|
||||
@@ -661,16 +661,16 @@ Utils::expected_str<void> TextDocument::saveImpl(const FilePath &filePath, bool
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
return make_unexpected(errorString);
|
||||
return Result::Error(errorString);
|
||||
d->m_autoSaveRevision = d->m_document.revision();
|
||||
if (autoSave)
|
||||
return {};
|
||||
return Result::Ok;
|
||||
|
||||
// inform about the new filename
|
||||
d->m_document.setModified(false); // also triggers update of the block revisions
|
||||
setFilePath(filePath.absoluteFilePath());
|
||||
emit changed();
|
||||
return {};
|
||||
return Result::Ok;
|
||||
}
|
||||
|
||||
QByteArray TextDocument::contents() const
|
||||
@@ -791,19 +791,19 @@ Core::IDocument::OpenResult TextDocument::openImpl(QString *errorString,
|
||||
return OpenResult::Success;
|
||||
}
|
||||
|
||||
expected_str<void> TextDocument::reload(QTextCodec *codec)
|
||||
Result TextDocument::reload(QTextCodec *codec)
|
||||
{
|
||||
QTC_ASSERT(codec, return make_unexpected(QString("No codec given")));
|
||||
QTC_ASSERT(codec, return Result::Error("No codec given"));
|
||||
setCodec(codec);
|
||||
return reload();
|
||||
}
|
||||
|
||||
expected_str<void> TextDocument::reload()
|
||||
Result TextDocument::reload()
|
||||
{
|
||||
return reload(filePath());
|
||||
}
|
||||
|
||||
expected_str<void> TextDocument::reload(const FilePath &realFilePath)
|
||||
Result TextDocument::reload(const FilePath &realFilePath)
|
||||
{
|
||||
emit aboutToReload();
|
||||
auto documentLayout =
|
||||
@@ -818,9 +818,8 @@ expected_str<void> TextDocument::reload(const FilePath &realFilePath)
|
||||
if (documentLayout)
|
||||
documentLayout->documentReloaded(this); // re-adds text marks
|
||||
emit reloadFinished(success);
|
||||
if (!success)
|
||||
return make_unexpected(errorString);
|
||||
return {};
|
||||
|
||||
return Result(success, errorString);
|
||||
}
|
||||
|
||||
bool TextDocument::setPlainText(const QString &text)
|
||||
@@ -837,11 +836,11 @@ bool TextDocument::setPlainText(const QString &text)
|
||||
return true;
|
||||
}
|
||||
|
||||
expected_str<void> TextDocument::reload(ReloadFlag flag, ChangeType type)
|
||||
Result TextDocument::reload(ReloadFlag flag, ChangeType type)
|
||||
{
|
||||
if (flag == FlagIgnore) {
|
||||
if (type != TypeContents)
|
||||
return {};
|
||||
return Result::Ok;
|
||||
|
||||
const bool wasModified = document()->isModified();
|
||||
{
|
||||
@@ -852,7 +851,7 @@ expected_str<void> TextDocument::reload(ReloadFlag flag, ChangeType type)
|
||||
}
|
||||
if (!wasModified)
|
||||
modificationChanged(true);
|
||||
return {};
|
||||
return Result::Ok;
|
||||
}
|
||||
return reload();
|
||||
}
|
||||
|
@@ -105,7 +105,7 @@ public:
|
||||
bool shouldAutoSave() const override;
|
||||
bool isModified() const override;
|
||||
bool isSaveAsAllowed() const override;
|
||||
Utils::expected_str<void> reload(ReloadFlag flag, ChangeType type) override;
|
||||
Utils::Result 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 Utils::expected_str<void> reload();
|
||||
Utils::expected_str<void> reload(const Utils::FilePath &realFilePath);
|
||||
virtual Utils::Result reload();
|
||||
Utils::Result 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;
|
||||
|
||||
Utils::expected_str<void> reload(QTextCodec *codec);
|
||||
Utils::Result reload(QTextCodec *codec);
|
||||
void cleanWhitespace(const QTextCursor &cursor);
|
||||
|
||||
virtual void triggerPendingUpdates();
|
||||
@@ -162,7 +162,7 @@ signals:
|
||||
|
||||
protected:
|
||||
virtual void applyFontSettings();
|
||||
Utils::expected_str<void> saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
|
||||
Utils::Result saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
|
||||
|
||||
private:
|
||||
OpenResult openImpl(QString *errorString,
|
||||
|
@@ -1862,7 +1862,7 @@ void TextEditorWidget::selectEncoding()
|
||||
const CodecSelectorResult result = Core::askForCodec(Core::ICore::dialogParent(), doc);
|
||||
switch (result.action) {
|
||||
case Core::CodecSelectorResult::Reload: {
|
||||
if (expected_str<void> res = doc->reload(result.codec); !res) {
|
||||
if (Result res = doc->reload(result.codec); !res) {
|
||||
QMessageBox::critical(this, Tr::tr("File Error"), res.error());
|
||||
break;
|
||||
}
|
||||
|
@@ -67,21 +67,21 @@ void SubmitEditorFile::setModified(bool modified)
|
||||
emit changed();
|
||||
}
|
||||
|
||||
expected_str<void> SubmitEditorFile::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
Result SubmitEditorFile::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
{
|
||||
FileSaver saver(filePath, QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
|
||||
saver.write(m_editor->fileContents());
|
||||
QString errorString;
|
||||
if (!saver.finalize(&errorString))
|
||||
return make_unexpected(errorString);
|
||||
return Result::Error(errorString);
|
||||
if (autoSave)
|
||||
return {};
|
||||
return Result::Ok;
|
||||
setFilePath(filePath.absoluteFilePath());
|
||||
setModified(false);
|
||||
if (!errorString.isEmpty())
|
||||
return make_unexpected(errorString);
|
||||
return Result::Error(errorString);
|
||||
emit changed();
|
||||
return {};
|
||||
return Result::Ok;
|
||||
}
|
||||
|
||||
IDocument::ReloadBehavior SubmitEditorFile::reloadBehavior(ChangeTrigger state, ChangeType type) const
|
||||
|
@@ -28,7 +28,7 @@ public:
|
||||
void setModified(bool modified = true);
|
||||
|
||||
protected:
|
||||
Utils::expected_str<void> saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
|
||||
Utils::Result saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
|
||||
|
||||
private:
|
||||
bool m_modified;
|
||||
|
Reference in New Issue
Block a user