From 362c781553494525fe901358142332e638c2b59b Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Sat, 12 Mar 2022 15:33:39 +0800 Subject: [PATCH] Gui: fix Customize -> Keyboard shortcut priroity list Add API Command::initAction() to force create action for all commands with shortcut in order to register with ShortcutManager to obtain a complete list of actions with the same shortcut. --- src/Gui/Command.cpp | 17 ++++++----------- src/Gui/Command.h | 4 ++-- src/Gui/DlgKeyboardImp.cpp | 11 +++++++++++ 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/Gui/Command.cpp b/src/Gui/Command.cpp index 291cc215d4..535c8b190b 100644 --- a/src/Gui/Command.cpp +++ b/src/Gui/Command.cpp @@ -259,7 +259,7 @@ bool Command::isViewOfType(Base::Type t) const return false; } -void Command::addTo(QWidget *pcWidget) +void Command::initAction() { if (!_pcAction) { _pcAction = createAction(); @@ -271,7 +271,11 @@ void Command::addTo(QWidget *pcWidget) setShortcut(ShortcutManager::instance()->getShortcut(getName(), getAccel())); testActive(); } +} +void Command::addTo(QWidget *pcWidget) +{ + initAction(); _pcAction->addTo(pcWidget); } @@ -283,16 +287,7 @@ void Command::addToGroup(ActionGroup* group, bool checkable) void Command::addToGroup(ActionGroup* group) { - if (!_pcAction) { - _pcAction = createAction(); -#ifdef FC_DEBUG - // Accelerator conflict can now be dynamically resolved in ShortcutManager - // - // printConflictingAccelerators(); -#endif - setShortcut(ShortcutManager::instance()->getShortcut(getName(), getAccel())); - testActive(); - } + initAction(); group->addAction(_pcAction->findChild()); } diff --git a/src/Gui/Command.h b/src/Gui/Command.h index 43d2f0601c..5d68582f0d 100644 --- a/src/Gui/Command.h +++ b/src/Gui/Command.h @@ -345,8 +345,6 @@ public: void testActive(); /// Enables or disables the command void setEnabled(bool); - /// (Re)Create the text for the tooltip (for example, when the shortcut is changed) - void recreateTooltip(const char* context, Action*); /// Command trigger source enum TriggerSource { /// No external trigger, e.g. invoked through Python @@ -370,6 +368,8 @@ public: void addTo(QWidget *); void addToGroup(ActionGroup *, bool checkable); void addToGroup(ActionGroup *); + /// Create the action if not exist + void initAction(); //@} diff --git a/src/Gui/DlgKeyboardImp.cpp b/src/Gui/DlgKeyboardImp.cpp index 27c1582b9a..3048d7e512 100644 --- a/src/Gui/DlgKeyboardImp.cpp +++ b/src/Gui/DlgKeyboardImp.cpp @@ -78,6 +78,17 @@ DlgCustomKeyboardImp::DlgCustomKeyboardImp( QWidget* parent ) { ui->setupUi(this); + // Force create actions for all commands with shortcut to register with ShortcutManager + for (auto cmd : Application::Instance->commandManager().getAllCommands()) { + if (cmd->getShortcut().size()) + cmd->initAction(); + } + QObject::connect(ShortcutManager::instance(), &ShortcutManager::shortcutChanged, this, + [](const char *cmdName) { + if (auto cmd = Application::Instance->commandManager().getCommandByName(cmdName)) + cmd->initAction(); + }); + conn = initCommandWidgets(ui->commandTreeWidget, nullptr, ui->categoryBox,