About all my projects
Gnome::Gio::MenuItem

Gnome::Gio::MenuItem

Description

Gnome::Gio::MenuItem is an opaque structure type. You must access it using the functions below.

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-menuitem

Creates a new Gnome::Gio::MenuItem.

If $label is non-undefined it is used to set the "label" attribute of the new item.

If $detailed-action is non-undefined it is used to set the "action" and possibly the "target" attribute of the new item. See .set-detailed-action() for more information.

method new-menuitem ( Str $label, Str $detailed-action --> Gnome::Gio::MenuItem \)
  • $label; the section label, or undefined.

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

new-from-model

Creates a Gnome::Gio::MenuItem as an exact copy of an existing menu item in a Gnome::Gio::MenuModel. $item-index must be valid (ie: be sure to call g_menu_model_get_n_items() first).

method new-from-model ( N-Object() $model, Int() $item-index --> Gnome::Gio::MenuItem \)
  • $model; a Gnome::Gio::MenuModel.

  • $item-index; the index of an item in $model.

new-section

Creates a new Gnome::Gio::MenuItem representing a section.

This is a convenience API around .new-menuitem() and .set-section().

The effect of having one menu appear as a section of another is exactly as it sounds: the items from $section become a direct part of the menu that $menu-item is added to.

Visual separation is typically displayed between two non-empty sections. If $label is non-undefined then it will be encorporated into this visual indication. This allows for labeled subsections of a menu.

As a simple example, consider a typical "Edit" menu from a simple program. It probably contains an "Undo" and "Redo" item, followed by a separator, followed by "Cut", "Copy" and "Paste".

This would be accomplished by creating three Gnome::Gio::Menu instances. The first would be populated with the "Undo" and "Redo" items, and the second with the "Cut", "Copy" and "Paste" items. The first and second menus would then be added as submenus of the third. In XML format, this would look something like the following:

The following example is exactly equivalent. It is more illustrative of the exact relationship between the menus and items (keeping in mind that the 'link' element defines a new menu that is linked to the containing one). The style of the second example is more verbose and difficult to read (and therefore not recommended except for the purpose of understanding what is really going on).

method new-section ( Str $label, N-Object() $section --> Gnome::Gio::MenuItem \)
  • $label; the section label, or undefined.

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

new-submenu

Creates a new Gnome::Gio::MenuItem representing a submenu.

This is a convenience API around .new-menuitem() and .set-submenu().

method new-submenu ( Str $label, N-Object() $submenu --> Gnome::Gio::MenuItem \)
  • $label; the section label, or undefined.

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

Methods

get-attribute This function is not yet available

Queries the named $attribute on $menu-item.

If the attribute exists and matches the Gnome::Glib::N-VariantType corresponding to $format-string then $format-string is used to deconstruct the value into the positional parameters and True is returned.

If the attribute does not exist, or it does exist but has the wrong type, then the positional parameters are ignored and False is returned.

method get-attribute ( Str $attribute, Str $format-string, … --> Bool )
  • $attribute; the attribute name to query.

  • $format-string; a Gnome::Glib::N-Variant format string.

  • …; …. Note that each argument must be specified as a type followed by its value!

Return value; True if the named attribute was found with the expected type.

get-attribute-value

Queries the named $attribute on $menu-item.

If $expected-type is specified and the attribute does not have this type, undefined is returned. undefined is also returned if the attribute simply does not exist.

method get-attribute-value ( Str $attribute, N-Object $expected-type --> N-Object )
  • $attribute; the attribute name to query.

  • $expected-type; the expected type of the attribute

Return value; the attribute value, or undefined.

Queries the named $link on $menu-item.

method get-link ( Str $link --> N-Object )
  • $link; the link name to query.

Return value; the link, or undefined.

set-action-and-target This function is not yet available

Sets or unsets the "action" and "target" attributes of $menu-item.

If $action is undefined then both the "action" and "target" attributes are unset (and $format-string is ignored along with the positional parameters).

If $action is non-undefined then the "action" attribute is set. $format-string is then inspected. If it is non-undefined then the proper position parameters are collected to create a Gnome::Glib::N-Variant instance to use as the target value. If it is undefined then the positional parameters are ignored and the "target" attribute is unset.

See also .set-action-and-target-value() for an equivalent call that directly accepts a Gnome::Glib::N-Variant. See .set-detailed-action() for a more convenient version that works with string-typed targets.

See also .set-action-and-target-value() for a description of the semantics of the action and target attributes.

method set-action-and-target ( Str $action, Str $format-string, … )
  • $action; the name of the action for this item.

  • $format-string; a GVariant format string.

  • …; …. Note that each argument must be specified as a type followed by its value!

set-action-and-target-value

Sets or unsets the "action" and "target" attributes of $menu-item.

If $action is undefined then both the "action" and "target" attributes are unset (and $target-value is ignored).

If $action is non-undefined then the "action" attribute is set. The "target" attribute is then set to the value of $target-value if it is non-undefined or unset otherwise.

Normal menu items (ie: not submenu, section or other custom item types) are expected to have the "action" attribute set to identify the action that they are associated with. The state type of the action help to determine the disposition of the menu item. See Gnome::Gio::R-Action and Gnome::Gio::R-ActionGroup for an overview of actions.

In general, clicking on the menu item will result in activation of the named action with the "target" attribute given as the parameter to the action invocation. If the "target" attribute is not set then the action is invoked with no parameter.

