forked from qt-creator/qt-creator
QtQuickToolbar: adds isAvailable() to IContextPane
isAvailable() returns true if a Quick ToolBar is available for that node
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user