On Thu, 23 May 2019 14:59:17 GMT, Ron Tarrant wrote:

On Thu, 23 May 2019 10:55:02 GMT, Alex X wrote:

On Wed, 22 May 2019 22:24:25 GMT, Alex X wrote:

Is there a way to get the menuitems from a menu. I really just need the id's of all the menuitems attached/appended. (it's loaded from a glade file so I don't have them directly)

Are you talking about the CSS ID's or just some way to identify which MenuItem has been selected by the user?

In Glade one can set the ID of a widget and then use that ID to reference the widgets in code. I've created the menu and items in glade and so the only way to really access them is by knowing the ID.

Also, How can I compare widgets in a menu to find out which menuitem was used in one handler?


The signal you want to connect is onActivate using the addOnActivate() function.

I've never used Glade, but perhaps some of the articles on my blog will help. The stuff on Menus starts here.

I looked at them but that is code and not applicable. I don't have to build a menu in code since I have it in glade. It makes it easier to maintain. I did initially look at that code to figure out how to do it because the glade code wasn't working... but I eventually figured out I had to use show and popup calls to show the items and the popup(I was going doing on and wasn't getting anything useful).

The activate does work but strangely though it does not seem to work as expected. The menuitem passed is related to the menuitem in glade. That is

if (mi is x)

fails where x is the menuitem created in glade. So ultimately it does the same as addOnButtonPress for my code at this point.

I imagine the mi is correct but the comparison is wrong.

I just found that getName gets the widget type(GtkMenuItem in this case) and getLabel will get the label text which I can use too check.

I just found this too:
"Objects may be given a name with the “id” attribute, which allows the application to retrieve them from the builder with gtkbuildergetobject(). An id is also necessary to use the object as property value in other parts of the UI definition. GTK+ reserves ids starting and ending with __ (3 underscores) for its own purposes."

So it seems that id's are not propagated in to gtkD...

It also seems the getName defaults to the object type if the name is not filled out in Glade(I don't use name's but ID's)...

So I have the option to use getName or getLabel to do what I want...

it would be easier to be able to compare the objects though.

I have a menuitem x that I get from the builder and I add the onActivate but x is not mi as stated above... The ideal solution would be to be able to compare them...

It seems that both are wrappers around the menu item... but I can't do something like

if (mi.gtkMenuItem is x.gtkMenuItem)

because gtkMenuItem(which is the same in both) is private making, unless there is another way, impossible to compare.