forked from qt-creator/qt-creator
Designer: Move "open" implementation to document.
This avoids that reloading needs to call back to the editor, and is in preparation to a complete move of "open" to the document. Change-Id: Ic24ecf7612c311055276e81edb080ab855590df9 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
This commit is contained in:
@@ -39,11 +39,6 @@
|
|||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QBuffer>
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QDesignerFormWindowInterface>
|
|
||||||
#include <QFileInfo>
|
|
||||||
|
|
||||||
namespace Designer {
|
namespace Designer {
|
||||||
|
|
||||||
using namespace Internal;
|
using namespace Internal;
|
||||||
@@ -58,49 +53,9 @@ FormWindowEditor::~FormWindowEditor()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormWindowEditor::finalizeInitialization()
|
|
||||||
{
|
|
||||||
// Revert to saved/load externally modified files.
|
|
||||||
connect(formWindowFile(), &FormWindowFile::reloadRequested,
|
|
||||||
[this](QString *errorString, const QString &fileName) {
|
|
||||||
open(errorString, fileName, fileName);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FormWindowEditor::open(QString *errorString, const QString &fileName, const QString &realFileName)
|
bool FormWindowEditor::open(QString *errorString, const QString &fileName, const QString &realFileName)
|
||||||
{
|
{
|
||||||
if (Designer::Constants::Internal::debug)
|
return formWindowFile()->open(errorString, fileName, realFileName);
|
||||||
qDebug() << "FormWindowEditor::open" << fileName;
|
|
||||||
|
|
||||||
auto document = qobject_cast<FormWindowFile *>(textDocument());
|
|
||||||
QDesignerFormWindowInterface *form = document->formWindow();
|
|
||||||
QTC_ASSERT(form, return false);
|
|
||||||
|
|
||||||
if (fileName.isEmpty())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
const QFileInfo fi(fileName);
|
|
||||||
const QString absfileName = fi.absoluteFilePath();
|
|
||||||
|
|
||||||
QString contents;
|
|
||||||
if (document->read(absfileName, &contents, errorString) != Utils::TextFileFormat::ReadSuccess)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
form->setFileName(absfileName);
|
|
||||||
const QByteArray contentsBA = contents.toUtf8();
|
|
||||||
QBuffer str;
|
|
||||||
str.setData(contentsBA);
|
|
||||||
str.open(QIODevice::ReadOnly);
|
|
||||||
if (!form->setContents(&str, errorString))
|
|
||||||
return false;
|
|
||||||
form->setDirty(fileName != realFileName);
|
|
||||||
|
|
||||||
document->syncXmlFromFormWindow();
|
|
||||||
document->setFilePath(Utils::FileName::fromString(absfileName));
|
|
||||||
document->setShouldAutoSave(false);
|
|
||||||
document->resourceHandler()->updateResources(true);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *FormWindowEditor::toolBar()
|
QWidget *FormWindowEditor::toolBar()
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ public:
|
|||||||
FormWindowEditor();
|
FormWindowEditor();
|
||||||
~FormWindowEditor();
|
~FormWindowEditor();
|
||||||
|
|
||||||
void finalizeInitialization();
|
|
||||||
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
|
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
|
||||||
QWidget *toolBar();
|
QWidget *toolBar();
|
||||||
bool isDesignModePreferred() const;
|
bool isDesignModePreferred() const;
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QBuffer>
|
||||||
#include <QDesignerFormWindowInterface>
|
#include <QDesignerFormWindowInterface>
|
||||||
#include <QDesignerFormWindowManagerInterface>
|
#include <QDesignerFormWindowManagerInterface>
|
||||||
#include <QDesignerFormEditorInterface>
|
#include <QDesignerFormEditorInterface>
|
||||||
@@ -71,6 +72,41 @@ FormWindowFile::FormWindowFile(QDesignerFormWindowInterface *form, QObject *pare
|
|||||||
m_resourceHandler, SLOT(updateResources()));
|
m_resourceHandler, SLOT(updateResources()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FormWindowFile::open(QString *errorString, const QString &fileName, const QString &realFileName)
|
||||||
|
{
|
||||||
|
if (Designer::Constants::Internal::debug)
|
||||||
|
qDebug() << "FormWindowFile::open" << fileName;
|
||||||
|
|
||||||
|
QDesignerFormWindowInterface *form = formWindow();
|
||||||
|
QTC_ASSERT(form, return false);
|
||||||
|
|
||||||
|
if (fileName.isEmpty())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
const QFileInfo fi(fileName);
|
||||||
|
const QString absfileName = fi.absoluteFilePath();
|
||||||
|
|
||||||
|
QString contents;
|
||||||
|
if (read(absfileName, &contents, errorString) != Utils::TextFileFormat::ReadSuccess)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
form->setFileName(absfileName);
|
||||||
|
const QByteArray contentsBA = contents.toUtf8();
|
||||||
|
QBuffer str;
|
||||||
|
str.setData(contentsBA);
|
||||||
|
str.open(QIODevice::ReadOnly);
|
||||||
|
if (!form->setContents(&str, errorString))
|
||||||
|
return false;
|
||||||
|
form->setDirty(fileName != realFileName);
|
||||||
|
|
||||||
|
syncXmlFromFormWindow();
|
||||||
|
setFilePath(Utils::FileName::fromString(absfileName));
|
||||||
|
setShouldAutoSave(false);
|
||||||
|
resourceHandler()->updateResources(true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool FormWindowFile::save(QString *errorString, const QString &name, bool autoSave)
|
bool FormWindowFile::save(QString *errorString, const QString &name, bool autoSave)
|
||||||
{
|
{
|
||||||
const FileName actualName = name.isEmpty() ? filePath() : FileName::fromString(name);
|
const FileName actualName = name.isEmpty() ? filePath() : FileName::fromString(name);
|
||||||
@@ -175,8 +211,7 @@ bool FormWindowFile::reload(QString *errorString, ReloadFlag flag, ChangeType ty
|
|||||||
emit changed();
|
emit changed();
|
||||||
} else {
|
} else {
|
||||||
emit aboutToReload();
|
emit aboutToReload();
|
||||||
emit reloadRequested(errorString, filePath().toString());
|
const bool success = open(errorString, filePath().toString(), filePath().toString());
|
||||||
const bool success = errorString->isEmpty();
|
|
||||||
emit reloadFinished(success);
|
emit reloadFinished(success);
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ public:
|
|||||||
explicit FormWindowFile(QDesignerFormWindowInterface *form, QObject *parent = 0);
|
explicit FormWindowFile(QDesignerFormWindowInterface *form, QObject *parent = 0);
|
||||||
~FormWindowFile() { }
|
~FormWindowFile() { }
|
||||||
|
|
||||||
|
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
|
||||||
|
|
||||||
// IDocument
|
// IDocument
|
||||||
bool save(QString *errorString, const QString &fileName, bool autoSave);
|
bool save(QString *errorString, const QString &fileName, bool autoSave);
|
||||||
bool setContents(const QByteArray &contents);
|
bool setContents(const QByteArray &contents);
|
||||||
@@ -72,10 +74,6 @@ public:
|
|||||||
QString formWindowContents() const;
|
QString formWindowContents() const;
|
||||||
ResourceHandler *resourceHandler() const;
|
ResourceHandler *resourceHandler() const;
|
||||||
|
|
||||||
signals:
|
|
||||||
// Internal
|
|
||||||
void reloadRequested(QString *errorString, const QString &);
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setFilePath(const Utils::FileName &);
|
void setFilePath(const Utils::FileName &);
|
||||||
void setShouldAutoSave(bool sad = true) { m_shouldAutoSave = sad; }
|
void setShouldAutoSave(bool sad = true) { m_shouldAutoSave = sad; }
|
||||||
|
|||||||
Reference in New Issue
Block a user