I am using the following to show a context menu when the “Menu” key is pressed when navigating a ColumnView with the keyboard
if key_val == Key::Menu && modifier == ModifierType::empty() {
if let Some(airport) = view.get_selection() {
// get rectangle of the selection
// let rect = self.airport_list.........................<<magic required here>>
if let Some(popover) = view.popover.borrow().as_ref() {
popover.set_pointing_to(None::<&Rectangle>);
popover.popup();
}
}
}
But I need help to find the right incantation to locate the popup menu adjacent to the selected item. Gnome Files shows the desired behaviour, but I have not been able to work out how it does it.
If you can get the widget, then use gtk_widget_compute_bounds(row, view) to get a graphene rectangle. Then manually assign the values inside the graphene rect to a GdkRectangle. Also make sure to set the parent of the popover to the view.
Thanks @kabushawarib, I understand getting the bounds of the widget, but what I was unable to find was how to locate the actual row widget when using a ColumnView.
Now following your clue and searching the nautilus code, I see it stores a pointer to the widget in each item in the model. Messy and need to add a chunk of cleanup code, but I suppose I can try and follow that pattern.