From b4af9ef7fa272bd2f174bf21ba6c49eafe89e226 Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Fri, 27 Sep 2024 07:46:22 -0400 Subject: Correctly handle profile list indices in dropdown With the option to hide some profiles, we need to track the list store index separately from the profile list iterator, so that the active selection in the dropdown is correct. We also need to allow an invalid selection, as an unavailable profile might be selected. --- src/cardwidget.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/cardwidget.cc b/src/cardwidget.cc index 7deba33..6f6ed76 100644 --- a/src/cardwidget.cc +++ b/src/cardwidget.cc @@ -73,19 +73,25 @@ void CardWidget::prepareMenu() { profileListStore->clear(); active_idx = -1; + /* Fill the ComboBox's Tree Model */ - for (uint32_t i = 0; i < profiles.size(); ++i) { + for (uint32_t i = 0, idx = 0; i < profiles.size(); ++i) { if (hideUnavailableProfiles && !availableProfiles[profiles[i].first]) continue; Gtk::TreeModel::Row row = *(profileListStore->append()); row[profileModel.name] = profiles[i].first; row[profileModel.desc] = profiles[i].second; + if (profiles[i].first == activeProfile) - active_idx = i; + active_idx = idx; + + /* Track the index in the list store, as we might have few entries than + * all the profiles if unavailable profiles are hidden. */ + idx++; } - if (active_idx >= 0) + if (profiles.size()) profileList->set_active(active_idx); codecListStore->clear(); -- cgit v1.2.3