forked from qt-creator/qt-creator
Core: Turn IDocument::OpenResult into a full class
... containing the previous enum and the error string. Utils::Result<> is not usable here, as the ReadError and CannotHandle error types are distinct. We might want to check whether it needs to stay like this. For now, make it easy to change into a Result<>. Change-Id: Ic51cf88625c91176ac6a8264f41dd10b7079e4f4 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -97,21 +97,20 @@ public:
|
|||||||
return type == TypeRemoved ? BehaviorSilent : IDocument::reloadBehavior(state, type);
|
return type == TypeRemoved ? BehaviorSilent : IDocument::reloadBehavior(state, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenResult open(QString *errorString, const FilePath &filePath,
|
OpenResult open(const FilePath &filePath, const FilePath &realFilePath) final
|
||||||
const FilePath &realFilePath) final
|
|
||||||
{
|
{
|
||||||
QTC_CHECK(filePath == realFilePath); // The bineditor can do no autosaving
|
QTC_CHECK(filePath == realFilePath); // The bineditor can do no autosaving
|
||||||
return openImpl(errorString, filePath);
|
return openImpl(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenResult openImpl(QString *errorString, const FilePath &filePath, quint64 offset = 0);
|
OpenResult openImpl(const FilePath &filePath, quint64 offset = 0);
|
||||||
|
|
||||||
void provideData(quint64 address);
|
void provideData(quint64 address);
|
||||||
|
|
||||||
void provideNewRange(quint64 offset)
|
void provideNewRange(quint64 offset)
|
||||||
{
|
{
|
||||||
if (filePath().exists())
|
if (filePath().exists())
|
||||||
openImpl(nullptr, filePath(), offset);
|
openImpl(filePath(), offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isModified() const final;
|
bool isModified() const final;
|
||||||
@@ -2119,36 +2118,27 @@ bool BinEditorDocument::setContents(const QByteArray &contents)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
IDocument::OpenResult BinEditorDocument::openImpl(QString *errorString, const FilePath &filePath, quint64 offset)
|
IDocument::OpenResult BinEditorDocument::openImpl(const FilePath &filePath, quint64 offset)
|
||||||
{
|
{
|
||||||
const qint64 size = filePath.fileSize();
|
const qint64 size = filePath.fileSize();
|
||||||
if (size < 0) {
|
if (size < 0) {
|
||||||
QString msg = Tr::tr("Cannot open %1: %2").arg(filePath.toUserOutput(), Tr::tr("File Error"));
|
QString msg = Tr::tr("Cannot open %1: %2").arg(filePath.toUserOutput(), Tr::tr("File Error"));
|
||||||
// FIXME: Was: file.errorString(), but we don't have a file anymore.
|
// FIXME: Was: file.errorString(), but we don't have a file anymore.
|
||||||
if (errorString)
|
QMessageBox::critical(ICore::dialogParent(), Tr::tr("File Error"), msg);
|
||||||
*errorString = msg;
|
return {OpenResult::ReadError, msg};
|
||||||
else
|
|
||||||
QMessageBox::critical(ICore::dialogParent(), Tr::tr("File Error"), msg);
|
|
||||||
return OpenResult::ReadError;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
QString msg = Tr::tr("The Binary Editor cannot open empty files.");
|
QString msg = Tr::tr("The Binary Editor cannot open empty files.");
|
||||||
if (errorString)
|
QMessageBox::critical(ICore::dialogParent(), Tr::tr("File Error"), msg);
|
||||||
*errorString = msg;
|
return {OpenResult::CannotHandle, msg};
|
||||||
else
|
|
||||||
QMessageBox::critical(ICore::dialogParent(), Tr::tr("File Error"), msg);
|
|
||||||
return OpenResult::CannotHandle;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size / 16 >= qint64(1) << 31) {
|
if (size / 16 >= qint64(1) << 31) {
|
||||||
// The limit is 2^31 lines (due to QText* interfaces) * 16 bytes per line.
|
// The limit is 2^31 lines (due to QText* interfaces) * 16 bytes per line.
|
||||||
QString msg = Tr::tr("The file is too big for the Binary Editor (max. 32GB).");
|
QString msg = Tr::tr("The file is too big for the Binary Editor (max. 32GB).");
|
||||||
if (errorString)
|
QMessageBox::critical(ICore::dialogParent(), Tr::tr("File Error"), msg);
|
||||||
*errorString = msg;
|
return {OpenResult::CannotHandle, msg};
|
||||||
else
|
|
||||||
QMessageBox::critical(ICore::dialogParent(), Tr::tr("File Error"), msg);
|
|
||||||
return OpenResult::CannotHandle;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (offset >= quint64(size))
|
if (offset >= quint64(size))
|
||||||
@@ -2189,10 +2179,9 @@ Result<> BinEditorDocument::reload(ReloadFlag flag, ChangeType type)
|
|||||||
return ResultOk;
|
return ResultOk;
|
||||||
emit aboutToReload();
|
emit aboutToReload();
|
||||||
clear();
|
clear();
|
||||||
QString errorString;
|
const OpenResult result = openImpl(filePath());
|
||||||
const bool success = (openImpl(&errorString, filePath()) == OpenResult::Success);
|
emit reloadFinished(result.code == OpenResult::Success);
|
||||||
emit reloadFinished(success);
|
return result;
|
||||||
return makeResult(success, errorString);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<> BinEditorDocument::saveImpl(const FilePath &filePath, bool autoSave)
|
Result<> BinEditorDocument::saveImpl(const FilePath &filePath, bool autoSave)
|
||||||
|
@@ -140,8 +140,7 @@ void ClangFormatConfigWidget::initEditor()
|
|||||||
Core::IEditorFactory *factory = factories.takeFirst();
|
Core::IEditorFactory *factory = factories.takeFirst();
|
||||||
m_editor.reset(factory->createEditor());
|
m_editor.reset(factory->createEditor());
|
||||||
|
|
||||||
QString errorString;
|
m_editor->document()->open(m_config->filePath(), m_config->filePath());
|
||||||
m_editor->document()->open(&errorString, m_config->filePath(), m_config->filePath());
|
|
||||||
m_editor->widget()->adjustSize();
|
m_editor->widget()->adjustSize();
|
||||||
|
|
||||||
invokeMethodForLanguageClientManager("documentOpened",
|
invokeMethodForLanguageClientManager("documentOpened",
|
||||||
@@ -273,9 +272,8 @@ void ClangFormatConfigWidget::reopenClangFormatDocument()
|
|||||||
{
|
{
|
||||||
GuardLocker locker(m_ignoreChanges);
|
GuardLocker locker(m_ignoreChanges);
|
||||||
|
|
||||||
QString errorString;
|
if (m_editor->document()->open(m_config->filePath(), m_config->filePath()).code
|
||||||
if (m_editor->document()->open(&errorString, m_config->filePath(), m_config->filePath())
|
== Core::IDocument::OpenResult::Success) {
|
||||||
== Core::IDocument::OpenResult::Success) {
|
|
||||||
invokeMethodForLanguageClientManager("documentOpened",
|
invokeMethodForLanguageClientManager("documentOpened",
|
||||||
Q_ARG(Core::IDocument *, m_editor->document()));
|
Q_ARG(Core::IDocument *, m_editor->document()));
|
||||||
}
|
}
|
||||||
|
@@ -147,11 +147,11 @@ private:
|
|||||||
class JsonSettingsDocument : public Core::IDocument
|
class JsonSettingsDocument : public Core::IDocument
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
JsonSettingsDocument(QUndoStack *undoStack);
|
JsonSettingsDocument(QUndoStack *undoStack);
|
||||||
|
|
||||||
OpenResult open(QString *errorString,
|
OpenResult open(const Utils::FilePath &filePath,
|
||||||
const Utils::FilePath &filePath,
|
|
||||||
const Utils::FilePath &realFilePath) override;
|
const Utils::FilePath &realFilePath) override;
|
||||||
|
|
||||||
Result<> saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
|
Result<> saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
|
||||||
@@ -380,26 +380,19 @@ JsonSettingsDocument::JsonSettingsDocument(QUndoStack *undoStack)
|
|||||||
m_ceSettings.setUndoStack(undoStack);
|
m_ceSettings.setUndoStack(undoStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::IDocument::OpenResult JsonSettingsDocument::open(QString *errorString,
|
IDocument::OpenResult JsonSettingsDocument::open(const FilePath &filePath,
|
||||||
const FilePath &filePath,
|
const FilePath &realFilePath)
|
||||||
const FilePath &realFilePath)
|
|
||||||
{
|
{
|
||||||
if (!filePath.isReadableFile())
|
if (!filePath.isReadableFile())
|
||||||
return OpenResult::ReadError;
|
return OpenResult::ReadError;
|
||||||
|
|
||||||
auto contents = realFilePath.fileContents();
|
Result<QByteArray> contents = realFilePath.fileContents();
|
||||||
if (!contents) {
|
if (!contents)
|
||||||
if (errorString)
|
return {OpenResult::ReadError, contents.error()};
|
||||||
*errorString = contents.error();
|
|
||||||
return OpenResult::ReadError;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto result = storeFromJson(*contents);
|
Result<Store> result = storeFromJson(*contents);
|
||||||
if (!result) {
|
if (!result)
|
||||||
if (errorString)
|
return {OpenResult::ReadError, result.error()};
|
||||||
*errorString = result.error();
|
|
||||||
return OpenResult::ReadError;
|
|
||||||
}
|
|
||||||
|
|
||||||
setFilePath(filePath);
|
setFilePath(filePath);
|
||||||
|
|
||||||
|
@@ -903,15 +903,14 @@ IEditor *EditorManagerPrivate::openEditor(EditorView *view, const FilePath &file
|
|||||||
factory = factories.isEmpty() ? nullptr : factories.takeFirst();
|
factory = factories.isEmpty() ? nullptr : factories.takeFirst();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
IDocument::OpenResult openResult = editor->document()->open(&errorString,
|
IDocument::OpenResult openResult = editor->document()->open(filePath, realFp);
|
||||||
filePath,
|
if (openResult.code == IDocument::OpenResult::Success)
|
||||||
realFp);
|
|
||||||
if (openResult == IDocument::OpenResult::Success)
|
|
||||||
break;
|
break;
|
||||||
|
errorString = openResult.error;
|
||||||
overrideCursor.reset();
|
overrideCursor.reset();
|
||||||
delete editor;
|
delete editor;
|
||||||
editor = nullptr;
|
editor = nullptr;
|
||||||
if (openResult == IDocument::OpenResult::ReadError) {
|
if (openResult.code == IDocument::OpenResult::ReadError) {
|
||||||
QMessageBox msgbox(QMessageBox::Critical,
|
QMessageBox msgbox(QMessageBox::Critical,
|
||||||
::Core::Tr::tr("File Error"),
|
::Core::Tr::tr("File Error"),
|
||||||
::Core::Tr::tr("Could not open \"%1\" for reading. "
|
::Core::Tr::tr("Could not open \"%1\" for reading. "
|
||||||
@@ -924,7 +923,7 @@ IEditor *EditorManagerPrivate::openEditor(EditorView *view, const FilePath &file
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
// can happen e.g. when trying to open an completely empty .qrc file
|
// can happen e.g. when trying to open an completely empty .qrc file
|
||||||
QTC_CHECK(openResult == IDocument::OpenResult::CannotHandle);
|
QTC_CHECK(openResult.code == IDocument::OpenResult::CannotHandle);
|
||||||
} else {
|
} else {
|
||||||
QTC_ASSERT(factory->isExternalEditor(),
|
QTC_ASSERT(factory->isExternalEditor(),
|
||||||
factory = factories.isEmpty() ? nullptr : factories.takeFirst();
|
factory = factories.isEmpty() ? nullptr : factories.takeFirst();
|
||||||
@@ -3019,7 +3018,7 @@ void EditorManager::runWithTemporaryEditor(const Utils::FilePath &filePath,
|
|||||||
if (!editor)
|
if (!editor)
|
||||||
continue;
|
continue;
|
||||||
editor->document()->setTemporary(true);
|
editor->document()->setTemporary(true);
|
||||||
if (editor->document()->open(nullptr, filePath, filePath) != IDocument::OpenResult::Success)
|
if (editor->document()->open(filePath, filePath).code != IDocument::OpenResult::Success)
|
||||||
continue;
|
continue;
|
||||||
callback(editor.get());
|
callback(editor.get());
|
||||||
break;
|
break;
|
||||||
|
@@ -315,9 +315,8 @@ Id IDocument::id() const
|
|||||||
\sa shouldAutoSave()
|
\sa shouldAutoSave()
|
||||||
\sa setFilePath()
|
\sa setFilePath()
|
||||||
*/
|
*/
|
||||||
IDocument::OpenResult IDocument::open(QString *errorString, const Utils::FilePath &filePath, const Utils::FilePath &realFilePath)
|
IDocument::OpenResult IDocument::open(const FilePath &filePath, const FilePath &realFilePath)
|
||||||
{
|
{
|
||||||
Q_UNUSED(errorString)
|
|
||||||
Q_UNUSED(filePath)
|
Q_UNUSED(filePath)
|
||||||
Q_UNUSED(realFilePath)
|
Q_UNUSED(realFilePath)
|
||||||
return OpenResult::CannotHandle;
|
return OpenResult::CannotHandle;
|
||||||
@@ -808,4 +807,9 @@ QString IDocument::uniqueDisplayName() const
|
|||||||
return d->uniqueDisplayName;
|
return d->uniqueDisplayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IDocument::OpenResult::operator Result<>() const
|
||||||
|
{
|
||||||
|
return makeResult(code == Success, error);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
@@ -26,10 +26,23 @@ class CORE_EXPORT IDocument : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum class OpenResult {
|
class OpenResult
|
||||||
Success,
|
{
|
||||||
ReadError,
|
public:
|
||||||
CannotHandle
|
enum Code {
|
||||||
|
Success,
|
||||||
|
ReadError,
|
||||||
|
CannotHandle
|
||||||
|
};
|
||||||
|
|
||||||
|
OpenResult() = default;
|
||||||
|
OpenResult(Code code) : code(code) {}
|
||||||
|
OpenResult(Code code, const QString &error) : code(code), error(error) {}
|
||||||
|
|
||||||
|
operator Utils::Result<>() const;
|
||||||
|
|
||||||
|
Code code;
|
||||||
|
QString error;
|
||||||
};
|
};
|
||||||
|
|
||||||
// This enum must match the indexes of the reloadBehavior widget
|
// This enum must match the indexes of the reloadBehavior widget
|
||||||
@@ -66,7 +79,7 @@ public:
|
|||||||
void setId(Utils::Id id);
|
void setId(Utils::Id id);
|
||||||
Utils::Id id() const;
|
Utils::Id id() const;
|
||||||
|
|
||||||
virtual OpenResult open(QString *errorString, const Utils::FilePath &filePath, const Utils::FilePath &realFilePath);
|
virtual OpenResult open(const Utils::FilePath &filePath, const Utils::FilePath &realFilePath);
|
||||||
|
|
||||||
Utils::Result<> save(const Utils::FilePath &filePath = {}, bool autoSave = false);
|
Utils::Result<> save(const Utils::FilePath &filePath = {}, bool autoSave = false);
|
||||||
|
|
||||||
|
@@ -82,9 +82,8 @@ public:
|
|||||||
|
|
||||||
// Open file
|
// Open file
|
||||||
QScopedPointer<TextEditor::BaseTextEditor> editor(TextEditor::createPlainTextEditor());
|
QScopedPointer<TextEditor::BaseTextEditor> editor(TextEditor::createPlainTextEditor());
|
||||||
QString error;
|
Core::IDocument::OpenResult res = editor->document()->open(document->filePath(), document->filePath());
|
||||||
editor->document()->open(&error, document->filePath(), document->filePath());
|
QVERIFY(res.error.isEmpty());
|
||||||
QVERIFY(error.isEmpty());
|
|
||||||
|
|
||||||
// Set cursor position
|
// Set cursor position
|
||||||
QTextCursor cursor = editor->textCursor();
|
QTextCursor cursor = editor->textCursor();
|
||||||
|
@@ -19,10 +19,10 @@
|
|||||||
#include <QTextDocument>
|
#include <QTextDocument>
|
||||||
#include <QUndoStack>
|
#include <QUndoStack>
|
||||||
|
|
||||||
|
using namespace Core;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace Designer {
|
namespace Designer::Internal {
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
FormWindowFile::FormWindowFile(QDesignerFormWindowInterface *form, QObject *parent)
|
FormWindowFile::FormWindowFile(QDesignerFormWindowInterface *form, QObject *parent)
|
||||||
: m_formWindow(form)
|
: m_formWindow(form)
|
||||||
@@ -43,9 +43,8 @@ FormWindowFile::FormWindowFile(QDesignerFormWindowInterface *form, QObject *pare
|
|||||||
m_resourceHandler, &ResourceHandler::updateResources);
|
m_resourceHandler, &ResourceHandler::updateResources);
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::IDocument::OpenResult FormWindowFile::open(QString *errorString,
|
IDocument::OpenResult FormWindowFile::open(const FilePath &filePath,
|
||||||
const Utils::FilePath &filePath,
|
const FilePath &realFilePath)
|
||||||
const Utils::FilePath &realFilePath)
|
|
||||||
{
|
{
|
||||||
if (Designer::Constants::Internal::debug)
|
if (Designer::Constants::Internal::debug)
|
||||||
qDebug() << "FormWindowFile::open" << filePath.toUserOutput();
|
qDebug() << "FormWindowFile::open" << filePath.toUserOutput();
|
||||||
@@ -57,21 +56,22 @@ Core::IDocument::OpenResult FormWindowFile::open(QString *errorString,
|
|||||||
return OpenResult::ReadError;
|
return OpenResult::ReadError;
|
||||||
|
|
||||||
QString contents;
|
QString contents;
|
||||||
Utils::TextFileFormat::ReadResult readResult = read(filePath.absoluteFilePath(),
|
QString errorString;
|
||||||
&contents,
|
TextFileFormat::ReadResult readResult = read(filePath.absoluteFilePath(),
|
||||||
errorString);
|
&contents,
|
||||||
|
&errorString);
|
||||||
if (readResult == Utils::TextFileFormat::ReadEncodingError)
|
if (readResult == Utils::TextFileFormat::ReadEncodingError)
|
||||||
return OpenResult::CannotHandle;
|
return {OpenResult::CannotHandle, errorString};
|
||||||
if (readResult != Utils::TextFileFormat::ReadSuccess)
|
if (readResult != Utils::TextFileFormat::ReadSuccess)
|
||||||
return OpenResult::ReadError;
|
return {OpenResult::ReadError, errorString};
|
||||||
|
|
||||||
form->setFileName(filePath.absoluteFilePath().toUrlishString());
|
form->setFileName(filePath.absoluteFilePath().toUrlishString());
|
||||||
const QByteArray contentsBA = contents.toUtf8();
|
const QByteArray contentsBA = contents.toUtf8();
|
||||||
QBuffer str;
|
QBuffer str;
|
||||||
str.setData(contentsBA);
|
str.setData(contentsBA);
|
||||||
str.open(QIODevice::ReadOnly);
|
str.open(QIODevice::ReadOnly);
|
||||||
if (!form->setContents(&str, errorString))
|
if (!form->setContents(&str, &errorString))
|
||||||
return OpenResult::CannotHandle;
|
return {OpenResult::CannotHandle, errorString};
|
||||||
form->setDirty(filePath != realFilePath);
|
form->setDirty(filePath != realFilePath);
|
||||||
|
|
||||||
syncXmlFromFormWindow();
|
syncXmlFromFormWindow();
|
||||||
@@ -201,11 +201,9 @@ Result<> FormWindowFile::reload(ReloadFlag flag, ChangeType type)
|
|||||||
return ResultOk;
|
return ResultOk;
|
||||||
} else {
|
} else {
|
||||||
emit aboutToReload();
|
emit aboutToReload();
|
||||||
QString errorString;
|
const OpenResult result = open(filePath(), filePath());
|
||||||
const bool success
|
emit reloadFinished(result.code == OpenResult::Success);
|
||||||
= (open(&errorString, filePath(), filePath()) == OpenResult::Success);
|
return result;
|
||||||
emit reloadFinished(success);
|
|
||||||
return makeResult(success, errorString);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,5 +267,4 @@ void FormWindowFile::slotFormWindowRemoved(QDesignerFormWindowInterface *w)
|
|||||||
m_formWindow = nullptr;
|
m_formWindow = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Designer::Internal
|
||||||
} // namespace Designer
|
|
||||||
|
@@ -26,7 +26,7 @@ public:
|
|||||||
~FormWindowFile() override { }
|
~FormWindowFile() override { }
|
||||||
|
|
||||||
// IDocument
|
// IDocument
|
||||||
OpenResult open(QString *errorString, const Utils::FilePath &filePath,
|
OpenResult open(const Utils::FilePath &filePath,
|
||||||
const Utils::FilePath &realFilePath) override;
|
const Utils::FilePath &realFilePath) override;
|
||||||
QByteArray contents() const override;
|
QByteArray contents() const override;
|
||||||
bool setContents(const QByteArray &contents) override;
|
bool setContents(const QByteArray &contents) override;
|
||||||
|
@@ -262,28 +262,26 @@ Result<> DiffEditorDocument::reload(ReloadFlag flag, ChangeType type)
|
|||||||
Q_UNUSED(type)
|
Q_UNUSED(type)
|
||||||
if (flag == FlagIgnore)
|
if (flag == FlagIgnore)
|
||||||
return ResultOk;
|
return ResultOk;
|
||||||
QString errorString;
|
return open(filePath(), filePath());
|
||||||
bool success = open(&errorString, filePath(), filePath()) == OpenResult::Success;
|
|
||||||
return makeResult(success, errorString);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::IDocument::OpenResult DiffEditorDocument::open(QString *errorString, const FilePath &filePath,
|
IDocument::OpenResult DiffEditorDocument::open(const FilePath &filePath, const FilePath &realFilePath)
|
||||||
const FilePath &realFilePath)
|
|
||||||
{
|
{
|
||||||
QTC_CHECK(filePath == realFilePath); // does not support autosave
|
QTC_CHECK(filePath == realFilePath); // does not support autosave
|
||||||
beginReload();
|
beginReload();
|
||||||
QString patch;
|
QString patch;
|
||||||
ReadResult readResult = read(filePath, &patch, errorString);
|
QString errorString;
|
||||||
|
ReadResult readResult = read(filePath, &patch, &errorString);
|
||||||
if (readResult == TextFileFormat::ReadIOError
|
if (readResult == TextFileFormat::ReadIOError
|
||||||
|| readResult == TextFileFormat::ReadMemoryAllocationError) {
|
|| readResult == TextFileFormat::ReadMemoryAllocationError) {
|
||||||
return OpenResult::ReadError;
|
return {OpenResult::ReadError, errorString};
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::optional<QList<FileData>> fileDataList = DiffUtils::readPatch(patch);
|
const std::optional<QList<FileData>> fileDataList = DiffUtils::readPatch(patch);
|
||||||
bool ok = fileDataList.has_value();
|
bool ok = fileDataList.has_value();
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
*errorString = Tr::tr("Could not parse patch file \"%1\". "
|
errorString = Tr::tr("Could not parse patch file \"%1\". "
|
||||||
"The content is not of unified diff format.")
|
"The content is not of unified diff format.")
|
||||||
.arg(filePath.toUserOutput());
|
.arg(filePath.toUserOutput());
|
||||||
} else {
|
} else {
|
||||||
setTemporary(false);
|
setTemporary(false);
|
||||||
@@ -295,7 +293,9 @@ Core::IDocument::OpenResult DiffEditorDocument::open(QString *errorString, const
|
|||||||
endReload(ok);
|
endReload(ok);
|
||||||
if (!ok && readResult == TextFileFormat::ReadEncodingError)
|
if (!ok && readResult == TextFileFormat::ReadEncodingError)
|
||||||
ok = selectEncoding();
|
ok = selectEncoding();
|
||||||
return ok ? OpenResult::Success : OpenResult::CannotHandle;
|
if (!ok)
|
||||||
|
return {OpenResult::CannotHandle, errorString};
|
||||||
|
return OpenResult::Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DiffEditorDocument::selectEncoding()
|
bool DiffEditorDocument::selectEncoding()
|
||||||
|
@@ -62,7 +62,7 @@ public:
|
|||||||
bool isSaveAsAllowed() const override;
|
bool isSaveAsAllowed() const override;
|
||||||
void reload();
|
void reload();
|
||||||
Utils::Result<> reload(ReloadFlag flag, ChangeType type) override;
|
Utils::Result<> reload(ReloadFlag flag, ChangeType type) override;
|
||||||
OpenResult open(QString *errorString, const Utils::FilePath &filePath,
|
OpenResult open(const Utils::FilePath &filePath,
|
||||||
const Utils::FilePath &realFilePath) override;
|
const Utils::FilePath &realFilePath) override;
|
||||||
bool selectEncoding();
|
bool selectEncoding();
|
||||||
State state() const { return m_state; }
|
State state() const { return m_state; }
|
||||||
|
@@ -25,6 +25,7 @@
|
|||||||
#include <QGraphicsSvgItem>
|
#include <QGraphicsSvgItem>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using namespace Core;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace ImageViewer::Internal {
|
namespace ImageViewer::Internal {
|
||||||
@@ -63,18 +64,15 @@ ImageViewerFile::~ImageViewerFile()
|
|||||||
cleanUp();
|
cleanUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::IDocument::OpenResult ImageViewerFile::open(QString *errorString,
|
IDocument::OpenResult ImageViewerFile::open(const FilePath &filePath, const FilePath &realfilePath)
|
||||||
const Utils::FilePath &filePath,
|
|
||||||
const Utils::FilePath &realfilePath)
|
|
||||||
{
|
{
|
||||||
QTC_CHECK(filePath == realfilePath); // does not support auto save
|
QTC_CHECK(filePath == realfilePath); // does not support auto save
|
||||||
OpenResult success = openImpl(errorString, filePath);
|
OpenResult res = openImpl(filePath);
|
||||||
emit openFinished(success == OpenResult::Success);
|
emit openFinished(res.code == OpenResult::Success);
|
||||||
return success;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::IDocument::OpenResult ImageViewerFile::openImpl(QString *errorString,
|
IDocument::OpenResult ImageViewerFile::openImpl(const FilePath &filePath)
|
||||||
const Utils::FilePath &filePath)
|
|
||||||
{
|
{
|
||||||
cleanUp();
|
cleanUp();
|
||||||
|
|
||||||
@@ -84,11 +82,8 @@ Core::IDocument::OpenResult ImageViewerFile::openImpl(QString *errorString,
|
|||||||
const QString &fileName = filePath.toUrlishString();
|
const QString &fileName = filePath.toUrlishString();
|
||||||
QByteArray format = QImageReader::imageFormat(fileName);
|
QByteArray format = QImageReader::imageFormat(fileName);
|
||||||
// if it is impossible to recognize a file format - file will not be open correctly
|
// if it is impossible to recognize a file format - file will not be open correctly
|
||||||
if (format.isEmpty()) {
|
if (format.isEmpty())
|
||||||
if (errorString)
|
return {OpenResult::CannotHandle, Tr::tr("Image format not supported.")};
|
||||||
*errorString = Tr::tr("Image format not supported.");
|
|
||||||
return OpenResult::CannotHandle;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef QT_NO_SVG
|
#ifndef QT_NO_SVG
|
||||||
if (format.startsWith("svg")) {
|
if (format.startsWith("svg")) {
|
||||||
@@ -97,9 +92,7 @@ Core::IDocument::OpenResult ImageViewerFile::openImpl(QString *errorString,
|
|||||||
if (!bound.isValid() || (qFuzzyIsNull(bound.width()) && qFuzzyIsNull(bound.height()))) {
|
if (!bound.isValid() || (qFuzzyIsNull(bound.width()) && qFuzzyIsNull(bound.height()))) {
|
||||||
delete m_tempSvgItem;
|
delete m_tempSvgItem;
|
||||||
m_tempSvgItem = nullptr;
|
m_tempSvgItem = nullptr;
|
||||||
if (errorString)
|
return {OpenResult::CannotHandle, Tr::tr("Failed to read SVG image.")};
|
||||||
*errorString = Tr::tr("Failed to read SVG image.");
|
|
||||||
return OpenResult::CannotHandle;
|
|
||||||
}
|
}
|
||||||
m_type = TypeSvg;
|
m_type = TypeSvg;
|
||||||
emit imageSizeChanged(m_tempSvgItem->boundingRect().size().toSize());
|
emit imageSizeChanged(m_tempSvgItem->boundingRect().size().toSize());
|
||||||
@@ -110,11 +103,9 @@ Core::IDocument::OpenResult ImageViewerFile::openImpl(QString *errorString,
|
|||||||
// force reading movie/image data, so we can catch completely invalid movies/images early:
|
// force reading movie/image data, so we can catch completely invalid movies/images early:
|
||||||
m_movie->jumpToNextFrame();
|
m_movie->jumpToNextFrame();
|
||||||
if (!m_movie->isValid()) {
|
if (!m_movie->isValid()) {
|
||||||
if (errorString)
|
|
||||||
*errorString = Tr::tr("Failed to read image.");
|
|
||||||
delete m_movie;
|
delete m_movie;
|
||||||
m_movie = nullptr;
|
m_movie = nullptr;
|
||||||
return OpenResult::CannotHandle;
|
return {OpenResult::CannotHandle, Tr::tr("Failed to read image.")};
|
||||||
}
|
}
|
||||||
m_type = TypeMovie;
|
m_type = TypeMovie;
|
||||||
connect(m_movie, &QMovie::resized, this, &ImageViewerFile::imageSizeChanged);
|
connect(m_movie, &QMovie::resized, this, &ImageViewerFile::imageSizeChanged);
|
||||||
@@ -122,11 +113,9 @@ Core::IDocument::OpenResult ImageViewerFile::openImpl(QString *errorString,
|
|||||||
} else {
|
} else {
|
||||||
m_pixmap = new QPixmap(fileName);
|
m_pixmap = new QPixmap(fileName);
|
||||||
if (m_pixmap->isNull()) {
|
if (m_pixmap->isNull()) {
|
||||||
if (errorString)
|
|
||||||
*errorString = Tr::tr("Failed to read image.");
|
|
||||||
delete m_pixmap;
|
delete m_pixmap;
|
||||||
m_pixmap = nullptr;
|
m_pixmap = nullptr;
|
||||||
return OpenResult::CannotHandle;
|
return {OpenResult::CannotHandle, Tr::tr("Failed to read image.")};
|
||||||
}
|
}
|
||||||
m_type = TypePixmap;
|
m_type = TypePixmap;
|
||||||
emit imageSizeChanged(m_pixmap->size());
|
emit imageSizeChanged(m_pixmap->size());
|
||||||
@@ -146,17 +135,15 @@ Core::IDocument::ReloadBehavior ImageViewerFile::reloadBehavior(ChangeTrigger st
|
|||||||
return BehaviorAsk;
|
return BehaviorAsk;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<> ImageViewerFile::reload(Core::IDocument::ReloadFlag flag,
|
Result<> ImageViewerFile::reload(IDocument::ReloadFlag flag, IDocument::ChangeType type)
|
||||||
Core::IDocument::ChangeType type)
|
|
||||||
{
|
{
|
||||||
Q_UNUSED(type)
|
Q_UNUSED(type)
|
||||||
if (flag == FlagIgnore)
|
if (flag == FlagIgnore)
|
||||||
return ResultOk;
|
return ResultOk;
|
||||||
emit aboutToReload();
|
emit aboutToReload();
|
||||||
QString errorString;
|
const OpenResult result = openImpl(filePath());
|
||||||
bool success = (openImpl(&errorString, filePath()) == OpenResult::Success);
|
emit reloadFinished( result.code == OpenResult::Success);
|
||||||
emit reloadFinished(success);
|
return result;
|
||||||
return makeResult(success, errorString);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QMovie *ImageViewerFile::movie() const
|
QMovie *ImageViewerFile::movie() const
|
||||||
|
@@ -35,8 +35,7 @@ public:
|
|||||||
ImageViewerFile();
|
ImageViewerFile();
|
||||||
~ImageViewerFile() override;
|
~ImageViewerFile() override;
|
||||||
|
|
||||||
OpenResult open(QString *errorString, const Utils::FilePath &filePath,
|
OpenResult open(const Utils::FilePath &filePath, 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::Result<> reload(ReloadFlag flag, ChangeType type) override;
|
Utils::Result<> reload(ReloadFlag flag, ChangeType type) override;
|
||||||
@@ -55,7 +54,7 @@ signals:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void cleanUp();
|
void cleanUp();
|
||||||
OpenResult openImpl(QString *errorString, const Utils::FilePath &filePath);
|
OpenResult openImpl(const Utils::FilePath &filePath);
|
||||||
|
|
||||||
ImageType m_type = TypeInvalid;
|
ImageType m_type = TypeInvalid;
|
||||||
#ifndef QT_NO_SVG
|
#ifndef QT_NO_SVG
|
||||||
|
@@ -19,10 +19,10 @@
|
|||||||
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace ModelEditor {
|
namespace ModelEditor::Internal {
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
class ModelDocument::ModelDocumentPrivate {
|
class ModelDocument::ModelDocumentPrivate
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
ExtDocumentController *documentController = nullptr;
|
ExtDocumentController *documentController = nullptr;
|
||||||
};
|
};
|
||||||
@@ -42,13 +42,12 @@ ModelDocument::~ModelDocument()
|
|||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::IDocument::OpenResult ModelDocument::open(QString *errorString,
|
Core::IDocument::OpenResult ModelDocument::open(const FilePath &filePath,
|
||||||
const FilePath &filePath,
|
|
||||||
const FilePath &realFilePath)
|
const FilePath &realFilePath)
|
||||||
{
|
{
|
||||||
Q_UNUSED(filePath)
|
Q_UNUSED(filePath)
|
||||||
|
|
||||||
OpenResult result = load(errorString, realFilePath);
|
OpenResult result = load(realFilePath);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +111,7 @@ ExtDocumentController *ModelDocument::documentController() const
|
|||||||
return d->documentController;
|
return d->documentController;
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::IDocument::OpenResult ModelDocument::load(QString *errorString, const FilePath &fileName)
|
Core::IDocument::OpenResult ModelDocument::load(const FilePath &fileName)
|
||||||
{
|
{
|
||||||
d->documentController = ModelEditorPlugin::modelsManager()->createModel(this);
|
d->documentController = ModelEditorPlugin::modelsManager()->createModel(this);
|
||||||
connect(d->documentController, &qmt::DocumentController::changed, this, &IDocument::changed);
|
connect(d->documentController, &qmt::DocumentController::changed, this, &IDocument::changed);
|
||||||
@@ -121,11 +120,11 @@ Core::IDocument::OpenResult ModelDocument::load(QString *errorString, const File
|
|||||||
d->documentController->loadProject(fileName);
|
d->documentController->loadProject(fileName);
|
||||||
setFilePath(d->documentController->projectController()->project()->fileName());
|
setFilePath(d->documentController->projectController()->project()->fileName());
|
||||||
} catch (const qmt::FileNotFoundException &ex) {
|
} catch (const qmt::FileNotFoundException &ex) {
|
||||||
*errorString = ex.errorMessage();
|
return {OpenResult::ReadError, ex.errorMessage()};
|
||||||
return OpenResult::ReadError;
|
|
||||||
} catch (const qmt::Exception &ex) {
|
} catch (const qmt::Exception &ex) {
|
||||||
*errorString = Tr::tr("Could not open \"%1\" for reading: %2.").arg(fileName.toUserOutput(), ex.errorMessage());
|
return {OpenResult::CannotHandle,
|
||||||
return OpenResult::CannotHandle;
|
Tr::tr("Could not open \"%1\" for reading: %2.")
|
||||||
|
.arg(fileName.toUserOutput(), ex.errorMessage())};
|
||||||
}
|
}
|
||||||
|
|
||||||
FilePath configPath = d->documentController->projectController()->project()->configPath();
|
FilePath configPath = d->documentController->projectController()->project()->configPath();
|
||||||
@@ -143,5 +142,4 @@ Core::IDocument::OpenResult ModelDocument::load(QString *errorString, const File
|
|||||||
return OpenResult::Success;
|
return OpenResult::Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace ModelEditor::Internal
|
||||||
} // namespace ModelEditor
|
|
||||||
|
@@ -8,8 +8,7 @@
|
|||||||
|
|
||||||
namespace qmt { class Uid; }
|
namespace qmt { class Uid; }
|
||||||
|
|
||||||
namespace ModelEditor {
|
namespace ModelEditor::Internal {
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
class ExtDocumentController;
|
class ExtDocumentController;
|
||||||
|
|
||||||
@@ -27,8 +26,7 @@ signals:
|
|||||||
void contentSet();
|
void contentSet();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OpenResult open(QString *errorString,
|
OpenResult open(const Utils::FilePath &filePath,
|
||||||
const Utils::FilePath &filePath,
|
|
||||||
const Utils::FilePath &realFilePath) override;
|
const Utils::FilePath &realFilePath) override;
|
||||||
bool shouldAutoSave() const override;
|
bool shouldAutoSave() const override;
|
||||||
bool isModified() const override;
|
bool isModified() const override;
|
||||||
@@ -37,7 +35,7 @@ public:
|
|||||||
|
|
||||||
ExtDocumentController *documentController() const;
|
ExtDocumentController *documentController() const;
|
||||||
|
|
||||||
OpenResult load(QString *errorString, const Utils::FilePath &fileName);
|
OpenResult load(const Utils::FilePath &fileName);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Utils::Result<> saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
|
Utils::Result<> saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
|
||||||
@@ -46,5 +44,4 @@ private:
|
|||||||
ModelDocumentPrivate *d;
|
ModelDocumentPrivate *d;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace ModelEditor::Internal
|
||||||
} // namespace ModelEditor
|
|
||||||
|
@@ -1081,7 +1081,7 @@ Core::IDocument::OpenResult ResourceModel::reload()
|
|||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
Core::IDocument::OpenResult result = m_resource_file.load();
|
Core::IDocument::OpenResult result = m_resource_file.load();
|
||||||
if (result == Core::IDocument::OpenResult::Success)
|
if (result.code == Core::IDocument::OpenResult::Success)
|
||||||
setDirty(false);
|
setDirty(false);
|
||||||
endResetModel();
|
endResetModel();
|
||||||
return result;
|
return result;
|
||||||
|
@@ -48,8 +48,7 @@ class ResourceEditorDocument final : public IDocument
|
|||||||
public:
|
public:
|
||||||
ResourceEditorDocument(QObject *parent = nullptr);
|
ResourceEditorDocument(QObject *parent = nullptr);
|
||||||
|
|
||||||
OpenResult open(QString *errorString, const FilePath &filePath,
|
OpenResult open(const FilePath &filePath, const FilePath &realFilePath) final;
|
||||||
const FilePath &realFilePath) final;
|
|
||||||
QString plainText() const { return m_model.contents(); }
|
QString plainText() const { return m_model.contents(); }
|
||||||
QByteArray contents() const final { return m_model.contents().toUtf8(); }
|
QByteArray contents() const final { return m_model.contents().toUtf8(); }
|
||||||
bool setContents(const QByteArray &contents) final;
|
bool setContents(const QByteArray &contents) final;
|
||||||
@@ -180,8 +179,7 @@ ResourceEditorImpl::~ResourceEditorImpl()
|
|||||||
delete m_toolBar;
|
delete m_toolBar;
|
||||||
}
|
}
|
||||||
|
|
||||||
IDocument::OpenResult ResourceEditorDocument::open(QString *errorString,
|
IDocument::OpenResult ResourceEditorDocument::open(const FilePath &filePath,
|
||||||
const FilePath &filePath,
|
|
||||||
const FilePath &realFilePath)
|
const FilePath &realFilePath)
|
||||||
{
|
{
|
||||||
if (debugResourceEditorW)
|
if (debugResourceEditorW)
|
||||||
@@ -192,9 +190,8 @@ IDocument::OpenResult ResourceEditorDocument::open(QString *errorString,
|
|||||||
m_model.setFilePath(realFilePath);
|
m_model.setFilePath(realFilePath);
|
||||||
|
|
||||||
OpenResult openResult = m_model.reload();
|
OpenResult openResult = m_model.reload();
|
||||||
if (openResult != OpenResult::Success) {
|
if (openResult.code != OpenResult::Success) {
|
||||||
if (errorString)
|
openResult.error = m_model.errorMessage();
|
||||||
*errorString = m_model.errorMessage();
|
|
||||||
setBlockDirtyChanged(false);
|
setBlockDirtyChanged(false);
|
||||||
emit loaded(false);
|
emit loaded(false);
|
||||||
return openResult;
|
return openResult;
|
||||||
@@ -249,7 +246,7 @@ bool ResourceEditorDocument::setContents(const QByteArray &contents)
|
|||||||
|
|
||||||
const FilePath originalFileName = m_model.filePath();
|
const FilePath originalFileName = m_model.filePath();
|
||||||
m_model.setFilePath(saver.filePath());
|
m_model.setFilePath(saver.filePath());
|
||||||
const bool success = (m_model.reload() == OpenResult::Success);
|
const bool success = (m_model.reload().code == OpenResult::Success);
|
||||||
m_model.setFilePath(originalFileName);
|
m_model.setFilePath(originalFileName);
|
||||||
m_shouldAutoSave = false;
|
m_shouldAutoSave = false;
|
||||||
if (debugResourceEditorW)
|
if (debugResourceEditorW)
|
||||||
@@ -286,10 +283,9 @@ Result<> ResourceEditorDocument::reload(ReloadFlag flag, ChangeType type)
|
|||||||
if (flag == FlagIgnore)
|
if (flag == FlagIgnore)
|
||||||
return ResultOk;
|
return ResultOk;
|
||||||
emit aboutToReload();
|
emit aboutToReload();
|
||||||
QString errorString;
|
const OpenResult result = open(filePath(), filePath());
|
||||||
const bool success = (open(&errorString, filePath(), filePath()) == OpenResult::Success);
|
emit reloadFinished(result.code == OpenResult::Success);
|
||||||
emit reloadFinished(success);
|
return result;
|
||||||
return makeResult(success, errorString);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceEditorDocument::dirtyChanged(bool dirty)
|
void ResourceEditorDocument::dirtyChanged(bool dirty)
|
||||||
|
@@ -121,7 +121,7 @@ static bool addFilesToResource(const FilePath &resourceFile,
|
|||||||
*notAdded = filePaths;
|
*notAdded = filePaths;
|
||||||
|
|
||||||
ResourceFile file(resourceFile);
|
ResourceFile file(resourceFile);
|
||||||
if (file.load() != IDocument::OpenResult::Success)
|
if (file.load().code != IDocument::OpenResult::Success)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
int index = file.indexOfPrefix(prefix, lang);
|
int index = file.indexOfPrefix(prefix, lang);
|
||||||
@@ -272,7 +272,7 @@ static void compressTree(FolderNode *n)
|
|||||||
void ResourceTopLevelNode::addInternalNodes()
|
void ResourceTopLevelNode::addInternalNodes()
|
||||||
{
|
{
|
||||||
ResourceFile file(filePath(), m_contents);
|
ResourceFile file(filePath(), m_contents);
|
||||||
if (file.load() != IDocument::OpenResult::Success)
|
if (file.load().code != IDocument::OpenResult::Success)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QMap<PrefixFolderLang, FolderNode *> folderNodes;
|
QMap<PrefixFolderLang, FolderNode *> folderNodes;
|
||||||
@@ -382,7 +382,7 @@ RemovedFilesFromProject ResourceTopLevelNode::removeFiles(const FilePaths &fileP
|
|||||||
bool ResourceTopLevelNode::addPrefix(const QString &prefix, const QString &lang)
|
bool ResourceTopLevelNode::addPrefix(const QString &prefix, const QString &lang)
|
||||||
{
|
{
|
||||||
ResourceFile file(filePath());
|
ResourceFile file(filePath());
|
||||||
if (file.load() != IDocument::OpenResult::Success)
|
if (file.load().code != IDocument::OpenResult::Success)
|
||||||
return false;
|
return false;
|
||||||
int index = file.addPrefix(prefix, lang);
|
int index = file.addPrefix(prefix, lang);
|
||||||
if (index == -1)
|
if (index == -1)
|
||||||
@@ -395,7 +395,7 @@ bool ResourceTopLevelNode::addPrefix(const QString &prefix, const QString &lang)
|
|||||||
bool ResourceTopLevelNode::removePrefix(const QString &prefix, const QString &lang)
|
bool ResourceTopLevelNode::removePrefix(const QString &prefix, const QString &lang)
|
||||||
{
|
{
|
||||||
ResourceFile file(filePath());
|
ResourceFile file(filePath());
|
||||||
if (file.load() != IDocument::OpenResult::Success)
|
if (file.load().code != IDocument::OpenResult::Success)
|
||||||
return false;
|
return false;
|
||||||
for (int i = 0; i < file.prefixCount(); ++i) {
|
for (int i = 0; i < file.prefixCount(); ++i) {
|
||||||
if (file.prefix(i) == prefix
|
if (file.prefix(i) == prefix
|
||||||
@@ -411,7 +411,7 @@ bool ResourceTopLevelNode::removePrefix(const QString &prefix, const QString &la
|
|||||||
bool ResourceTopLevelNode::removeNonExistingFiles()
|
bool ResourceTopLevelNode::removeNonExistingFiles()
|
||||||
{
|
{
|
||||||
ResourceFile file(filePath());
|
ResourceFile file(filePath());
|
||||||
if (file.load() != IDocument::OpenResult::Success)
|
if (file.load().code != IDocument::OpenResult::Success)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
QFileInfo fi;
|
QFileInfo fi;
|
||||||
@@ -490,7 +490,7 @@ RemovedFilesFromProject ResourceFolderNode::removeFiles(const FilePaths &filePat
|
|||||||
if (notRemoved)
|
if (notRemoved)
|
||||||
*notRemoved = filePaths;
|
*notRemoved = filePaths;
|
||||||
ResourceFile file(m_topLevelNode->filePath());
|
ResourceFile file(m_topLevelNode->filePath());
|
||||||
if (file.load() != IDocument::OpenResult::Success)
|
if (file.load().code != IDocument::OpenResult::Success)
|
||||||
return RemovedFilesFromProject::Error;
|
return RemovedFilesFromProject::Error;
|
||||||
int index = file.indexOfPrefix(m_prefix, m_lang);
|
int index = file.indexOfPrefix(m_prefix, m_lang);
|
||||||
if (index == -1)
|
if (index == -1)
|
||||||
@@ -518,7 +518,8 @@ bool ResourceFolderNode::canRenameFile(const FilePath &oldFilePath, const FilePa
|
|||||||
bool fileEntryExists = false;
|
bool fileEntryExists = false;
|
||||||
ResourceFile file(m_topLevelNode->filePath());
|
ResourceFile file(m_topLevelNode->filePath());
|
||||||
|
|
||||||
int index = (file.load() != IDocument::OpenResult::Success) ? -1 :file.indexOfPrefix(m_prefix, m_lang);
|
int index = (file.load().code != IDocument::OpenResult::Success)
|
||||||
|
? -1 : file.indexOfPrefix(m_prefix, m_lang);
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
for (int j = 0; j < file.fileCount(index); ++j) {
|
for (int j = 0; j < file.fileCount(index); ++j) {
|
||||||
if (file.file(index, j) == oldFilePath.toUrlishString()) {
|
if (file.file(index, j) == oldFilePath.toUrlishString()) {
|
||||||
@@ -534,7 +535,7 @@ bool ResourceFolderNode::canRenameFile(const FilePath &oldFilePath, const FilePa
|
|||||||
bool ResourceFolderNode::renameFiles(const FilePairs &filesToRename, FilePaths *notRenamed)
|
bool ResourceFolderNode::renameFiles(const FilePairs &filesToRename, FilePaths *notRenamed)
|
||||||
{
|
{
|
||||||
ResourceFile file(m_topLevelNode->filePath());
|
ResourceFile file(m_topLevelNode->filePath());
|
||||||
if (file.load() != IDocument::OpenResult::Success)
|
if (file.load().code != IDocument::OpenResult::Success)
|
||||||
return false;
|
return false;
|
||||||
int index = file.indexOfPrefix(m_prefix, m_lang);
|
int index = file.indexOfPrefix(m_prefix, m_lang);
|
||||||
if (index == -1)
|
if (index == -1)
|
||||||
@@ -566,7 +567,7 @@ bool ResourceFolderNode::renameFiles(const FilePairs &filesToRename, FilePaths *
|
|||||||
bool ResourceFolderNode::renamePrefix(const QString &prefix, const QString &lang)
|
bool ResourceFolderNode::renamePrefix(const QString &prefix, const QString &lang)
|
||||||
{
|
{
|
||||||
ResourceFile file(m_topLevelNode->filePath());
|
ResourceFile file(m_topLevelNode->filePath());
|
||||||
if (file.load() != IDocument::OpenResult::Success)
|
if (file.load().code != IDocument::OpenResult::Success)
|
||||||
return false;
|
return false;
|
||||||
int index = file.indexOfPrefix(m_prefix, m_lang);
|
int index = file.indexOfPrefix(m_prefix, m_lang);
|
||||||
if (index == -1)
|
if (index == -1)
|
||||||
|
@@ -18,7 +18,8 @@
|
|||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
using namespace ScxmlEditor::Common;
|
using namespace ScxmlEditor::Common;
|
||||||
using namespace ScxmlEditor::Internal;
|
|
||||||
|
namespace ScxmlEditor::Internal {
|
||||||
|
|
||||||
ScxmlEditorDocument::ScxmlEditorDocument(MainWidget *designWidget, QObject *parent)
|
ScxmlEditorDocument::ScxmlEditorDocument(MainWidget *designWidget, QObject *parent)
|
||||||
: m_designWidget(designWidget)
|
: m_designWidget(designWidget)
|
||||||
@@ -34,9 +35,8 @@ ScxmlEditorDocument::ScxmlEditorDocument(MainWidget *designWidget, QObject *pare
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::IDocument::OpenResult ScxmlEditorDocument::open(QString *errorString,
|
Core::IDocument::OpenResult ScxmlEditorDocument::open(const FilePath &filePath,
|
||||||
const Utils::FilePath &filePath,
|
const FilePath &realFilePath)
|
||||||
const Utils::FilePath &realFilePath)
|
|
||||||
{
|
{
|
||||||
Q_UNUSED(realFilePath)
|
Q_UNUSED(realFilePath)
|
||||||
|
|
||||||
@@ -47,10 +47,8 @@ Core::IDocument::OpenResult ScxmlEditorDocument::open(QString *errorString,
|
|||||||
return OpenResult::ReadError;
|
return OpenResult::ReadError;
|
||||||
|
|
||||||
const FilePath &absoluteFilePath = filePath.absoluteFilePath();
|
const FilePath &absoluteFilePath = filePath.absoluteFilePath();
|
||||||
if (!m_designWidget->load(absoluteFilePath.toUrlishString())) {
|
if (!m_designWidget->load(absoluteFilePath.toUrlishString()))
|
||||||
*errorString = m_designWidget->errorMessage();
|
return {OpenResult::ReadError, m_designWidget->errorMessage()};
|
||||||
return OpenResult::ReadError;
|
|
||||||
}
|
|
||||||
|
|
||||||
setFilePath(absoluteFilePath);
|
setFilePath(absoluteFilePath);
|
||||||
|
|
||||||
@@ -137,3 +135,5 @@ void ScxmlEditorDocument::syncXmlFromDesignWidget()
|
|||||||
{
|
{
|
||||||
document()->setPlainText(designWidgetContents());
|
document()->setPlainText(designWidgetContents());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace ScxmlEditor::Internal
|
||||||
|
@@ -13,9 +13,7 @@ QT_FORWARD_DECLARE_CLASS(QDesignerFormWindowInterface)
|
|||||||
|
|
||||||
namespace ScxmlEditor {
|
namespace ScxmlEditor {
|
||||||
|
|
||||||
namespace Common {
|
namespace Common { class MainWidget; }
|
||||||
class MainWidget;
|
|
||||||
} // namespace Common
|
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -27,9 +25,7 @@ public:
|
|||||||
explicit ScxmlEditorDocument(Common::MainWidget *designWidget, QObject *parent = nullptr);
|
explicit ScxmlEditorDocument(Common::MainWidget *designWidget, QObject *parent = nullptr);
|
||||||
|
|
||||||
// IDocument
|
// IDocument
|
||||||
OpenResult open(QString *errorString,
|
OpenResult open(const Utils::FilePath &filePath, const Utils::FilePath &realFilePath) override;
|
||||||
const Utils::FilePath &filePath,
|
|
||||||
const Utils::FilePath &realFilePath) override;
|
|
||||||
bool shouldAutoSave() const override;
|
bool shouldAutoSave() const override;
|
||||||
bool isSaveAsAllowed() const override;
|
bool isSaveAsAllowed() const override;
|
||||||
bool isModified() const override;
|
bool isModified() const override;
|
||||||
|
@@ -11,10 +11,10 @@
|
|||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
#include <utils/qtcprocess.h>
|
#include <utils/qtcprocess.h>
|
||||||
|
|
||||||
|
using namespace Core;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace Squish {
|
namespace Squish::Internal {
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
static const char kItemSeparator = '\n';
|
static const char kItemSeparator = '\n';
|
||||||
static const char kPropertySeparator = '\t';
|
static const char kPropertySeparator = '\t';
|
||||||
@@ -28,12 +28,11 @@ ObjectsMapDocument::ObjectsMapDocument()
|
|||||||
connect(m_contentModel, &ObjectsMapModel::modelChanged, this, [this] { setModified(true); });
|
connect(m_contentModel, &ObjectsMapModel::modelChanged, this, [this] { setModified(true); });
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::IDocument::OpenResult ObjectsMapDocument::open(QString *errorString,
|
IDocument::OpenResult ObjectsMapDocument::open(const FilePath &fileName,
|
||||||
const Utils::FilePath &fileName,
|
const FilePath &realFileName)
|
||||||
const Utils::FilePath &realFileName)
|
|
||||||
{
|
{
|
||||||
OpenResult result = openImpl(errorString, fileName, realFileName);
|
OpenResult result = openImpl(fileName, realFileName);
|
||||||
if (result == OpenResult::Success) {
|
if (result.code == OpenResult::Success) {
|
||||||
setFilePath(fileName);
|
setFilePath(fileName);
|
||||||
setModified(fileName != realFileName);
|
setModified(fileName != realFileName);
|
||||||
}
|
}
|
||||||
@@ -72,19 +71,18 @@ void ObjectsMapDocument::setModified(bool modified)
|
|||||||
emit changed();
|
emit changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<> ObjectsMapDocument::reload(Core::IDocument::ReloadFlag flag,
|
Result<> ObjectsMapDocument::reload(IDocument::ReloadFlag flag, IDocument::ChangeType type)
|
||||||
Core::IDocument::ChangeType type)
|
|
||||||
{
|
{
|
||||||
Q_UNUSED(type)
|
Q_UNUSED(type)
|
||||||
if (flag == FlagIgnore)
|
if (flag == FlagIgnore)
|
||||||
return ResultOk;
|
return ResultOk;
|
||||||
emit aboutToReload();
|
emit aboutToReload();
|
||||||
QString errorString;
|
const OpenResult result = openImpl(filePath(), filePath());
|
||||||
const bool success = (openImpl(&errorString, filePath(), filePath()) == OpenResult::Success);
|
const bool success = result.code == OpenResult::Success;
|
||||||
if (success)
|
if (success)
|
||||||
setModified(false);
|
setModified(false);
|
||||||
emit reloadFinished(success);
|
emit reloadFinished(success);
|
||||||
return makeResult(success, errorString);
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ObjectsMapDocument::buildObjectsMapTree(const QByteArray &contents)
|
bool ObjectsMapDocument::buildObjectsMapTree(const QByteArray &contents)
|
||||||
@@ -175,36 +173,31 @@ QByteArray ObjectsMapDocument::contents() const
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::IDocument::OpenResult ObjectsMapDocument::openImpl(QString *error,
|
IDocument::OpenResult ObjectsMapDocument::openImpl(const FilePath &fileName,
|
||||||
const Utils::FilePath &fileName,
|
const FilePath &realFileName)
|
||||||
const Utils::FilePath &realFileName)
|
|
||||||
{
|
{
|
||||||
if (fileName.isEmpty())
|
if (fileName.isEmpty())
|
||||||
return OpenResult::CannotHandle;
|
return OpenResult::CannotHandle;
|
||||||
|
|
||||||
QByteArray text;
|
QByteArray text;
|
||||||
if (realFileName.fileName() == "objects.map") {
|
if (realFileName.fileName() == "objects.map") {
|
||||||
Utils::FileReader reader;
|
FileReader reader;
|
||||||
if (!reader.fetch(realFileName, error))
|
if (const Result<> res = reader.fetch(realFileName); !res)
|
||||||
return OpenResult::ReadError;
|
return {OpenResult::ReadError, res.error()};
|
||||||
|
|
||||||
text = reader.text();
|
text = reader.text();
|
||||||
} else {
|
} else {
|
||||||
const Utils::FilePath base = settings().squishPath();
|
const FilePath base = settings().squishPath();
|
||||||
if (base.isEmpty()) {
|
if (base.isEmpty()) {
|
||||||
if (error)
|
return {OpenResult::ReadError, Tr::tr("Incomplete Squish settings. "
|
||||||
error->append(Tr::tr("Incomplete Squish settings. "
|
"Missing Squish installation path.")};
|
||||||
"Missing Squish installation path."));
|
|
||||||
return OpenResult::ReadError;
|
|
||||||
}
|
|
||||||
const Utils::FilePath exe = base.pathAppended("lib/exec/objectmaptool").withExecutableSuffix();
|
|
||||||
if (!exe.isExecutableFile()) {
|
|
||||||
if (error)
|
|
||||||
error->append(Tr::tr("objectmaptool not found."));
|
|
||||||
return OpenResult::ReadError;
|
|
||||||
}
|
}
|
||||||
|
const FilePath exe = base.pathAppended("lib/exec/objectmaptool").withExecutableSuffix();
|
||||||
|
if (!exe.isExecutableFile())
|
||||||
|
return {OpenResult::ReadError, Tr::tr("objectmaptool not found.")};
|
||||||
|
|
||||||
Utils::Process objectMapReader;
|
|
||||||
|
Process objectMapReader;
|
||||||
objectMapReader.setCommand({exe, {"--scriptMap", "--mode", "read",
|
objectMapReader.setCommand({exe, {"--scriptMap", "--mode", "read",
|
||||||
"--scriptedObjectMapPath", realFileName.toUserOutput()}});
|
"--scriptedObjectMapPath", realFileName.toUserOutput()}});
|
||||||
objectMapReader.setUtf8Codec();
|
objectMapReader.setUtf8Codec();
|
||||||
@@ -212,11 +205,8 @@ Core::IDocument::OpenResult ObjectsMapDocument::openImpl(QString *error,
|
|||||||
objectMapReader.waitForFinished();
|
objectMapReader.waitForFinished();
|
||||||
text = objectMapReader.cleanedStdOut().toUtf8();
|
text = objectMapReader.cleanedStdOut().toUtf8();
|
||||||
}
|
}
|
||||||
if (!setContents(text)) {
|
if (!setContents(text))
|
||||||
if (error)
|
return {OpenResult::ReadError, Tr::tr("Failure while parsing objects.map content.")};
|
||||||
error->append(Tr::tr("Failure while parsing objects.map content."));
|
|
||||||
return OpenResult::ReadError;
|
|
||||||
}
|
|
||||||
return OpenResult::Success;
|
return OpenResult::Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,5 +234,4 @@ bool ObjectsMapDocument::writeFile(const Utils::FilePath &fileName) const
|
|||||||
return objectMapWriter.result() == Utils::ProcessResult::FinishedWithSuccess;
|
return objectMapWriter.result() == Utils::ProcessResult::FinishedWithSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Squish::Internal
|
||||||
} // namespace Squish
|
|
||||||
|
@@ -7,8 +7,7 @@
|
|||||||
|
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
|
||||||
namespace Squish {
|
namespace Squish::Internal {
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
class ObjectsMapModel;
|
class ObjectsMapModel;
|
||||||
|
|
||||||
@@ -18,8 +17,7 @@ class ObjectsMapDocument : public Core::IDocument
|
|||||||
public:
|
public:
|
||||||
ObjectsMapDocument();
|
ObjectsMapDocument();
|
||||||
|
|
||||||
OpenResult open(QString *errorString,
|
OpenResult open(const Utils::FilePath &fileName,
|
||||||
const Utils::FilePath &fileName,
|
|
||||||
const Utils::FilePath &realFileName) override;
|
const Utils::FilePath &realFileName) override;
|
||||||
Utils::FilePath fallbackSaveAsPath() const override;
|
Utils::FilePath fallbackSaveAsPath() const override;
|
||||||
QString fallbackSaveAsFileName() const override;
|
QString fallbackSaveAsFileName() const override;
|
||||||
@@ -37,8 +35,7 @@ protected:
|
|||||||
Utils::Result<> 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(const Utils::FilePath &fileName,
|
||||||
const Utils::FilePath &fileName,
|
|
||||||
const Utils::FilePath &realFileName);
|
const Utils::FilePath &realFileName);
|
||||||
bool buildObjectsMapTree(const QByteArray &contents);
|
bool buildObjectsMapTree(const QByteArray &contents);
|
||||||
bool writeFile(const Utils::FilePath &fileName) const;
|
bool writeFile(const Utils::FilePath &fileName) const;
|
||||||
@@ -48,5 +45,4 @@ private:
|
|||||||
bool m_isModified;
|
bool m_isModified;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Squish::Internal
|
||||||
} // namespace Squish
|
|
||||||
|
@@ -754,31 +754,29 @@ bool TextDocument::isModified() const
|
|||||||
return d->m_document.isModified();
|
return d->m_document.isModified();
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::IDocument::OpenResult TextDocument::open(QString *errorString,
|
IDocument::OpenResult TextDocument::open(const FilePath &filePath, const FilePath &realFilePath)
|
||||||
const Utils::FilePath &filePath,
|
|
||||||
const Utils::FilePath &realFilePath)
|
|
||||||
{
|
{
|
||||||
emit aboutToOpen(filePath, realFilePath);
|
emit aboutToOpen(filePath, realFilePath);
|
||||||
OpenResult success = openImpl(errorString, filePath, realFilePath, /*reload =*/ false);
|
OpenResult result = openImpl(filePath, realFilePath, /*reload =*/ false);
|
||||||
if (success == OpenResult::Success) {
|
if (result.code == OpenResult::Success) {
|
||||||
setMimeType(Utils::mimeTypeForFile(filePath, MimeMatchMode::MatchDefaultAndRemote).name());
|
setMimeType(Utils::mimeTypeForFile(filePath, MimeMatchMode::MatchDefaultAndRemote).name());
|
||||||
setTabSettings(d->m_tabSettings);
|
setTabSettings(d->m_tabSettings);
|
||||||
emit openFinishedSuccessfully();
|
emit openFinishedSuccessfully();
|
||||||
}
|
}
|
||||||
return success;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::IDocument::OpenResult TextDocument::openImpl(QString *errorString,
|
IDocument::OpenResult TextDocument::openImpl(const FilePath &filePath,
|
||||||
const Utils::FilePath &filePath,
|
const FilePath &realFilePath,
|
||||||
const Utils::FilePath &realFilePath,
|
bool reload)
|
||||||
bool reload)
|
|
||||||
{
|
{
|
||||||
QStringList content;
|
QStringList content;
|
||||||
|
QString errorString;
|
||||||
|
|
||||||
ReadResult readResult = Utils::TextFileFormat::ReadIOError;
|
ReadResult readResult = TextFileFormat::ReadIOError;
|
||||||
|
|
||||||
if (!filePath.isEmpty()) {
|
if (!filePath.isEmpty()) {
|
||||||
readResult = read(realFilePath, &content, errorString);
|
readResult = read(realFilePath, &content, &errorString);
|
||||||
const int chunks = content.size();
|
const int chunks = content.size();
|
||||||
|
|
||||||
// Don't call setUndoRedoEnabled(true) when reload is true and filenames are different,
|
// Don't call setUndoRedoEnabled(true) when reload is true and filenames are different,
|
||||||
@@ -829,7 +827,7 @@ Core::IDocument::OpenResult TextDocument::openImpl(QString *errorString,
|
|||||||
setFilePath(filePath);
|
setFilePath(filePath);
|
||||||
}
|
}
|
||||||
if (readResult == Utils::TextFileFormat::ReadIOError)
|
if (readResult == Utils::TextFileFormat::ReadIOError)
|
||||||
return OpenResult::ReadError;
|
return {OpenResult::ReadError, errorString};
|
||||||
return OpenResult::Success;
|
return OpenResult::Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -853,15 +851,13 @@ Result<> TextDocument::reload(const FilePath &realFilePath)
|
|||||||
if (documentLayout)
|
if (documentLayout)
|
||||||
documentLayout->documentAboutToReload(this); // removes text marks non-permanently
|
documentLayout->documentAboutToReload(this); // removes text marks non-permanently
|
||||||
|
|
||||||
QString errorString;
|
const OpenResult result = openImpl(filePath(), realFilePath, /*reload =*/true);
|
||||||
bool success = openImpl(&errorString, filePath(), realFilePath, /*reload =*/true)
|
|
||||||
== OpenResult::Success;
|
|
||||||
|
|
||||||
if (documentLayout)
|
if (documentLayout)
|
||||||
documentLayout->documentReloaded(this); // re-adds text marks
|
documentLayout->documentReloaded(this); // re-adds text marks
|
||||||
emit reloadFinished(success);
|
emit reloadFinished(result.code == OpenResult::Success);
|
||||||
|
|
||||||
return makeResult(success, errorString);
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TextDocument::setPlainText(const QString &text)
|
bool TextDocument::setPlainText(const QString &text)
|
||||||
|
@@ -117,8 +117,7 @@ public:
|
|||||||
void setFallbackSaveAsPath(const Utils::FilePath &fallbackSaveAsPath);
|
void setFallbackSaveAsPath(const Utils::FilePath &fallbackSaveAsPath);
|
||||||
void setFallbackSaveAsFileName(const QString &fallbackSaveAsFileName);
|
void setFallbackSaveAsFileName(const QString &fallbackSaveAsFileName);
|
||||||
|
|
||||||
OpenResult open(QString *errorString, const Utils::FilePath &filePath,
|
OpenResult open(const Utils::FilePath &filePath, const Utils::FilePath &realFilePath) override;
|
||||||
const Utils::FilePath &realFilePath) override;
|
|
||||||
virtual Utils::Result<> reload();
|
virtual Utils::Result<> reload();
|
||||||
Utils::Result<> reload(const Utils::FilePath &realFilePath);
|
Utils::Result<> reload(const Utils::FilePath &realFilePath);
|
||||||
|
|
||||||
@@ -170,8 +169,7 @@ protected:
|
|||||||
virtual void slotCodeStyleSettingsChanged(); // Used in CppEditorDocumet
|
virtual void slotCodeStyleSettingsChanged(); // Used in CppEditorDocumet
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OpenResult openImpl(QString *errorString,
|
OpenResult openImpl(const Utils::FilePath &filePath,
|
||||||
const Utils::FilePath &filePath,
|
|
||||||
const Utils::FilePath &realFileName,
|
const Utils::FilePath &realFileName,
|
||||||
bool reload);
|
bool reload);
|
||||||
void cleanWhitespace(QTextCursor &cursor, bool inEntireDocument, bool cleanIndentation);
|
void cleanWhitespace(QTextCursor &cursor, bool inEntireDocument, bool cleanIndentation);
|
||||||
|
@@ -27,15 +27,14 @@ SubmitEditorFile::SubmitEditorFile(VcsBaseSubmitEditor *editor) :
|
|||||||
this, &IDocument::contentsChanged);
|
this, &IDocument::contentsChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
IDocument::OpenResult SubmitEditorFile::open(QString *errorString, const FilePath &filePath,
|
IDocument::OpenResult SubmitEditorFile::open(const FilePath &filePath, const FilePath &realFilePath)
|
||||||
const FilePath &realFilePath)
|
|
||||||
{
|
{
|
||||||
if (filePath.isEmpty())
|
if (filePath.isEmpty())
|
||||||
return OpenResult::ReadError;
|
return OpenResult::ReadError;
|
||||||
|
|
||||||
FileReader reader;
|
FileReader reader;
|
||||||
if (!reader.fetch(realFilePath, errorString))
|
if (const Result<> res = reader.fetch(realFilePath); !res)
|
||||||
return OpenResult::ReadError;
|
return {OpenResult::ReadError, res.error()};
|
||||||
|
|
||||||
const QString text = QString::fromLocal8Bit(reader.text());
|
const QString text = QString::fromLocal8Bit(reader.text());
|
||||||
if (!m_editor->setFileContents(text.toUtf8()))
|
if (!m_editor->setFileContents(text.toUtf8()))
|
||||||
|
@@ -17,8 +17,8 @@ class SubmitEditorFile : public Core::IDocument
|
|||||||
public:
|
public:
|
||||||
explicit SubmitEditorFile(VcsBaseSubmitEditor *editor);
|
explicit SubmitEditorFile(VcsBaseSubmitEditor *editor);
|
||||||
|
|
||||||
OpenResult open(QString *errorString, const Utils::FilePath &filePath,
|
OpenResult open(const Utils::FilePath &filePath, const Utils::FilePath &realFilePath) override;
|
||||||
const Utils::FilePath &realFilePath) override;
|
|
||||||
QByteArray contents() const override;
|
QByteArray contents() const override;
|
||||||
bool setContents(const QByteArray &contents) override;
|
bool setContents(const QByteArray &contents) override;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user