Commit bb64cc70 authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

QtQuickToolbar: adds isAvailable() to IContextPane

isAvailable() returns true if a Quick ToolBar is available
for that node
parent d02c4083
......@@ -54,6 +54,7 @@ public:
virtual ~IContextPane() {}
virtual void apply(TextEditor::BaseTextEditorEditable *editor, Document::Ptr doc, const QmlJS::Snapshot &snapshot, AST::Node *node, bool update, bool force = false) = 0;
virtual void setEnabled(bool) = 0;
virtual bool isAvailable(TextEditor::BaseTextEditorEditable *editor, Document::Ptr doc, const QmlJS::Snapshot &snapshot, AST::Node *node) = 0;
virtual QWidget* widget() = 0;
};
......
......@@ -68,8 +68,10 @@ QmlContextPane::~QmlContextPane()
void QmlContextPane::apply(TextEditor::BaseTextEditorEditable *editor, Document::Ptr doc, const QmlJS::Snapshot &snapshot, AST::Node *node, bool update, bool force)
{
if (!Internal::BauhausPlugin::pluginInstance()->settings().enableContextPane && !force)
if (!Internal::BauhausPlugin::pluginInstance()->settings().enableContextPane && !force && !update) {
contextWidget()->hide();
return;
}
if (doc.isNull())
return;
......@@ -169,6 +171,36 @@ void QmlContextPane::apply(TextEditor::BaseTextEditorEditable *editor, Document:
}
bool QmlContextPane::isAvailable(TextEditor::BaseTextEditorEditable *, Document::Ptr doc, const QmlJS::Snapshot &snapshot, AST::Node *node)
{
if (doc.isNull())
return false;
if (!node)
return false;
LookupContext::Ptr lookupContext = LookupContext::create(doc, snapshot, QList<Node*>());
const Interpreter::ObjectValue *scopeObject = doc->bind()->findQmlObject(node);
QStringList prototypes;
while (scopeObject) {
prototypes.append(scopeObject->className());
scopeObject = scopeObject->prototype(lookupContext->context());
}
if (prototypes.contains("Rectangle") ||
prototypes.contains("Image") ||
prototypes.contains("BorderImage") ||
prototypes.contains("TextEdit") ||
prototypes.contains("TextInput") ||
prototypes.contains("PropertyAnimation") ||
prototypes.contains("Text"))
return true;
return false;
}
void QmlContextPane::setProperty(const QString &propertyName, const QVariant &value)
{
......
......@@ -29,6 +29,7 @@ public:
QmlContextPane(QObject *parent = 0);
~QmlContextPane();
void apply(TextEditor::BaseTextEditorEditable *editor, QmlJS::Document::Ptr doc, const QmlJS::Snapshot &snapshot, QmlJS::AST::Node *node, bool update, bool force = 0);
bool isAvailable(TextEditor::BaseTextEditorEditable *editor, QmlJS::Document::Ptr doc, const QmlJS::Snapshot &snapshot, QmlJS::AST::Node *node);
void setProperty(const QString &propertyName, const QVariant &value);
void removeProperty(const QString &propertyName);
void setEnabled(bool);
......
Supports Markdown
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