GncGtkListUIItem::set_option_from_ui_item: Iterate over selected items

Instead of all possible items.
This commit is contained in:
John Ralls
2023-07-20 14:22:42 -07:00
parent 84eb084375
commit 9891a68f44

View File

@@ -1168,20 +1168,20 @@ public:
} }
g_signal_handlers_unblock_by_func(selection, (gpointer)list_changed_cb, &option); g_signal_handlers_unblock_by_func(selection, (gpointer)list_changed_cb, &option);
} }
void set_option_from_ui_item(GncOption& option) noexcept override void set_option_from_ui_item(GncOption& option) noexcept override
{ {
auto widget{GTK_TREE_VIEW(get_widget())}; auto widget{GTK_TREE_VIEW(get_widget())};
auto selection{gtk_tree_view_get_selection(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; 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 path{static_cast<GtkTreePath*>(row->data)};
auto selected{gtk_tree_selection_path_is_selected(selection, path)}; auto indices{gtk_tree_path_get_indices(path)};
gtk_tree_path_free(path); vec.push_back(*indices);
if (selected)
vec.push_back(row);
} }
g_list_free_full(selected_rows, (GDestroyNotify)gtk_tree_path_free);
option.set_value(vec); option.set_value(vec);
} }
}; };