forked from qt-creator/qt-creator
Core: Make IDocument::save() return an expected_str<void>
That's today's posh way for success-bool-with-error-string. Change-Id: Ica56592766a401701d7e9c59cf07fc0929e399e1 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -1517,10 +1517,10 @@ private:
|
||||
|
||||
bool isSaveAsAllowed() const override { return false; }
|
||||
|
||||
bool saveImpl(QString *errorString, const FilePath &filePath, bool autoSave = false) override
|
||||
expected_str<void> saveImpl(const FilePath &filePath, bool autoSave) override
|
||||
{
|
||||
m_editorWidget->preSave();
|
||||
bool result = TextDocument::saveImpl(errorString, filePath, autoSave);
|
||||
expected_str<void> result = TextDocument::saveImpl(filePath, autoSave);
|
||||
m_editorWidget->postSave();
|
||||
return result;
|
||||
}
|
||||
|
@@ -121,7 +121,7 @@ public:
|
||||
bool isSaveAsAllowed() const final { return true; }
|
||||
|
||||
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) final;
|
||||
bool saveImpl(QString *errorString, const Utils::FilePath &filePath, bool autoSave) final;
|
||||
Utils::expected_str<void> 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); }
|
||||
@@ -2194,16 +2194,13 @@ bool BinEditorDocument::reload(QString *errorString, ReloadFlag flag, ChangeType
|
||||
return success;
|
||||
}
|
||||
|
||||
bool BinEditorDocument::saveImpl(QString *errorString, const FilePath &filePath, bool autoSave)
|
||||
expected_str<void> BinEditorDocument::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
{
|
||||
QTC_ASSERT(!autoSave, return true); // bineditor does not support autosave - it would be a bit expensive
|
||||
if (expected_str<void> res = save(this->filePath(), filePath); !res) {
|
||||
if (errorString)
|
||||
*errorString = res.error();
|
||||
return false;
|
||||
}
|
||||
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)
|
||||
return res;
|
||||
setFilePath(filePath);
|
||||
return true;
|
||||
return {};
|
||||
}
|
||||
|
||||
class BinEditorImpl final : public IEditor, public EditorService
|
||||
|
@@ -1953,8 +1953,8 @@ void ClangdTestCompletion::testCompleteAfterProjectChange()
|
||||
EditorManager::openEditor(project()->projectFilePath()));
|
||||
QVERIFY(proFileEditor);
|
||||
proFileEditor->insert("DEFINES += PROJECT_CONFIGURATION_1\n");
|
||||
QString saveError;
|
||||
QVERIFY2(proFileEditor->document()->save(&saveError), qPrintable(saveError));
|
||||
const expected_str<void> res = proFileEditor->document()->save();
|
||||
QVERIFY2(res, qPrintable(res.error()));
|
||||
QVERIFY(waitForSignalOrTimeout(project(), &Project::anyParsingFinished, timeOutInMs()));
|
||||
QVERIFY(waitForSignalOrTimeout(LanguageClientManager::instance(),
|
||||
&LanguageClientManager::clientRemoved,
|
||||
|
@@ -329,8 +329,7 @@ void ClangFormatConfigWidget::apply()
|
||||
if (!m_editorWidget->isEnabled())
|
||||
return;
|
||||
|
||||
QString errorString;
|
||||
m_editor->document()->save(&errorString, m_config->filePath());
|
||||
m_editor->document()->save(m_config->filePath());
|
||||
}
|
||||
|
||||
TextEditor::CodeStyleEditorWidget *createClangFormatConfigWidget(
|
||||
|
@@ -38,12 +38,11 @@ void VirtualFileSystemOverlay::update()
|
||||
if (saved.revision != document->document()->revision()) {
|
||||
saved.path.removeRecursively();
|
||||
saved.revision = document->document()->revision();
|
||||
QString error;
|
||||
saved.path = m_root.filePath(doc->filePath().fileName() + ".auto");
|
||||
while (saved.path.exists())
|
||||
saved.path = saved.path.stringAppended(".1");
|
||||
if (!doc->save(&error, saved.path, true)) {
|
||||
qCDebug(LOG) << error;
|
||||
if (Utils::expected_str<void> res = doc->save(saved.path, true); !res) {
|
||||
qCDebug(LOG) << res.error();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@@ -154,9 +154,7 @@ public:
|
||||
const Utils::FilePath &filePath,
|
||||
const Utils::FilePath &realFilePath) override;
|
||||
|
||||
bool saveImpl(QString *errorString,
|
||||
const Utils::FilePath &filePath = Utils::FilePath(),
|
||||
bool autoSave = false) override;
|
||||
Utils::expected_str<void> saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
|
||||
|
||||
bool setContents(const QByteArray &contents) override;
|
||||
|
||||
@@ -411,7 +409,7 @@ Core::IDocument::OpenResult JsonSettingsDocument::open(QString *errorString,
|
||||
return OpenResult::Success;
|
||||
}
|
||||
|
||||
bool JsonSettingsDocument::saveImpl(QString *errorString, const FilePath &newFilePath, bool autoSave)
|
||||
expected_str<void> JsonSettingsDocument::saveImpl(const FilePath &newFilePath, bool autoSave)
|
||||
{
|
||||
Store store;
|
||||
|
||||
@@ -435,14 +433,12 @@ bool JsonSettingsDocument::saveImpl(QString *errorString, const FilePath &newFil
|
||||
setFilePath(newFilePath);
|
||||
}
|
||||
|
||||
auto result = path.writeFileContents(jsonFromStore(store));
|
||||
if (!result && errorString) {
|
||||
*errorString = result.error();
|
||||
return false;
|
||||
}
|
||||
expected_str<qint64> result = path.writeFileContents(jsonFromStore(store));
|
||||
if (!result)
|
||||
return make_unexpected(result.error());
|
||||
|
||||
emit changed();
|
||||
return true;
|
||||
return {};
|
||||
}
|
||||
|
||||
bool JsonSettingsDocument::isModified() const
|
||||
|
@@ -174,7 +174,7 @@ bool BaseFileWizardFactory::postGenerateOpenEditors(const GeneratedFiles &l, QSt
|
||||
return false;
|
||||
}
|
||||
editor->document()->formatContents();
|
||||
editor->document()->save(nullptr);
|
||||
editor->document()->save();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@@ -715,8 +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
|
||||
|
||||
QString errorString;
|
||||
if (!document->save(&errorString, savePath, false)) {
|
||||
if (const expected_str<void> res = document->save(savePath, false); !res) {
|
||||
if (isReadOnly) {
|
||||
QFile ofi(savePath.toString());
|
||||
// Check whether the existing file is writable
|
||||
@@ -727,7 +726,7 @@ bool DocumentManager::saveDocument(IDocument *document,
|
||||
*isReadOnly = false;
|
||||
}
|
||||
QMessageBox::critical(ICore::dialogParent(), Tr::tr("File Error"),
|
||||
Tr::tr("Error while saving file: %1").arg(errorString));
|
||||
Tr::tr("Error while saving file: %1").arg(res.error()));
|
||||
out:
|
||||
ret = false;
|
||||
}
|
||||
|
@@ -343,14 +343,14 @@ IDocument::OpenResult IDocument::open(QString *errorString, const Utils::FilePat
|
||||
\sa saved()
|
||||
\sa filePath()
|
||||
*/
|
||||
bool IDocument::save(QString *errorString, const Utils::FilePath &filePath, bool autoSave)
|
||||
expected_str<void> IDocument::save(const FilePath &filePath, bool autoSave)
|
||||
{
|
||||
const Utils::FilePath savePath = filePath.isEmpty() ? this->filePath() : filePath;
|
||||
const FilePath savePath = filePath.isEmpty() ? this->filePath() : filePath;
|
||||
emit aboutToSave(savePath, autoSave);
|
||||
const bool success = saveImpl(errorString, savePath, autoSave);
|
||||
if (success)
|
||||
const expected_str<void> res = saveImpl(savePath, autoSave);
|
||||
if (res)
|
||||
emit saved(savePath, autoSave);
|
||||
return success;
|
||||
return res;
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -360,18 +360,15 @@ bool IDocument::save(QString *errorString, const Utils::FilePath &filePath, bool
|
||||
document should avoid cleanups or other operations that it does for
|
||||
user-requested saves.
|
||||
|
||||
Use \a errorString to return an error message if saving failed.
|
||||
|
||||
Returns whether saving was successful.
|
||||
Returns whether saving was successful, including an error message when it was not.
|
||||
|
||||
The default implementation does nothing and returns \c false.
|
||||
*/
|
||||
bool IDocument::saveImpl(QString *errorString, const Utils::FilePath &filePath, bool autoSave)
|
||||
expected_str<void> IDocument::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
{
|
||||
Q_UNUSED(errorString)
|
||||
Q_UNUSED(filePath)
|
||||
Q_UNUSED(autoSave)
|
||||
return false;
|
||||
return make_unexpected(Tr::tr("Not implemented"));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -653,8 +650,11 @@ void IDocument::setMimeType(const QString &mimeType)
|
||||
*/
|
||||
bool IDocument::autoSave(QString *errorString, const FilePath &filePath)
|
||||
{
|
||||
if (!save(errorString, filePath, true))
|
||||
const expected_str<void> res = save(filePath, true);
|
||||
if (!res) {
|
||||
*errorString = res.error();
|
||||
return false;
|
||||
}
|
||||
d->autoSavePath = filePath;
|
||||
return true;
|
||||
}
|
||||
|
@@ -68,7 +68,7 @@ public:
|
||||
|
||||
virtual OpenResult open(QString *errorString, const Utils::FilePath &filePath, const Utils::FilePath &realFilePath);
|
||||
|
||||
bool save(QString *errorString, const Utils::FilePath &filePath = Utils::FilePath(), bool autoSave = false);
|
||||
Utils::expected_str<void> save(const Utils::FilePath &filePath = {}, bool autoSave = false);
|
||||
|
||||
virtual QByteArray contents() const;
|
||||
virtual bool setContents(const QByteArray &contents);
|
||||
@@ -131,9 +131,8 @@ signals:
|
||||
void filePathChanged(const Utils::FilePath &oldName, const Utils::FilePath &newName);
|
||||
|
||||
protected:
|
||||
virtual bool saveImpl(QString *errorString,
|
||||
const Utils::FilePath &filePath = Utils::FilePath(),
|
||||
bool autoSave = false);
|
||||
virtual Utils::expected_str<void>
|
||||
saveImpl(const Utils::FilePath &filePath = {}, bool autoSave = false);
|
||||
|
||||
private:
|
||||
Internal::IDocumentPrivate *d;
|
||||
|
@@ -489,10 +489,10 @@ TextEditor::TabSettings CppEditorDocument::tabSettings() const
|
||||
return indenter()->tabSettings().value_or(TextEditor::TextDocument::tabSettings());
|
||||
}
|
||||
|
||||
bool CppEditorDocument::saveImpl(QString *errorString, const FilePath &filePath, bool autoSave)
|
||||
expected_str<void> CppEditorDocument::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
{
|
||||
if (!indenter()->formatOnSave() || autoSave)
|
||||
return TextEditor::TextDocument::saveImpl(errorString, filePath, autoSave);
|
||||
return TextEditor::TextDocument::saveImpl(filePath, autoSave);
|
||||
|
||||
auto *layout = qobject_cast<TextEditor::TextDocumentLayout *>(document()->documentLayout());
|
||||
const int documentRevision = layout->lastSaveRevision;
|
||||
@@ -530,7 +530,7 @@ bool CppEditorDocument::saveImpl(QString *errorString, const FilePath &filePath,
|
||||
settings.m_cleanWhitespace = false;
|
||||
setStorageSettings(settings);
|
||||
|
||||
return TextEditor::TextDocument::saveImpl(errorString, filePath, autoSave);
|
||||
return TextEditor::TextDocument::saveImpl(filePath, autoSave);
|
||||
}
|
||||
|
||||
bool CppEditorDocument::usesClangd() const
|
||||
|
@@ -67,12 +67,9 @@ signals:
|
||||
|
||||
protected:
|
||||
void applyFontSettings() override;
|
||||
bool saveImpl(QString *errorString,
|
||||
const Utils::FilePath &filePath = Utils::FilePath(),
|
||||
bool autoSave = false) override;
|
||||
Utils::expected_str<void> saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
|
||||
|
||||
private:
|
||||
|
||||
void invalidateFormatterCache();
|
||||
void onFilePathChanged(const Utils::FilePath &oldPath, const Utils::FilePath &newPath);
|
||||
void onMimeTypeChanged();
|
||||
|
@@ -84,31 +84,35 @@ Core::IDocument::OpenResult FormWindowFile::open(QString *errorString,
|
||||
return OpenResult::Success;
|
||||
}
|
||||
|
||||
bool FormWindowFile::saveImpl(QString *errorString, const FilePath &filePath, bool autoSave)
|
||||
expected_str<void> FormWindowFile::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
{
|
||||
QTC_ASSERT(m_formWindow, return false);
|
||||
QTC_ASSERT(m_formWindow, return make_unexpected(QString()));
|
||||
|
||||
if (filePath.isEmpty())
|
||||
return false;
|
||||
return make_unexpected(QString());
|
||||
|
||||
const QString oldFormName = m_formWindow->fileName();
|
||||
if (!autoSave)
|
||||
m_formWindow->setFileName(filePath.toString());
|
||||
const bool writeOK = writeFile(filePath, errorString);
|
||||
QString errorString;
|
||||
const bool writeOK = writeFile(filePath, &errorString);
|
||||
m_shouldAutoSave = false;
|
||||
if (autoSave)
|
||||
return writeOK;
|
||||
if (autoSave) {
|
||||
if (writeOK)
|
||||
return {};
|
||||
return make_unexpected(errorString);
|
||||
}
|
||||
|
||||
if (!writeOK) {
|
||||
m_formWindow->setFileName(oldFormName);
|
||||
return false;
|
||||
return make_unexpected(errorString);
|
||||
}
|
||||
|
||||
m_formWindow->setDirty(false);
|
||||
setFilePath(filePath);
|
||||
updateIsModified();
|
||||
|
||||
return true;
|
||||
return {};
|
||||
}
|
||||
|
||||
QByteArray FormWindowFile::contents() const
|
||||
|
@@ -52,7 +52,7 @@ public:
|
||||
void updateIsModified();
|
||||
|
||||
protected:
|
||||
bool saveImpl(QString *errorString, const Utils::FilePath &filePath, bool autoSave) override;
|
||||
Utils::expected_str<void> saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
|
||||
|
||||
private:
|
||||
void slotFormWindowRemoved(QDesignerFormWindowInterface *w);
|
||||
|
@@ -234,18 +234,18 @@ bool DiffEditorDocument::isSaveAsAllowed() const
|
||||
return state() == LoadOK;
|
||||
}
|
||||
|
||||
bool DiffEditorDocument::saveImpl(QString *errorString, const FilePath &filePath, bool autoSave)
|
||||
expected_str<void> DiffEditorDocument::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
{
|
||||
Q_UNUSED(errorString)
|
||||
Q_UNUSED(autoSave)
|
||||
|
||||
QString errorString;
|
||||
if (state() != LoadOK)
|
||||
return false;
|
||||
return make_unexpected(errorString);
|
||||
|
||||
const bool ok = write(filePath, format(), plainText(), errorString);
|
||||
const bool ok = write(filePath, format(), plainText(), &errorString);
|
||||
|
||||
if (!ok)
|
||||
return false;
|
||||
return make_unexpected(errorString);
|
||||
|
||||
setController(nullptr);
|
||||
setDescription({});
|
||||
@@ -256,7 +256,7 @@ bool DiffEditorDocument::saveImpl(QString *errorString, const FilePath &filePath
|
||||
setPreferredDisplayName({});
|
||||
emit temporaryStateChanged();
|
||||
|
||||
return true;
|
||||
return {};
|
||||
}
|
||||
|
||||
void DiffEditorDocument::reload()
|
||||
|
@@ -75,7 +75,7 @@ signals:
|
||||
void descriptionChanged();
|
||||
|
||||
protected:
|
||||
bool saveImpl(QString *errorString, const Utils::FilePath &filePath, bool autoSave) override;
|
||||
Utils::expected_str<void> saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
|
||||
|
||||
private:
|
||||
void beginReload();
|
||||
|
@@ -19,7 +19,7 @@
|
||||
#include <utils/id.h>
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
using Utils::FilePath;
|
||||
using namespace Utils;
|
||||
|
||||
namespace ModelEditor {
|
||||
namespace Internal {
|
||||
@@ -54,19 +54,16 @@ Core::IDocument::OpenResult ModelDocument::open(QString *errorString,
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ModelDocument::saveImpl(QString *errorString, const FilePath &filePath, bool autoSave)
|
||||
expected_str<void> ModelDocument::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
{
|
||||
if (!d->documentController) {
|
||||
*errorString = Tr::tr("No model loaded. Cannot save.");
|
||||
return false;
|
||||
}
|
||||
if (!d->documentController)
|
||||
return make_unexpected(Tr::tr("No model loaded. Cannot save."));
|
||||
|
||||
d->documentController->projectController()->setFileName(filePath);
|
||||
try {
|
||||
d->documentController->projectController()->save();
|
||||
} catch (const qmt::Exception &ex) {
|
||||
*errorString = ex.errorMessage();
|
||||
return false;
|
||||
return make_unexpected(ex.errorMessage());
|
||||
}
|
||||
|
||||
if (autoSave) {
|
||||
@@ -76,7 +73,7 @@ bool ModelDocument::saveImpl(QString *errorString, const FilePath &filePath, boo
|
||||
emit changed();
|
||||
}
|
||||
|
||||
return true;
|
||||
return {};
|
||||
}
|
||||
|
||||
bool ModelDocument::shouldAutoSave() const
|
||||
|
@@ -40,7 +40,7 @@ public:
|
||||
OpenResult load(QString *errorString, const Utils::FilePath &fileName);
|
||||
|
||||
protected:
|
||||
bool saveImpl(QString *errorString, const Utils::FilePath &filePath, bool autoSave) override;
|
||||
Utils::expected_str<void> saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
|
||||
|
||||
private:
|
||||
ModelDocumentPrivate *d;
|
||||
|
@@ -435,7 +435,7 @@ void JsonWizard::openFiles(const JsonWizard::GeneratorFiles &files)
|
||||
bool openedSomething = stringValue("DoNotOpenFile") == "true";
|
||||
static const auto formatFile = [](Core::IEditor *editor) {
|
||||
editor->document()->formatContents();
|
||||
editor->document()->save(nullptr);
|
||||
editor->document()->save();
|
||||
};
|
||||
for (const JsonWizard::GeneratorFile &f : files) {
|
||||
const Core::GeneratedFile &file = f.file;
|
||||
|
@@ -242,10 +242,9 @@ void AssetExporter::onQmlFileLoaded()
|
||||
.arg(designDocument->displayName()));
|
||||
} else {
|
||||
exportComponent(m_view->rootModelNode());
|
||||
QString error;
|
||||
if (!m_view->saveQmlFile(&error)) {
|
||||
if (Utils::expected_str<void> res = m_view->saveQmlFile(); !res) {
|
||||
ExportNotification::addError(tr("Error saving component file. %1")
|
||||
.arg(error.isEmpty()? tr("Unknown") : error));
|
||||
.arg(res.error().isEmpty()? tr("Unknown") : res.error()));
|
||||
}
|
||||
}
|
||||
notifyProgress((m_totalFileCount - m_exportFiles.count()) * 0.8 / m_totalFileCount);
|
||||
|
@@ -49,13 +49,14 @@ bool AssetExporterView::loadQmlFile(const Utils::FilePath &path, uint timeoutSec
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AssetExporterView::saveQmlFile(QString *error) const
|
||||
Utils::expected_str<void> AssetExporterView::saveQmlFile() const
|
||||
{
|
||||
if (!m_currentEditor) {
|
||||
qCDebug(loggerWarn) << "Saving QML file failed. No editor.";
|
||||
return false;
|
||||
return Utils::make_unexpected(QString("Saving QML file failed. No editor."));
|
||||
}
|
||||
return m_currentEditor->document()->save(error);
|
||||
|
||||
return m_currentEditor->document()->save();
|
||||
}
|
||||
|
||||
void AssetExporterView::modelAttached(Model *model)
|
||||
|
@@ -28,7 +28,7 @@ public:
|
||||
AssetExporterView(ExternalDependenciesInterface &externalDependencies);
|
||||
|
||||
bool loadQmlFile(const Utils::FilePath &path, uint timeoutSecs = 10);
|
||||
bool saveQmlFile(QString *error) const;
|
||||
Utils::expected_str<void> saveQmlFile() const;
|
||||
|
||||
void modelAttached(Model *model) override;
|
||||
void instanceInformationsChanged(const QMultiHash<ModelNode, InformationName> &informationChangeHash) override;
|
||||
|
@@ -67,7 +67,7 @@ signals:
|
||||
void loaded(bool success);
|
||||
|
||||
private:
|
||||
bool saveImpl(QString *errorString, const FilePath &filePath, bool autoSave) final;
|
||||
Utils::expected_str<void> saveImpl(const FilePath &filePath, bool autoSave) final;
|
||||
void dirtyChanged(bool);
|
||||
|
||||
RelativeResourceModel m_model;
|
||||
@@ -209,22 +209,20 @@ IDocument::OpenResult ResourceEditorDocument::open(QString *errorString,
|
||||
return OpenResult::Success;
|
||||
}
|
||||
|
||||
bool ResourceEditorDocument::saveImpl(QString *errorString, const FilePath &filePath, bool autoSave)
|
||||
expected_str<void> ResourceEditorDocument::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
{
|
||||
if (debugResourceEditorW)
|
||||
qDebug() << ">ResourceEditorW::saveImpl: " << filePath;
|
||||
|
||||
if (filePath.isEmpty())
|
||||
return false;
|
||||
return make_unexpected(QString()); // FIXME: better message
|
||||
|
||||
m_blockDirtyChanged = true;
|
||||
m_model.setFilePath(filePath);
|
||||
if (!m_model.save()) {
|
||||
if (errorString)
|
||||
*errorString = m_model.errorMessage();
|
||||
m_model.setFilePath(this->filePath());
|
||||
m_blockDirtyChanged = false;
|
||||
return false;
|
||||
return make_unexpected(m_model.errorMessage());
|
||||
}
|
||||
|
||||
m_shouldAutoSave = false;
|
||||
@@ -232,14 +230,14 @@ bool ResourceEditorDocument::saveImpl(QString *errorString, const FilePath &file
|
||||
m_model.setFilePath(this->filePath());
|
||||
m_model.setDirty(true);
|
||||
m_blockDirtyChanged = false;
|
||||
return true;
|
||||
return {};
|
||||
}
|
||||
|
||||
setFilePath(filePath);
|
||||
m_blockDirtyChanged = false;
|
||||
|
||||
emit changed();
|
||||
return true;
|
||||
return {};
|
||||
}
|
||||
|
||||
bool ResourceEditorDocument::setContents(const QByteArray &contents)
|
||||
|
@@ -58,23 +58,22 @@ Core::IDocument::OpenResult ScxmlEditorDocument::open(QString *errorString,
|
||||
return OpenResult::Success;
|
||||
}
|
||||
|
||||
bool ScxmlEditorDocument::saveImpl(QString *errorString, const FilePath &filePath, bool autoSave)
|
||||
Utils::expected_str<void> ScxmlEditorDocument::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
{
|
||||
if (filePath.isEmpty())
|
||||
return false;
|
||||
return make_unexpected(QString());
|
||||
bool dirty = m_designWidget->isDirty();
|
||||
|
||||
m_designWidget->setFileName(filePath.toString());
|
||||
if (!m_designWidget->save()) {
|
||||
*errorString = m_designWidget->errorMessage();
|
||||
m_designWidget->setFileName(this->filePath().toString());
|
||||
return false;
|
||||
return make_unexpected(m_designWidget->errorMessage());
|
||||
}
|
||||
|
||||
if (autoSave) {
|
||||
m_designWidget->setFileName(this->filePath().toString());
|
||||
m_designWidget->save();
|
||||
return true;
|
||||
return {};
|
||||
}
|
||||
|
||||
setFilePath(filePath);
|
||||
@@ -82,7 +81,7 @@ bool ScxmlEditorDocument::saveImpl(QString *errorString, const FilePath &filePat
|
||||
if (dirty != m_designWidget->isDirty())
|
||||
emit changed();
|
||||
|
||||
return true;
|
||||
return {};
|
||||
}
|
||||
|
||||
void ScxmlEditorDocument::setFilePath(const FilePath &newName)
|
||||
|
@@ -46,7 +46,7 @@ signals:
|
||||
void reloadRequested(QString *errorString, const QString &);
|
||||
|
||||
protected:
|
||||
bool saveImpl(QString *errorString, const Utils::FilePath &filePath, bool autoSave) override;
|
||||
Utils::expected_str<void> saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
|
||||
|
||||
private:
|
||||
QPointer<Common::MainWidget> m_designWidget;
|
||||
|
@@ -13,6 +13,8 @@
|
||||
|
||||
#include <QtCore5Compat/QTextCodec>
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
namespace Squish {
|
||||
namespace Internal {
|
||||
|
||||
@@ -40,25 +42,20 @@ Core::IDocument::OpenResult ObjectsMapDocument::open(QString *errorString,
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ObjectsMapDocument::saveImpl(QString *errorString,
|
||||
const Utils::FilePath &filePath,
|
||||
bool autoSave)
|
||||
expected_str<void> ObjectsMapDocument::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
{
|
||||
if (filePath.isEmpty())
|
||||
return false;
|
||||
return make_unexpected(QString());
|
||||
|
||||
const bool writeOk = writeFile(filePath);
|
||||
if (!writeOk) {
|
||||
if (errorString)
|
||||
*errorString = Tr::tr("Failed to write \"%1\"").arg(filePath.toUserOutput());
|
||||
return false;
|
||||
}
|
||||
if (!writeOk)
|
||||
return make_unexpected(Tr::tr("Failed to write \"%1\"").arg(filePath.toUserOutput()));
|
||||
|
||||
if (!autoSave) {
|
||||
setModified(false);
|
||||
setFilePath(filePath);
|
||||
}
|
||||
return true;
|
||||
return {};
|
||||
}
|
||||
|
||||
Utils::FilePath ObjectsMapDocument::fallbackSaveAsPath() const
|
||||
|
@@ -34,7 +34,7 @@ public:
|
||||
ObjectsMapModel *model() const { return m_contentModel; }
|
||||
|
||||
protected:
|
||||
bool saveImpl(QString *errorString, const Utils::FilePath &fileName, bool autoSave) override;
|
||||
Utils::expected_str<void> saveImpl(const Utils::FilePath &fileName, bool autoSave) override;
|
||||
|
||||
private:
|
||||
OpenResult openImpl(QString *error,
|
||||
|
@@ -280,7 +280,7 @@ bool RefactoringFile::apply()
|
||||
|
||||
fileChanged();
|
||||
if (withUnmodifiedEditor && EditorManager::autoSaveAfterRefactoring())
|
||||
m_editor->textDocument()->save(nullptr, m_filePath, false);
|
||||
m_editor->textDocument()->save(m_filePath, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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()).
|
||||
*/
|
||||
bool TextDocument::saveImpl(QString *errorString, const FilePath &filePath, bool autoSave)
|
||||
Utils::expected_str<void> TextDocument::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
{
|
||||
QTextCursor cursor(&d->m_document);
|
||||
|
||||
@@ -644,7 +644,8 @@ bool TextDocument::saveImpl(QString *errorString, const FilePath &filePath, bool
|
||||
}
|
||||
}
|
||||
|
||||
const bool ok = write(filePath, saveFormat, plainText(), errorString);
|
||||
QString errorString;
|
||||
const bool ok = write(filePath, saveFormat, plainText(), &errorString);
|
||||
|
||||
// restore text cursor and scroll bar positions
|
||||
if (autoSave && undos < d->m_document.availableUndoSteps()) {
|
||||
@@ -660,16 +661,16 @@ bool TextDocument::saveImpl(QString *errorString, const FilePath &filePath, bool
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
return false;
|
||||
return make_unexpected(errorString);
|
||||
d->m_autoSaveRevision = d->m_document.revision();
|
||||
if (autoSave)
|
||||
return true;
|
||||
return {};
|
||||
|
||||
// inform about the new filename
|
||||
d->m_document.setModified(false); // also triggers update of the block revisions
|
||||
setFilePath(filePath.absoluteFilePath());
|
||||
emit changed();
|
||||
return true;
|
||||
return {};
|
||||
}
|
||||
|
||||
QByteArray TextDocument::contents() const
|
||||
|
@@ -162,7 +162,7 @@ signals:
|
||||
|
||||
protected:
|
||||
virtual void applyFontSettings();
|
||||
bool saveImpl(QString *errorString, const Utils::FilePath &filePath, bool autoSave) override;
|
||||
Utils::expected_str<void> saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
|
||||
|
||||
private:
|
||||
OpenResult openImpl(QString *errorString,
|
||||
|
@@ -67,20 +67,21 @@ void SubmitEditorFile::setModified(bool modified)
|
||||
emit changed();
|
||||
}
|
||||
|
||||
bool SubmitEditorFile::saveImpl(QString *errorString, const FilePath &filePath, bool autoSave)
|
||||
expected_str<void> SubmitEditorFile::saveImpl(const FilePath &filePath, bool autoSave)
|
||||
{
|
||||
FileSaver saver(filePath, QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
|
||||
saver.write(m_editor->fileContents());
|
||||
if (!saver.finalize(errorString))
|
||||
return false;
|
||||
QString errorString;
|
||||
if (!saver.finalize(&errorString))
|
||||
return make_unexpected(errorString);
|
||||
if (autoSave)
|
||||
return true;
|
||||
return {};
|
||||
setFilePath(filePath.absoluteFilePath());
|
||||
setModified(false);
|
||||
if (!errorString->isEmpty())
|
||||
return false;
|
||||
if (!errorString.isEmpty())
|
||||
return make_unexpected(errorString);
|
||||
emit changed();
|
||||
return true;
|
||||
return {};
|
||||
}
|
||||
|
||||
IDocument::ReloadBehavior SubmitEditorFile::reloadBehavior(ChangeTrigger state, ChangeType type) const
|
||||
|
@@ -28,7 +28,7 @@ public:
|
||||
void setModified(bool modified = true);
|
||||
|
||||
protected:
|
||||
bool saveImpl(QString *errorString, const Utils::FilePath &filePath, bool autoSave) override;
|
||||
Utils::expected_str<void> saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
|
||||
|
||||
private:
|
||||
bool m_modified;
|
||||
|
Reference in New Issue
Block a user