If the action has no state then the menu item is usually drawn as a plain menu item (ie: with no additional decoration).

If the action has a boolean state then the menu item is usually drawn as a toggle menu item (ie: with a checkmark or equivalent indication). The item should be marked as 'toggled' or 'checked' when the boolean state is True.

If the action has a string state then the menu item is usually drawn as a radio menu item (ie: with a radio bullet or equivalent indication). The item should be marked as 'selected' when the string state is equal to the value of the $target property.

See .set-action-and-target() or .set-detailed-action() for two equivalent calls that are probably more convenient for most uses.

method set-action-and-target-value ( Str $action, N-Object $target-value )
  • $action; the name of the action for this item.

  • $target-value; a Gnome::Glib::N-Variant to use as the action target

set-attribute This function is not yet available

Sets or unsets an attribute on $menu-item.

The attribute to set or unset is specified by $attribute. This can be one of the standard attribute names G_MENU_ATTRIBUTE_LABEL, G_MENU_ATTRIBUTE_ACTION, G_MENU_ATTRIBUTE_TARGET, or a custom attribute name. Attribute names are restricted to lowercase characters, numbers and '-'. Furthermore, the names must begin with a lowercase character, must not end with a '-', and must not contain consecutive dashes.

If $format-string is non-undefined then the proper position parameters are collected to create a Gnome::Glib::N-Variant instance to use as the attribute value. If it is undefined then the positional parameterrs are ignored and the named attribute is unset.

See also .set-attribute-value() for an equivalent call that directly accepts a Gnome::Glib::N-Variant.

method set-attribute ( Str $attribute, Str $format-string, … )
  • $attribute; the attribute to set.

  • $format-string; a Gnome::Glib::N-Variant format string, or undefined.

  • …; …. Note that each argument must be specified as a type followed by its value!

set-attribute-value

Sets or unsets an attribute on $menu-item.

The attribute to set or unset is specified by $attribute. This can be one of the standard attribute names G_MENU_ATTRIBUTE_LABEL, G_MENU_ATTRIBUTE_ACTION, G_MENU_ATTRIBUTE_TARGET, or a custom attribute name. Attribute names are restricted to lowercase characters, numbers and '-'. Furthermore, the names must begin with a lowercase character, must not end with a '-', and must not contain consecutive dashes.

must consist only of lowercase ASCII characters, digits and '-'.

If $value is non-undefined then it is used as the new value for the attribute. If $value is undefined then the attribute is unset. If the $value Gnome::Glib::N-Variant is floating, it is consumed.

See also .set-attribute() for a more convenient way to do the same.

method set-attribute-value ( Str $attribute, N-Object $value )
  • $attribute; the attribute to set.

  • $value; a Gnome::Glib::N-Variant to use as the value, or undefined

set-detailed-action

Sets the "action" and possibly the "target" attribute of $menu-item.

The format of $detailed-action is the same format parsed by g_action_parse_detailed_name().

See .set-action-and-target() or .set-action-and-target-value() for more flexible (but slightly less convenient) alternatives.

See also .set-action-and-target-value() for a description of the semantics of the action and target attributes.

method set-detailed-action ( Str $detailed-action )
  • $detailed-action; the "detailed" action string.

set-icon

Sets (or unsets) the icon on $menu-item.

This call is the same as calling g_icon_serialize() and using the result as the value to .set-attribute-value() for G_MENU_ATTRIBUTE_ICON.

This API is only intended for use with "noun" menu items; things like bookmarks or applications in an "Open With" menu. Don't use it on menu items corresponding to verbs (eg: stock icons for 'Save' or 'Quit').

If $icon is undefined then the icon is unset.

method set-icon ( N-Object() $icon )
  • $icon; a Gnome::Gio::R-Icon, or undefined.

set-label

Sets or unsets the "label" attribute of $menu-item.

If $label is non-undefined it is used as the label for the menu item. If it is undefined then the label attribute is unset.

method set-label ( Str $label )
  • $label; the label to set, or undefined to unset.

Creates a link from $menu-item to $model if non-undefined, or unsets it.

Links are used to establish a relationship between a particular menu item and another menu. For example, G_MENU_LINK_SUBMENU is used to associate a submenu with a particular menu item, and G_MENU_LINK_SECTION is used to create a section. Other types of link can be used, but there is no guarantee that clients will be able to make sense of them. Link types are restricted to lowercase characters, numbers and '-'. Furthermore, the names must begin with a lowercase character, must not end with a '-', and must not contain consecutive dashes.

method set-link ( Str $link, N-Object() $model )
  • $link; type of link to establish or unset.

  • $model; the Gnome::Gio::MenuModel to link to (or undefined to unset).

set-section

Sets or unsets the "section" link of $menu-item to $section.

The effect of having one menu appear as a section of another is exactly as it sounds: the items from $section become a direct part of the menu that $menu-item is added to. See .new-section() for more information about what it means for a menu item to be a section.

method set-section ( N-Object() $section )
  • $section; a Gnome::Gio::MenuModel, or undefined.

set-submenu

Sets or unsets the "submenu" link of $menu-item to $submenu.

If $submenu is non-undefined, it is linked to. If it is undefined then the link is unset.

The effect of having one menu appear as a submenu of another is exactly as it sounds.

method set-submenu ( N-Object() $submenu )
  • $submenu; a Gnome::Gio::MenuModel, or undefined.