Class MenuItem
- All Implemented Interfaces:
Proxy
GMenuItem
is an opaque structure type. You must access it using the
functions below.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
MenuItem.Builder<B extends MenuItem.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionCreates a newGMenuItem
.MenuItem
(MemorySegment address) Create a MenuItem proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected MenuItem
asParent()
Returns this instance as if it were its parent type.static MenuItem.Builder
<? extends MenuItem.Builder> builder()
AMenuItem.Builder
object constructs aMenuItem
with the specified properties.static MenuItem
Creates aGMenuItem
as an exact copy of an existing menu item in aGMenuModel
.boolean
getAttribute
(String attribute, String formatString, Object... varargs) Queries the namedattribute
on this MenuItem.getAttributeValue
(String attribute, @Nullable VariantType expectedType) Queries the namedattribute
on this MenuItem.Queries the namedlink
on this MenuItem.static Type
getType()
Get the GType of the MenuItem classstatic MenuItem
Creates a newGMenuItem
representing a section.void
setActionAndTarget
(@Nullable String action, @Nullable String formatString, Object... varargs) Sets or unsets the "action" and "target" attributes of this MenuItem.void
setActionAndTargetValue
(@Nullable String action, @Nullable Variant targetValue) Sets or unsets the "action" and "target" attributes of this MenuItem.void
setAttribute
(String attribute, @Nullable String formatString, Object... varargs) Sets or unsets an attribute on this MenuItem.void
setAttributeValue
(String attribute, @Nullable Variant value) Sets or unsets an attribute on this MenuItem.void
setDetailedAction
(String detailedAction) Sets the "action" and possibly the "target" attribute of this MenuItem.void
Sets (or unsets) the icon on this MenuItem.void
Sets or unsets the "label" attribute of this MenuItem.void
Creates a link from this MenuItem tomodel
if non-null
, or unsets it.void
setSection
(@Nullable MenuModel section) Sets or unsets the "section" link of this MenuItem tosection
.void
setSubmenu
(@Nullable MenuModel submenu) Sets or unsets the "submenu" link of this MenuItem tosubmenu
.static MenuItem
Creates a newGMenuItem
representing a submenu.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getMemoryLayout, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
MenuItem
Create a MenuItem proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
MenuItem
Creates a newGMenuItem
.If
label
is non-null
it is used to set the "label" attribute of the new item.If
detailedAction
is non-null
it is used to set the "action" and possibly the "target" attribute of the new item. See g_menu_item_set_detailed_action() for more information.- Parameters:
label
- the section label, ornull
detailedAction
- the detailed action string, ornull
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type. -
fromModel
Creates aGMenuItem
as an exact copy of an existing menu item in aGMenuModel
.itemIndex
must be valid (ie: be sure to call g_menu_model_get_n_items() first).- Parameters:
model
- aGMenuModel
itemIndex
- the index of an item inmodel
- Returns:
- a new
GMenuItem
.
-
section
Creates a newGMenuItem
representing a section.This is a convenience API around g_menu_item_new() and g_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 thatmenuItem
is added to.Visual separation is typically displayed between two non-empty sections. If
label
is non-null
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>
- Parameters:
label
- the section label, ornull
section
- aGMenuModel
with the items of the section- Returns:
- a new
GMenuItem
-
getAttribute
Queries the namedattribute
on this MenuItem.If the attribute exists and matches the
GVariantType
corresponding toformatString
thenformatString
is used to deconstruct the value into the positional parameters andtrue
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.- Parameters:
attribute
- the attribute name to queryformatString
- aGVariant
format stringvarargs
- positional parameters, as performatString
- Returns:
true
if the named attribute was found with the expected type
-
getAttributeValue
Queries the namedattribute
on this MenuItem.If
expectedType
is specified and the attribute does not have this type,null
is returned.null
is also returned if the attribute simply does not exist.- Parameters:
attribute
- the attribute name to queryexpectedType
- the expected type of the attribute- Returns:
- the attribute value, or
null
-
getLink
-
setActionAndTarget
public void setActionAndTarget(@Nullable @Nullable String action, @Nullable @Nullable String formatString, Object... varargs) Sets or unsets the "action" and "target" attributes of this MenuItem.If
action
isnull
then both the "action" and "target" attributes are unset (andformatString
is ignored along with the positional parameters).If
action
is non-null
then the "action" attribute is set.formatString
is then inspected. If it is non-null
then the proper position parameters are collected to create aGVariant
instance to use as the target value. If it isnull
then the positional parameters are ignored and the "target" attribute is unset.See also g_menu_item_set_action_and_target_value() for an equivalent call that directly accepts a
GVariant
. See g_menu_item_set_detailed_action() for a more convenient version that works with string-typed targets.See also g_menu_item_set_action_and_target_value() for a description of the semantics of the action and target attributes.
- Parameters:
action
- the name of the action for this itemformatString
- a GVariant format stringvarargs
- positional parameters, as performatString
-
setActionAndTargetValue
public void setActionAndTargetValue(@Nullable @Nullable String action, @Nullable @Nullable Variant targetValue) Sets or unsets the "action" and "target" attributes of this MenuItem.If
action
isnull
then both the "action" and "target" attributes are unset (andtargetValue
is ignored).If
action
is non-null
then the "action" attribute is set. The "target" attribute is then set to the value oftargetValue
if it is non-null
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
andGActionGroup
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 g_menu_item_set_action_and_target() or g_menu_item_set_detailed_action() for two equivalent calls that are probably more convenient for most uses.
- Parameters:
action
- the name of the action for this itemtargetValue
- aGVariant
to use as the action target
-
setAttribute
public void setAttribute(String attribute, @Nullable @Nullable String formatString, Object... varargs) Sets or unsets an attribute on this MenuItem.The attribute to set or unset is specified by
attribute
. This can be one of the standard attribute namesG_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
formatString
is non-null
then the proper position parameters are collected to create aGVariant
instance to use as the attribute value. If it isnull
then the positional parameterrs are ignored and the named attribute is unset.See also g_menu_item_set_attribute_value() for an equivalent call that directly accepts a
GVariant
.- Parameters:
attribute
- the attribute to setformatString
- aGVariant
format string, ornull
varargs
- positional parameters, as performatString
-
setAttributeValue
Sets or unsets an attribute on this MenuItem.The attribute to set or unset is specified by
attribute
. This can be one of the standard attribute namesG_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-null
then it is used as the new value for the attribute. Ifvalue
isnull
then the attribute is unset. If thevalue
GVariant
is floating, it is consumed.See also g_menu_item_set_attribute() for a more convenient way to do the same.
- Parameters:
attribute
- the attribute to setvalue
- aGVariant
to use as the value, ornull
-
setDetailedAction
Sets the "action" and possibly the "target" attribute of this MenuItem.The format of
detailedAction
is the same format parsed by g_action_parse_detailed_name().See g_menu_item_set_action_and_target() or g_menu_item_set_action_and_target_value() for more flexible (but slightly less convenient) alternatives.
See also g_menu_item_set_action_and_target_value() for a description of the semantics of the action and target attributes.
- Parameters:
detailedAction
- the "detailed" action string
-
setIcon
Sets (or unsets) the icon on this MenuItem.This call is the same as calling g_icon_serialize() and using the result as the value to g_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
isnull
then the icon is unset.- Parameters:
icon
- aGIcon
, ornull
-
setLabel
Sets or unsets the "label" attribute of this MenuItem.If
label
is non-null
it is used as the label for the menu item. If it isnull
then the label attribute is unset.- Parameters:
label
- the label to set, ornull
to unset
-
setLink
Creates a link from this MenuItem tomodel
if non-null
, 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, andG_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.- Parameters:
link
- type of link to establish or unsetmodel
- theGMenuModel
to link to (ornull
to unset)
-
setSection
Sets or unsets the "section" link of this MenuItem tosection
.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 this MenuItem is added to. See g_menu_item_new_section() for more information about what it means for a menu item to be a section.- Parameters:
section
- aGMenuModel
, ornull
-
builder
AMenuItem.Builder
object constructs aMenuItem
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withMenuItem.Builder.build()
.
-