summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorArun Raghavan <arun@asymptotic.io>2024-09-27 07:46:22 -0400
committerArun Raghavan <arun@asymptotic.io>2024-09-27 07:46:22 -0400
commitb4af9ef7fa272bd2f174bf21ba6c49eafe89e226 (patch)
tree2393aa96067aad9c7a8454715e6c32ba9153e330 /src
parent72055b484a8a7e94a0d75afd7ed6154fefee2c76 (diff)
Correctly handle profile list indices in dropdownHEADmaster
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.
Diffstat (limited to 'src')
-rw-r--r--src/cardwidget.cc12
1 files 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();