2011-02-18 11:47:15 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
|
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Contact: Nokia Corporation (info@qt.nokia.com)
|
2011-02-18 11:47:15 +01:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
2011-02-18 11:47:15 +01:00
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2011-02-18 11:47:15 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2011-02-18 11:47:15 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-05-06 15:05:37 +02:00
|
|
|
** Nokia at info@qt.nokia.com.
|
2011-02-18 11:47:15 +01:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
2010-08-12 15:48:24 +02:00
|
|
|
#include "quicktoolbar.h"
|
|
|
|
|
#include <contextpanewidget.h>
|
|
|
|
|
#include <quicktoolbarsettingspage.h>
|
|
|
|
|
|
|
|
|
|
#include <utils/changeset.h>
|
|
|
|
|
#include <qmljs/parser/qmljsast_p.h>
|
|
|
|
|
#include <qmljs/qmljsdocument.h>
|
|
|
|
|
#include <qmljs/qmljspropertyreader.h>
|
|
|
|
|
#include <qmljs/qmljsrewriter.h>
|
|
|
|
|
#include <qmljs/qmljsindenter.h>
|
2011-07-01 13:51:53 +02:00
|
|
|
#include <qmljs/qmljscontext.h>
|
2010-08-12 15:48:24 +02:00
|
|
|
#include <qmljs/qmljsbind.h>
|
|
|
|
|
#include <qmljs/qmljsscopebuilder.h>
|
2010-08-18 16:25:05 +02:00
|
|
|
#include <qmljs/qmljsevaluate.h>
|
2010-08-12 15:48:24 +02:00
|
|
|
#include <texteditor/basetexteditor.h>
|
|
|
|
|
#include <texteditor/tabsettings.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <customcolordialog.h>
|
2011-01-24 12:29:48 +01:00
|
|
|
|
|
|
|
|
#include <QtCore/QDebug>
|
2010-08-12 15:48:24 +02:00
|
|
|
|
|
|
|
|
using namespace QmlJS;
|
|
|
|
|
using namespace AST;
|
|
|
|
|
using namespace QmlEditorWidgets;
|
|
|
|
|
|
|
|
|
|
namespace QmlJSEditor {
|
|
|
|
|
|
|
|
|
|
static inline QString textAt(const Document* doc,
|
|
|
|
|
const SourceLocation &from,
|
|
|
|
|
const SourceLocation &to)
|
|
|
|
|
{
|
|
|
|
|
return doc->source().mid(from.offset, to.end() - from.begin());
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-08 12:47:49 +02:00
|
|
|
static inline const ObjectValue * getPropertyChangesTarget(Node *node, const ScopeChain &scopeChain)
|
2010-08-18 16:25:05 +02:00
|
|
|
{
|
|
|
|
|
UiObjectInitializer *initializer = 0;
|
|
|
|
|
if (UiObjectDefinition *definition = cast<UiObjectDefinition *>(node))
|
|
|
|
|
initializer = definition->initializer;
|
|
|
|
|
if (UiObjectBinding *binding = cast<UiObjectBinding *>(node))
|
|
|
|
|
initializer = binding->initializer;
|
|
|
|
|
if (initializer) {
|
|
|
|
|
for (UiObjectMemberList *members = initializer->members; members; members = members->next) {
|
|
|
|
|
if (UiScriptBinding *scriptBinding = cast<UiScriptBinding *>(members->member)) {
|
|
|
|
|
if (scriptBinding->qualifiedId
|
2010-11-23 14:15:50 +01:00
|
|
|
&& scriptBinding->qualifiedId->name->asString() == QLatin1String("target")
|
|
|
|
|
&& ! scriptBinding->qualifiedId->next) {
|
2011-08-08 12:26:22 +02:00
|
|
|
Evaluate evaluator(&scopeChain);
|
2011-08-08 12:47:49 +02:00
|
|
|
const Value *targetValue = evaluator(scriptBinding->statement);
|
|
|
|
|
if (const ObjectValue *targetObject = value_cast<const ObjectValue *>(targetValue)) {
|
2010-11-23 14:15:50 +01:00
|
|
|
return targetObject;
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
2010-08-18 16:25:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-08-18 16:39:07 +02:00
|
|
|
return 0;
|
2010-08-18 16:25:05 +02:00
|
|
|
}
|
|
|
|
|
|
2011-07-04 12:51:42 +02:00
|
|
|
QuickToolBar::QuickToolBar(QObject *parent)
|
|
|
|
|
: ::QmlJS::IContextPane(parent)
|
|
|
|
|
, m_editor(0)
|
|
|
|
|
, m_blockWriting(false)
|
2010-08-12 15:48:24 +02:00
|
|
|
{
|
|
|
|
|
m_node = 0;
|
|
|
|
|
contextWidget();
|
|
|
|
|
|
|
|
|
|
m_propertyOrder
|
|
|
|
|
<< QLatin1String("id")
|
|
|
|
|
<< QLatin1String("name")
|
|
|
|
|
<< QLatin1String("target")
|
|
|
|
|
<< QLatin1String("property")
|
|
|
|
|
<< QLatin1String("x")
|
|
|
|
|
<< QLatin1String("y")
|
|
|
|
|
<< QLatin1String("width")
|
|
|
|
|
<< QLatin1String("height")
|
|
|
|
|
<< QLatin1String("position")
|
|
|
|
|
<< QLatin1String("color")
|
|
|
|
|
<< QLatin1String("radius")
|
|
|
|
|
<< QLatin1String("text")
|
|
|
|
|
<< QLatin1String("font.family")
|
|
|
|
|
<< QLatin1String("font.bold")
|
|
|
|
|
<< QLatin1String("font.italic")
|
|
|
|
|
<< QLatin1String("font.underline")
|
|
|
|
|
<< QLatin1String("font.strikeout")
|
|
|
|
|
<< QString::null
|
|
|
|
|
<< QLatin1String("states")
|
|
|
|
|
<< QLatin1String("transitions")
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QuickToolBar::~QuickToolBar()
|
|
|
|
|
{
|
|
|
|
|
//if the pane was never activated the widget is not in a widget tree
|
|
|
|
|
if (!m_widget.isNull())
|
|
|
|
|
delete m_widget.data();
|
|
|
|
|
m_widget.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-08 12:47:49 +02:00
|
|
|
void QuickToolBar::apply(TextEditor::BaseTextEditor *editor, Document::Ptr document, const ScopeChain *scopeChain, AST::Node *node, bool update, bool force)
|
2010-08-12 15:48:24 +02:00
|
|
|
{
|
|
|
|
|
if (!QuickToolBarSettings::get().enableContextPane && !force && !update) {
|
|
|
|
|
contextWidget()->hide();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-21 15:41:58 +02:00
|
|
|
if (document.isNull())
|
2010-08-12 15:48:24 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (update && editor != m_editor)
|
|
|
|
|
return; //do not update for different editor
|
|
|
|
|
|
|
|
|
|
m_blockWriting = true;
|
|
|
|
|
|
2011-08-08 12:47:49 +02:00
|
|
|
const ObjectValue *scopeObject = document->bind()->findQmlObject(node);
|
2010-08-12 15:48:24 +02:00
|
|
|
|
2011-03-10 13:05:23 +01:00
|
|
|
bool isPropertyChanges = false;
|
|
|
|
|
|
2011-08-08 12:26:22 +02:00
|
|
|
if (scopeChain && scopeObject) {
|
2010-10-21 15:41:58 +02:00
|
|
|
m_prototypes.clear();
|
2011-08-08 12:47:49 +02:00
|
|
|
foreach (const ObjectValue *object,
|
|
|
|
|
PrototypeIterator(scopeObject, scopeChain->context()).all()) {
|
2010-11-12 14:53:00 +01:00
|
|
|
m_prototypes.append(object->className());
|
2010-10-21 15:41:58 +02:00
|
|
|
}
|
2010-08-12 15:48:24 +02:00
|
|
|
|
2010-10-21 15:41:58 +02:00
|
|
|
if (m_prototypes.contains("PropertyChanges")) {
|
2011-03-10 13:05:23 +01:00
|
|
|
isPropertyChanges = true;
|
2011-08-08 12:47:49 +02:00
|
|
|
const ObjectValue *targetObject = getPropertyChangesTarget(node, *scopeChain);
|
2010-10-21 15:41:58 +02:00
|
|
|
m_prototypes.clear();
|
2010-11-12 14:53:00 +01:00
|
|
|
if (targetObject) {
|
2011-08-08 12:47:49 +02:00
|
|
|
foreach (const ObjectValue *object,
|
|
|
|
|
PrototypeIterator(targetObject, scopeChain->context()).all()) {
|
2010-11-12 14:53:00 +01:00
|
|
|
m_prototypes.append(object->className());
|
|
|
|
|
}
|
2010-10-21 15:41:58 +02:00
|
|
|
}
|
2010-08-18 16:25:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-21 15:41:58 +02:00
|
|
|
setEnabled(document->isParsedCorrectly());
|
2010-08-12 15:48:24 +02:00
|
|
|
m_editor = editor;
|
|
|
|
|
contextWidget()->setParent(editor->widget()->parentWidget());
|
|
|
|
|
contextWidget()->colorDialog()->setParent(editor->widget()->parentWidget());
|
|
|
|
|
|
|
|
|
|
if (cast<UiObjectDefinition*>(node) || cast<UiObjectBinding*>(node)) {
|
|
|
|
|
UiObjectDefinition *objectDefinition = cast<UiObjectDefinition*>(node);
|
|
|
|
|
UiObjectBinding *objectBinding = cast<UiObjectBinding*>(node);
|
|
|
|
|
|
|
|
|
|
QString name;
|
2010-09-08 16:29:12 +02:00
|
|
|
quint32 offset = 0;
|
|
|
|
|
quint32 end = 0;
|
|
|
|
|
UiObjectInitializer *initializer = 0;
|
2010-08-12 15:48:24 +02:00
|
|
|
if (objectDefinition) {
|
|
|
|
|
name = objectDefinition->qualifiedTypeNameId->name->asString();
|
|
|
|
|
initializer = objectDefinition->initializer;
|
|
|
|
|
offset = objectDefinition->firstSourceLocation().offset;
|
|
|
|
|
end = objectDefinition->lastSourceLocation().end();
|
|
|
|
|
} else if (objectBinding) {
|
|
|
|
|
name = objectBinding->qualifiedTypeNameId->name->asString();
|
|
|
|
|
initializer = objectBinding->initializer;
|
|
|
|
|
offset = objectBinding->firstSourceLocation().offset;
|
|
|
|
|
end = objectBinding->lastSourceLocation().end();
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-08 12:26:22 +02:00
|
|
|
if (!scopeChain) {
|
2010-11-11 16:32:46 +01:00
|
|
|
if (name != m_oldType)
|
|
|
|
|
m_prototypes.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_oldType = name;
|
|
|
|
|
|
2010-10-21 15:41:58 +02:00
|
|
|
m_prototypes.append(name);
|
|
|
|
|
|
2010-08-12 15:48:24 +02:00
|
|
|
int line1;
|
|
|
|
|
int column1;
|
|
|
|
|
int line2;
|
|
|
|
|
int column2;
|
|
|
|
|
m_editor->convertPosition(offset, &line1, &column1); //get line
|
|
|
|
|
m_editor->convertPosition(end, &line2, &column2); //get line
|
|
|
|
|
|
|
|
|
|
QRegion reg;
|
|
|
|
|
if (line1 > -1 && line2 > -1)
|
2011-02-21 16:02:26 +01:00
|
|
|
reg = m_editor->editorWidget()->translatedLineRegion(line1 - 1, line2);
|
2010-08-12 15:48:24 +02:00
|
|
|
|
|
|
|
|
QRect rect;
|
|
|
|
|
rect.setHeight(widget()->height() + 10);
|
|
|
|
|
rect.setWidth(reg.boundingRect().width() - reg.boundingRect().left());
|
|
|
|
|
rect.moveTo(reg.boundingRect().topLeft());
|
|
|
|
|
reg = reg.intersect(rect);
|
|
|
|
|
|
2010-10-21 15:41:58 +02:00
|
|
|
if (contextWidget()->acceptsType(m_prototypes)) {
|
2010-08-12 15:48:24 +02:00
|
|
|
m_node = 0;
|
2010-10-21 15:41:58 +02:00
|
|
|
PropertyReader propertyReader(document, initializer);
|
2011-02-21 16:02:26 +01:00
|
|
|
QTextCursor tc(editor->editorWidget()->document());
|
2010-08-12 15:48:24 +02:00
|
|
|
tc.setPosition(offset);
|
2011-02-21 16:02:26 +01:00
|
|
|
QPoint p1 = editor->editorWidget()->mapToParent(editor->editorWidget()->viewport()->mapToParent(editor->editorWidget()->cursorRect(tc).topLeft()) - QPoint(0, contextWidget()->height() + 10));
|
2010-08-12 15:48:24 +02:00
|
|
|
tc.setPosition(end);
|
2011-02-21 16:02:26 +01:00
|
|
|
QPoint p2 = editor->editorWidget()->mapToParent(editor->editorWidget()->viewport()->mapToParent(editor->editorWidget()->cursorRect(tc).bottomLeft()) + QPoint(0, 10));
|
2010-08-12 15:48:24 +02:00
|
|
|
QPoint offset = QPoint(10, 0);
|
|
|
|
|
if (reg.boundingRect().width() < 400)
|
|
|
|
|
offset = QPoint(400 - reg.boundingRect().width() + 10 ,0);
|
2011-02-21 16:02:26 +01:00
|
|
|
QPoint p3 = editor->editorWidget()->mapToParent(editor->editorWidget()->viewport()->mapToParent(reg.boundingRect().topRight()) + offset);
|
2010-08-12 15:48:24 +02:00
|
|
|
p2.setX(p1.x());
|
2011-03-10 13:05:23 +01:00
|
|
|
contextWidget()->setIsPropertyChanges(isPropertyChanges);
|
|
|
|
|
if (!update)
|
|
|
|
|
contextWidget()->setType(m_prototypes);
|
2010-08-12 15:48:24 +02:00
|
|
|
if (!update)
|
|
|
|
|
contextWidget()->activate(p3 , p1, p2, QuickToolBarSettings::get().pinContextPane);
|
|
|
|
|
else
|
|
|
|
|
contextWidget()->rePosition(p3 , p1, p2, QuickToolBarSettings::get().pinContextPane);
|
|
|
|
|
contextWidget()->setOptions(QuickToolBarSettings::get().enableContextPane, QuickToolBarSettings::get().pinContextPane);
|
2010-10-21 15:41:58 +02:00
|
|
|
contextWidget()->setPath(document->path());
|
2010-08-12 15:48:24 +02:00
|
|
|
contextWidget()->setProperties(&propertyReader);
|
2010-10-21 15:41:58 +02:00
|
|
|
m_doc = document;
|
2010-08-12 15:48:24 +02:00
|
|
|
m_node = node;
|
|
|
|
|
} else {
|
|
|
|
|
contextWidget()->setParent(0);
|
|
|
|
|
contextWidget()->hide();
|
|
|
|
|
contextWidget()->colorDialog()->hide();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
contextWidget()->setParent(0);
|
|
|
|
|
contextWidget()->hide();
|
|
|
|
|
contextWidget()->colorDialog()->hide();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_blockWriting = false;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
bool QuickToolBar::isAvailable(TextEditor::BaseTextEditor *, Document::Ptr document, AST::Node *node)
|
2010-08-12 15:48:24 +02:00
|
|
|
{
|
2010-10-21 15:41:58 +02:00
|
|
|
if (document.isNull())
|
2010-08-12 15:48:24 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (!node)
|
|
|
|
|
return false;
|
|
|
|
|
|
2010-10-21 15:41:58 +02:00
|
|
|
QString name;
|
2010-08-12 15:48:24 +02:00
|
|
|
|
2010-10-21 15:41:58 +02:00
|
|
|
UiObjectDefinition *objectDefinition = cast<UiObjectDefinition*>(node);
|
|
|
|
|
UiObjectBinding *objectBinding = cast<UiObjectBinding*>(node);
|
|
|
|
|
if (objectDefinition) {
|
|
|
|
|
name = objectDefinition->qualifiedTypeNameId->name->asString();
|
2010-08-12 15:48:24 +02:00
|
|
|
|
2010-10-21 15:41:58 +02:00
|
|
|
} else if (objectBinding) {
|
|
|
|
|
name = objectBinding->qualifiedTypeNameId->name->asString();
|
2010-08-26 10:50:00 +02:00
|
|
|
}
|
2010-08-12 15:48:24 +02:00
|
|
|
|
2010-10-21 15:41:58 +02:00
|
|
|
QStringList prototypes;
|
|
|
|
|
prototypes.append(name);
|
2010-08-18 16:25:05 +02:00
|
|
|
|
2010-08-26 10:50:00 +02:00
|
|
|
if (prototypes.contains("Rectangle") ||
|
2010-08-12 15:48:24 +02:00
|
|
|
prototypes.contains("Image") ||
|
|
|
|
|
prototypes.contains("BorderImage") ||
|
|
|
|
|
prototypes.contains("TextEdit") ||
|
|
|
|
|
prototypes.contains("TextInput") ||
|
|
|
|
|
prototypes.contains("PropertyAnimation") ||
|
2010-10-21 15:41:58 +02:00
|
|
|
prototypes.contains("NumberAnimation") ||
|
|
|
|
|
prototypes.contains("Text") ||
|
|
|
|
|
prototypes.contains("PropertyChanges"))
|
2010-08-26 10:50:00 +02:00
|
|
|
return true;
|
2010-08-12 15:48:24 +02:00
|
|
|
|
2010-08-26 10:50:00 +02:00
|
|
|
return false;
|
2010-08-12 15:48:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QuickToolBar::setProperty(const QString &propertyName, const QVariant &value)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
QString stringValue = value.toString();
|
|
|
|
|
if (value.type() == QVariant::Color)
|
|
|
|
|
stringValue = QChar('\"') + value.toString() + QChar('\"');
|
|
|
|
|
|
|
|
|
|
if (cast<UiObjectDefinition*>(m_node) || cast<UiObjectBinding*>(m_node)) {
|
|
|
|
|
UiObjectDefinition *objectDefinition = cast<UiObjectDefinition*>(m_node);
|
|
|
|
|
UiObjectBinding *objectBinding = cast<UiObjectBinding*>(m_node);
|
|
|
|
|
|
2011-07-21 09:12:10 +02:00
|
|
|
UiObjectInitializer *initializer = 0;
|
2010-08-12 15:48:24 +02:00
|
|
|
if (objectDefinition)
|
|
|
|
|
initializer = objectDefinition->initializer;
|
|
|
|
|
else if (objectBinding)
|
|
|
|
|
initializer = objectBinding->initializer;
|
|
|
|
|
|
|
|
|
|
Utils::ChangeSet changeSet;
|
|
|
|
|
Rewriter rewriter(m_doc->source(), &changeSet, m_propertyOrder);
|
|
|
|
|
|
|
|
|
|
int line = -1;
|
|
|
|
|
int endLine;
|
|
|
|
|
|
|
|
|
|
Rewriter::BindingType bindingType = Rewriter::ScriptBinding;
|
|
|
|
|
|
|
|
|
|
if (stringValue.contains("{") && stringValue.contains("}"))
|
|
|
|
|
bindingType = Rewriter::ObjectBinding;
|
|
|
|
|
|
|
|
|
|
PropertyReader propertyReader(m_doc, initializer);
|
|
|
|
|
if (propertyReader.hasProperty(propertyName)) {
|
|
|
|
|
rewriter.changeBinding(initializer, propertyName, stringValue, bindingType);
|
|
|
|
|
} else {
|
|
|
|
|
rewriter.addBinding(initializer, propertyName, stringValue, bindingType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int column;
|
|
|
|
|
|
|
|
|
|
int changeSetPos = changeSet.operationList().last().pos1;
|
|
|
|
|
int changeSetLength = changeSet.operationList().last().text.length();
|
2011-02-21 16:02:26 +01:00
|
|
|
QTextCursor tc = m_editor->editorWidget()->textCursor();
|
2010-08-12 15:48:24 +02:00
|
|
|
tc.beginEditBlock();
|
|
|
|
|
changeSet.apply(&tc);
|
|
|
|
|
|
|
|
|
|
m_editor->convertPosition(changeSetPos, &line, &column); //get line
|
|
|
|
|
m_editor->convertPosition(changeSetPos + changeSetLength, &endLine, &column); //get line
|
|
|
|
|
|
|
|
|
|
if (line > 0) {
|
2011-02-21 16:02:26 +01:00
|
|
|
TextEditor::TabSettings ts = m_editor->editorWidget()->tabSettings();
|
2010-08-12 15:48:24 +02:00
|
|
|
QmlJSIndenter indenter;
|
|
|
|
|
indenter.setTabSize(ts.m_tabSize);
|
|
|
|
|
indenter.setIndentSize(ts.m_indentSize);
|
|
|
|
|
|
|
|
|
|
for (int i=line;i<=endLine;i++) {
|
2011-02-21 16:02:26 +01:00
|
|
|
QTextBlock start = m_editor->editorWidget()->document()->findBlockByNumber(i);
|
|
|
|
|
QTextBlock end = m_editor->editorWidget()->document()->findBlockByNumber(i);
|
2010-08-12 15:48:24 +02:00
|
|
|
|
|
|
|
|
if (end.isValid()) {
|
2011-02-21 16:02:26 +01:00
|
|
|
const int indent = indenter.indentForBottomLine(m_editor->editorWidget()->document()->begin(), end.next(), QChar::Null);
|
2010-08-12 15:48:24 +02:00
|
|
|
ts.indentLine(start, indent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
tc.endEditBlock();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QuickToolBar::removeProperty(const QString &propertyName)
|
|
|
|
|
{
|
|
|
|
|
if (cast<UiObjectDefinition*>(m_node) || cast<UiObjectBinding*>(m_node)) {
|
|
|
|
|
UiObjectDefinition *objectDefinition = cast<UiObjectDefinition*>(m_node);
|
|
|
|
|
UiObjectBinding *objectBinding = cast<UiObjectBinding*>(m_node);
|
|
|
|
|
|
2011-07-21 09:12:10 +02:00
|
|
|
UiObjectInitializer *initializer = 0;
|
2010-08-12 15:48:24 +02:00
|
|
|
if (objectDefinition)
|
|
|
|
|
initializer = objectDefinition->initializer;
|
|
|
|
|
else if (objectBinding)
|
|
|
|
|
initializer = objectBinding->initializer;
|
|
|
|
|
|
|
|
|
|
PropertyReader propertyReader(m_doc, initializer);
|
|
|
|
|
if (propertyReader.hasProperty(propertyName)) {
|
|
|
|
|
Utils::ChangeSet changeSet;
|
|
|
|
|
Rewriter rewriter(m_doc->source(), &changeSet, m_propertyOrder);
|
|
|
|
|
rewriter.removeBindingByName(initializer, propertyName);
|
2011-02-21 16:02:26 +01:00
|
|
|
QTextCursor tc(m_editor->editorWidget()->document());
|
2010-08-12 15:48:24 +02:00
|
|
|
changeSet.apply(&tc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QuickToolBar::setEnabled(bool b)
|
|
|
|
|
{
|
|
|
|
|
if (m_widget)
|
|
|
|
|
contextWidget()->currentWidget()->setEnabled(b);
|
|
|
|
|
if (!b)
|
|
|
|
|
widget()->hide();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QWidget* QuickToolBar::widget()
|
|
|
|
|
{
|
|
|
|
|
return contextWidget();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QuickToolBar::onPropertyChanged(const QString &name, const QVariant &value)
|
|
|
|
|
{
|
|
|
|
|
if (m_blockWriting)
|
|
|
|
|
return;
|
|
|
|
|
if (!m_doc)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
setProperty(name, value);
|
|
|
|
|
m_doc.clear(); //the document is outdated
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QuickToolBar::onPropertyRemovedAndChange(const QString &remove, const QString &change, const QVariant &value, bool removeFirst)
|
|
|
|
|
{
|
|
|
|
|
if (m_blockWriting)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!m_doc)
|
|
|
|
|
return;
|
|
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
QTextCursor tc(m_editor->editorWidget()->document());
|
2010-08-12 15:48:24 +02:00
|
|
|
tc.beginEditBlock();
|
|
|
|
|
|
|
|
|
|
if (removeFirst) {
|
|
|
|
|
removeProperty(remove);
|
|
|
|
|
setProperty(change, value);
|
|
|
|
|
} else {
|
|
|
|
|
setProperty(change, value);
|
|
|
|
|
removeProperty(remove);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tc.endEditBlock();
|
|
|
|
|
|
|
|
|
|
m_doc.clear(); //the document is outdated
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QuickToolBar::onPinnedChanged(bool b)
|
|
|
|
|
{
|
|
|
|
|
QuickToolBarSettings settings = QuickToolBarSettings::get();
|
|
|
|
|
settings.pinContextPane = b;
|
|
|
|
|
settings.set();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QuickToolBar::onEnabledChanged(bool b)
|
|
|
|
|
{
|
|
|
|
|
QuickToolBarSettings settings = QuickToolBarSettings::get();
|
|
|
|
|
settings.pinContextPane = b;
|
|
|
|
|
settings.enableContextPane = b;
|
|
|
|
|
settings.set();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ContextPaneWidget* QuickToolBar::contextWidget()
|
|
|
|
|
{
|
|
|
|
|
if (m_widget.isNull()) { //lazily recreate widget
|
|
|
|
|
m_widget = new ContextPaneWidget;
|
|
|
|
|
connect(m_widget.data(), SIGNAL(propertyChanged(QString,QVariant)), this, SLOT(onPropertyChanged(QString,QVariant)));
|
|
|
|
|
connect(m_widget.data(), SIGNAL(removeProperty(QString)), this, SLOT(onPropertyRemoved(QString)));
|
|
|
|
|
connect(m_widget.data(), SIGNAL(removeAndChangeProperty(QString,QString,QVariant, bool)), this, SLOT(onPropertyRemovedAndChange(QString,QString,QVariant, bool)));
|
|
|
|
|
connect(m_widget.data(), SIGNAL(enabledChanged(bool)), this, SLOT(onEnabledChanged(bool)));
|
|
|
|
|
connect(m_widget.data(), SIGNAL(pinnedChanged(bool)), this, SLOT(onPinnedChanged(bool)));
|
2010-08-13 13:56:23 +02:00
|
|
|
connect(m_widget.data(), SIGNAL(closed()), this, SIGNAL(closed()));
|
2010-08-12 15:48:24 +02:00
|
|
|
}
|
|
|
|
|
return m_widget.data();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QuickToolBar::onPropertyRemoved(const QString &propertyName)
|
|
|
|
|
{
|
|
|
|
|
if (m_blockWriting)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!m_doc)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
removeProperty(propertyName);
|
|
|
|
|
m_doc.clear(); //the document is outdated
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} //QmlDesigner
|