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).
- Since:
- 2.32
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classMenu.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.MenuModel$Impl, MenuModel.MenuModelClassNested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass -
Constructor Summary
ConstructorsConstructorDescriptionMenu()Creates a new Menu.Menu(MemorySegment address) Create a Menu proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionvoidConvenience function for appending a normal menu item to the end ofmenu.Combine g_menu_item_new() and g_menu_insert_item() for a more flexible alternative.voidappendItem(MenuItem item) Appendsitemto the end ofmenu.voidappendSection(@Nullable String label, MenuModel section) Convenience function for appending a section menu item to the end ofmenu.Combine g_menu_item_new_section() and g_menu_insert_item() for a more flexible alternative.voidappendSubmenu(@Nullable String label, MenuModel submenu) Convenience function for appending a submenu menu item to the end ofmenu.Combine g_menu_item_new_submenu() and g_menu_insert_item() for a more flexible alternative.protected MenuasParent()Returns this instance as if it were its parent type.static Menu.Builder<? extends Menu.Builder> builder()AMenu.Builderobject constructs aMenuwith the specified properties.voidfreeze()Marks this Menu as frozen.static @Nullable TypegetType()Get the GType of the Menu classvoidConvenience function for inserting a normal menu item intomenu.Combine g_menu_item_new() and g_menu_insert_item() for a more flexible alternative.voidinsertItem(int position, MenuItem item) Insertsitemintomenu.voidinsertSection(int position, @Nullable String label, MenuModel section) Convenience function for inserting a section menu item intomenu.Combine g_menu_item_new_section() and g_menu_insert_item() for a more flexible alternative.voidinsertSubmenu(int position, @Nullable String label, MenuModel submenu) Convenience function for inserting a submenu menu item intomenu.Combine g_menu_item_new_submenu() and g_menu_insert_item() for a more flexible alternative.voidConvenience function for prepending a normal menu item to the start ofmenu.Combine g_menu_item_new() and g_menu_insert_item() for a more flexible alternative.voidprependItem(MenuItem item) Prependsitemto the start ofmenu.voidprependSection(@Nullable String label, MenuModel section) Convenience function for prepending a section menu item to the start ofmenu.Combine g_menu_item_new_section() and g_menu_insert_item() for a more flexible alternative.voidprependSubmenu(@Nullable String label, MenuModel submenu) Convenience function for prepending a submenu menu item to the start ofmenu.Combine g_menu_item_new_submenu() and g_menu_insert_item() for a more flexible alternative.voidremove(int position) Removes an item from the menu.voidRemoves 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, onItemsChangedMethods 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, 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, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.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 new Menu.
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, 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 ofmenu.Combine g_menu_item_new() and g_menu_insert_item() for a more flexible alternative.- Parameters:
label- the section label, ornulldetailedAction- the detailed action string, ornull- Since:
- 2.32
-
appendItem
Appendsitemto the end ofmenu.See g_menu_insert_item() for more information.
- Parameters:
item- aGMenuItemto append- Since:
- 2.32
-
appendSection
Convenience function for appending a section menu item to the end ofmenu.Combine g_menu_item_new_section() and g_menu_insert_item() for a more flexible alternative.- Parameters:
label- the section label, ornullsection- aGMenuModelwith the items of the section- Since:
- 2.32
-
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
GMenuAPI must no longer be used.This function causes g_menu_model_is_mutable() to begin returning
false, which has some positive performance implications.- Since:
- 2.32
-
insert
Convenience function for inserting a normal menu item intomenu.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, ornulldetailedAction- the detailed action string, ornull- Since:
- 2.32
-
insertItem
Insertsitemintomenu.The "insertion" is actually done by copying all of the attribute and link values of
itemand using them to form a new item withinmenu.As such,itemitself is not really inserted, but rather, a menu item that is exactly the same as the one presently described byitem.This means that
itemis 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
itemonce 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- theGMenuItemto insert- Since:
- 2.32
-
insertSection
Convenience function for inserting a section menu item intomenu.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, ornullsection- aGMenuModelwith the items of the section- Since:
- 2.32
-
prepend
Convenience function for prepending a normal menu item to the start ofmenu.Combine g_menu_item_new() and g_menu_insert_item() for a more flexible alternative.- Parameters:
label- the section label, ornulldetailedAction- the detailed action string, ornull- Since:
- 2.32
-
prependItem
Prependsitemto the start ofmenu.See g_menu_insert_item() for more information.
- Parameters:
item- aGMenuItemto prepend- Since:
- 2.32
-
prependSection
Convenience function for prepending a section menu item to the start ofmenu.Combine g_menu_item_new_section() and g_menu_insert_item() for a more flexible alternative.- Parameters:
label- the section label, ornullsection- aGMenuModelwith the items of the section- Since:
- 2.32
-
remove
public void remove(int position) Removes an item from the menu.positiongives 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- Since:
- 2.32
-
removeAll
public void removeAll()Removes all items in the menu.- Since:
- 2.38
-
builder
AMenu.Builderobject constructs aMenuwith the specified properties. Use the variousset...()methods to set properties, and finish construction withMenu.Builder.build().- Returns:
- the builder object
-