From 31095c1205f769dd6dccaf4bb8f60ab14e56fe7c Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Thu, 16 May 2024 12:48:30 +0200 Subject: [PATCH] Import Matcher - select row if none is selected yet when right-clicking the list of matches --- gnucash/import-export/import-main-matcher.cpp | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/gnucash/import-export/import-main-matcher.cpp b/gnucash/import-export/import-main-matcher.cpp index bcbb1d74695..84f795bbde1 100644 --- a/gnucash/import-export/import-main-matcher.cpp +++ b/gnucash/import-export/import-main-matcher.cpp @@ -1462,15 +1462,27 @@ gnc_gen_trans_onButtonPressed_cb (GtkTreeView *treeview, GdkEventButton *event_button = (GdkEventButton *) event; if (event_button->button == GDK_BUTTON_SECONDARY) { - 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. - GtkTreeSelection *selection = gtk_tree_view_get_selection (treeview); + DEBUG("Right mouseClick detected - popup the menu."); + + auto 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) { - GList* selected; 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(selected->data), model) == GNCImport_ADD) gnc_gen_trans_view_popup_menu (treeview, event, info); g_list_free_full (selected, (GDestroyNotify)gtk_tree_path_free);