About all my projects
Gnome::Gio::Menu

Gnome::Gio::Menu

Description

Gnome::Gio::Menu is a simple implementation of Gnome::Gio::Menu. You populate a Gnome::Gio::Menu by adding Gnome::Gio::Menu instances to it.

There are some convenience functions to allow you to directly add items (avoiding Gnome::Gio::Menu) for the common cases. To add a regular item, use .insert(). To add a section, use .insert-section(). To add a submenu, use .insert-submenu().

Uml Diagram

No caption

Class initialization

new

:native-object

Create an object using a native object from an object of the same type found elsewhere. See also Gnome::N::TopLevelSupportClass.

multi method new ( N-Object() :$native-object! )

new-menu

Creates a new Gnome::Gio::Menu.

The new menu has no items.

method new-menu ( --> Gnome::Gio::Menu \)

Methods

append

Convenience function for appending a normal menu item to the end of $menu. Combine .item-new() and .insert-item() for a more flexible alternative.

method append ( Str $label, Str $detailed-action )
  • $label; the section label, or undefined.

  • $detailed-action; the detailed action string, or undefined.

append-item

Appends $item to the end of $menu.

See .insert-item() for more information.

method append-item ( N-Object() $item )
  • $item; a Gnome::Gio::MenuItem to append.

append-section

Convenience function for appending a section menu item to the end of $menu. Combine .item-new-section() and .insert-item() for a more flexible alternative.

method append-section ( Str $label, N-Object() $section )
  • $label; the section label, or undefined.

  • $section; a Gnome::Gio::MenuModel with the items of the section.

append-submenu

Convenience function for appending a submenu menu item to the end of $menu. Combine .item-new-submenu() and .insert-item() for a more flexible alternative.

method append-submenu ( Str $label, N-Object() $submenu )
  • $label; the section label, or undefined.

  • $submenu; a Gnome::Gio::MenuModel with the items of the submenu.

freeze

Marks $menu as frozen.

After the menu is frozen, it is an error to attempt to make any changes to it. In effect this means that the Gnome::Gio::Menu API must no longer be used.

This function causes .model-is-mutable() to begin returning False, which has some positive performance implications.

method freeze ( )

insert

Convenience function for inserting a normal menu item into $menu. Combine .item-new() and .insert-item() for a more flexible alternative.

method insert ( Int() $position, Str $label, Str $detailed-action )
  • $position; the position at which to insert the item.

  • $label; the section label, or undefined.

  • $detailed-action; the detailed action string, or undefined.

insert-item

Inserts $item into $menu.

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. As such, $item itself is not really inserted, but rather, a menu item that is exactly the same as the one presently described by $item.

This means that $item is essentially useless after the insertion occurs. Any changes you make to it are ignored unless it is inserted again (at which point its updated values will be copied).

You should probably just free $item once you're done.

There are many convenience functions to take care of common cases. See .insert(), .insert-section() and .insert-submenu() as well as "prepend" and "append" variants of each of these functions.

method insert-item ( Int() $position, N-Object() $item )
  • $position; the position at which to insert the item.

  • $item; the Gnome::Gio::MenuItem to insert.

insert-section

Convenience function for inserting a section menu item into $menu. Combine .item-new-section() and .insert-item() for a more flexible alternative.

method insert-section ( Int() $position, Str $label, N-Object() $section )
  • $position; the position at which to insert the item.

  • $label; the section label, or undefined.

  • $section; a Gnome::Gio::MenuModel with the items of the section.

insert-submenu

Convenience function for inserting a submenu menu item into $menu. Combine .item-new-submenu() and .insert-item() for a more flexible alternative.

method insert-submenu ( Int() $position, Str $label, N-Object() $submenu )
  • $position; the position at which to insert the item.

  • $label; the section label, or undefined.

  • $submenu; a Gnome::Gio::MenuModel with the items of the submenu.

prepend

Convenience function for prepending a normal menu item to the start of $menu. Combine .item-new() and .insert-item() for a more flexible alternative.

method prepend ( Str $label, Str $detailed-action )
  • $label; the section label, or undefined.

  • $detailed-action; the detailed action string, or undefined.

prepend-item

Prepends $item to the start of $menu.

See .insert-item() for more information.

method prepend-item ( N-Object() $item )
  • $item; a Gnome::Gio::MenuItem to prepend.

prepend-section

Convenience function for prepending a section menu item to the start of $menu. Combine .item-new-section() and .insert-item() for a more flexible alternative.

method prepend-section ( Str $label, N-Object() $section )
  • $label; the section label, or undefined.

  • $section; a Gnome::Gio::MenuModel with the items of the section.

prepend-submenu

Convenience function for prepending a submenu menu item to the start of $menu. Combine .item-new-submenu() and .insert-item() for a more flexible alternative.

method prepend-submenu ( Str $label, N-Object() $submenu )
  • $label; the section label, or undefined.

  • $submenu; a Gnome::Gio::MenuModel with the items of the submenu.

remove

Removes an item from the menu. $position gives the index of the item to remove.

It is an error if position is not in range the range from 0 to one less than the number of items in the menu.

It is not possible to remove items by identity since items are added to the menu simply by copying their links and attributes (ie: identity of the item itself is not preserved).

method remove ( Int() $position )
  • $position; the position of the item to remove.

remove-all

Removes all items in the menu.

method remove-all ( )