From afbdad999d68137e71cf9e97b0c1ae64c44e22d5 Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Tue, 23 May 2023 06:57:02 +0200 Subject: [PATCH] Core: Add Command::actionForContext Change-Id: I04ea463e1e9f4addafbea78c6302a488d7992ccd Reviewed-by: Eike Ziller Reviewed-by: --- src/plugins/coreplugin/actionmanager/command.cpp | 9 +++++++++ src/plugins/coreplugin/actionmanager/command.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/src/plugins/coreplugin/actionmanager/command.cpp b/src/plugins/coreplugin/actionmanager/command.cpp index 592ba08faac..ab78bf50892 100644 --- a/src/plugins/coreplugin/actionmanager/command.cpp +++ b/src/plugins/coreplugin/actionmanager/command.cpp @@ -289,6 +289,15 @@ QAction *Command::action() const return d->m_action; } +QAction *Command::actionForContext(const Utils::Id &contextId) const +{ + auto it = d->m_contextActionMap.find(contextId); + if (it == d->m_contextActionMap.end()) + return nullptr; + + return *it; +} + QString Command::stringWithAppendedShortcut(const QString &str) const { return Utils::ProxyAction::stringWithAppendedShortcut(str, keySequence()); diff --git a/src/plugins/coreplugin/actionmanager/command.h b/src/plugins/coreplugin/actionmanager/command.h index b900a50f55a..73dd92a5eb8 100644 --- a/src/plugins/coreplugin/actionmanager/command.h +++ b/src/plugins/coreplugin/actionmanager/command.h @@ -57,6 +57,8 @@ public: Utils::Id id() const; QAction *action() const; + QAction *actionForContext(const Utils::Id &contextId) const; + Context context() const; void setAttribute(CommandAttribute attr);