Next: <GMenuLinkIter>, Previous: <GMenuAttributeIter>, Up: Classes   [Index]


1.54 <GMenuItem> ¶

Class: <GMenuItem> ¶

It derives from <GObject>.

<GMenuItem> is an opaque structure type. You must access it using the functions below.

Procedures ¶

Method: menu-item:get-attribute-value self attribute [expected-type] ⇒ %return ¶
Method: get-attribute-value self attribute [expected-type] ⇒ %return ¶

Queries the named attribute on self.

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

self

Passed: a <GMenuItem>.

a <GMenuItem>

attribute

Passed: a string.

the attribute name to query

expected-type

Passed, or left out: a <GVariantType>, or #f.

the expected type of the attribute

%return

Returned: a <GVariant>, or #f.

the attribute value, or #f

Method: menu-item:get-link self link ⇒ %return ¶
Method: get-link self link ⇒ %return ¶

Queries the named link on self.

self

Passed: a <GMenuItem>.

a <GMenuItem>

link

Passed: a string.

the link name to query

%return

Returned: a <GMenuModel>, or #f.

the link, or #f

Procedure: menu-item:new [label] [detailed-action] ⇒ %return ¶

Creates a new <GMenuItem>.

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

If detailed-action is non-#f it is used to set the "action" and possibly the "target" attribute of the new item. See menu-item:set-detailed-action for more information.

label

Passed, or left out: a string, or #f.

the section label, or #f

detailed-action

Passed, or left out: a string, or #f.

the detailed action string, or #f

%return

Returned: a <GMenuItem>.

a new <GMenuItem>

Procedure: menu-item:new-from-model model item-index ⇒ %return ¶

Creates a <GMenuItem> as an exact copy of an existing menu item in a <GMenuModel>.

item-index must be valid (ie: be sure to call menu-model:get-n-items first).

model

Passed: a <GMenuModel>.

a <GMenuModel>

item-index

Passed: a 32-bit integer.

the index of an item in model

%return

Returned: a <GMenuItem>.

a new <GMenuItem>.

Procedure: menu-item:new-section label section ⇒ %return ¶

Creates a new <GMenuItem> representing a section.

This is a convenience API around menu-item:new and menu-item: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-#f then it will be incorporated 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 <GMenu> 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:


<menu id='edit-menu'>
  <section>
    <item label='Undo'/>
    <item label='Redo'/>
  </section>
  <section>
    <item label='Cut'/>
    <item label='Copy'/>
    <item label='Paste'/>
  </section>
</menu>

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).


<menu id='edit-menu'>
  <item>
    <link name='section'>
      <item label='Undo'/>
      <item label='Redo'/>
    </link>
  </item>
  <item>
    <link name='section'>
      <item label='Cut'/>
      <item label='Copy'/>
      <item label='Paste'/>
    </link>
  </item>
</menu>
label

Passed: a string, or #f.

the section label, or #f

section

Passed: a <GMenuModel>.

a <GMenuModel> with the items of the section

%return

Returned: a <GMenuItem>.

a new <GMenuItem>

Procedure: menu-item:new-submenu label submenu ⇒ %return ¶

Creates a new <GMenuItem> representing a submenu.

This is a convenience API around menu-item:new and menu-item:set-submenu.

label

Passed: a string, or #f.

the section label, or #f

submenu

Passed: a <GMenuModel>.

a <GMenuModel> with the items of the submenu

%return

Returned: a <GMenuItem>.

a new <GMenuItem>

Method: menu-item:set-action-and-target-value self [action] [target-value] ¶
Method: set-action-and-target-value self [action] [target-value] ¶

Sets or unsets the "action" and "target" attributes of self.

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

If action is non-#f then the "action" attribute is set. The "target" attribute is then set to the value of target-value if it is non-#f 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 <GAction> and <GActionGroup> 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 #t.

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 g_menu_item_set_action_and_target() or menu-item:set-detailed-action for two equivalent calls that are probably more convenient for most uses.

self

Passed: a <GMenuItem>.

a <GMenuItem>

action

Passed, or left out: a string, or #f.

the name of the action for this item

target-value

Passed, or left out: a <GVariant>, or #f.

a <GVariant> to use as the action target

Method: menu-item:set-attribute-value self attribute [value] ¶
Method: set-attribute-value self attribute [value] ¶

Sets or unsets an attribute on self.

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-#f then it is used as the new value for the attribute. If value is #f then the attribute is unset. If the value <GVariant> is floating, it is consumed.

See also g_menu_item_set_attribute() for a more convenient way to do the same.

self

Passed: a <GMenuItem>.

a <GMenuItem>

attribute

Passed: a string.

the attribute to set

value

Passed, or left out: a <GVariant>, or #f.

a <GVariant> to use as the value, or #f

Method: menu-item:set-detailed-action self detailed-action ¶
Method: set-detailed-action self detailed-action ¶

Sets the "action" and possibly the "target" attribute of self.

The format of detailed-action is the same format parsed by action-parse-detailed-name.

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

See also menu-item:set-action-and-target-value for a description of the semantics of the action and target attributes.

self

Passed: a <GMenuItem>.

a <GMenuItem>

detailed-action

Passed: a string.

the "detailed" action string

Method: menu-item:set-icon self icon ¶
Method: set-icon self icon ¶

Sets (or unsets) the icon on self.

This call is the same as calling icon:serialize and using the result as the value to menu-item: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 #f then the icon is unset.

self

Passed: a <GMenuItem>.

a <GMenuItem>

icon

Passed: a <GIcon>.

a <GIcon>, or #f

Method: menu-item:set-label self [label] ¶
Method: set-label self [label] ¶

Sets or unsets the "label" attribute of self.

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

self

Passed: a <GMenuItem>.

a <GMenuItem>

label

Passed, or left out: a string, or #f.

the label to set, or #f to unset

Method: menu-item:set-link self link [model] ¶
Method: set-link self link [model] ¶

Creates a link from self to model if non-#f, 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.

self

Passed: a <GMenuItem>.

a <GMenuItem>

link

Passed: a string.

type of link to establish or unset

model

Passed, or left out: a <GMenuModel>, or #f.

the <GMenuModel> to link to (or #f to unset)

Method: menu-item:set-section self [section] ¶
Method: set-section self [section] ¶

Sets or unsets the "section" link of self 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 self is added to. See menu-item:new-section for more information about what it means for a menu item to be a section.

self

Passed: a <GMenuItem>.

a <GMenuItem>

section

Passed, or left out: a <GMenuModel>, or #f.

a <GMenuModel>, or #f

Method: menu-item:set-submenu self [submenu] ¶
Method: set-submenu self [submenu] ¶

Sets or unsets the "submenu" link of self to submenu.

If submenu is non-#f, it is linked to. If it is #f then the link is unset.

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

self

Passed: a <GMenuItem>.

a <GMenuItem>

submenu

Passed, or left out: a <GMenuModel>, or #f.

a <GMenuModel>, or #f


Next: <GMenuLinkIter>, Previous: <GMenuAttributeIter>, Up: Classes   [Index]