forked from qt-creator/qt-creator
QuickToolBar: support for PropertyChanges
The ToolBar now detects the target type of the target of a PropertyChanges object.
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include <qmljs/qmljsinterpreter.h>
|
||||
#include <qmljs/qmljsbind.h>
|
||||
#include <qmljs/qmljsscopebuilder.h>
|
||||
#include <qmljs/qmljsevaluate.h>
|
||||
#include <texteditor/basetexteditor.h>
|
||||
#include <texteditor/tabsettings.h>
|
||||
#include <coreplugin/icore.h>
|
||||
@@ -31,6 +32,34 @@ static inline QString textAt(const Document* doc,
|
||||
return doc->source().mid(from.offset, to.end() - from.begin());
|
||||
}
|
||||
|
||||
static inline const Interpreter::ObjectValue * getPropertyChangesTarget(Node *node, LookupContext::Ptr lookupContext)
|
||||
{
|
||||
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
|
||||
&& scriptBinding->qualifiedId->name->asString() == QLatin1String("target")
|
||||
&& ! scriptBinding->qualifiedId->next) {
|
||||
if (ExpressionStatement *expressionStatement = cast<ExpressionStatement *>(scriptBinding->statement)) {
|
||||
Evaluate evaluator(lookupContext->context());
|
||||
const Interpreter::Value *targetValue = evaluator(expressionStatement->expression);
|
||||
if (const Interpreter::ObjectValue *targetObject = Interpreter::value_cast<const Interpreter::ObjectValue *>(targetValue)) {
|
||||
return targetObject;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QuickToolBar::QuickToolBar(QObject *parent) : ::QmlJS::IContextPane(parent), m_blockWriting(false)
|
||||
{
|
||||
m_node = 0;
|
||||
@@ -92,6 +121,15 @@ void QuickToolBar::apply(TextEditor::BaseTextEditorEditable *editor, Document::P
|
||||
scopeObject = scopeObject->prototype(lookupContext->context());
|
||||
}
|
||||
|
||||
if (prototypes.contains("PropertyChanges")) {
|
||||
const Interpreter::ObjectValue *targetObject = getPropertyChangesTarget(node, lookupContext);
|
||||
prototypes.clear();
|
||||
while (targetObject) {
|
||||
prototypes.append(targetObject->className());
|
||||
targetObject = targetObject->prototype(lookupContext->context());
|
||||
}
|
||||
}
|
||||
|
||||
setEnabled(doc->isParsedCorrectly());
|
||||
m_editor = editor;
|
||||
contextWidget()->setParent(editor->widget()->parentWidget());
|
||||
@@ -190,6 +228,15 @@ bool QuickToolBar::isAvailable(TextEditor::BaseTextEditorEditable *, Document::P
|
||||
scopeObject = scopeObject->prototype(lookupContext->context());
|
||||
}
|
||||
|
||||
if (prototypes.contains("PropertyChanges")) {
|
||||
const Interpreter::ObjectValue *targetObject = getPropertyChangesTarget(node, lookupContext);
|
||||
prototypes.clear();
|
||||
while (targetObject) {
|
||||
prototypes.append(targetObject->className());
|
||||
targetObject = targetObject->prototype(lookupContext->context());
|
||||
}
|
||||
}
|
||||
|
||||
if (prototypes.contains("Rectangle") ||
|
||||
prototypes.contains("Image") ||
|
||||
prototypes.contains("BorderImage") ||
|
||||
|
Reference in New Issue
Block a user