diff --git a/src/Gui/DlgMacroExecuteImp.cpp b/src/Gui/DlgMacroExecuteImp.cpp index b361c20b41..1abe1feb82 100644 --- a/src/Gui/DlgMacroExecuteImp.cpp +++ b/src/Gui/DlgMacroExecuteImp.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #endif #include @@ -45,6 +46,8 @@ #include "Macro.h" #include "MainWindow.h" #include "PythonEditor.h" +#include "Workbench.h" +#include "WorkbenchManager.h" using namespace Gui; @@ -757,7 +760,7 @@ Note: your changes will be applied when you next switch workbenches\n")); **/ QString instructions2 = - tr("Walkthrough instructions: Click right arrow button (->), then Close."); + tr("Walkthrough instructions: Select macro from list, then click right arrow button (->), then Close."); auto workbenchBox = setupToolbarPage->findChild(QString::fromLatin1("workbenchBox")); if (!workbenchBox) { @@ -769,10 +772,7 @@ Note: your changes will be applied when you next switch workbenches\n")); int globalIdx = workbenchBox->findData(QString::fromLatin1("Global")); if (globalIdx != -1) { workbenchBox->setCurrentIndex(globalIdx); - QMetaObject::invokeMethod(setupToolbarPage, - "on_workbenchBox_activated", - Qt::DirectConnection, - Q_ARG(int, globalIdx)); + setupToolbarPage->activateWorkbenchBox(globalIdx); } else { Base::Console().Warning("Toolbar walkthrough: Unable to find Global workbench\n"); @@ -786,7 +786,7 @@ Note: your changes will be applied when you next switch workbenches\n")); } else { newButton->setStyleSheet(QString::fromLatin1("color:red")); - instructions2 = tr("Walkthrough instructions: Click New, then right arrow (->) " + instructions2 = tr("Walkthrough instructions: Click New, select macro, then right arrow (->) " "button, then Close."); } } @@ -812,10 +812,6 @@ Note: your changes will be applied when you next switch workbenches\n")); int macrosIdx = categoryBox->findText(tr("Macros")); if (macrosIdx != -1) { categoryBox->setCurrentIndex(macrosIdx); - QMetaObject::invokeMethod(setupToolbarPage, - "on_categoryBox_activated", - Qt::DirectConnection, - Q_ARG(int, macrosIdx)); } else { Base::Console().Warning("Toolbar walkthrough: Unable to find Macros in categoryBox\n"); @@ -832,31 +828,39 @@ Note: your changes will be applied when you next switch workbenches\n")); toolbarTreeWidget->expandAll(); } - /** preselect macro command for user **/ - - auto commandTreeWidget = - setupToolbarPage->findChild(QString::fromLatin1("commandTreeWidget")); - if (!commandTreeWidget) { - Base::Console().Warning("Toolbar walkthrough: Unable to find commandTreeWidget\n"); - } - else { - if (!hasMacroCommand) { // will be the last in the list, the one just created - commandTreeWidget->setCurrentItem( - commandTreeWidget->topLevelItem(commandTreeWidget->topLevelItemCount() - 1)); - commandTreeWidget->scrollToItem(commandTreeWidget->currentItem()); + /** preselect macro command for user after a short delay to allow time for the + tree widget to populate all the actions + **/ + QTimer::singleShot(500, [=]() { + auto commandTreeWidget = + setupToolbarPage->findChild(QString::fromLatin1("commandTreeWidget")); + if (!commandTreeWidget) { + Base::Console().Warning("Toolbar walkthrough: Unable to find commandTreeWidget\n"); } - else { // pre-select it for the user (will be the macro menu text) - QList items = - commandTreeWidget->findItems(macroMenuText, - Qt::MatchFixedString | Qt::MatchWrap, - 1); - if (!items.empty()) { - commandTreeWidget->setCurrentItem(items[0]); + else { + if (!hasMacroCommand) { // will be the last in the list, the one just created + commandTreeWidget->setCurrentItem( + commandTreeWidget->topLevelItem(commandTreeWidget->topLevelItemCount() - 1)); commandTreeWidget->scrollToItem(commandTreeWidget->currentItem()); } + else { // pre-select it for the user (will be the macro menu text) + QList items = + commandTreeWidget->findItems(macroMenuText, + Qt::MatchFixedString | Qt::MatchWrap, + 1); + if (!items.empty()) { + commandTreeWidget->setCurrentItem(items[0]); + commandTreeWidget->scrollToItem(commandTreeWidget->currentItem()); + } + } } - } + }); dlg.exec(); + // refresh toolbar so new icon shows up immediately + Workbench* active = Gui::WorkbenchManager::instance()->active(); + if (active) { + active->activate(); + } } diff --git a/src/Gui/DlgToolbarsImp.cpp b/src/Gui/DlgToolbarsImp.cpp index 36d6e4a25d..b317d4c9e8 100644 --- a/src/Gui/DlgToolbarsImp.cpp +++ b/src/Gui/DlgToolbarsImp.cpp @@ -172,6 +172,11 @@ void DlgCustomToolbars::hideEvent(QHideEvent* event) void DlgCustomToolbars::onActivateCategoryBox() {} +// called from DlgMacroExecuteImp toolbar walkthrough function +void DlgCustomToolbars::activateWorkbenchBox(int index) { + onWorkbenchBoxActivated(index); +} + void DlgCustomToolbars::onWorkbenchBoxActivated(int index) { QVariant data = ui->workbenchBox->itemData(index, Qt::UserRole); diff --git a/src/Gui/DlgToolbarsImp.h b/src/Gui/DlgToolbarsImp.h index 10f05a51b9..5b5cfa430f 100644 --- a/src/Gui/DlgToolbarsImp.h +++ b/src/Gui/DlgToolbarsImp.h @@ -52,6 +52,9 @@ protected: explicit DlgCustomToolbars(Type, QWidget* parent = nullptr); ~DlgCustomToolbars() override; +public: + void activateWorkbenchBox(int index); // Public accessor for DlgMacroExecuteImp + protected: void setupConnections(); void onWorkbenchBoxActivated(int index);