Import Matcher - select row if none is selected yet when right-clicking the list of matches

This commit is contained in:
Geert Janssens 2024-05-16 12:48:30 +02:00
parent f7f42bf6fb
commit 31095c1205

View File

@ -1462,15 +1462,27 @@ gnc_gen_trans_onButtonPressed_cb (GtkTreeView *treeview,
GdkEventButton *event_button = (GdkEventButton *) event; GdkEventButton *event_button = (GdkEventButton *) event;
if (event_button->button == GDK_BUTTON_SECONDARY) if (event_button->button == GDK_BUTTON_SECONDARY)
{ {
DEBUG("Right mouseClick detected- popup the menu."); DEBUG("Right mouseClick detected - popup the menu.");
// Only pop up the menu if there's more than 1 selected transaction,
// or the selected transaction is an ADD. auto selection = gtk_tree_view_get_selection (treeview);
GtkTreeSelection *selection = gtk_tree_view_get_selection (treeview); auto selected_rows = gtk_tree_selection_count_selected_rows (selection);
/* If no rows are selected yet, select the row that was clicked on
* before proceeding */
if (!selected_rows)
{
GtkTreePath* path = nullptr;
if (gtk_tree_view_get_path_at_pos (treeview, event_button->x,
event_button->y, &path, nullptr, nullptr, nullptr))
{
gtk_tree_selection_select_path (selection, path);
selected_rows++;
gtk_tree_path_free (path);
}
}
if (gtk_tree_selection_count_selected_rows (selection) > 0) if (gtk_tree_selection_count_selected_rows (selection) > 0)
{ {
GList* selected;
GtkTreeModel *model; GtkTreeModel *model;
selected = gtk_tree_selection_get_selected_rows (selection, &model); auto selected = gtk_tree_selection_get_selected_rows (selection, &model);
if (get_action_for_path (static_cast<GtkTreePath*>(selected->data), model) == GNCImport_ADD) if (get_action_for_path (static_cast<GtkTreePath*>(selected->data), model) == GNCImport_ADD)
gnc_gen_trans_view_popup_menu (treeview, event, info); gnc_gen_trans_view_popup_menu (treeview, event, info);
g_list_free_full (selected, (GDestroyNotify)gtk_tree_path_free); g_list_free_full (selected, (GDestroyNotify)gtk_tree_path_free);