Shortcuts and menu accelators

hi
i’m somehow struggling with gtkmm-4.0 about shortcuts and menu accellators. I would welcome any link to read forward or piece of example if possible. i have menu that is dinamically created for that i created sub object for menues. In some part i have subitems call same action but with different additional parameter value. now i would like for each menu-item to create shortcut and to show on menu the accellarator that user specifies. further is term shortcut app or win based and accellator menu based?
in eclipse i most of the time don’t get methods for object for autocomplition so its bit difficult and slow to do research. even if i create shortcut to be visible in menu i would be happy.
i use

Glib::Variant<std::string> val = Glib::Variant<std::string>(g_variant_new_string(additional.c_str()));
menuItem->item->set_action_and_target(action,val)

menu

Hi,

I don’t know about C++, here is what I do in Python.

First, create an action that allows a state (here "s" means “string”):

action = Gio.SimpleAction.new('myaction', GLib.VariantType("s"))
action.connect('activate', on_action)
window.add_action(action)

Here I attached it to an ApplicationWindow, but you can create your own Gio.SimpleActionGroup instead if needed.

Then, when building the menu, give the full detailed name of the action, including the parameter value:

menu.append(_("Apples"), 'win.myaction::apples')
menu.append(_("Oranges"), 'win.myaction::oranges')

For passing a string, use group.action::string (I think group.action('string') may work too).
For passing integers, use group.action(123)

And make sure the keyboard accel matches too:

application.set_accels_for_action('win.myaction::apples', ['F3'])
1 Like

i will try thank you