Class EntryCompletion

All Implemented Interfaces:
PointerInterface

public class EntryCompletion extends Object
`GtkEntryCompletion` is an auxiliary object to provide completion functionality
for `GtkEntry`.

It implements the [iface@Gtk.CellLayout] interface, to allow the user
to add extra cells to the `GtkTreeView` with completion matches.

“Completion functionality” means that when the user modifies the text
in the entry, `GtkEntryCompletion` checks which rows in the model match
the current content of the entry, and displays a list of matches.
By default, the matching is done by comparing the entry text
case-insensitively against the text column of the model (see
[method@Gtk.EntryCompletion.set_text_column]), but this can be overridden
with a custom match function (see [method@Gtk.EntryCompletion.set_match_func]).

When the user selects a completion, the content of the entry is
updated. By default, the content of the entry is replaced by the
text column of the model, but this can be overridden by connecting
to the [signal@Gtk.EntryCompletion::match-selected] signal and updating the
entry in the signal handler. Note that you should return %TRUE from
the signal handler to suppress the default behaviour.

To add completion functionality to an entry, use
[method@Gtk.Entry.set_completion].

`GtkEntryCompletion` uses a [class@Gtk.TreeModelFilter] model to
represent the subset of the entire model that is currently matching.
While the `GtkEntryCompletion` signals
[signal@Gtk.EntryCompletion::match-selected] and
[signal@Gtk.EntryCompletion::cursor-on-match] take the original model
and an iter pointing to that model as arguments, other callbacks and
signals (such as `GtkCellLayoutDataFunc` or
[signal@Gtk.CellArea::apply-attributes)]
will generally take the filter model as argument. As long as you are
only calling [method@Gtk.TreeModel.get], this will make no difference to
you. If for some reason, you need the original model, use
[method@Gtk.TreeModelFilter.get_model]. Don’t forget to use
[method@Gtk.TreeModelFilter.convert_iter_to_child_iter] to obtain a
matching iter.

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

  • Field Details

  • Constructor Details

    • EntryCompletion

      public EntryCompletion(PointerContainer pointer)
    • EntryCompletion

      public EntryCompletion()
      Creates a new `GtkEntryCompletion` object.
  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • newWithAreaEntryCompletion

      public static EntryCompletion newWithAreaEntryCompletion(@Nonnull CellArea area)
      Creates a new `GtkEntryCompletion` object using the
      specified @area.

      The `GtkCellArea` is used to layout cells in the underlying
      `GtkTreeViewColumn` for the drop-down menu.
      Parameters:
      area - the `GtkCellArea` used to layout cells
      Returns:
      A newly created `GtkEntryCompletion` object
    • complete

      public void complete()
      Requests a completion operation, or in other words a refiltering of the
      current list with completions, using the current key.

      The completion list view will be updated accordingly.
    • computePrefix

      public Str computePrefix(@Nonnull Str key)
      Computes the common prefix that is shared by all rows in @completion
      that start with @key.

      If no row matches @key, %NULL will be returned.
      Note that a text column must have been set for this function to work,
      see [method@Gtk.EntryCompletion.set_text_column] for details.
      Parameters:
      key - The text to complete for
      Returns:
      The common prefix all rows starting with @key
    • computePrefix

      public Str computePrefix(String key)
      Computes the common prefix that is shared by all rows in @completion
      that start with @key.

      If no row matches @key, %NULL will be returned.
      Note that a text column must have been set for this function to work,
      see [method@Gtk.EntryCompletion.set_text_column] for details.
      Parameters:
      key - The text to complete for
      Returns:
      The common prefix all rows starting with @key
    • getCompletionPrefix

      public Str getCompletionPrefix()
      Get the original text entered by the user that triggered
      the completion or %NULL if there’s no completion ongoing.
      Returns:
      the prefix for the current completion
    • getEntry

      public Widget getEntry()
      Gets the entry @completion has been attached to.
      Returns:
      The entry @completion has been attached to
    • getInlineCompletion

      public boolean getInlineCompletion()
      Returns whether the common prefix of the possible completions should
      be automatically inserted in the entry.
      Returns:
      %TRUE if inline completion is turned on
    • getInlineSelection

      public boolean getInlineSelection()
      Returns %TRUE if inline-selection mode is turned on.
      Returns:
      %TRUE if inline-selection mode is on
    • getMinimumKeyLength

      public int getMinimumKeyLength()
      Returns the minimum key length as set for @completion.
      Returns:
      The currently used minimum key length
    • getModel

      public TreeModel getModel()
      Returns the model the `GtkEntryCompletion` is using as data source.

      Returns %NULL if the model is unset.
      Returns:
      A `GtkTreeModel`
    • getPopupCompletion

      public boolean getPopupCompletion()
      Returns whether the completions should be presented in a popup window.
      Returns:
      %TRUE if popup completion is turned on
    • getPopupSetWidth

      public boolean getPopupSetWidth()
      Returns whether the completion popup window will be resized to the
      width of the entry.
      Returns:
      %TRUE if the popup window will be resized to the width of the entry
    • getPopupSingleMatch

      public boolean getPopupSingleMatch()
      Returns whether the completion popup window will appear even if there is
      only a single match.
      Returns:
      %TRUE if the popup window will appear regardless of the number of matches
    • getTextColumn

      public int getTextColumn()
      Returns the column in the model of @completion to get strings from.
      Returns:
      the column containing the strings
    • insertPrefix

      public void insertPrefix()
      Requests a prefix insertion.
    • setInlineCompletion

      public void setInlineCompletion(boolean inline_completion)
      Sets whether the common prefix of the possible completions should
      be automatically inserted in the entry.
      Parameters:
      inline_completion - %TRUE to do inline completion
    • setInlineSelection

      public void setInlineSelection(boolean inline_selection)
      Sets whether it is possible to cycle through the possible completions
      inside the entry.
      Parameters:
      inline_selection - %TRUE to do inline selection
    • setMatchFunc

      public void setMatchFunc(EntryCompletion.OnEntryCompletionMatchFunc func, @Nullable Pointer func_data, EntryCompletion.OnDestroyNotify func_notify)
      Sets the match function for @completion to be @func.

      The match function is used to determine if a row should or
      should not be in the completion list.
      Parameters:
      func - the `GtkEntryCompletion`MatchFunc to use
      func_data - user data for @func
      func_notify - destroy notify for @func_data.
    • setMinimumKeyLength

      public void setMinimumKeyLength(int length)
      Requires the length of the search key for @completion to be at least
      @length.

      This is useful for long lists, where completing using a small
      key takes a lot of time and will come up with meaningless results anyway
      (ie, a too large dataset).
      Parameters:
      length - the minimum length of the key in order to start completing
    • setModel

      public void setModel(@Nullable TreeModel model)
      Sets the model for a `GtkEntryCompletion`.

      If @completion already has a model set, it will remove it
      before setting the new model. If model is %NULL, then it
      will unset the model.
      Parameters:
      model - the `GtkTreeModel`
    • setPopupCompletion

      public void setPopupCompletion(boolean popup_completion)
      Sets whether the completions should be presented in a popup window.
      Parameters:
      popup_completion - %TRUE to do popup completion
    • setPopupSetWidth

      public void setPopupSetWidth(boolean popup_set_width)
      Sets whether the completion popup window will be resized to be the same
      width as the entry.
      Parameters:
      popup_set_width - %TRUE to make the width of the popup the same as the entry
    • setPopupSingleMatch

      public void setPopupSingleMatch(boolean popup_single_match)
      Sets whether the completion popup window will appear even if there is
      only a single match.

      You may want to set this to %FALSE if you
      are using [property@Gtk.EntryCompletion:inline-completion].
      Parameters:
      popup_single_match - %TRUE if the popup should appear even for a single match
    • setTextColumn

      public void setTextColumn(int column)
      Convenience function for setting up the most used case of this code: a
      completion list with just strings.

      This function will set up @completion
      to have a list displaying all (and just) strings in the completion list,
      and to get those strings from @column in the model of @completion.

      This functions creates and adds a `GtkCellRendererText` for the selected
      column. If you need to set the text column, but don't want the cell
      renderer, use g_object_set() to set the
      [property@Gtk.EntryCompletion:text-column] property directly.
      Parameters:
      column - the column in the model of @completion to get strings from
    • onCursorOnMatch

      public SignalHandler onCursorOnMatch(EntryCompletion.OnCursorOnMatch signal)
      Connect to signal "cursor-on-match".
      See EntryCompletion.OnCursorOnMatch.onCursorOnMatch(ch.bailu.gtk.gtk.TreeModel, ch.bailu.gtk.gtk.TreeIter) for signal description.
      Field SIGNAL_ON_CURSOR_ON_MATCH contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onInsertPrefix

      public SignalHandler onInsertPrefix(EntryCompletion.OnInsertPrefix signal)
      Connect to signal "insert-prefix".
      See EntryCompletion.OnInsertPrefix.onInsertPrefix(ch.bailu.gtk.type.Str) for signal description.
      Field SIGNAL_ON_INSERT_PREFIX contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onMatchSelected

      public SignalHandler onMatchSelected(EntryCompletion.OnMatchSelected signal)
      Connect to signal "match-selected".
      See EntryCompletion.OnMatchSelected.onMatchSelected(ch.bailu.gtk.gtk.TreeModel, ch.bailu.gtk.gtk.TreeIter) for signal description.
      Field SIGNAL_ON_MATCH_SELECTED contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onNoMatches

      public SignalHandler onNoMatches(EntryCompletion.OnNoMatches signal)
      Connect to signal "no-matches".
      See EntryCompletion.OnNoMatches.onNoMatches() for signal description.
      Field SIGNAL_ON_NO_MATCHES contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • asBuildable

      public Buildable asBuildable()
      Implements interface Buildable. Call this to get access to interface functions.
      Returns:
      Buildable
    • asCellLayout

      public CellLayout asCellLayout()
      Implements interface CellLayout. Call this to get access to interface functions.
      Returns:
      CellLayout
    • 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()