Class SingleSelection

All Implemented Interfaces:
PointerInterface

public class SingleSelection extends Object
`GtkSingleSelection` is a `GtkSelectionModel` that allows selecting a single
item.

Note that the selection is *persistent* -- if the selected item is removed
and re-added in the same [signal@Gio.ListModel::items-changed] emission, it
stays selected. In particular, this means that changing the sort order of an
underlying sort model will preserve the selection.

https://docs.gtk.org/gtk4/class.SingleSelection.html

  • Constructor Details

    • SingleSelection

      public SingleSelection(PointerContainer pointer)
    • SingleSelection

      public SingleSelection(@Nullable ListModel model)
      Creates a new selection to handle @model.
      Parameters:
      model - the `GListModel` to manage
  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • getAutoselect

      public boolean getAutoselect()
      Checks if autoselect has been enabled or disabled via
      gtk_single_selection_set_autoselect().
      Returns:
      %TRUE if autoselect is enabled
    • getCanUnselect

      public boolean getCanUnselect()
      If %TRUE, gtk_selection_model_unselect_item() is supported and allows
      unselecting the selected item.
      Returns:
      %TRUE to support unselecting
    • getModel

      public ListModel getModel()
      Gets the model that @self is wrapping.
      Returns:
      The model being wrapped
    • getSelected

      public int getSelected()
      Gets the position of the selected item.

      If no item is selected, %GTK_INVALID_LIST_POSITION is returned.
      Returns:
      The position of the selected item
    • getSelectedItem

      public Pointer getSelectedItem()
      Gets the selected item.

      If no item is selected, %NULL is returned.
      Returns:
      The selected item
    • setAutoselect

      public void setAutoselect(boolean autoselect)
      Enables or disables autoselect.

      If @autoselect is %TRUE, @self will enforce that an item is always
      selected. It will select a new item when the currently selected
      item is deleted and it will disallow unselecting the current item.
      Parameters:
      autoselect - %TRUE to always select an item
    • setCanUnselect

      public void setCanUnselect(boolean can_unselect)
      If %TRUE, unselecting the current item via
      gtk_selection_model_unselect_item() is supported.

      Note that setting [property@Gtk.SingleSelection:autoselect] will
      cause unselecting to not work, so it practically makes no sense
      to set both at the same time the same time.
      Parameters:
      can_unselect - %TRUE to allow unselecting
    • setModel

      public void setModel(@Nullable ListModel model)
      Sets the model that @self should wrap.

      If @model is %NULL, @self will be empty.
      Parameters:
      model - A `GListModel` to wrap
    • setSelected

      public void setSelected(int position)
      Selects the item at the given position.

      If the list does not have an item at @position or
      %GTK_INVALID_LIST_POSITION is given, the behavior depends on the
      value of the [property@Gtk.SingleSelection:autoselect] property:
      If it is set, no change will occur and the old item will stay
      selected. If it is unset, the selection will be unset and no item
      will be selected.
      Parameters:
      position - the item to select or %GTK_INVALID_LIST_POSITION
    • asListModel

      public ListModel asListModel()
      Implements interface ListModel. Call this to get access to interface functions.
      Returns:
      ListModel
    • asSelectionModel

      public SelectionModel asSelectionModel()
      Implements interface SelectionModel. Call this to get access to interface functions.
      Returns:
      SelectionModel
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()