From 9891a68f443fd2021876cd7e34ea2710ef742825 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Thu, 20 Jul 2023 14:22:42 -0700 Subject: [PATCH] GncGtkListUIItem::set_option_from_ui_item: Iterate over selected items Instead of all possible items. --- gnucash/gnome-utils/gnc-option-gtk-ui.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/gnucash/gnome-utils/gnc-option-gtk-ui.cpp b/gnucash/gnome-utils/gnc-option-gtk-ui.cpp index 086faf2b4a..747d646051 100644 --- a/gnucash/gnome-utils/gnc-option-gtk-ui.cpp +++ b/gnucash/gnome-utils/gnc-option-gtk-ui.cpp @@ -1168,20 +1168,20 @@ public: } g_signal_handlers_unblock_by_func(selection, (gpointer)list_changed_cb, &option); } + void set_option_from_ui_item(GncOption& option) noexcept override { auto widget{GTK_TREE_VIEW(get_widget())}; auto selection{gtk_tree_view_get_selection(widget)}; - auto rows{option.num_permissible_values()}; + auto selected_rows{gtk_tree_selection_get_selected_rows(selection, nullptr)}; GncMultichoiceOptionIndexVec vec; - for (size_t row = 0; row < rows; ++row) + for (auto row = selected_rows; row; row = g_list_next(row)) { - auto path{gtk_tree_path_new_from_indices(row, -1)}; - auto selected{gtk_tree_selection_path_is_selected(selection, path)}; - gtk_tree_path_free(path); - if (selected) - vec.push_back(row); + auto path{static_cast(row->data)}; + auto indices{gtk_tree_path_get_indices(path)}; + vec.push_back(*indices); } + g_list_free_full(selected_rows, (GDestroyNotify)gtk_tree_path_free); option.set_value(vec); } };