Gtk-rs menu and action quesions

I'm working on a gemini browser widget which is subclassed from a gtk4::TextView. When I add a link to the widget during rendering of a page, I want the context menu to have the additional items "Open link in new tab" and "Open link in new window". I've got those two entries added now, by creating the menu and menu items, but without any actions being associated with the menu items.

What I think I want to happen, is for selecting either of those menu items to emit a custom signal with the url in String form attached, so that the program itself can then handle to signal in the way it sees fit. This widget subclass is being implemented as a separate crate because I want it to be reusable, so I'm trying to wrap my head around how to go about creating the action, because every time I've used SimpleAction I've had to add that action to the window via gtk4::Window::add_action, but being split off into a separate crate the widget doesn't have any reference to it's top level window.

Anyway, not sure where to go with this at the moment. I have the following two ideas:

  • Get a handle on the window by calling gtk4::Widget::root() inside this crate - but this returns None until the window has been shown, which means I can't initialize my viewer widget until the window is already shown, and in my proof of concept browser that doesn't happen for the first tab
  • Create the action in this crate, and make it pub, then call add_action on the window.

Any insight is appreciated.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.