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.
This commit is contained in:
Arun Raghavan 2024-09-27 07:46:22 -04:00
parent 72055b484a
commit b4af9ef7fa

View file

@ -73,19 +73,25 @@ void CardWidget::prepareMenu() {
profileListStore->clear(); profileListStore->clear();
active_idx = -1; active_idx = -1;
/* Fill the ComboBox's Tree Model */ /* 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]) if (hideUnavailableProfiles && !availableProfiles[profiles[i].first])
continue; continue;
Gtk::TreeModel::Row row = *(profileListStore->append()); Gtk::TreeModel::Row row = *(profileListStore->append());
row[profileModel.name] = profiles[i].first; row[profileModel.name] = profiles[i].first;
row[profileModel.desc] = profiles[i].second; row[profileModel.desc] = profiles[i].second;
if (profiles[i].first == activeProfile) 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); profileList->set_active(active_idx);
codecListStore->clear(); codecListStore->clear();