GtkPopoverMenu – New widget for complex popovers

So, continuing my work on porting nautilus to gaction and gmenu, we found some problems that gtk+ could manage better.

For instance, creating menus with GMenu is very convenient only if your menu doesn’t have complex widgets like a GtkScale or if you want to really control how everything is displayed or you need to hide/show menu items on the fly.

That was the case of nautilus, which needs GtkScale and hide/show menu items on the fly.

So far I achieved a way to hide/show GMenu items on the fly, but it feels like a hack, so it was not very convenient.

After some discussion, Mathias Clasen created a new way to do complex popovers or menus, which is just a GtkWidget, so you are free for completely put and manage whatever you want in there, but with the advantatges of associating buttons to actions, so the button becomes a radio action, a simple item, or whatever based on the associated action.

Now we have a GtkPopoverMenu widget, which is the widget you have to use for associating directly to a button with gtk_menu_button_set_popover() and then, you have GtkModelButton which acts as a generic button which defines it’s looks based on the action associated and you can use it inside a GtkPopoverMenu. So for example, if you have a stateless action associated to a GtkModelButton, it becomes a single menu item, it the action is stateful and has no target, it becomes a check button, and finally if the action is stateful and has a target, it becomes a radio button.

Finally you can have iconic buttons, that is, buttons that looks like buttons 😉 with <property name=”iconic”>True</property> .

Other widgets can’t have actions associated, like GtkScale, at least for now. But since you can put it in the widget, is not a big deal, and you connect to the change signal of the widget and then in the handler trigger the action you want, and then is like you associated an action to that widget.

So far so good, I ported nautilus to this, and it looks promising!

So, my advice is:

Use GMenu always you can.

If you need buttons, that although they are supported in GMenu, you can’t manage its visuals; special widgets, or add/hide items on the fly; then, use GtkPopoverMenu and GtkModelButtons.

Not sure how this split is good or not, maybe we should find a common way to do things so new people are not confused about that. But for now, it’s a very nice solution.

Thanks Mathias for the work and the effort he put to find a solution for this.