class Gtk::TreeSelection

Overview

The selection object for Gtk::TreeView

The Gtk::TreeSelection object is a helper object to manage the selection for a Gtk::TreeView widget. The Gtk::TreeSelection object is automatically created when a new Gtk::TreeView widget is created, and cannot exist independently of this widget. The primary reason the Gtk::TreeSelection objects exists is for cleanliness of code and API. That is, there is no conceptual reason all these functions could not be methods on the Gtk::TreeView widget instead of a separate function.

The Gtk::TreeSelection object is gotten from a Gtk::TreeView by calling gtk_tree_view_get_selection(). It can be manipulated to check the selection status of the tree, as well as select and deselect individual rows. Selection is done completely view side. As a result, multiple views of the same model can have completely different selections. Additionally, you cannot change the selection of a row on the model that is not currently displayed by the view without expanding its parents first.

One of the important things to remember when monitoring the selection of a view is that the Gtk::TreeSelection::changed signal is mostly a hint. That is, it may only emit one signal when a range of rows is selected. Additionally, it may on occasion emit a Gtk::TreeSelection::changed signal when nothing has happened (mostly as a result of programmers calling select_row on an already selected row).

Defined in:

lib/gi-crystal/src/auto/gtk-4.0/tree_selection.cr
lib/gtk4/src/bindings/gtk/tree_selection.cr

Constructors

Class Method Summary

Instance Method Summary

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 : UInt32 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(pointer : Pointer(Void), transfer : GICrystal::Transfer)
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 self.new #

Initialize a new TreeSelection.


def self.new(*, mode : Gtk::SelectionMode? = nil) #

Class Method Detail

def self.g_type : UInt64 #

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


Instance Method Detail

def changed_signal #

def count_selected_rows : Int32 #

Returns the number of rows that have been selected in @tree.


def iter_is_selected(iter : Gtk::TreeIter) : Bool #

Returns true if the row at @iter is currently selected.


def mode : Gtk::SelectionMode #

Gets the selection mode for @selection. See gtk_tree_selection_set_mode().


def mode=(type : Gtk::SelectionMode) : Nil #

Sets the selection mode of the @selection. If the previous type was %GTK_SELECTION_MULTIPLE, then the anchor is kept selected, if it was previously selected.


def path_is_selected(path : Gtk::TreePath) : Bool #

Returns true if the row pointed to by @path is currently selected. If @path does not point to a valid location, false is returned


def select_all : Nil #

Selects all the nodes. @selection must be set to %GTK_SELECTION_MULTIPLE mode.


def select_function=(func : Gtk::TreeSelectionFunc?) : Nil #

Sets the selection function.

If set, this function is called before any node is selected or unselected, giving some control over which nodes are selected. The select function should return true if the state of the node may be toggled, and false if the state of the node should be left unchanged.


def select_iter(iter : Gtk::TreeIter) : Nil #

Selects the specified iterator.


def select_path(path : Gtk::TreePath) : Nil #

Select the row at @path.


def select_range(start_path : Gtk::TreePath, end_path : Gtk::TreePath) : Nil #

Selects a range of nodes, determined by @start_path and @end_path inclusive. @selection must be set to %GTK_SELECTION_MULTIPLE mode.


def selected : Gtk::TreeIter #

Sets @iter to the currently selected node if @selection is set to %GTK_SELECTION_SINGLE or %GTK_SELECTION_BROWSE. @iter may be NULL if you just want to test if @selection has any selected nodes. @model is filled with the current model as a convenience. This function will not work if you use @selection is %GTK_SELECTION_MULTIPLE.


def selected_foreach(func : Gtk::TreeSelectionForeachFunc, data : Pointer(Void)?) : Nil #

Calls a function for each selected node. Note that you cannot modify the tree or selection from within this function. As a result, gtk_tree_selection_get_selected_rows() might be more useful.


def selected_rows : GLib::List #

Creates a list of path of all selected rows. Additionally, if you are planning on modifying the model after calling this function, you may want to convert the returned list into a list of Gtk::TreeRowReferences. To do this, you can use gtk_tree_row_reference_new().

To free the return value, use: |[ g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free); ]|


def tree_view : Gtk::TreeView #

Returns the tree view associated with @selection.


def unselect_all : Nil #

Unselects all the nodes.


def unselect_iter(iter : Gtk::TreeIter) : Nil #

Unselects the specified iterator.


def unselect_path(path : Gtk::TreePath) : Nil #

Unselects the row at @path.


def unselect_range(start_path : Gtk::TreePath, end_path : Gtk::TreePath) : Nil #

Unselects a range of nodes, determined by @start_path and @end_path inclusive.