From d10a7aae7c399909d079e6887f628c7e1836fe03 Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Mon, 14 Mar 2022 10:24:57 +0800 Subject: [PATCH] Gui: fix command completer selection on item activate --- src/Gui/DlgKeyboardImp.cpp | 16 ++++++++++------ src/Gui/DlgKeyboardImp.h | 5 ++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Gui/DlgKeyboardImp.cpp b/src/Gui/DlgKeyboardImp.cpp index 3048d7e512..bbe95b7ac2 100644 --- a/src/Gui/DlgKeyboardImp.cpp +++ b/src/Gui/DlgKeyboardImp.cpp @@ -111,13 +111,16 @@ DlgCustomKeyboardImp::~DlgCustomKeyboardImp() { } -void DlgCustomKeyboardImp::initCommandCompleter(QLineEdit *edit, QComboBox *combo, QTreeWidget *commandTreeWidget) +void DlgCustomKeyboardImp::initCommandCompleter(QLineEdit *edit, + QComboBox *combo, + QTreeWidget *commandTreeWidget, + QTreeWidgetItem *separatorItem) { edit->setPlaceholderText(tr("Type to search...")); auto completer = new CommandCompleter(edit, edit); QObject::connect(completer, &CommandCompleter::commandActivated, - [combo, commandTreeWidget](const QByteArray &name) { + [=](const QByteArray &name) { CommandManager & cCmdMgr = Application::Instance->commandManager(); Command *cmd = cCmdMgr.getCommandByName(name.constData()); if (!cmd) @@ -128,8 +131,9 @@ void DlgCustomKeyboardImp::initCommandCompleter(QLineEdit *edit, QComboBox *comb if (index < 0) return; if (index != combo->currentIndex()) { + QSignalBlocker blocker(combo); combo->setCurrentIndex(index); - combo->activated(index); + populateCommandList(commandTreeWidget, separatorItem, combo); } for (int i=0 ; itopLevelItemCount(); ++i) { QTreeWidgetItem *item = commandTreeWidget->topLevelItem(i); @@ -207,10 +211,10 @@ DlgCustomKeyboardImp::initCommandList(QTreeWidget *commandTreeWidget, }); QObject::connect(ShortcutManager::instance(), &ShortcutManager::shortcutChanged, - [timer]() { timer->start(100); }); + timer, [timer]() { timer->start(100); }); QObject::connect(combo, QOverload::of(&QComboBox::activated), - [timer]() { timer->start(100); }); + timer, [timer]() { timer->start(100); }); return Application::Instance->commandManager().signalChanged.connect([timer](){ timer->start(100); @@ -273,7 +277,7 @@ DlgCustomKeyboardImp::initCommandWidgets(QTreeWidget *commandTreeWidget, AccelLineEdit *editShortcut, AccelLineEdit *currentShortcut) { - initCommandCompleter(editCommand, comboGroups, commandTreeWidget); + initCommandCompleter(editCommand, comboGroups, commandTreeWidget, separatorItem); auto conn = initCommandList(commandTreeWidget, separatorItem, comboGroups); if (priorityList && buttonUp && buttonDown) { diff --git a/src/Gui/DlgKeyboardImp.h b/src/Gui/DlgKeyboardImp.h index a7982699e3..24b8f79fd2 100644 --- a/src/Gui/DlgKeyboardImp.h +++ b/src/Gui/DlgKeyboardImp.h @@ -90,7 +90,10 @@ protected: /** @name Internal helper function for handling command list widgets */ //@{ - static void initCommandCompleter(QLineEdit *, QComboBox *combo, QTreeWidget *treeWidget); + static void initCommandCompleter(QLineEdit *, + QComboBox *combo, + QTreeWidget *treeWidget, + QTreeWidgetItem *separatorItem); static boost::signals2::connection initCommandList(QTreeWidget *, QTreeWidgetItem *, QComboBox *combo); static void initPriorityList(QTreeWidget *, QAbstractButton *buttonUp, QAbstractButton *buttonDown); static void populateCommandGroups(QComboBox *);