forked from qt-creator/qt-creator
Design mode/Qt Designer: clean-up Part II: Fix undo.
Re-introduce FormEditorFile that delegates dirty handling to the form window. Change DesignerXmlEditable to be an IEditor that embeds TextEditable so that the PlainTextEditor can work with it, but delegates relevant functionality to FormEditorFile. Centralize all form window creation code that was scattered around in FormEditorW::createEditor() and have that return a struct Editor data, which is passed to FormEditorStack. Update the text editor only on open/createNew/switch away from design mode.
This commit is contained in:
@@ -39,7 +39,8 @@ HEADERS += formeditorplugin.h \
|
|||||||
designerxmleditor.h \
|
designerxmleditor.h \
|
||||||
designercontext.h \
|
designercontext.h \
|
||||||
faketoolbar.h \
|
faketoolbar.h \
|
||||||
formeditorstack.h
|
formeditorstack.h \
|
||||||
|
editordata.h
|
||||||
|
|
||||||
SOURCES += formeditorplugin.cpp \
|
SOURCES += formeditorplugin.cpp \
|
||||||
formeditorfactory.cpp \
|
formeditorfactory.cpp \
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
|
|
||||||
#include <QtGui/QWidget>
|
#include <QtGui/QWidget>
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
|
#include <QtCore/QSettings>
|
||||||
|
|
||||||
enum { debug = 0 };
|
enum { debug = 0 };
|
||||||
|
|
||||||
|
|||||||
@@ -29,64 +29,157 @@
|
|||||||
|
|
||||||
#include "designerxmleditor.h"
|
#include "designerxmleditor.h"
|
||||||
#include "designerconstants.h"
|
#include "designerconstants.h"
|
||||||
|
#include "qt_private/formwindowbase_p.h"
|
||||||
|
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/modemanager.h>
|
#include <coreplugin/modemanager.h>
|
||||||
#include <coreplugin/imode.h>
|
#include <coreplugin/imode.h>
|
||||||
#include <coreplugin/coreconstants.h>
|
#include <coreplugin/coreconstants.h>
|
||||||
#include <coreplugin/uniqueidmanager.h>
|
#include <coreplugin/uniqueidmanager.h>
|
||||||
#include <QDebug>
|
#include <texteditor/basetextdocument.h>
|
||||||
|
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
|
#include <QtDesigner/QDesignerFormWindowInterface>
|
||||||
|
|
||||||
|
#include <QtCore/QDebug>
|
||||||
|
#include <QtCore/QFileInfo>
|
||||||
|
#include <QtCore/QFile>
|
||||||
|
|
||||||
namespace Designer {
|
namespace Designer {
|
||||||
namespace Internal {
|
|
||||||
DesignerXmlEditor::DesignerXmlEditor(QWidget *parent) : TextEditor::PlainTextEditor(parent)
|
DesignerXmlEditorEditable::DesignerXmlEditorEditable(Internal::DesignerXmlEditor *editor,
|
||||||
|
QDesignerFormWindowInterface *form,
|
||||||
|
QObject *parent) :
|
||||||
|
Core::IEditor(parent),
|
||||||
|
m_textEditable(editor),
|
||||||
|
m_file(form)
|
||||||
{
|
{
|
||||||
setReadOnly(true);
|
Core::UniqueIDManager *uidm = Core::UniqueIDManager::instance();
|
||||||
connect(Core::ICore::instance()->editorManager(), SIGNAL(currentEditorChanged(Core::IEditor*)),
|
m_context << uidm->uniqueIdentifier(QLatin1String(Designer::Constants::K_DESIGNER_XML_EDITOR_ID));
|
||||||
SLOT(updateEditorInfoBar(Core::IEditor*)));
|
m_context << uidm->uniqueIdentifier(QLatin1String(Designer::Constants::C_DESIGNER_XML_EDITOR));
|
||||||
|
connect(form, SIGNAL(changed()), this, SIGNAL(changed()));
|
||||||
|
// Revert to saved/load externally modified files
|
||||||
|
connect(&m_file, SIGNAL(reload(QString)), this, SLOT(slotOpen(QString)));
|
||||||
}
|
}
|
||||||
|
|
||||||
DesignerXmlEditor::~DesignerXmlEditor()
|
bool DesignerXmlEditorEditable::createNew(const QString &contents)
|
||||||
{
|
{
|
||||||
|
if (Designer::Constants::Internal::debug)
|
||||||
|
qDebug() << "DesignerXmlEditorEditable::createNew" << contents.size();
|
||||||
|
|
||||||
|
syncXmlEditor(QString());
|
||||||
|
|
||||||
|
QDesignerFormWindowInterface *form = m_file.formWindow();
|
||||||
|
QTC_ASSERT(form, return false);
|
||||||
|
|
||||||
|
if (contents.isEmpty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
form->setContents(contents);
|
||||||
|
if (form->mainContainer() == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
syncXmlEditor(contents);
|
||||||
|
m_file.setFileName(QString());
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DesignerXmlEditor::open(const QString &fileName)
|
void DesignerXmlEditorEditable::slotOpen(const QString &fileName)
|
||||||
{
|
{
|
||||||
bool res = TextEditor::PlainTextEditor::open(fileName);
|
open(fileName);
|
||||||
QPlainTextEdit::setReadOnly(true);
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesignerXmlEditor::updateEditorInfoBar(Core::IEditor *editor)
|
bool DesignerXmlEditorEditable::open(const QString &fileName)
|
||||||
{
|
{
|
||||||
if (editor == editableInterface()) {
|
if (Designer::Constants::Internal::debug)
|
||||||
Core::EditorManager::instance()->showEditorInfoBar(Constants::INFO_READ_ONLY,
|
qDebug() << "DesignerXmlEditorEditable::open" << fileName;
|
||||||
tr("This file can only be edited in Design Mode."),
|
|
||||||
"Open Designer", this, SLOT(designerOpened()));
|
QDesignerFormWindowInterface *form = m_file.formWindow();
|
||||||
|
QTC_ASSERT(form, return false);
|
||||||
|
|
||||||
|
if (fileName.isEmpty()) {
|
||||||
|
setDisplayName(tr("untitled"));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
if (!editor)
|
|
||||||
Core::EditorManager::instance()->hideEditorInfoBar(Constants::INFO_READ_ONLY);
|
const QFileInfo fi(fileName);
|
||||||
|
const QString absfileName = fi.absoluteFilePath();
|
||||||
|
|
||||||
|
QFile file(absfileName);
|
||||||
|
if (!file.open(QIODevice::ReadOnly|QIODevice::Text))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
form->setFileName(absfileName);
|
||||||
|
|
||||||
|
const QString contents = QString::fromUtf8(file.readAll());
|
||||||
|
form->setContents(contents);
|
||||||
|
file.close();
|
||||||
|
if (!form->mainContainer())
|
||||||
|
return false;
|
||||||
|
form->setDirty(false);
|
||||||
|
syncXmlEditor(contents);
|
||||||
|
|
||||||
|
setDisplayName(fi.fileName());
|
||||||
|
m_file.setFileName(absfileName);
|
||||||
|
|
||||||
|
emit changed();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesignerXmlEditor::designerOpened()
|
void DesignerXmlEditorEditable::syncXmlEditor()
|
||||||
{
|
{
|
||||||
Core::ICore::instance()->modeManager()->activateMode(Core::Constants::MODE_DESIGN);
|
if (Designer::Constants::Internal::debug)
|
||||||
|
qDebug() << "DesignerXmlEditorEditable::syncXmlEditor" << m_file.fileName();
|
||||||
|
syncXmlEditor(contents());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
void DesignerXmlEditorEditable::syncXmlEditor(const QString &contents)
|
||||||
|
{
|
||||||
|
m_textEditable.editor()->setPlainText(contents);
|
||||||
|
m_textEditable.editor()->setReadOnly(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
Core::IFile *DesignerXmlEditorEditable::file()
|
||||||
|
{
|
||||||
|
return &m_file;
|
||||||
|
}
|
||||||
|
|
||||||
QString DesignerXmlEditorEditable::id() const
|
QString DesignerXmlEditorEditable::id() const
|
||||||
{
|
{
|
||||||
return QLatin1String(Designer::Constants::K_DESIGNER_XML_EDITOR_ID);
|
return QLatin1String(Designer::Constants::K_DESIGNER_XML_EDITOR_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
DesignerXmlEditorEditable::DesignerXmlEditorEditable(Internal::DesignerXmlEditor *editor)
|
QString DesignerXmlEditorEditable::displayName() const
|
||||||
: TextEditor::PlainTextEditorEditable(editor)
|
|
||||||
{
|
{
|
||||||
Core::UniqueIDManager *uidm = Core::UniqueIDManager::instance();
|
return m_textEditable.displayName();
|
||||||
m_context << uidm->uniqueIdentifier(Designer::Constants::K_DESIGNER_XML_EDITOR_ID);
|
}
|
||||||
m_context << uidm->uniqueIdentifier(Designer::Constants::C_DESIGNER_XML_EDITOR);
|
|
||||||
|
void DesignerXmlEditorEditable::setDisplayName(const QString &title)
|
||||||
|
{
|
||||||
|
m_textEditable.setDisplayName(title);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DesignerXmlEditorEditable::duplicateSupported() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Core::IEditor *DesignerXmlEditorEditable::duplicate(QWidget *)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray DesignerXmlEditorEditable::saveState() const
|
||||||
|
{
|
||||||
|
return m_textEditable.saveState();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DesignerXmlEditorEditable::restoreState(const QByteArray &state)
|
||||||
|
{
|
||||||
|
return m_textEditable.restoreState(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<int> DesignerXmlEditorEditable::context() const
|
QList<int> DesignerXmlEditorEditable::context() const
|
||||||
@@ -94,17 +187,78 @@ QList<int> DesignerXmlEditorEditable::context() const
|
|||||||
return m_context;
|
return m_context;
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::IEditor *DesignerXmlEditorEditable::duplicate(QWidget *parent)
|
QWidget *DesignerXmlEditorEditable::widget()
|
||||||
|
{
|
||||||
|
return m_textEditable.widget();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DesignerXmlEditorEditable::isTemporary() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget *DesignerXmlEditorEditable::toolBar()
|
||||||
{
|
{
|
||||||
Q_UNUSED(parent);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString DesignerXmlEditorEditable::contents() const
|
||||||
|
{
|
||||||
|
const qdesigner_internal::FormWindowBase *fw = qobject_cast<const qdesigner_internal::FormWindowBase *>(m_file.formWindow());
|
||||||
|
QTC_ASSERT(fw, return QString());
|
||||||
|
return fw->fileContents(); // No warnings about spacers here
|
||||||
|
}
|
||||||
|
|
||||||
|
TextEditor::BaseTextDocument *DesignerXmlEditorEditable::textDocument()
|
||||||
|
{
|
||||||
|
return qobject_cast<TextEditor::BaseTextDocument*>(m_textEditable.file());
|
||||||
|
}
|
||||||
|
|
||||||
|
TextEditor::PlainTextEditorEditable *DesignerXmlEditorEditable::textEditable()
|
||||||
|
{
|
||||||
|
return &m_textEditable;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
|
DesignerXmlEditor::DesignerXmlEditor(QDesignerFormWindowInterface *form,
|
||||||
|
QWidget *parent) :
|
||||||
|
TextEditor::PlainTextEditor(parent),
|
||||||
|
m_editable(new DesignerXmlEditorEditable(this, form))
|
||||||
|
{
|
||||||
|
setReadOnly(true);
|
||||||
|
connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
|
||||||
|
SLOT(updateEditorInfoBar(Core::IEditor*)));
|
||||||
|
}
|
||||||
|
|
||||||
TextEditor::BaseTextEditorEditable *DesignerXmlEditor::createEditableInterface()
|
TextEditor::BaseTextEditorEditable *DesignerXmlEditor::createEditableInterface()
|
||||||
{
|
{
|
||||||
return new DesignerXmlEditorEditable(this);
|
if (Designer::Constants::Internal::debug)
|
||||||
|
qDebug() << "DesignerXmlEditor::createEditableInterface()";
|
||||||
|
return m_editable->textEditable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DesignerXmlEditor::updateEditorInfoBar(Core::IEditor *editor)
|
||||||
|
{
|
||||||
|
if (editor == m_editable) {
|
||||||
|
Core::EditorManager::instance()->showEditorInfoBar(Constants::INFO_READ_ONLY,
|
||||||
|
tr("This file can only be edited in Design Mode."),
|
||||||
|
"Open Designer", this, SLOT(designerModeClicked()));
|
||||||
|
}
|
||||||
|
if (!editor)
|
||||||
|
Core::EditorManager::instance()->hideEditorInfoBar(Constants::INFO_READ_ONLY);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DesignerXmlEditor::designerModeClicked()
|
||||||
|
{
|
||||||
|
Core::ICore::instance()->modeManager()->activateMode(QLatin1String(Core::Constants::MODE_DESIGN));
|
||||||
|
}
|
||||||
|
|
||||||
|
DesignerXmlEditorEditable *DesignerXmlEditor::designerEditable() const
|
||||||
|
{
|
||||||
|
return m_editable;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} // namespace Designer
|
} // namespace Designer
|
||||||
|
|
||||||
|
|||||||
@@ -31,58 +31,106 @@
|
|||||||
#define DESIGNERXMLEDITOR_H
|
#define DESIGNERXMLEDITOR_H
|
||||||
|
|
||||||
#include "designer_export.h"
|
#include "designer_export.h"
|
||||||
|
#include "formwindowfile.h"
|
||||||
|
|
||||||
#include <texteditor/plaintexteditor.h>
|
#include <texteditor/plaintexteditor.h>
|
||||||
#include <texteditor/basetexteditor.h>
|
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
class IEditor;
|
|
||||||
class IMode;
|
class IMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace TextEditor {
|
||||||
|
class BaseTextDocument;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Designer {
|
namespace Designer {
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
class DesignerXmlEditor;
|
class DesignerXmlEditor;
|
||||||
}
|
}
|
||||||
|
|
||||||
class DESIGNER_EXPORT DesignerXmlEditorEditable : public TextEditor::PlainTextEditorEditable
|
// The actual Core::IEditor belonging to Qt Designer. It internally embeds
|
||||||
|
// a TextEditor::PlainTextEditorEditable which is used to make the
|
||||||
|
// Read-only edit mode XML text editor work and delegates some functionality
|
||||||
|
// to it. However, the isDirty() handling is delegated to the FormWindowFile,
|
||||||
|
// which is the Core::IFile used for it.
|
||||||
|
class DESIGNER_EXPORT DesignerXmlEditorEditable : public Core::IEditor
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit DesignerXmlEditorEditable(Internal::DesignerXmlEditor *editor);
|
explicit DesignerXmlEditorEditable(Internal::DesignerXmlEditor *editor,
|
||||||
QList<int> context() const;
|
QDesignerFormWindowInterface *form,
|
||||||
|
QObject *parent = 0);
|
||||||
|
|
||||||
bool duplicateSupported() const { return false; }
|
// IEditor
|
||||||
Core::IEditor *duplicate(QWidget *parent);
|
virtual bool createNew(const QString &contents = QString());
|
||||||
|
virtual bool open(const QString &fileName = QString());
|
||||||
|
virtual Core::IFile *file();
|
||||||
virtual QString id() const;
|
virtual QString id() const;
|
||||||
|
virtual QString displayName() const;
|
||||||
|
virtual void setDisplayName(const QString &title);
|
||||||
|
|
||||||
|
virtual bool duplicateSupported() const;
|
||||||
|
virtual IEditor *duplicate(QWidget *parent);
|
||||||
|
|
||||||
|
virtual QByteArray saveState() const;
|
||||||
|
virtual bool restoreState(const QByteArray &state);
|
||||||
|
|
||||||
|
virtual bool isTemporary() const;
|
||||||
|
|
||||||
|
virtual QWidget *toolBar();
|
||||||
|
|
||||||
|
// IContext
|
||||||
|
virtual QList<int> context() const;
|
||||||
|
virtual QWidget *widget();
|
||||||
|
|
||||||
|
// For uic code model support
|
||||||
|
QString contents() const;
|
||||||
|
|
||||||
|
TextEditor::BaseTextDocument *textDocument();
|
||||||
|
TextEditor::PlainTextEditorEditable *textEditable();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void syncXmlEditor();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void slotOpen(const QString &fileName);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void syncXmlEditor(const QString &contents);
|
||||||
|
|
||||||
|
TextEditor::PlainTextEditorEditable m_textEditable;
|
||||||
|
Internal::FormWindowFile m_file;
|
||||||
QList<int> m_context;
|
QList<int> m_context;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/* A stub-like, read-only text editor which displays UI files as text. Could be used as a
|
||||||
* A stub-like, read-only text editor which displays UI files as text. Could be used as a
|
|
||||||
* read/write editor too, but due to lack of XML editor, highlighting and other such
|
* read/write editor too, but due to lack of XML editor, highlighting and other such
|
||||||
* functionality, editing is disabled.
|
* functionality, editing is disabled.
|
||||||
*/
|
* Provides an informational title bar containing a button triggering a
|
||||||
|
* switch to design mode.
|
||||||
|
* Internally manages DesignerXmlEditorEditable and uses the plain text
|
||||||
|
* editable embedded in it. */
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class DesignerXmlEditor : public TextEditor::PlainTextEditor
|
class DesignerXmlEditor : public TextEditor::PlainTextEditor
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit DesignerXmlEditor(QWidget *parent = 0);
|
explicit DesignerXmlEditor(QDesignerFormWindowInterface *form,
|
||||||
virtual ~DesignerXmlEditor();
|
QWidget *parent = 0);
|
||||||
bool open(const QString &fileName = QString());
|
|
||||||
|
DesignerXmlEditorEditable *designerEditable() const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void designerOpened();
|
void designerModeClicked();
|
||||||
void updateEditorInfoBar(Core::IEditor *editor);
|
void updateEditorInfoBar(Core::IEditor *editor);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual TextEditor::BaseTextEditorEditable *createEditableInterface();
|
virtual TextEditor::BaseTextEditorEditable *createEditableInterface();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
DesignerXmlEditorEditable *m_editable;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Internal
|
} // Internal
|
||||||
|
|||||||
49
src/plugins/designer/editordata.h
Normal file
49
src/plugins/designer/editordata.h
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
/**************************************************************************
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator
|
||||||
|
**
|
||||||
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
**
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** Commercial Usage
|
||||||
|
**
|
||||||
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||||
|
** accordance with the Qt Commercial License Agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
**
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** If you are unsure which license is appropriate for your use, please
|
||||||
|
** contact the sales department at http://qt.nokia.com/contact.
|
||||||
|
**
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
#ifndef EDITORDATA_H
|
||||||
|
#define EDITORDATA_H
|
||||||
|
|
||||||
|
namespace Designer {
|
||||||
|
class FormWindowEditor;
|
||||||
|
class DesignerXmlEditorEditable;
|
||||||
|
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
// Associates XML and its form editor
|
||||||
|
struct EditorData {
|
||||||
|
EditorData() : xmlEditor(0), formEditor(0) {}
|
||||||
|
DesignerXmlEditorEditable *xmlEditor;
|
||||||
|
Designer::FormWindowEditor *formEditor;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace Designer
|
||||||
|
|
||||||
|
#endif // EDITORDATA_H
|
||||||
@@ -92,9 +92,9 @@ QDockWidget* const* EditorWidget::designerDockWidgets() const
|
|||||||
return m_designerDockWidgets;
|
return m_designerDockWidgets;
|
||||||
}
|
}
|
||||||
|
|
||||||
Designer::FormWindowEditor *EditorWidget::createFormWindowEditor(DesignerXmlEditorEditable *xmlEditor)
|
void EditorWidget::add(const EditorData &d)
|
||||||
{
|
{
|
||||||
return m_stack->createFormWindowEditor(xmlEditor);
|
m_stack->add(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EditorWidget::removeFormWindowEditor(Core::IEditor *xmlEditor)
|
bool EditorWidget::removeFormWindowEditor(Core::IEditor *xmlEditor)
|
||||||
|
|||||||
@@ -34,9 +34,6 @@
|
|||||||
|
|
||||||
#include <utils/fancymainwindow.h>
|
#include <utils/fancymainwindow.h>
|
||||||
|
|
||||||
#include <QtCore/QHash>
|
|
||||||
#include <QtCore/QVariant>
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QDesignerFormWindowInterface;
|
class QDesignerFormWindowInterface;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
@@ -49,10 +46,11 @@ class FormWindowEditor;
|
|||||||
class DesignerXmlEditorEditable;
|
class DesignerXmlEditorEditable;
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
struct EditorData;
|
||||||
class FormEditorStack;
|
class FormEditorStack;
|
||||||
class FormEditorW;
|
class FormEditorW;
|
||||||
/* Form editor splitter used as editor window. Contains the shared designer
|
|
||||||
* windows. */
|
// Design mode main view.
|
||||||
class EditorWidget : public Utils::FancyMainWindow
|
class EditorWidget : public Utils::FancyMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -63,7 +61,7 @@ public:
|
|||||||
QDockWidget* const* designerDockWidgets() const;
|
QDockWidget* const* designerDockWidgets() const;
|
||||||
|
|
||||||
// Form editor stack API
|
// Form editor stack API
|
||||||
Designer::FormWindowEditor *createFormWindowEditor(DesignerXmlEditorEditable *xmlEditor);
|
void add(const EditorData &d);
|
||||||
bool removeFormWindowEditor(Core::IEditor *xmlEditor);
|
bool removeFormWindowEditor(Core::IEditor *xmlEditor);
|
||||||
bool setVisibleEditor(Core::IEditor *xmlEditor);
|
bool setVisibleEditor(Core::IEditor *xmlEditor);
|
||||||
Designer::FormWindowEditor *formWindowEditorForXmlEditor(const Core::IEditor *xmlEditor) const;
|
Designer::FormWindowEditor *formWindowEditorForXmlEditor(const Core::IEditor *xmlEditor) const;
|
||||||
|
|||||||
@@ -30,32 +30,34 @@
|
|||||||
#include "formeditorfactory.h"
|
#include "formeditorfactory.h"
|
||||||
#include "formeditorw.h"
|
#include "formeditorw.h"
|
||||||
#include "formwindoweditor.h"
|
#include "formwindoweditor.h"
|
||||||
|
#include "editordata.h"
|
||||||
#include "designerconstants.h"
|
#include "designerconstants.h"
|
||||||
#include "designerxmleditor.h"
|
#include "designerxmleditor.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/fileiconprovider.h>
|
#include <coreplugin/fileiconprovider.h>
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <texteditor/texteditorsettings.h>
|
|
||||||
|
|
||||||
#include <QtCore/QFileInfo>
|
#include <QtCore/QFileInfo>
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
|
|
||||||
using namespace Designer::Internal;
|
|
||||||
using namespace Designer::Constants;
|
using namespace Designer::Constants;
|
||||||
|
|
||||||
|
namespace Designer {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
FormEditorFactory::FormEditorFactory()
|
FormEditorFactory::FormEditorFactory()
|
||||||
: Core::IEditorFactory(Core::ICore::instance()),
|
: Core::IEditorFactory(Core::ICore::instance()),
|
||||||
m_mimeTypes(QLatin1String(FORM_MIMETYPE))
|
m_mimeTypes(QLatin1String(FORM_MIMETYPE))
|
||||||
{
|
{
|
||||||
Core::FileIconProvider *iconProvider = Core::FileIconProvider::instance();
|
Core::FileIconProvider *iconProvider = Core::FileIconProvider::instance();
|
||||||
iconProvider->registerIconOverlayForSuffix(QIcon(":/formeditor/images/qt_ui.png"),
|
iconProvider->registerIconOverlayForSuffix(QIcon(QLatin1String(":/formeditor/images/qt_ui.png")),
|
||||||
QLatin1String("ui"));
|
QLatin1String("ui"));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString FormEditorFactory::id() const
|
QString FormEditorFactory::id() const
|
||||||
{
|
{
|
||||||
return QLatin1String(DESIGNER_XML_EDITOR_ID); //FORMEDITOR_ID);
|
return QLatin1String(DESIGNER_XML_EDITOR_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString FormEditorFactory::displayName() const
|
QString FormEditorFactory::displayName() const
|
||||||
@@ -71,12 +73,16 @@ Core::IFile *FormEditorFactory::open(const QString &fileName)
|
|||||||
|
|
||||||
Core::IEditor *FormEditorFactory::createEditor(QWidget *parent)
|
Core::IEditor *FormEditorFactory::createEditor(QWidget *parent)
|
||||||
{
|
{
|
||||||
DesignerXmlEditor *xmlEditor = new DesignerXmlEditor(parent);
|
const EditorData data = FormEditorW::instance()->createEditor(parent);
|
||||||
TextEditor::TextEditorSettings::instance()->initializeEditor(xmlEditor);
|
return data.xmlEditor;
|
||||||
return xmlEditor->editableInterface();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList FormEditorFactory::mimeTypes() const
|
QStringList FormEditorFactory::mimeTypes() const
|
||||||
{
|
{
|
||||||
return m_mimeTypes;
|
return m_mimeTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace Designer
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ namespace Internal {
|
|||||||
class FormEditorFactory : public Core::IEditorFactory
|
class FormEditorFactory : public Core::IEditorFactory
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FormEditorFactory();
|
FormEditorFactory();
|
||||||
|
|
||||||
|
|||||||
@@ -33,28 +33,21 @@
|
|||||||
#include "formeditorw.h"
|
#include "formeditorw.h"
|
||||||
#include "designerconstants.h"
|
#include "designerconstants.h"
|
||||||
|
|
||||||
#include <texteditor/basetextdocument.h>
|
#include <coreplugin/coreconstants.h>
|
||||||
|
#include <coreplugin/modemanager.h>
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/imode.h>
|
||||||
#include <coreplugin/icore.h>
|
|
||||||
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QDesignerFormWindowInterface>
|
#include <QDesignerFormWindowInterface>
|
||||||
#include <QDesignerFormWindowManagerInterface>
|
#include <QDesignerFormWindowManagerInterface>
|
||||||
#include <QDesignerFormEditorInterface>
|
#include <QDesignerFormEditorInterface>
|
||||||
#include "qt_private/formwindowbase_p.h"
|
|
||||||
|
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
|
|
||||||
namespace Designer {
|
namespace Designer {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
FormEditorStack::FormXmlData::FormXmlData() :
|
|
||||||
xmlEditor(0), formEditor(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
FormEditorStack::FormEditorStack(QWidget *parent) :
|
FormEditorStack::FormEditorStack(QWidget *parent) :
|
||||||
QStackedWidget(parent),
|
QStackedWidget(parent),
|
||||||
m_designerCore(0)
|
m_designerCore(0)
|
||||||
@@ -62,28 +55,24 @@ FormEditorStack::FormEditorStack(QWidget *parent) :
|
|||||||
setObjectName(QLatin1String("FormEditorStack"));
|
setObjectName(QLatin1String("FormEditorStack"));
|
||||||
}
|
}
|
||||||
|
|
||||||
Designer::FormWindowEditor *FormEditorStack::createFormWindowEditor(DesignerXmlEditorEditable *xmlEditor)
|
void FormEditorStack::add(const EditorData &data)
|
||||||
{
|
{
|
||||||
FormEditorW *few = FormEditorW::instance();
|
|
||||||
if (m_designerCore == 0) { // Initialize first time here
|
if (m_designerCore == 0) { // Initialize first time here
|
||||||
m_designerCore = few->designerEditor();
|
m_designerCore = data.formEditor->formWindow()->core();
|
||||||
connect(m_designerCore->formWindowManager(), SIGNAL(activeFormWindowChanged(QDesignerFormWindowInterface*)),
|
connect(m_designerCore->formWindowManager(), SIGNAL(activeFormWindowChanged(QDesignerFormWindowInterface*)),
|
||||||
this, SLOT(updateFormWindowSelectionHandles()));
|
this, SLOT(updateFormWindowSelectionHandles()));
|
||||||
|
connect(Core::ModeManager::instance(), SIGNAL(currentModeAboutToChange(Core::IMode*)),
|
||||||
|
this, SLOT(modeAboutToChange(Core::IMode*)));
|
||||||
}
|
}
|
||||||
FormXmlData data;
|
|
||||||
data.formEditor = few->createFormWindowEditor(this);
|
|
||||||
data.formEditor->setFile(xmlEditor->file());
|
|
||||||
data.xmlEditor = xmlEditor;
|
|
||||||
addWidget(data.formEditor);
|
|
||||||
m_formEditors.append(data);
|
|
||||||
|
|
||||||
setFormEditorData(data.formEditor, xmlEditor->contents());
|
|
||||||
|
|
||||||
TextEditor::BaseTextDocument *document = qobject_cast<TextEditor::BaseTextDocument*>(xmlEditor->file());
|
|
||||||
connect(document, SIGNAL(reloaded()), SLOT(reloadDocument()));
|
|
||||||
if (Designer::Constants::Internal::debug)
|
if (Designer::Constants::Internal::debug)
|
||||||
qDebug() << "FormEditorStack::createFormWindowEditor" << data.formEditor;
|
qDebug() << "FormEditorStack::add" << data.xmlEditor << data.formEditor;
|
||||||
return data.formEditor;
|
|
||||||
|
m_formEditors.append(data);
|
||||||
|
addWidget(data.formEditor);
|
||||||
|
|
||||||
|
if (Designer::Constants::Internal::debug)
|
||||||
|
qDebug() << "FormEditorStack::add" << data.formEditor;
|
||||||
}
|
}
|
||||||
|
|
||||||
int FormEditorStack::indexOf(const QDesignerFormWindowInterface *fw) const
|
int FormEditorStack::indexOf(const QDesignerFormWindowInterface *fw) const
|
||||||
@@ -125,7 +114,6 @@ bool FormEditorStack::removeFormWindowEditor(Core::IEditor *xmlEditor)
|
|||||||
const int i = indexOf(xmlEditor);
|
const int i = indexOf(xmlEditor);
|
||||||
if (i == -1) // Fail silently as this is invoked for all editors.
|
if (i == -1) // Fail silently as this is invoked for all editors.
|
||||||
return false;
|
return false;
|
||||||
disconnect(m_formEditors[i].formEditor->formWindow(), SIGNAL(changed()), this, SLOT(formChanged()));
|
|
||||||
removeWidget(m_formEditors[i].formEditor->widget());
|
removeWidget(m_formEditors[i].formEditor->widget());
|
||||||
delete m_formEditors[i].formEditor;
|
delete m_formEditors[i].formEditor;
|
||||||
m_formEditors.removeAt(i);
|
m_formEditors.removeAt(i);
|
||||||
@@ -150,7 +138,7 @@ void FormEditorStack::updateFormWindowSelectionHandles()
|
|||||||
if (Designer::Constants::Internal::debug)
|
if (Designer::Constants::Internal::debug)
|
||||||
qDebug() << "updateFormWindowSelectionHandles";
|
qDebug() << "updateFormWindowSelectionHandles";
|
||||||
QDesignerFormWindowInterface *activeFormWindow = m_designerCore->formWindowManager()->activeFormWindow();
|
QDesignerFormWindowInterface *activeFormWindow = m_designerCore->formWindowManager()->activeFormWindow();
|
||||||
foreach(const FormXmlData &fdm, m_formEditors) {
|
foreach(const EditorData &fdm, m_formEditors) {
|
||||||
const bool active = activeFormWindow == fdm.formEditor->formWindow();
|
const bool active = activeFormWindow == fdm.formEditor->formWindow();
|
||||||
fdm.formEditor->updateFormWindowSelectionHandles(active);
|
fdm.formEditor->updateFormWindowSelectionHandles(active);
|
||||||
}
|
}
|
||||||
@@ -162,39 +150,15 @@ Designer::FormWindowEditor *FormEditorStack::formWindowEditorForXmlEditor(const
|
|||||||
return i != -1 ? m_formEditors.at(i).formEditor : static_cast<Designer::FormWindowEditor *>(0);
|
return i != -1 ? m_formEditors.at(i).formEditor : static_cast<Designer::FormWindowEditor *>(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormEditorStack::reloadDocument()
|
void FormEditorStack::modeAboutToChange(Core::IMode *m)
|
||||||
{
|
{
|
||||||
if (Designer::Constants::Internal::debug)
|
if (Designer::Constants::Internal::debug && m)
|
||||||
qDebug() << "FormEditorStack::reloadDocument()";
|
qDebug() << "FormEditorStack::modeAboutToChange" << m->id();
|
||||||
const int index = currentIndex();
|
|
||||||
if (index >= 0)
|
|
||||||
setFormEditorData(m_formEditors[index].formEditor, m_formEditors[index].xmlEditor->contents());
|
|
||||||
}
|
|
||||||
|
|
||||||
void FormEditorStack::setFormEditorData(Designer::FormWindowEditor *formEditor, const QString &contents)
|
// Sync the editor when leaving design mode
|
||||||
{
|
if (m && m->id() == QLatin1String(Core::Constants::MODE_DESIGN))
|
||||||
if (Designer::Constants::Internal::debug)
|
foreach(const EditorData &data, m_formEditors)
|
||||||
qDebug() << "FormEditorStack::setFormEditorData()";
|
data.xmlEditor->syncXmlEditor();
|
||||||
disconnect(formEditor->formWindow(), SIGNAL(changed()), this, SLOT(formChanged()));
|
|
||||||
formEditor->createNew(contents);
|
|
||||||
connect(formEditor->formWindow(), SIGNAL(changed()), SLOT(formChanged()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void FormEditorStack::formChanged()
|
|
||||||
{
|
|
||||||
const int index = currentIndex();
|
|
||||||
if (index < 0)
|
|
||||||
return;
|
|
||||||
if (Core::IEditor *currentEditor = Core::EditorManager::instance()->currentEditor()) {
|
|
||||||
if (m_formEditors[index].xmlEditor == currentEditor) {
|
|
||||||
FormXmlData &xmlData = m_formEditors[index];
|
|
||||||
TextEditor::BaseTextDocument *doc = qobject_cast<TextEditor::BaseTextDocument*>(xmlData.xmlEditor->file());
|
|
||||||
QTC_ASSERT(doc, return);
|
|
||||||
if (doc) // Save quietly (without spacer's warning).
|
|
||||||
if (const qdesigner_internal::FormWindowBase *fwb = qobject_cast<const qdesigner_internal::FormWindowBase *>(xmlData.formEditor->formWindow()))
|
|
||||||
doc->document()->setPlainText(fwb->fileContents());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // Internal
|
} // Internal
|
||||||
|
|||||||
@@ -30,6 +30,8 @@
|
|||||||
#ifndef FORMEDITORSTACK_H
|
#ifndef FORMEDITORSTACK_H
|
||||||
#define FORMEDITORSTACK_H
|
#define FORMEDITORSTACK_H
|
||||||
|
|
||||||
|
#include "editordata.h"
|
||||||
|
|
||||||
#include <QtGui/QStackedWidget>
|
#include <QtGui/QStackedWidget>
|
||||||
#include <QtCore/QList>
|
#include <QtCore/QList>
|
||||||
#include <QtCore/QString>
|
#include <QtCore/QString>
|
||||||
@@ -41,6 +43,7 @@ QT_END_NAMESPACE
|
|||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
class IEditor;
|
class IEditor;
|
||||||
|
class IMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Designer {
|
namespace Designer {
|
||||||
@@ -49,11 +52,11 @@ class DesignerXmlEditorEditable;
|
|||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
/**
|
/* FormEditorStack: Maintains a stack of Qt Designer form windows embedded
|
||||||
* A wrapper for Qt Designer form editors, so that they can be used in Design mode.
|
* into a scrollarea and their associated XML editors.
|
||||||
* FormEditorW owns an instance of this class, and creates new form editors when
|
* Takes care of updating the XML editor once design mode is left.
|
||||||
* needed.
|
* Also updates the maincontainer resize handles when the active form
|
||||||
*/
|
* window changes. */
|
||||||
class FormEditorStack : public QStackedWidget
|
class FormEditorStack : public QStackedWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -61,29 +64,23 @@ class FormEditorStack : public QStackedWidget
|
|||||||
public:
|
public:
|
||||||
explicit FormEditorStack(QWidget *parent = 0);
|
explicit FormEditorStack(QWidget *parent = 0);
|
||||||
|
|
||||||
Designer::FormWindowEditor *createFormWindowEditor(DesignerXmlEditorEditable *xmlEditor);
|
void add(const EditorData &d);
|
||||||
bool removeFormWindowEditor(Core::IEditor *xmlEditor);
|
bool removeFormWindowEditor(Core::IEditor *xmlEditor);
|
||||||
|
|
||||||
bool setVisibleEditor(Core::IEditor *xmlEditor);
|
bool setVisibleEditor(Core::IEditor *xmlEditor);
|
||||||
Designer::FormWindowEditor *formWindowEditorForXmlEditor(const Core::IEditor *xmlEditor) const;
|
Designer::FormWindowEditor *formWindowEditorForXmlEditor(const Core::IEditor *xmlEditor) const;
|
||||||
Designer::FormWindowEditor *formWindowEditorForFormWindow(const QDesignerFormWindowInterface *fw) const;
|
Designer::FormWindowEditor *formWindowEditorForFormWindow(const QDesignerFormWindowInterface *fw) const;
|
||||||
FormWindowEditor *activeFormWindow() const;
|
FormWindowEditor *activeFormWindow() const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void formChanged();
|
|
||||||
void reloadDocument();
|
|
||||||
void updateFormWindowSelectionHandles();
|
void updateFormWindowSelectionHandles();
|
||||||
|
void modeAboutToChange(Core::IMode *);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline int indexOf(const QDesignerFormWindowInterface *) const;
|
inline int indexOf(const QDesignerFormWindowInterface *) const;
|
||||||
inline int indexOf(const Core::IEditor *xmlEditor) const;
|
inline int indexOf(const Core::IEditor *xmlEditor) const;
|
||||||
|
|
||||||
void setFormEditorData(Designer::FormWindowEditor *formEditor, const QString &contents);
|
QList<EditorData> m_formEditors;
|
||||||
struct FormXmlData {
|
|
||||||
FormXmlData();
|
|
||||||
DesignerXmlEditorEditable *xmlEditor;
|
|
||||||
Designer::FormWindowEditor *formEditor;
|
|
||||||
};
|
|
||||||
QList<FormXmlData> m_formEditors;
|
|
||||||
QDesignerFormEditorInterface *m_designerCore;
|
QDesignerFormEditorInterface *m_designerCore;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -34,12 +34,12 @@
|
|||||||
#include "settingsmanager.h"
|
#include "settingsmanager.h"
|
||||||
#include "settingspage.h"
|
#include "settingspage.h"
|
||||||
#include "editorwidget.h"
|
#include "editorwidget.h"
|
||||||
|
#include "editordata.h"
|
||||||
#include "qtcreatorintegration.h"
|
#include "qtcreatorintegration.h"
|
||||||
#include "designerxmleditor.h"
|
#include "designerxmleditor.h"
|
||||||
#include "designercontext.h"
|
#include "designercontext.h"
|
||||||
#include "editorwidget.h"
|
#include "editorwidget.h"
|
||||||
|
|
||||||
#include <texteditor/basetextdocument.h>
|
|
||||||
#include <coreplugin/modemanager.h>
|
#include <coreplugin/modemanager.h>
|
||||||
#include <coreplugin/designmode.h>
|
#include <coreplugin/designmode.h>
|
||||||
#include <coreplugin/coreconstants.h>
|
#include <coreplugin/coreconstants.h>
|
||||||
@@ -47,6 +47,7 @@
|
|||||||
#include <coreplugin/uniqueidmanager.h>
|
#include <coreplugin/uniqueidmanager.h>
|
||||||
#include <coreplugin/actionmanager/actionmanager.h>
|
#include <coreplugin/actionmanager/actionmanager.h>
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
|
#include <texteditor/texteditorsettings.h>
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
@@ -213,7 +214,7 @@ FormEditorW::~FormEditorW()
|
|||||||
m_self = 0;
|
m_self = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add an action to toggle the view state of a dock window
|
// Add an actioon to toggle the view state of a dock window
|
||||||
void FormEditorW::addDockViewAction(Core::ActionManager *am,
|
void FormEditorW::addDockViewAction(Core::ActionManager *am,
|
||||||
int index, const QList<int> &context,
|
int index, const QList<int> &context,
|
||||||
const QString &title, const QString &id)
|
const QString &title, const QString &id)
|
||||||
@@ -651,13 +652,27 @@ void FormEditorW::addToolAction(QAction *a,
|
|||||||
c1->addAction(command);
|
c1->addAction(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
FormWindowEditor *FormEditorW::createFormWindowEditor(QWidget* parentWidget)
|
EditorData FormEditorW::createEditor(QWidget *parent)
|
||||||
{
|
{
|
||||||
|
if (Designer::Constants::Internal::debug)
|
||||||
|
qDebug() << "FormEditorW::createEditor";
|
||||||
|
// Create and associate form and text editor.
|
||||||
|
EditorData data;
|
||||||
m_fwm->closeAllPreviews();
|
m_fwm->closeAllPreviews();
|
||||||
QDesignerFormWindowInterface *form = m_fwm->createFormWindow(0);
|
qdesigner_internal::FormWindowBase *form = qobject_cast<qdesigner_internal::FormWindowBase *>(m_fwm->createFormWindow(0));
|
||||||
|
QTC_ASSERT(form, return data);
|
||||||
connect(form, SIGNAL(toolChanged(int)), this, SLOT(toolChanged(int)));
|
connect(form, SIGNAL(toolChanged(int)), this, SLOT(toolChanged(int)));
|
||||||
|
form->setDesignerGrid(qdesigner_internal::FormWindowBase::defaultDesignerGrid());
|
||||||
qdesigner_internal::FormWindowBase::setupDefaultAction(form);
|
qdesigner_internal::FormWindowBase::setupDefaultAction(form);
|
||||||
return new FormWindowEditor(form, parentWidget);
|
data.formEditor = new FormWindowEditor(form);
|
||||||
|
DesignerXmlEditor *xmlEditor = new DesignerXmlEditor(form, parent);
|
||||||
|
TextEditor::TextEditorSettings::instance()->initializeEditor(xmlEditor);
|
||||||
|
data.xmlEditor = xmlEditor->designerEditable();
|
||||||
|
data.formEditor->setFile(data.xmlEditor->file());
|
||||||
|
connect(data.formEditor, SIGNAL(formWindowSizeChanged(int,int)),
|
||||||
|
xmlEditor, SIGNAL(changed()));
|
||||||
|
m_editorWidget->add(data);
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormEditorW::updateShortcut(QObject *command)
|
void FormEditorW::updateShortcut(QObject *command)
|
||||||
@@ -681,11 +696,8 @@ void FormEditorW::currentEditorChanged(Core::IEditor *editor)
|
|||||||
QTC_ASSERT(xmlEditor, return);
|
QTC_ASSERT(xmlEditor, return);
|
||||||
ensureInitStage(FullyInitialized);
|
ensureInitStage(FullyInitialized);
|
||||||
FormWindowEditor *fw = m_editorWidget->formWindowEditorForXmlEditor(xmlEditor);
|
FormWindowEditor *fw = m_editorWidget->formWindowEditorForXmlEditor(xmlEditor);
|
||||||
if (fw) {
|
QTC_ASSERT(fw, return)
|
||||||
m_editorWidget->setVisibleEditor(xmlEditor);
|
m_editorWidget->setVisibleEditor(xmlEditor);
|
||||||
} else {
|
|
||||||
fw = m_editorWidget->createFormWindowEditor(xmlEditor);
|
|
||||||
}
|
|
||||||
m_fwm->setActiveFormWindow(fw->formWindow());
|
m_fwm->setActiveFormWindow(fw->formWindow());
|
||||||
m_actionGroupEditMode->setVisible(true);
|
m_actionGroupEditMode->setVisible(true);
|
||||||
m_modeActionSeparator->setVisible(true);
|
m_modeActionSeparator->setVisible(true);
|
||||||
|
|||||||
@@ -31,7 +31,6 @@
|
|||||||
#define FORMEDITORW_H
|
#define FORMEDITORW_H
|
||||||
|
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
#include <QtCore/QPointer>
|
|
||||||
#include <QtCore/QStringList>
|
#include <QtCore/QStringList>
|
||||||
#include <QtCore/QMap>
|
#include <QtCore/QMap>
|
||||||
|
|
||||||
@@ -45,9 +44,6 @@ class QDesignerFormWindowInterface;
|
|||||||
|
|
||||||
class QAction;
|
class QAction;
|
||||||
class QActionGroup;
|
class QActionGroup;
|
||||||
class QFocusEvent;
|
|
||||||
|
|
||||||
class QWidget;
|
|
||||||
class QSignalMapper;
|
class QSignalMapper;
|
||||||
class QSettings;
|
class QSettings;
|
||||||
class QToolBar;
|
class QToolBar;
|
||||||
@@ -64,7 +60,6 @@ class ActionContainer;
|
|||||||
class ICore;
|
class ICore;
|
||||||
class IEditor;
|
class IEditor;
|
||||||
class Command;
|
class Command;
|
||||||
class IMode;
|
|
||||||
class DesignMode;
|
class DesignMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,6 +68,7 @@ class FormWindowEditor;
|
|||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
|
struct EditorData;
|
||||||
class EditorWidget;
|
class EditorWidget;
|
||||||
class SettingsPage;
|
class SettingsPage;
|
||||||
class DesignerContext;
|
class DesignerContext;
|
||||||
@@ -113,11 +109,11 @@ public:
|
|||||||
// Deletes an existing instance if there is one.
|
// Deletes an existing instance if there is one.
|
||||||
static void deleteInstance();
|
static void deleteInstance();
|
||||||
|
|
||||||
|
EditorData createEditor(QWidget *parent);
|
||||||
|
|
||||||
inline QDesignerFormEditorInterface *designerEditor() const { return m_formeditor; }
|
inline QDesignerFormEditorInterface *designerEditor() const { return m_formeditor; }
|
||||||
inline QWidget * const*designerSubWindows() const { return m_designerSubWindows; }
|
inline QWidget * const*designerSubWindows() const { return m_designerSubWindows; }
|
||||||
|
|
||||||
FormWindowEditor *createFormWindowEditor(QWidget* parentWidget);
|
|
||||||
|
|
||||||
FormWindowEditor *activeFormWindow() const;
|
FormWindowEditor *activeFormWindow() const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|||||||
@@ -96,26 +96,12 @@ FormWindowEditor::FormWindowEditor(QDesignerFormWindowInterface *form,
|
|||||||
m_sessionNode(0),
|
m_sessionNode(0),
|
||||||
m_sessionWatcher(0)
|
m_sessionWatcher(0)
|
||||||
{
|
{
|
||||||
connect(formWindow(), SIGNAL(selectionChanged()), this, SIGNAL(changed()));
|
|
||||||
connect(this, SIGNAL(formWindowSizeChanged(int,int)), this, SLOT(slotFormSizeChanged(int,int)));
|
connect(this, SIGNAL(formWindowSizeChanged(int,int)), this, SLOT(slotFormSizeChanged(int,int)));
|
||||||
connect(formWindow(), SIGNAL(changed()), this, SIGNAL(changed()));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormWindowEditor::setFile(Core::IFile *file)
|
void FormWindowEditor::setFile(Core::IFile *file)
|
||||||
{
|
{
|
||||||
if (m_file) {
|
m_file = file;
|
||||||
disconnect(m_file, SIGNAL(changed()), this, SIGNAL(changed()));
|
|
||||||
disconnect(m_file, SIGNAL(changed()), this, SLOT(updateResources()));
|
|
||||||
}
|
|
||||||
|
|
||||||
m_file = file;
|
|
||||||
formWindow()->setFileName(file->fileName());
|
|
||||||
|
|
||||||
if (m_file) {
|
|
||||||
connect(m_file, SIGNAL(changed()), this, SIGNAL(changed()));
|
|
||||||
connect(m_file, SIGNAL(changed()), this, SLOT(updateResources()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FormWindowEditor::~FormWindowEditor()
|
FormWindowEditor::~FormWindowEditor()
|
||||||
@@ -127,26 +113,6 @@ FormWindowEditor::~FormWindowEditor()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FormWindowEditor::createNew(const QString &contents)
|
|
||||||
{
|
|
||||||
if (Designer::Constants::Internal::debug)
|
|
||||||
qDebug() << Q_FUNC_INFO << contents.size() << "chars";
|
|
||||||
|
|
||||||
if (!formWindow())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
formWindow()->setContents(contents);
|
|
||||||
if (!formWindow()->mainContainer())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (qdesigner_internal::FormWindowBase *fw = qobject_cast<qdesigner_internal::FormWindowBase *>(formWindow()))
|
|
||||||
fw->setDesignerGrid(qdesigner_internal::FormWindowBase::defaultDesignerGrid());
|
|
||||||
|
|
||||||
initializeResources();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void FormWindowEditor::initializeResources(const QString & /* fileName */)
|
void FormWindowEditor::initializeResources(const QString & /* fileName */)
|
||||||
{
|
{
|
||||||
ProjectExplorer::ProjectExplorerPlugin *pe = ProjectExplorer::ProjectExplorerPlugin::instance();
|
ProjectExplorer::ProjectExplorerPlugin *pe = ProjectExplorer::ProjectExplorerPlugin::instance();
|
||||||
@@ -167,11 +133,6 @@ void FormWindowEditor::initializeResources(const QString & /* fileName */)
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateResources();
|
updateResources();
|
||||||
|
|
||||||
QDesignerFormWindowManagerInterface *fwm = FormEditorW::instance()->designerEditor()->formWindowManager();
|
|
||||||
fwm->setActiveFormWindow(formWindow());
|
|
||||||
|
|
||||||
emit changed();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormWindowEditor::updateResources()
|
void FormWindowEditor::updateResources()
|
||||||
@@ -202,13 +163,6 @@ Core::IFile *FormWindowEditor::file() const
|
|||||||
return m_file;
|
return m_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString FormWindowEditor::contents() const
|
|
||||||
{
|
|
||||||
if (!formWindow())
|
|
||||||
return QString();
|
|
||||||
return formWindow()->contents();
|
|
||||||
}
|
|
||||||
|
|
||||||
void FormWindowEditor::slotFormSizeChanged(int w, int h)
|
void FormWindowEditor::slotFormSizeChanged(int w, int h)
|
||||||
{
|
{
|
||||||
if (Designer::Constants::Internal::debug)
|
if (Designer::Constants::Internal::debug)
|
||||||
@@ -217,5 +171,4 @@ void FormWindowEditor::slotFormSizeChanged(int w, int h)
|
|||||||
formWindow()->setDirty(true);
|
formWindow()->setDirty(true);
|
||||||
static const QString geometry = QLatin1String("geometry");
|
static const QString geometry = QLatin1String("geometry");
|
||||||
FormEditorW::instance()->designerEditor()->propertyEditor()->setPropertyValue(geometry, QRect(0,0,w,h) );
|
FormEditorW::instance()->designerEditor()->propertyEditor()->setPropertyValue(geometry, QRect(0,0,w,h) );
|
||||||
emit changed();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,6 @@
|
|||||||
#ifndef FORMWINDOWEDITOR_H
|
#ifndef FORMWINDOWEDITOR_H
|
||||||
#define FORMWINDOWEDITOR_H
|
#define FORMWINDOWEDITOR_H
|
||||||
|
|
||||||
#include "designer_export.h"
|
|
||||||
#include "widgethost.h"
|
#include "widgethost.h"
|
||||||
|
|
||||||
#include <QtCore/QStringList>
|
#include <QtCore/QStringList>
|
||||||
@@ -58,15 +57,10 @@ public:
|
|||||||
QWidget *parent = 0);
|
QWidget *parent = 0);
|
||||||
~FormWindowEditor();
|
~FormWindowEditor();
|
||||||
|
|
||||||
// IEditor
|
|
||||||
bool createNew(const QString &contents);
|
|
||||||
void setFile(Core::IFile *file);
|
void setFile(Core::IFile *file);
|
||||||
QString contents() const;
|
QString contents() const;
|
||||||
Core::IFile *file() const;
|
Core::IFile *file() const;
|
||||||
|
|
||||||
signals:
|
|
||||||
void changed();
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updateResources();
|
void updateResources();
|
||||||
void slotFormSizeChanged(int w, int h);
|
void slotFormSizeChanged(int w, int h);
|
||||||
@@ -74,8 +68,6 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
void initializeResources(const QString &fileName = QString());
|
void initializeResources(const QString &fileName = QString());
|
||||||
|
|
||||||
QWidget *m_containerWidget;
|
|
||||||
QString m_displayName;
|
|
||||||
QPointer<Core::IFile> m_file;
|
QPointer<Core::IFile> m_file;
|
||||||
QStringList m_originalUiQrcPaths;
|
QStringList m_originalUiQrcPaths;
|
||||||
ProjectExplorer::SessionNode *m_sessionNode;
|
ProjectExplorer::SessionNode *m_sessionNode;
|
||||||
|
|||||||
@@ -31,8 +31,8 @@
|
|||||||
#include "designerconstants.h"
|
#include "designerconstants.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
|
||||||
#include <utils/reloadpromptutils.h>
|
#include <utils/reloadpromptutils.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QtDesigner/QDesignerFormWindowInterface>
|
#include <QtDesigner/QDesignerFormWindowInterface>
|
||||||
#include <QtDesigner/QDesignerFormEditorInterface>
|
#include <QtDesigner/QDesignerFormEditorInterface>
|
||||||
@@ -42,17 +42,15 @@
|
|||||||
|
|
||||||
#include <QtCore/QFile>
|
#include <QtCore/QFile>
|
||||||
#include <QtCore/QFileInfo>
|
#include <QtCore/QFileInfo>
|
||||||
#include <QtCore/QDir>
|
|
||||||
#include <QtCore/QByteArray>
|
#include <QtCore/QByteArray>
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
|
|
||||||
using namespace Designer::Internal;
|
namespace Designer {
|
||||||
using namespace Designer::Constants;
|
namespace Internal {
|
||||||
using namespace SharedTools;
|
|
||||||
|
|
||||||
FormWindowFile::FormWindowFile(QDesignerFormWindowInterface *form, QObject *parent)
|
FormWindowFile::FormWindowFile(QDesignerFormWindowInterface *form, QObject *parent)
|
||||||
: Core::IFile(parent),
|
: Core::IFile(parent),
|
||||||
m_mimeType(QLatin1String(FORM_MIMETYPE)),
|
m_mimeType(QLatin1String(Designer::Constants::FORM_MIMETYPE)),
|
||||||
m_formWindow(form)
|
m_formWindow(form)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -64,6 +62,8 @@ bool FormWindowFile::save(const QString &name /*= QString()*/)
|
|||||||
if (Designer::Constants::Internal::debug)
|
if (Designer::Constants::Internal::debug)
|
||||||
qDebug() << Q_FUNC_INFO << name << "->" << actualName;
|
qDebug() << Q_FUNC_INFO << name << "->" << actualName;
|
||||||
|
|
||||||
|
QTC_ASSERT(m_formWindow, return false);
|
||||||
|
|
||||||
if (actualName.isEmpty())
|
if (actualName.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -94,9 +94,9 @@ QString FormWindowFile::fileName() const
|
|||||||
|
|
||||||
bool FormWindowFile::isModified() const
|
bool FormWindowFile::isModified() const
|
||||||
{
|
{
|
||||||
if (Designer::Constants::Internal::debug)
|
if (Designer::Constants::Internal::debug > 1)
|
||||||
qDebug() << Q_FUNC_INFO << m_formWindow->isDirty();
|
qDebug() << Q_FUNC_INFO << m_formWindow->isDirty();
|
||||||
return m_formWindow->isDirty();
|
return m_formWindow && m_formWindow->isDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FormWindowFile::isReadOnly() const
|
bool FormWindowFile::isReadOnly() const
|
||||||
@@ -204,3 +204,11 @@ void FormWindowFile::setFileName(const QString &fname)
|
|||||||
{
|
{
|
||||||
m_fileName = fname;
|
m_fileName = fname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QDesignerFormWindowInterface *FormWindowFile::formWindow() const
|
||||||
|
{
|
||||||
|
return m_formWindow;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace Designer
|
||||||
|
|||||||
@@ -32,8 +32,7 @@
|
|||||||
|
|
||||||
#include <coreplugin/ifile.h>
|
#include <coreplugin/ifile.h>
|
||||||
|
|
||||||
#include "widgethost.h"
|
#include <QtCore/QPointer>
|
||||||
#include "designerconstants.h"
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QDesignerFormWindowInterface;
|
class QDesignerFormWindowInterface;
|
||||||
@@ -65,9 +64,12 @@ public:
|
|||||||
|
|
||||||
// Internal
|
// Internal
|
||||||
void setSuggestedFileName(const QString &fileName);
|
void setSuggestedFileName(const QString &fileName);
|
||||||
|
|
||||||
bool writeFile(const QString &fileName, QString &errorString) const;
|
bool writeFile(const QString &fileName, QString &errorString) const;
|
||||||
bool writeFile(QFile &file, QString &errorString) const;
|
bool writeFile(QFile &file, QString &errorString) const;
|
||||||
|
|
||||||
|
QDesignerFormWindowInterface *formWindow() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
// Internal
|
// Internal
|
||||||
void reload(const QString &);
|
void reload(const QString &);
|
||||||
@@ -78,10 +80,12 @@ public slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
const QString m_mimeType;
|
const QString m_mimeType;
|
||||||
|
|
||||||
QString m_fileName;
|
QString m_fileName;
|
||||||
QString m_suggestedName;
|
QString m_suggestedName;
|
||||||
|
// Might actually go out of scope before the IEditor due
|
||||||
QDesignerFormWindowInterface *m_formWindow;
|
// to deleting the WidgetHost which owns it.
|
||||||
|
QPointer<QDesignerFormWindowInterface> m_formWindow;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
Reference in New Issue
Block a user