Commit 88eb60d3 authored by hjk's avatar hjk

Designer: Use a BaseTextEditorFactory to create the Xml editor

Change-Id: Iac80f6ef017a7c5acf1ed89ac0ece83c6a67abec
Reviewed-by: default avatarChristian Stenger <christian.stenger@digia.com>
parent afd56bd8
......@@ -25,8 +25,7 @@ HEADERS += formeditorplugin.h \
formeditorstack.h \
editordata.h \
resourcehandler.h \
qtdesignerformclasscodegenerator.h \
designerxmleditorwidget.h
qtdesignerformclasscodegenerator.h
SOURCES += formeditorplugin.cpp \
formeditorfactory.cpp \
......@@ -44,8 +43,7 @@ SOURCES += formeditorplugin.cpp \
designercontext.cpp \
formeditorstack.cpp \
resourcehandler.cpp \
qtdesignerformclasscodegenerator.cpp \
designerxmleditorwidget.cpp
qtdesignerformclasscodegenerator.cpp
equals(TEST, 1) {
SOURCES += gotoslot_test.cpp
......
......@@ -31,7 +31,6 @@ QtcPlugin {
"designer_export.h",
"designerconstants.h",
"designercontext.cpp", "designercontext.h",
"designerxmleditorwidget.cpp", "designerxmleditorwidget.h",
"editordata.h",
"editorwidget.cpp", "editorwidget.h",
"formeditorfactory.cpp", "formeditorfactory.h",
......
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "designerxmleditorwidget.h"
#include "formwindoweditor.h"
#include <utils/qtcassert.h>
#include <QDesignerFormWindowInterface>
#include <QDebug>
namespace Designer {
namespace Internal {
DesignerXmlEditorWidget::DesignerXmlEditorWidget(QDesignerFormWindowInterface *form)
{
TextEditor::BaseTextDocumentPtr doc(new FormWindowFile(form));
setTextDocument(doc);
m_editor = new FormWindowEditor(this);
setupAsPlainEditor();
setReadOnly(true);
configureMimeType(doc->mimeType());
}
FormWindowEditor *DesignerXmlEditorWidget::designerEditor() const
{
return m_editor;
}
Internal::FormWindowFile *DesignerXmlEditorWidget::formWindowFile() const
{
return qobject_cast<FormWindowFile *>(textDocument());
}
} // namespace Internal
} // namespace Designer
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef DESIGNERXMLEDITORWIDGET_H
#define DESIGNERXMLEDITORWIDGET_H
#include "formwindowfile.h"
#include <texteditor/basetexteditor.h>
#include <QSharedPointer>
QT_BEGIN_NAMESPACE
class QDesignerFormWindowInterface;
QT_END_NAMESPACE
namespace Designer {
class FormWindowEditor;
namespace Internal {
/* 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
* functionality, editing is disabled.
* Provides an informational title bar containing a button triggering a
* switch to design mode.
* Internally manages a FormWindowEditor and uses the plain text
* editable embedded in it. */
class DesignerXmlEditorWidget : public TextEditor::BaseTextEditorWidget
{
Q_OBJECT
public:
explicit DesignerXmlEditorWidget(QDesignerFormWindowInterface *form);
FormWindowEditor *designerEditor() const;
Internal::FormWindowFile *formWindowFile() const;
private:
FormWindowEditor *m_editor;
};
} // Internal
} // Designer
#endif // DESIGNERXMLEDITORWIDGET_H
......@@ -31,7 +31,6 @@
#include "formeditorw.h"
#include "formwindoweditor.h"
#include "editordata.h"
#include "designerxmleditorwidget.h"
#include <coreplugin/coreconstants.h>
#include <coreplugin/icore.h>
......
......@@ -30,6 +30,7 @@
#include "formeditorplugin.h"
#include "formeditorfactory.h"
#include "formeditorw.h"
#include "formwindoweditor.h"
#include "formwizard.h"
#ifdef CPP_ENABLED
......
......@@ -30,6 +30,7 @@
#include "formeditorstack.h"
#include "formwindoweditor.h"
#include "formeditorw.h"
#include "formwindowfile.h"
#include <widgethost.h>
......@@ -188,7 +189,7 @@ void FormEditorStack::modeAboutToChange(Core::IMode *m)
// Sync the editor when entering edit mode
if (m && m->id() == Core::Constants::MODE_EDIT)
foreach (const EditorData &data, m_formEditors)
data.formWindowEditor->syncXmlEditor();
data.formWindowEditor->formWindowFile()->syncXmlFromFormWindow();
}
} // Internal
......
......@@ -29,12 +29,12 @@
#include "formeditorw.h"
#include "formwindoweditor.h"
#include "formwindowfile.h"
#include "settingsmanager.h"
#include "settingspage.h"
#include "editorwidget.h"
#include "editordata.h"
#include "qtcreatorintegration.h"
#include "designerxmleditorwidget.h"
#include "designercontext.h"
#include "resourcehandler.h"
#include <widgethost.h>
......@@ -104,9 +104,45 @@ using namespace Designer::Constants;
namespace Designer {
namespace Internal {
/* 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
* functionality, editing is disabled.
* Provides an informational title bar containing a button triggering a
* switch to design mode.
* Internally manages a FormWindowEditor and uses the plain text
* editable embedded in it. */
class DesignerXmlEditorWidget : public TextEditor::BaseTextEditorWidget
{
public:
DesignerXmlEditorWidget() {}
void finalizeInitialization()
{
setupAsPlainEditor();
setReadOnly(true);
}
};
class FormWindowEditorFactory : public TextEditor::BaseTextEditorFactory
{
public:
FormWindowEditorFactory()
{
setId(Designer::Constants::K_DESIGNER_XML_EDITOR_ID);
setDocumentCreator([this]() { return new FormWindowFile(m_form); });
setEditorCreator([]() { return new FormWindowEditor; });
setEditorWidgetCreator([]() { return new Internal::DesignerXmlEditorWidget; });
setDuplicatedSupported(false);
}
QDesignerFormWindowInterface *m_form;
};
static FormWindowEditorFactory *m_xmlEditorFactory = 0;
// --------- FormEditorW
FormEditorW *FormEditorW::m_self = 0;
static FormEditorW *m_self = 0;
FormEditorW::FormEditorW() :
m_formeditor(QDesignerComponents::createFormEditor(0)),
......@@ -154,6 +190,8 @@ FormEditorW::FormEditorW() :
this, SLOT(currentEditorChanged(Core::IEditor*)));
connect(m_shortcutMapper, SIGNAL(mapped(QObject*)),
this, SLOT(updateShortcut(QObject*)));
m_xmlEditorFactory = new FormWindowEditorFactory;
}
FormEditorW::~FormEditorW()
......@@ -176,6 +214,7 @@ FormEditorW::~FormEditorW()
m_settingsPages.clear();
delete m_integration;
delete m_xmlEditorFactory ;
m_self = 0;
}
......@@ -633,15 +672,16 @@ EditorData FormEditorW::createEditor()
QDesignerFormWindowInterface *form = m_fwm->createFormWindow(0);
QTC_ASSERT(form, return data);
connect(form, SIGNAL(toolChanged(int)), this, SLOT(toolChanged(int)));
m_xmlEditorFactory->m_form = form;
ResourceHandler *resourceHandler = new ResourceHandler(form);
data.widgetHost = new SharedTools::WidgetHost( /* parent */ 0, form);
DesignerXmlEditorWidget *xmlEditor = new DesignerXmlEditorWidget(form);
data.formWindowEditor = xmlEditor->designerEditor();
connect(data.formWindowEditor->document(), SIGNAL(filePathChanged(QString,QString)),
data.formWindowEditor = qobject_cast<FormWindowEditor *>(m_xmlEditorFactory->createEditor());
connect(data.formWindowEditor->textDocument(), SIGNAL(filePathChanged(QString,QString)),
resourceHandler, SLOT(updateResources()));
m_editorWidget->add(data);
m_toolBar->addEditor(xmlEditor->designerEditor());
m_toolBar->addEditor(data.formWindowEditor);
return data;
}
......
......@@ -158,8 +158,6 @@ private:
Core::Id groupId = Core::Id());
QToolBar *createEditorToolBar() const;
static FormEditorW *m_self;
QDesignerFormEditorInterface *m_formeditor;
QDesignerIntegrationInterface *m_integration;
QDesignerFormWindowManagerInterface *m_fwm;
......
......@@ -31,7 +31,6 @@
#include "formwindowfile.h"
#include "designerconstants.h"
#include "resourcehandler.h"
#include "designerxmleditorwidget.h"
#include <coreplugin/coreconstants.h>
#include <texteditor/basetextdocument.h>
......@@ -45,25 +44,23 @@
namespace Designer {
FormWindowEditor::FormWindowEditor(TextEditor::BaseTextEditorWidget *widget)
FormWindowEditor::FormWindowEditor()
{
setWidget(widget);
setDuplicateSupported(false);
setContext(Core::Context(Designer::Constants::K_DESIGNER_XML_EDITOR_ID,
Designer::Constants::C_DESIGNER_XML_EDITOR));
// Revert to saved/load externally modified files.
connect(formWindowFile(), SIGNAL(reloadRequested(QString*,QString)),
this, SLOT(slotOpen(QString*,QString)), Qt::DirectConnection);
addContext(Designer::Constants::K_DESIGNER_XML_EDITOR_ID);
addContext(Designer::Constants::C_DESIGNER_XML_EDITOR);
}
FormWindowEditor::~FormWindowEditor()
{
}
void FormWindowEditor::slotOpen(QString *errorString, const QString &fileName)
void FormWindowEditor::finalizeInitialization()
{
open(errorString, fileName, fileName);
// Revert to saved/load externally modified files.
connect(formWindowFile(), &Internal::FormWindowFile::reloadRequested,
[this](QString *errorString, const QString &fileName) {
open(errorString, fileName, fileName);
});
}
bool FormWindowEditor::open(QString *errorString, const QString &fileName, const QString &realFileName)
......@@ -103,13 +100,6 @@ bool FormWindowEditor::open(QString *errorString, const QString &fileName, const
return true;
}
void FormWindowEditor::syncXmlEditor()
{
if (Designer::Constants::Internal::debug)
qDebug() << "FormWindowEditor::syncXmlEditor" << formWindowFile()->filePath();
formWindowFile()->syncXmlFromFormWindow();
}
QWidget *FormWindowEditor::toolBar()
{
return 0;
......@@ -122,7 +112,7 @@ QString FormWindowEditor::contents() const
Internal::FormWindowFile *FormWindowEditor::formWindowFile() const
{
return qobject_cast<Internal::FormWindowFile *>(const_cast<FormWindowEditor *>(this)->textDocument());
return qobject_cast<Internal::FormWindowFile *>(textDocument());
}
bool FormWindowEditor::isDesignModePreferred() const
......
......@@ -34,15 +34,9 @@
#include <coreplugin/editormanager/ieditor.h>
#include <texteditor/basetexteditor.h>
QT_BEGIN_NAMESPACE
class QDesignerFormWindowInterface;
QT_END_NAMESPACE
namespace Designer {
namespace Internal {
class FormWindowFile;
}
namespace Internal { class FormWindowFile; }
// IEditor that is used for the QDesignerFormWindowInterface
// It is a read-only text editor that shows the XML of the form.
......@@ -55,28 +49,21 @@ class DESIGNER_EXPORT FormWindowEditor : public TextEditor::BaseTextEditor
{
Q_PROPERTY(QString contents READ contents)
Q_OBJECT
public:
explicit FormWindowEditor(TextEditor::BaseTextEditorWidget *widget);
virtual ~FormWindowEditor();
// IEditor
virtual bool open(QString *errorString, const QString &fileName, const QString &realFileName);
virtual QWidget *toolBar();
public:
FormWindowEditor();
~FormWindowEditor();
virtual bool isDesignModePreferred() const;
void finalizeInitialization();
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
QWidget *toolBar();
bool isDesignModePreferred() const;
// For uic code model support
QString contents() const;
// Convenience access.
Internal::FormWindowFile *formWindowFile() const;
public slots:
void syncXmlEditor();
private slots:
void slotOpen(QString *errorString, const QString &fileName);
};
} // namespace Designer
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment