Class CompletionContext<T extends GObject>

All Implemented Interfaces:
Iterable<T>, Collection<T>, List<T>, SequencedCollection<T>, ListModel<T>, Proxy, ListModelJavaList<T>

@Generated("org.javagi.JavaGI") public class CompletionContext<T extends GObject> extends GObject implements ListModel<T>

The context of a completion.

GtkSourceCompletionContext contains information about an attept to display completion proposals to the user based on typed text in the View.

When typing, Completion may use registered CompletionProvider to determine if there may be results which could be displayed. If so, a GtkSourceCompletionContext is created with information that is provided to the CompletionProvider to populate results which might be useful to the user.

CompletionProvider are expected to provide ListModel with CompletionProposal which may be joined together in a list of results for the user. They are also responsible for how the contents are displayed using CompletionCell which allows for some level of customization.

  • Constructor Details

    • CompletionContext

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

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

    • getType

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

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

      protected CompletionContext 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 GObject
      Returns:
      the instance as if it were its parent type
    • getActivation

      public CompletionActivation getActivation()
      Gets the mode for which the context was activated.
    • getBounds

      public boolean getBounds(@Nullable TextIter begin, @Nullable TextIter end)

      Gets the bounds for the completion, which is the beginning of the current word (taking break characters into account) to the current insertion cursor.

      If begin is non-null, it will be set to the start position of the current word being completed.

      If end is non-null, it will be set to the insertion cursor for the current word being completed.

      Parameters:
      begin - a GtkTextIter
      end - a GtkTextIter
      Returns:
      true if the marks are still valid and begin or end was set.
    • getBuffer

      public @Nullable Buffer getBuffer()

      Gets the underlying buffer used by the context.

      This is a convenience function to get the buffer via the GtkSourceCompletion property.

      Returns:
      a GtkTextBuffer or null
    • getBusy

      public boolean getBusy()
      Gets the "busy" property. This is set to true while the completion context is actively fetching proposals from registered GtkSourceCompletionProvider's.
      Returns:
      true if the context is busy
    • getCompletion

      public @Nullable Completion getCompletion()
      Gets the GtkSourceCompletion that created the context.
      Returns:
      an GtkSourceCompletion or null
    • getEmpty

      public boolean getEmpty()

      Checks if any proposals have been provided to the context.

      Out of convenience, this function will return true if this CompletionContext is null.

      Returns:
      true if there are no proposals in the context
    • getLanguage

      public @Nullable Language getLanguage()
      Gets the language of the underlying buffer, if any.
      Returns:
      a GtkSourceLanguage or null
    • getProposalsForProvider

      public @Nullable ListModel getProposalsForProvider(CompletionProvider provider)

      Gets the GListModel associated with the provider.

      You can connect to GtkSourceCompletionContext::model-changed to receive notifications about when the model has been replaced by a new model.

      Parameters:
      provider - a GtkSourceCompletionProvider
      Returns:
      a GListModel or null
      Since:
      5.6
    • getView

      public @Nullable View getView()
      Gets the text view for the context.
      Returns:
      a GtkSourceView or null
    • getWord

      public String getWord()
      Gets the word that is being completed up to the position of the insert mark.
      Returns:
      a string containing the current word
    • listProviders

      public ListModel listProviders()
      Gets the providers that are associated with the context.
      Returns:
      a GListModel of GtkSourceCompletionProvider
      Since:
      5.6
    • setProposalsForProvider

      public void setProposalsForProvider(CompletionProvider provider, @Nullable ListModel results)

      This function allows providers to update their results for a context outside of a call to CompletionProvider.populateAsync(CompletionContext, Cancellable, AsyncReadyCallback).

      This can be used to immediately return results for a provider while it does additional asynchronous work. Doing so will allow the completions to update while the operation is in progress.

      Parameters:
      provider - an GtkSourceCompletionProvider
      results - a GListModel or null
    • onProviderModelChanged

      Emitted when a provider changes a model.

      This signal is primarily useful for GtkSourceCompletionProvider's that want to track other providers in context. For example, it can be used to create a "top results" provider.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      Since:
      5.6
      See Also:
    • emitProviderModelChanged

      public void emitProviderModelChanged(@Nullable CompletionProvider provider, @Nullable ListModel model)
      Emits the "provider-model-changed" signal. See onProviderModelChanged(CompletionContext.ProviderModelChangedCallback).
    • builder

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