Class Menu
- All Implemented Interfaces:
Proxy
GMenu
is a simple implementation of MenuModel
.
You populate a GMenu
by adding MenuItem
instances to it.
There are some convenience functions to allow you to directly
add items (avoiding MenuItem
) for the common cases. To add
a regular item, use insert(int, java.lang.String, java.lang.String)
. To add a section, use
insertSection(int, java.lang.String, org.gnome.gio.MenuModel)
. To add a submenu, use
insertSubmenu(int, java.lang.String, org.gnome.gio.MenuModel)
.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Menu.Builder<B extends Menu.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.Nested classes/interfaces inherited from class org.gnome.gio.MenuModel
MenuModel.ItemsChangedCallback, MenuModel.MenuModelClass, MenuModel.MenuModelImpl
Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionMenu()
Creates a newGMenu
.Menu
(MemorySegment address) Create a Menu proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Convenience function for appending a normal menu item to the end of this Menu.void
appendItem
(MenuItem item) Appendsitem
to the end of this Menu.void
appendSection
(@Nullable String label, MenuModel section) Convenience function for appending a section menu item to the end of this Menu.void
appendSubmenu
(@Nullable String label, MenuModel submenu) Convenience function for appending a submenu menu item to the end of this Menu.protected Menu
asParent()
Returns this instance as if it were its parent type.static Menu.Builder
<? extends Menu.Builder> builder()
AMenu.Builder
object constructs aMenu
with the specified properties.void
freeze()
Marks this Menu as frozen.static Type
getType()
Get the GType of the Menu classvoid
Convenience function for inserting a normal menu item into this Menu.void
insertItem
(int position, MenuItem item) Insertsitem
into this Menu.void
insertSection
(int position, @Nullable String label, MenuModel section) Convenience function for inserting a section menu item into this Menu.void
insertSubmenu
(int position, @Nullable String label, MenuModel submenu) Convenience function for inserting a submenu menu item into this Menu.void
Convenience function for prepending a normal menu item to the start of this Menu.void
prependItem
(MenuItem item) Prependsitem
to the start of this Menu.void
prependSection
(@Nullable String label, MenuModel section) Convenience function for prepending a section menu item to the start of this Menu.void
prependSubmenu
(@Nullable String label, MenuModel submenu) Convenience function for prepending a submenu menu item to the start of this Menu.void
remove
(int position) Removes an item from the menu.void
Removes all items in the menu.Methods inherited from class org.gnome.gio.MenuModel
emitItemsChanged, getItemAttribute, getItemAttributes, getItemAttributeValue, getItemLink, getItemLinks, getMemoryLayout, getNItems, isMutable, itemsChanged, iterateItemAttributes, iterateItemLinks, onItemsChanged
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, 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
-
Menu
Create a Menu proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
Menu
public Menu()Creates a newGMenu
.The new menu has no items.
-
-
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. -
append
Convenience function for appending a normal menu item to the end of this Menu. Combine g_menu_item_new() and g_menu_insert_item() for a more flexible alternative.- Parameters:
label
- the section label, ornull
detailedAction
- the detailed action string, ornull
-
appendItem
Appendsitem
to the end of this Menu.See g_menu_insert_item() for more information.
- Parameters:
item
- aGMenuItem
to append
-
appendSection
Convenience function for appending a section menu item to the end of this Menu. Combine g_menu_item_new_section() and g_menu_insert_item() for a more flexible alternative.- Parameters:
label
- the section label, ornull
section
- aGMenuModel
with the items of the section
-
freeze
public void freeze()Marks this 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
GMenu
API must no longer be used.This function causes g_menu_model_is_mutable() to begin returning
false
, which has some positive performance implications. -
insert
public void insert(int position, @Nullable @Nullable String label, @Nullable @Nullable String detailedAction) Convenience function for inserting a normal menu item into this Menu. Combine g_menu_item_new() and g_menu_insert_item() for a more flexible alternative.- Parameters:
position
- the position at which to insert the itemlabel
- the section label, ornull
detailedAction
- the detailed action string, ornull
-
insertItem
Insertsitem
into this 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 this Menu. As such,item
itself is not really inserted, but rather, a menu item that is exactly the same as the one presently described byitem
.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 g_menu_insert(), g_menu_insert_section() and g_menu_insert_submenu() as well as "prepend" and "append" variants of each of these functions.
- Parameters:
position
- the position at which to insert the itemitem
- theGMenuItem
to insert
-
insertSection
Convenience function for inserting a section menu item into this Menu. Combine g_menu_item_new_section() and g_menu_insert_item() for a more flexible alternative.- Parameters:
position
- the position at which to insert the itemlabel
- the section label, ornull
section
- aGMenuModel
with the items of the section
-
prepend
Convenience function for prepending a normal menu item to the start of this Menu. Combine g_menu_item_new() and g_menu_insert_item() for a more flexible alternative.- Parameters:
label
- the section label, ornull
detailedAction
- the detailed action string, ornull
-
prependItem
Prependsitem
to the start of this Menu.See g_menu_insert_item() for more information.
- Parameters:
item
- aGMenuItem
to prepend
-
prependSection
Convenience function for prepending a section menu item to the start of this Menu. Combine g_menu_item_new_section() and g_menu_insert_item() for a more flexible alternative.- Parameters:
label
- the section label, ornull
section
- aGMenuModel
with the items of the section
-
remove
public void remove(int position) 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).
- Parameters:
position
- the position of the item to remove
-
removeAll
public void removeAll()Removes all items in the menu. -
builder
AMenu.Builder
object constructs aMenu
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withMenu.Builder.build()
.
-