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.
This commit is contained in:
Zheng, Lei
2022-03-12 15:33:39 +08:00
committed by wwmayer
parent 93c4c0884e
commit 362c781553
3 changed files with 19 additions and 13 deletions

View File

@@ -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<QAction*>());
}

View File

@@ -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();
//@}

View File

@@ -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,