From 13e2f93baec120a14dc24a6a3832424250d446a0 Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Sun, 3 Jan 2021 16:01:08 -0600 Subject: [PATCH] Fix bug due to early return Github user @marioalexis84 found a bug that caused only the first page of the most recently-added workbench to show. This refactors the AddPage() static function to eliminate the early return statement that was the cause of that bug. --- src/Gui/DlgPreferencesImp.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Gui/DlgPreferencesImp.cpp b/src/Gui/DlgPreferencesImp.cpp index d0be413089..d5d327090c 100644 --- a/src/Gui/DlgPreferencesImp.cpp +++ b/src/Gui/DlgPreferencesImp.cpp @@ -183,18 +183,27 @@ void DlgPreferencesImp::changeGroup(QListWidgetItem *current, QListWidgetItem *p */ void DlgPreferencesImp::addPage(const std::string& className, const std::string& group) { + std::list::iterator groupToAddTo = _pages.end(); for (std::list::iterator it = _pages.begin(); it != _pages.end(); ++it) { if (it->first == group) { - it->second.push_back(className); - return; + groupToAddTo = it; + break; } } - std::list pages; - pages.push_back(className); - _pages.push_back(std::make_pair(group, pages)); + if (groupToAddTo != _pages.end()) { + // The group exists: add this page to the end of the list + groupToAddTo->second.push_back(className); + } + else { + // This is a new group: create it, with its one page + std::list pages; + pages.push_back(className); + _pages.push_back(std::make_pair(group, pages)); + } if (DlgPreferencesImp::_activeDialog != nullptr) { + // If the dialog is currently showing, tell it to insert the new page _activeDialog->reloadPages(); } }