forked from qt-creator/qt-creator
Allow designeractions to target specific views
This is needed for the "connect signal to event dialog" which resides in a different plugin but needs to be opened from the connection editor. Change-Id: I9e200791831fa46d65e5f833e14a0d893fc29432 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -53,6 +53,11 @@ public:
|
|||||||
LowestPriority = ComponentCoreConstants::priorityLast
|
LowestPriority = ComponentCoreConstants::priorityLast
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class Target {
|
||||||
|
Undefined,
|
||||||
|
ConnectionEditor
|
||||||
|
};
|
||||||
|
|
||||||
virtual ~ActionInterface() = default;
|
virtual ~ActionInterface() = default;
|
||||||
|
|
||||||
virtual QAction *action() const = 0;
|
virtual QAction *action() const = 0;
|
||||||
@@ -61,6 +66,7 @@ public:
|
|||||||
virtual int priority() const = 0;
|
virtual int priority() const = 0;
|
||||||
virtual Type type() const = 0;
|
virtual Type type() const = 0;
|
||||||
virtual void currentContextChanged(const SelectionContext &selectionState) = 0;
|
virtual void currentContextChanged(const SelectionContext &selectionState) = 0;
|
||||||
|
virtual Target target() const { return Target::Undefined; }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -1461,6 +1461,16 @@ void DesignerActionManager::addCreatorCommand(Core::Command *command, const QByt
|
|||||||
addDesignerAction(new CommandAction(command, category, priority, overrideIcon));
|
addDesignerAction(new CommandAction(command, category, priority, overrideIcon));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<QSharedPointer<ActionInterface> > DesignerActionManager::actionsForTarget(const ActionInterface::Target &target)
|
||||||
|
{
|
||||||
|
QList<QSharedPointer<ActionInterface> > out;
|
||||||
|
for (auto interface : m_designerActions)
|
||||||
|
if (interface->target() == target)
|
||||||
|
out << interface;
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
QList<ActionInterface* > DesignerActionManager::designerActions() const
|
QList<ActionInterface* > DesignerActionManager::designerActions() const
|
||||||
{
|
{
|
||||||
return Utils::transform(m_designerActions, [](const QSharedPointer<ActionInterface> &pointer) {
|
return Utils::transform(m_designerActions, [](const QSharedPointer<ActionInterface> &pointer) {
|
||||||
|
@@ -106,6 +106,9 @@ public:
|
|||||||
void addDesignerAction(ActionInterface *newAction);
|
void addDesignerAction(ActionInterface *newAction);
|
||||||
void addCreatorCommand(Core::Command *command, const QByteArray &category, int priority,
|
void addCreatorCommand(Core::Command *command, const QByteArray &category, int priority,
|
||||||
const QIcon &overrideIcon = QIcon());
|
const QIcon &overrideIcon = QIcon());
|
||||||
|
|
||||||
|
QList<QSharedPointer<ActionInterface>> actionsForTarget(const ActionInterface::Target &target);
|
||||||
|
|
||||||
QList<ActionInterface* > designerActions() const;
|
QList<ActionInterface* > designerActions() const;
|
||||||
|
|
||||||
void createDefaultDesignerActions();
|
void createDefaultDesignerActions();
|
||||||
|
@@ -172,6 +172,16 @@ void ConnectionViewWidget::contextMenuEvent(QContextMenuEvent *event)
|
|||||||
m_connectionEditor->updateWindowName();
|
m_connectionEditor->updateWindowName();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QMap<QString, QVariant> data;
|
||||||
|
data["ModelNode"] = index.siblingAtColumn(ConnectionModel::TargetModelNodeRow).data();
|
||||||
|
data["Signal"] = index.siblingAtColumn(ConnectionModel::TargetPropertyNameRow).data();
|
||||||
|
DesignerActionManager &designerActionManager = QmlDesignerPlugin::instance()->designerActionManager();
|
||||||
|
for (auto actionInterface : designerActionManager.actionsForTarget(ActionInterface::Target::ConnectionEditor)) {
|
||||||
|
auto *action = actionInterface->action();
|
||||||
|
action->setData(data);
|
||||||
|
menu.addAction(action);
|
||||||
|
}
|
||||||
|
|
||||||
menu.exec(event->globalPos());
|
menu.exec(event->globalPos());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user