forked from qt-creator/qt-creator
Moved Creator specific code to a subclas.
This commit is contained in:
@@ -40,7 +40,7 @@
|
|||||||
#include <stateseditorwidget.h>
|
#include <stateseditorwidget.h>
|
||||||
#include <formeditorview.h>
|
#include <formeditorview.h>
|
||||||
#include <formeditorwidget.h>
|
#include <formeditorwidget.h>
|
||||||
#include <plaintexteditmodifier.h>
|
#include <basetexteditmodifier.h>
|
||||||
#include <componenttextmodifier.h>
|
#include <componenttextmodifier.h>
|
||||||
#include <metainfo.h>
|
#include <metainfo.h>
|
||||||
#include <invalidargumentexception.h>
|
#include <invalidargumentexception.h>
|
||||||
@@ -92,7 +92,7 @@ public:
|
|||||||
QWeakPointer<QmlDesigner::Model> masterModel;
|
QWeakPointer<QmlDesigner::Model> masterModel;
|
||||||
QWeakPointer<QPlainTextEdit> textEdit;
|
QWeakPointer<QPlainTextEdit> textEdit;
|
||||||
QWeakPointer<RewriterView> rewriterView;
|
QWeakPointer<RewriterView> rewriterView;
|
||||||
QmlDesigner::PlainTextEditModifier *textModifier;
|
QmlDesigner::BaseTextEditModifier *textModifier;
|
||||||
QmlDesigner::ComponentTextModifier *componentTextModifier;
|
QmlDesigner::ComponentTextModifier *componentTextModifier;
|
||||||
QWeakPointer<SubComponentManager> subComponentManager;
|
QWeakPointer<SubComponentManager> subComponentManager;
|
||||||
QWeakPointer<Internal::ViewLogger> viewLogger;
|
QWeakPointer<Internal::ViewLogger> viewLogger;
|
||||||
@@ -326,7 +326,7 @@ QList<RewriterView::Error> DesignDocumentController::loadMaster(QPlainTextEdit *
|
|||||||
connect(edit, SIGNAL(modificationChanged(bool)),
|
connect(edit, SIGNAL(modificationChanged(bool)),
|
||||||
this, SIGNAL(dirtyStateChanged(bool)));
|
this, SIGNAL(dirtyStateChanged(bool)));
|
||||||
|
|
||||||
m_d->textModifier = new PlainTextEditModifier(m_d->textEdit.data());
|
m_d->textModifier = new BaseTextEditModifier(m_d->textEdit.data());
|
||||||
|
|
||||||
m_d->componentTextModifier = 0;
|
m_d->componentTextModifier = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
#include "designdocumentcontrollerview.h"
|
#include "designdocumentcontrollerview.h"
|
||||||
#include <rewriterview.h>
|
#include <rewriterview.h>
|
||||||
#include <plaintexteditmodifier.h>
|
#include <basetexteditmodifier.h>
|
||||||
#include <metainfo.h>
|
#include <metainfo.h>
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
@@ -102,7 +102,7 @@ QString DesignDocumentControllerView::toText() const
|
|||||||
outputModel->setMetaInfo(model()->metaInfo());
|
outputModel->setMetaInfo(model()->metaInfo());
|
||||||
QPlainTextEdit textEdit;
|
QPlainTextEdit textEdit;
|
||||||
textEdit.setPlainText("import Qt 4.6; Item {}");
|
textEdit.setPlainText("import Qt 4.6; Item {}");
|
||||||
PlainTextEditModifier modifier(&textEdit);
|
BaseTextEditModifier modifier(&textEdit);
|
||||||
|
|
||||||
QScopedPointer<RewriterView> rewriterView(new RewriterView(RewriterView::Amend, 0));
|
QScopedPointer<RewriterView> rewriterView(new RewriterView(RewriterView::Amend, 0));
|
||||||
rewriterView->setTextModifier(&modifier);
|
rewriterView->setTextModifier(&modifier);
|
||||||
@@ -126,7 +126,7 @@ void DesignDocumentControllerView::fromText(QString text)
|
|||||||
QPlainTextEdit textEdit;
|
QPlainTextEdit textEdit;
|
||||||
QString imports("import Qt 4.6;\n");
|
QString imports("import Qt 4.6;\n");
|
||||||
textEdit.setPlainText(imports + text);
|
textEdit.setPlainText(imports + text);
|
||||||
PlainTextEditModifier modifier(&textEdit);
|
BaseTextEditModifier modifier(&textEdit);
|
||||||
|
|
||||||
QScopedPointer<RewriterView> rewriterView(new RewriterView(RewriterView::Amend, 0));
|
QScopedPointer<RewriterView> rewriterView(new RewriterView(RewriterView::Amend, 0));
|
||||||
rewriterView->setTextModifier(&modifier);
|
rewriterView->setTextModifier(&modifier);
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ SOURCES += $$PWD/model/abstractview.cpp \
|
|||||||
$$PWD/model/modeltotextmerger.cpp \
|
$$PWD/model/modeltotextmerger.cpp \
|
||||||
$$PWD/model/texttomodelmerger.cpp \
|
$$PWD/model/texttomodelmerger.cpp \
|
||||||
$$PWD/model/plaintexteditmodifier.cpp \
|
$$PWD/model/plaintexteditmodifier.cpp \
|
||||||
|
$$PWD/model/basetexteditmodifier.cpp \
|
||||||
$$PWD/model/componenttextmodifier.cpp \
|
$$PWD/model/componenttextmodifier.cpp \
|
||||||
$$PWD/model/textmodifier.cpp \
|
$$PWD/model/textmodifier.cpp \
|
||||||
$$PWD/model/qmlmodelview.cpp \
|
$$PWD/model/qmlmodelview.cpp \
|
||||||
@@ -158,6 +159,7 @@ HEADERS += $$PWD/include/corelib_global.h \
|
|||||||
$$PWD/model/internalnodeabstractproperty.h \
|
$$PWD/model/internalnodeabstractproperty.h \
|
||||||
$$PWD/include/nodeabstractproperty.h \
|
$$PWD/include/nodeabstractproperty.h \
|
||||||
$$PWD/include/plaintexteditmodifier.h \
|
$$PWD/include/plaintexteditmodifier.h \
|
||||||
|
$$PWD/include/basetexteditmodifier.h \
|
||||||
$$PWD/include/componenttextmodifier.h \
|
$$PWD/include/componenttextmodifier.h \
|
||||||
$$PWD/include/textmodifier.h \
|
$$PWD/include/textmodifier.h \
|
||||||
$$PWD/model/modeltotextmerger.h \
|
$$PWD/model/modeltotextmerger.h \
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public:
|
|||||||
|
|
||||||
virtual void replace(int offset, int length, const QString &replacement);
|
virtual void replace(int offset, int length, const QString &replacement);
|
||||||
virtual void move(const MoveInfo &moveInfo);
|
virtual void move(const MoveInfo &moveInfo);
|
||||||
virtual void indent(int offset, int length);
|
virtual void indent(int offset, int length) = 0;
|
||||||
|
|
||||||
virtual void startGroup();
|
virtual void startGroup();
|
||||||
virtual void flushGroup();
|
virtual void flushGroup();
|
||||||
@@ -73,6 +73,10 @@ public:
|
|||||||
virtual void deactivateChangeSignals();
|
virtual void deactivateChangeSignals();
|
||||||
virtual void reactivateChangeSignals();
|
virtual void reactivateChangeSignals();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QPlainTextEdit *plainTextEdit() const
|
||||||
|
{ return m_textEdit; }
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void textEditChanged();
|
void textEditChanged();
|
||||||
|
|
||||||
|
|||||||
60
src/plugins/qmldesigner/core/model/basetexteditmodifier.cpp
Normal file
60
src/plugins/qmldesigner/core/model/basetexteditmodifier.cpp
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/**************************************************************************
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator
|
||||||
|
**
|
||||||
|
** Copyright (c) 2009 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.
|
||||||
|
**
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
#include "basetexteditmodifier.h"
|
||||||
|
|
||||||
|
#include <texteditor/basetexteditor.h>
|
||||||
|
|
||||||
|
using namespace QmlDesigner;
|
||||||
|
|
||||||
|
BaseTextEditModifier::BaseTextEditModifier(QPlainTextEdit *textEdit):
|
||||||
|
PlainTextEditModifier(textEdit)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseTextEditModifier::indent(int offset, int length)
|
||||||
|
{
|
||||||
|
if (length == 0 || offset < 0 || offset + length >= text().length())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// qDebug() << "PlainTextEditModifier::indent(" << offset << "," << length << ")";
|
||||||
|
if (TextEditor::BaseTextEditor *bte = dynamic_cast<TextEditor::BaseTextEditor*>(plainTextEdit())) {
|
||||||
|
// qDebug() << "**** Doing indentation";
|
||||||
|
// find the applicable block:
|
||||||
|
QTextDocument *doc = bte->document();
|
||||||
|
QTextCursor tc(doc);
|
||||||
|
tc.beginEditBlock();
|
||||||
|
tc.setPosition(offset);
|
||||||
|
tc.setPosition(offset + length, QTextCursor::KeepAnchor);
|
||||||
|
bte->indentInsertedText(tc);
|
||||||
|
tc.endEditBlock();
|
||||||
|
} else {
|
||||||
|
// qDebug() << "**** Skipping indentation";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,7 +29,6 @@
|
|||||||
|
|
||||||
#include "plaintexteditmodifier.h"
|
#include "plaintexteditmodifier.h"
|
||||||
|
|
||||||
#include <texteditor/basetexteditor.h>
|
|
||||||
#include <utils/changeset.h>
|
#include <utils/changeset.h>
|
||||||
|
|
||||||
#include <QtGui/QPlainTextEdit>
|
#include <QtGui/QPlainTextEdit>
|
||||||
@@ -113,27 +112,6 @@ void PlainTextEditModifier::move(const MoveInfo &moveInfo)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlainTextEditModifier::indent(int offset, int length)
|
|
||||||
{
|
|
||||||
if (length == 0 || offset < 0 || offset + length >= text().length())
|
|
||||||
return;
|
|
||||||
|
|
||||||
// qDebug() << "PlainTextEditModifier::indent(" << offset << "," << length << ")";
|
|
||||||
if (TextEditor::BaseTextEditor *bte = dynamic_cast<TextEditor::BaseTextEditor*>(m_textEdit)) {
|
|
||||||
// qDebug() << "**** Doing indentation";
|
|
||||||
// find the applicable block:
|
|
||||||
QTextDocument *doc = bte->document();
|
|
||||||
QTextCursor tc(doc);
|
|
||||||
tc.beginEditBlock();
|
|
||||||
tc.setPosition(offset);
|
|
||||||
tc.setPosition(offset + length, QTextCursor::KeepAnchor);
|
|
||||||
bte->indentInsertedText(tc);
|
|
||||||
tc.endEditBlock();
|
|
||||||
} else {
|
|
||||||
// qDebug() << "**** Skipping indentation";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlainTextEditModifier::startGroup()
|
void PlainTextEditModifier::startGroup()
|
||||||
{
|
{
|
||||||
if (!m_changeSet)
|
if (!m_changeSet)
|
||||||
|
|||||||
Reference in New Issue
Block a user