I have the menu setup just fine, and it emits win.copy, win.cut, etc. actions, and I have action handlers that they invoke properly, but I’m not sure how to map these to the proper built-in actions in such a way that it works for whatever widget(s) is focused . (For example, in FF, if I highlight any text on this page, and choose “Copy” from the window’s top-level “Edit” menu, the selected text is copied to the clipboard.)
Hello, the built-in actions are on the individual widgets and are prefixed with clipboard. In your action handler, you will usually want to chain to that action. A very simple example might look like this:
You can also try to use gtk_window_get_focus to track the focus of the current window, but this may be unnecessary. Usually document-based applications will always activate on the main widget for that window.
Doesn’t work, unfortunately. I can’t see how to make gtk_widget_activate_action() work without giving it a widget, and the widget returned by gtk_window_get_focus()is the currently focused menu item button widget, not the entry (or other text) widget being edited.
To anyone reading this: the solution is a bit more complex. You have to track focus, and look for a sequence of GtkPopoverMenuBarItem/GtkModelButton (possibly also a GtkScrolledWindow, and null focus) focuses just after the focus of a textual widget, then copy/paste/whatever to it, and then refocus that text widget. But this is made difficult since there are no GTK_ type check macros exposed for GtkPopoverMenuBarItem/GtkModelButton.
Just tracking the last text widget focused would cause incorrect behavior if focuses changes in a way that should invalidate it, e.g., switching the tab of a notebook.