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,