Class ContextMenuItem

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public final class ContextMenuItem extends InitiallyUnowned

One item of a WebKitContextMenu.

The WebKitContextMenu is composed of WebKitContextMenuItems. These items can be created from a GtkAction, from a WebKitContextMenuAction or from a WebKitContextMenuAction and a label. These WebKitContextMenuActions denote stock actions for the items. You can also create separators and submenus.

  • Constructor Details

    • ContextMenuItem

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

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

    • getType

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

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

      protected ContextMenuItem 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 InitiallyUnowned
      Returns:
      the instance as if it were its parent type
    • fromGaction

      public static ContextMenuItem fromGaction(Action action, String label, @Nullable Variant target)

      Creates a new WebKitContextMenuItem for the given action and label.

      On activation target will be passed as parameter to the callback.

      Parameters:
      action - a GAction
      label - the menu item label text
      target - a GVariant to use as the action target
      Returns:
      the newly created WebKitContextMenuItem object.
      Since:
      2.18
    • fromStockAction

      public static ContextMenuItem fromStockAction(ContextMenuAction action)

      Creates a new WebKitContextMenuItem for the given stock action.

      Stock actions are handled automatically by WebKit so that, for example, when a menu item created with a ContextMenuAction.STOP is activated the action associated will be handled by WebKit and the current load operation will be stopped. You can get the GAction of a WebKitContextMenuItem created with a WebKitContextMenuAction with webkit_context_menu_item_get_gaction() and connect to the GSimpleAction::activate signal to be notified when the item is activated, but you can't prevent the associated action from being performed.

      Parameters:
      action - a WebKitContextMenuAction stock action
      Returns:
      the newly created WebKitContextMenuItem object.
    • fromStockActionWithLabel

      public static ContextMenuItem fromStockActionWithLabel(ContextMenuAction action, String label)

      Creates a new WebKitContextMenuItem for the given stock action using the given label.

      Stock actions have a predefined label, this method can be used to create a WebKitContextMenuItem for a WebKitContextMenuAction but using a custom label.

      Parameters:
      action - a WebKitContextMenuAction stock action
      label - a custom label text to use instead of the predefined one
      Returns:
      the newly created WebKitContextMenuItem object.
    • separator

      public static ContextMenuItem separator()
      Creates a new WebKitContextMenuItem representing a separator.
      Returns:
      the newly created WebKitContextMenuItem object.
    • withSubmenu

      public static ContextMenuItem withSubmenu(String label, ContextMenu submenu)
      Creates a new WebKitContextMenuItem using the given label with a submenu.
      Parameters:
      label - the menu item label text
      submenu - a WebKitContextMenu to set
      Returns:
      the newly created WebKitContextMenuItem object.
    • getGaction

      public Action getGaction()
      Gets the action associated to this ContextMenuItem as a GAction.
      Returns:
      the GAction associated to the WebKitContextMenuItem, or null if this ContextMenuItem is a separator.
      Since:
      2.18
    • getGactionTarget

      public @Nullable Variant getGactionTarget()
      Gets the target GVariant associated with item.
      Returns:
      the target GVariant of the WebKitContextMenuItem, or null if this ContextMenuItem was not created with webkit_context_menu_item_new_from_gaction() or if no target was specified.
      Since:
      2.52
    • getStockAction

      public ContextMenuAction getStockAction()

      Gets the WebKitContextMenuAction of item.

      If the WebKitContextMenuItem was not created for a stock action ContextMenuAction.CUSTOM will be returned. If the WebKitContextMenuItem is a separator ContextMenuAction.NO_ACTION will be returned.

      Returns:
      the WebKitContextMenuAction of this ContextMenuItem
    • getSubmenu

      public ContextMenu getSubmenu()
      Gets the submenu of item.
      Returns:
      the WebKitContextMenu representing the submenu of this ContextMenuItem or null if this ContextMenuItem doesn't have a submenu.
    • getTitle

      public String getTitle()
      Gets the title of item.
      Returns:
      the title of item, or null if this ContextMenuItem is a separator.
      Since:
      2.52
    • isSeparator

      public boolean isSeparator()
      Checks whether this ContextMenuItem is a separator.
      Returns:
      true is this ContextMenuItem is a separator or false otherwise
    • setSubmenu

      public void setSubmenu(@Nullable ContextMenu submenu)

      Sets or replaces the this ContextMenuItem submenu.

      If submenu is null the current submenu of this ContextMenuItem is removed.

      Parameters:
      submenu - a WebKitContextMenu
    • builder

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