Avoid warnings on right click in GTK wxDataViewCtrl while editing

The code handling right button click used the path of the item under
mouse without checking if there was any item, resulting in GTK+ warnings
due to the use of an invalid item.

Simply add a check for the item validity: we definitely don't want to
select it if it's invalid anyhow.
This commit is contained in:
Vadim Zeitlin 2018-12-06 22:55:42 +01:00
parent da612f02b5
commit dc1aa3097c

View File

@ -4591,12 +4591,15 @@ gtk_dataview_button_press_callback( GtkWidget *WXUNUSED(widget),
// If the right click is on an item that isn't selected, select it, as is // If the right click is on an item that isn't selected, select it, as is
// commonly done. Do not do it if the item under mouse is already selected, // commonly done. Do not do it if the item under mouse is already selected,
// because it could be a part of multi-item selection. // because it could be a part of multi-item selection.
if ( path )
{
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dv->GtkGetTreeView())); GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dv->GtkGetTreeView()));
if ( !gtk_tree_selection_path_is_selected(selection, path) ) if ( !gtk_tree_selection_path_is_selected(selection, path) )
{ {
gtk_tree_selection_unselect_all(selection); gtk_tree_selection_unselect_all(selection);
gtk_tree_selection_select_path(selection, path); gtk_tree_selection_select_path(selection, path);
} }
}
wxDataViewEvent wxDataViewEvent
event(wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, dv, dv->GTKPathToItem(path)); event(wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, dv, dv->GTKPathToItem(path));