Class Menu

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class Menu extends MenuModel

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, String, String). To add a section, use insertSection(int, String, MenuModel). To add a submenu, use insertSubmenu(int, String, MenuModel).

Since:
2.32
  • Constructor Details

    • Menu

      public Menu(MemorySegment address)
      Create a Menu instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • Menu

      public Menu()
      Create a new Menu.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the Menu class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected Menu asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class MenuModel
      Returns:
      the instance as if it were its parent type
    • append

      public void append(@Nullable String label, @Nullable String detailedAction)
      Convenience function for appending a normal menu item to the end of menu. Combine g_menu_item_new() and g_menu_insert_item() for a more flexible alternative.
      Parameters:
      label - the section label, or null
      detailedAction - the detailed action string, or null
      Since:
      2.32
    • appendItem

      public void appendItem(MenuItem item)

      Appends item to the end of menu.

      See g_menu_insert_item() for more information.

      Parameters:
      item - a GMenuItem to append
      Since:
      2.32
    • appendSection

      public void appendSection(@Nullable String label, MenuModel section)
      Convenience function for appending a section menu item to the end of menu. Combine g_menu_item_new_section() and g_menu_insert_item() for a more flexible alternative.
      Parameters:
      label - the section label, or null
      section - a GMenuModel with the items of the section
      Since:
      2.32
    • appendSubmenu

      public void appendSubmenu(@Nullable String label, MenuModel submenu)
      Convenience function for appending a submenu menu item to the end of menu. Combine g_menu_item_new_submenu() and g_menu_insert_item() for a more flexible alternative.
      Parameters:
      label - the section label, or null
      submenu - a GMenuModel with the items of the submenu
      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 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.

      Since:
      2.32
    • insert

      public void insert(int position, @Nullable String label, @Nullable String detailedAction)
      Convenience function for inserting a normal menu item into 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 item
      label - the section label, or null
      detailedAction - the detailed action string, or null
      Since:
      2.32
    • insertItem

      public void insertItem(int position, MenuItem item)

      Inserts item into 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 menu. As such, item itself is not really inserted, but rather, a menu item that is exactly the same as the one presently described by item.

      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 item
      item - the GMenuItem to insert
      Since:
      2.32
    • insertSection

      public void insertSection(int position, @Nullable String label, MenuModel section)
      Convenience function for inserting a section menu item into 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 item
      label - the section label, or null
      section - a GMenuModel with the items of the section
      Since:
      2.32
    • insertSubmenu

      public void insertSubmenu(int position, @Nullable String label, MenuModel submenu)
      Convenience function for inserting a submenu menu item into menu. Combine g_menu_item_new_submenu() and g_menu_insert_item() for a more flexible alternative.
      Parameters:
      position - the position at which to insert the item
      label - the section label, or null
      submenu - a GMenuModel with the items of the submenu
      Since:
      2.32
    • prepend

      public void prepend(@Nullable String label, @Nullable String detailedAction)
      Convenience function for prepending a normal menu item to the start of menu. Combine g_menu_item_new() and g_menu_insert_item() for a more flexible alternative.
      Parameters:
      label - the section label, or null
      detailedAction - the detailed action string, or null
      Since:
      2.32
    • prependItem

      public void prependItem(MenuItem item)

      Prepends item to the start of menu.

      See g_menu_insert_item() for more information.

      Parameters:
      item - a GMenuItem to prepend
      Since:
      2.32
    • prependSection

      public void prependSection(@Nullable String label, MenuModel section)
      Convenience function for prepending a section menu item to the start of menu. Combine g_menu_item_new_section() and g_menu_insert_item() for a more flexible alternative.
      Parameters:
      label - the section label, or null
      section - a GMenuModel with the items of the section
      Since:
      2.32
    • prependSubmenu

      public void prependSubmenu(@Nullable String label, MenuModel submenu)
      Convenience function for prepending a submenu menu item to the start of menu. Combine g_menu_item_new_submenu() and g_menu_insert_item() for a more flexible alternative.
      Parameters:
      label - the section label, or null
      submenu - a GMenuModel with the items of the submenu
      Since:
      2.32
    • 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
      Since:
      2.32
    • removeAll

      public void removeAll()
      Removes all items in the menu.
      Since:
      2.38
    • builder

      public static Menu.Builder<? extends Menu.Builder> builder()
      A Menu.Builder object constructs a Menu with the specified properties. Use the various set...() methods to set properties, and finish construction with Menu.Builder.build().
      Returns:
      the builder object