How to do context menus in Gtk4?

Hi!
After some trying I learned how to make a popup-menu over a widget (context-menu) in Gtk3. Now I’m trying to do the same in Gtk4, where all seems to have changed. The code below defines a GtkPopoverMenu from a GMenu and a GActionGroup for the main window. If I run the code und right klick on the label, the context menu appears as expected. But the actions from the ActionGroup are not associated with the buttons in the popup (label text is grey) and the handlers are not called. So there is something missing to really connected the actions to the buttons in the popup. My hope is that somebody knows what is missing…

function first_handler(a, v)
    println("Hello")
end

function second_handler(a, v)
    println("Hello Hello")
end

function menutest()
    win = GtkWindow("menutest")
  
    menu = GMenu()
    firstitem = GMenuItem("First", "win.first")
    push!(menu, firstitem)
    seconditem = GMenuItem("Second", "win.second")
    push!(menu, seconditem)
    popper = GtkPopoverMenu(menu, has_arrow = false, position = Gtk4.PositionType_RIGHT)

    ag = GLib.G_.SimpleActionGroup_new()
    add_action(GActionMap(ag), "win.first", first_handler)
    add_action(GActionMap(ag), "win.second", second_handler)
    Gtk4.G_.insert_action_group(win, "win", GActionGroup(ag))

    lab = GtkLabel("The label")
    push!(win, lab)
    Gtk4.G_.set_parent(popper, lab)

    g = GtkGestureClick(lab)
    g.button = 3  # accept right button
    signal_connect(g, "pressed") do controller, n_press, x, y
        popup(popper)
        return Cint(true) # event taken
    end

    show(win)
end

menutest()

It should work if you drop the “win.” from the action names in the add_action calls:

add_action(GActionMap(ag), "first", first_handler)
add_action(GActionMap(ag), "second", second_handler)

When you insert the action group with the name “win”, the actions within that group have the “win.” prefix added.

Ah, thanks very much! That did the job! Tried several variations for the action keys, but not this one … :joy: