How to get bounding rectangle of selected row in a ColumnView

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.

Adapted from: src/nautilus-files-view.c · 74a3296359cfc766e5898dcda632cbbe98e38a5f · GNOME / Files · GitLab

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.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.