On 02/01/2017 05:49 PM, dlang user wrote:

I am trying to add new MenuItems to the context menu of a SourceView. So I hooked into the addOnPopulatePopup callback which looks like this:

   SourceView sourceView = new SourceView();

private void onTextViewPopulatePopup(Widget w, TextView v)
   Menu m = new Menu(cast(GtkMenu*)w.getWidgetStruct());
   m.append(new MenuItem("Test", &onTestMenuItem, "Test"));

The issue that I am having is that the Menu is being sent as Widget, first I tried casting the Widget w to a Menu, but that didn't work.

The way I was able to get it to work was to cast the GtkWidget* to a GTKMenu*.

Is this a bug, or the correct way to do it?

At some point we should try and make the cast work, but for now the
workaround you found will do the trick.