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
bindings/gtk/tree_selection.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class GObject::Object

==(other : self) ==, 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) | Nil data, finalize finalize, freeze_notify : Nil freeze_notify, getv(names : Enumerable(String), values : Enumerable(_)) : Nil getv, hash(hasher) hash, 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) | Nil qdata, ref_count : UInt32 ref_count, run_dispose : Nil run_dispose, set_data(key : String, data : Pointer(Void) | Nil) : Nil set_data, set_property(property_name : String, value : _) : Nil set_property, steal_data(key : String) : Pointer(Void) | Nil steal_data, steal_qdata(quark : UInt32) : Pointer(Void) | Nil 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, 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

cast?(obj : GObject::Object) : self | Nil cast?, compat_control(what : UInt64, data : Pointer(Void) | Nil) : 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.


[View source]
def self.new(*, mode : Gtk::SelectionMode | Nil = nil) #

[View source]

Class Method Detail

def self.g_type : UInt64 #

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


[View source]

Instance Method Detail

def ==(other : self) #
Description copied from class Reference

Returns true if this reference is the same as other. Invokes same?.


def changed_signal #

[View source]
def count_selected_rows : Int32 #

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


[View source]
def hash(hasher) #
Description copied from class Reference

See Object#hash(hasher)


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

Returns true if the row at iter is currently selected.


[View source]
def mode : Gtk::SelectionMode #

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


[View source]
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.


[View source]
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


[View source]
def select_all : Nil #

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


[View source]
def select_function=(func : Gtk::TreeSelectionFunc | Nil) : 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.


[View source]
def select_iter(iter : Gtk::TreeIter) : Nil #

Selects the specified iterator.


[View source]
def select_path(path : Gtk::TreePath) : Nil #

Select the row at path.


[View source]
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.


[View source]
def select_row(row : Int32) : Nil #

[View source]
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.


[View source]
def selected_foreach(func : Gtk::TreeSelectionForeachFunc, data : Pointer(Void) | Nil) : 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.


[View source]
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); ]|


[View source]
def tree_view : Gtk::TreeView #

Returns the tree view associated with selection.


[View source]
def unselect_all : Nil #

Unselects all the nodes.


[View source]
def unselect_iter(iter : Gtk::TreeIter) : Nil #

Unselects the specified iterator.


[View source]
def unselect_path(path : Gtk::TreePath) : Nil #

Unselects the row at path.


[View source]
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.


[View source]