class Gtk::EntryCompletion


GtkEntryCompletion is an auxiliary object to provide completion functionality for GtkEntry.

It implements the 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 Gtk::EntryCompletion#text_column=), but this can be overridden with a custom match function (see Gtk::EntryCompletion#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 Gtk::Entry#completion=.

GtkEntryCompletion uses a 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 Gtk::TreeModel#get, this will make no difference to you. If for some reason, you need the original model, use Gtk::TreeModelFilter#model. Don’t forget to use Gtk::TreeModelFilter#convert_iter_to_child_iter to obtain a matching iter.

Included Modules

Defined in:



Class Method Summary

Instance Method Summary

Instance methods inherited from module Gtk::CellLayout

add_attribute(cell : Gtk::CellRenderer, attribute : String, column : Int32) : Nil add_attribute, area : Gtk::CellArea? area, cells : GLib::List cells, clear : Nil clear, clear_attributes(cell : Gtk::CellRenderer) : Nil clear_attributes, pack_end(cell : Gtk::CellRenderer, expand : Bool) : Nil pack_end, pack_start(cell : Gtk::CellRenderer, expand : Bool) : Nil pack_start, reorder(cell : Gtk::CellRenderer, position : Int32) : Nil reorder, set_cell_data_func(cell : Gtk::CellRenderer, func : Gtk::CellLayoutDataFunc?) : Nil set_cell_data_func, to_unsafe to_unsafe

Instance methods inherited from module Gtk::Buildable

buildable_id : String? buildable_id, to_unsafe to_unsafe

Instance methods inherited from class GObject::Object

bind_property(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags) : GObject::Binding bind_property, bind_property_full(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags, transform_to : GObject::Closure, transform_from : GObject::Closure) : GObject::Binding bind_property_full, data(key : String) : Pointer(Void)? data, finalize finalize, freeze_notify : Nil freeze_notify, getv(names : Enumerable(String), values : Enumerable(_)) : Nil getv, notify(property_name : String) : Nil notify, notify_by_pspec(pspec : GObject::ParamSpec) : Nil notify_by_pspec, notify_signal notify_signal, property(property_name : String, value : _) : Nil property, qdata(quark : UInt32) : Pointer(Void)? qdata, ref_count ref_count, run_dispose : Nil run_dispose, set_data(key : String, data : Pointer(Void)?) : Nil set_data, set_property(property_name : String, value : _) : Nil set_property, steal_data(key : String) : Pointer(Void)? steal_data, steal_qdata(quark : UInt32) : Pointer(Void)? steal_qdata, thaw_notify : Nil thaw_notify, to_unsafe : Pointer(Void) to_unsafe, watch_closure(closure : GObject::Closure) : Nil watch_closure

Constructor methods inherited from class GObject::Object

cast(obj : GObject::Object) : self cast, cast?(obj : GObject::Object) : self? cast?, new new, newv(object_type : UInt64, parameters : Enumerable(GObject::Parameter)) : self newv

Class methods inherited from class GObject::Object

compat_control(what : UInt64, data : Pointer(Void)?) : UInt64 compat_control, g_type : UInt64 g_type, interface_find_property(g_iface : GObject::TypeInterface, property_name : String) : GObject::ParamSpec interface_find_property, interface_list_properties(g_iface : GObject::TypeInterface) : Enumerable(GObject::ParamSpec) interface_list_properties

Constructor Detail

def #

Creates a new GtkEntryCompletion object.

def*, cell_area : Gtk::CellArea? = nil, inline_completion : Bool? = nil, inline_selection : Bool? = nil, minimum_key_length : Int32? = nil, model : Gtk::TreeModel? = nil, popup_completion : Bool? = nil, popup_set_width : Bool? = nil, popup_single_match : Bool? = nil, text_column : Int32? = nil) #

def self.new_with_area(area : Gtk::CellArea) : self #

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.

Class Method Detail

def self.g_type : UInt64 #

Returns the type id (GType) registered in GLib type system.

Instance Method Detail

def cell_area : Gtk::CellArea? #

def cell_area=(value : Gtk::CellArea?) : Gtk::CellArea? #

def complete : Nil #

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.

def completion_prefix : String? #

Get the original text entered by the user that triggered the completion or %NULL if there’s no completion ongoing.

def compute_prefix(key : String) : String? #

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 Gtk::EntryCompletion#text_column= for details.

def cursor_on_match_signal #

def entry : Gtk::Widget #

Gets the entry @completion has been attached to.

def inline_completion : Bool #

Returns whether the common prefix of the possible completions should be automatically inserted in the entry.

def inline_completion=(inline_completion : Bool) : Nil #

Sets whether the common prefix of the possible completions should be automatically inserted in the entry.

def inline_completion? : Bool #

def inline_selection : Bool #

Returns %TRUE if inline-selection mode is turned on.

def inline_selection=(inline_selection : Bool) : Nil #

Sets whether it is possible to cycle through the possible completions inside the entry.

def inline_selection? : Bool #

def insert_prefix : Nil #

Requests a prefix insertion.

def insert_prefix_signal #

def match_func=(func : Gtk::EntryCompletionMatchFunc) : Nil #

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.

def match_selected_signal #

def minimum_key_length : Int32 #

Returns the minimum key length as set for @completion.

def minimum_key_length=(length : Int32) : Nil #

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).

def model : Gtk::TreeModel? #

Returns the model the GtkEntryCompletion is using as data source.

Returns %NULL if the model is unset.

def model=(model : Gtk::TreeModel?) : Nil #

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.

def no_matches_signal #

def popup_completion : Bool #

Returns whether the completions should be presented in a popup window.

def popup_completion=(popup_completion : Bool) : Nil #

Sets whether the completions should be presented in a popup window.

def popup_completion? : Bool #

def popup_set_width : Bool #

Returns whether the completion popup window will be resized to the width of the entry.

def popup_set_width=(popup_set_width : Bool) : Nil #

Sets whether the completion popup window will be resized to be the same width as the entry.

def popup_set_width? : Bool #

def popup_single_match : Bool #

Returns whether the completion popup window will appear even if there is only a single match.

def popup_single_match=(popup_single_match : Bool) : Nil #

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].

def popup_single_match? : Bool #

def text_column : Int32 #

Returns the column in the model of @completion to get strings from.

def text_column=(column : Int32) : Nil #

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.