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