GtkApplicationWindow with dynamic menu labels

Hi,

I was wondering how to dynamically change menu labels of a GtkApplicationWindow dynamically… In my case I have Undo and Redo menu items that I can enable/disable with g_simple_action_set_enabled, depending on the status of the undo stack, but I have no clue on how to change the label with a message that reflects what would be the action if the Undo/Redo item would be clicked (like e.g. Undo typing).

Any thoughts?

Thanks!

Tom

Depending on the language you’re using, you might consider either an object or a struct that ‘captures’ each “do” event. (You would have to decide how granular you wanna get). It could then contain:

  • something descriptive to add into the menu,
  • whatever it took to ‘do’ what was done (which could also serve as ‘redo’ code), and
  • whatever it would take to undo.

Then push/pull those structs/objects on/off the stack.

I implemented something like this in PHP years ago and it worked great.

You cannot modify menu items after adding them to a GMenu. The only way to change a label is to use g_menu_remove() and g_menu_insert(). If you have undo and redo in their own section, you can keep a reference to the section GMenu and use g_menu_remove_all() so you don’t need to specify the item positions. (This is less helpful if you are creating the menu via XML.)

That is interesting and a bit surprising for me, as we have

[EDIT]

OK, from

we have

The “insertion” is actually done by copying all of the attribute and link values of item and using them to form a new item within menu .

So modifying can not work indeed.

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