Gtk::TreeSelection
class Gtk::TreeSelection
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 independentally 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 methods could not be methods on the Gtk::TreeView widget instead of a separate methods.
The Gtk::TreeSelection object is gotten from a Gtk::TreeView by calling Gtk::TreeView#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 "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 "changed" signal when nothing has happened (mostly as a result of programmers calling select_row on an already selected row).
Instance Methods
mode
-
Gets the selection mode for selection. See Gtk::TreeSelection#mode=.
- Returns: the current selection mode
mode=(type)
-
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.
- type: The selection mode (GtkSelectionMode)
- Returns: type
set_mode(type)
-
Same as Gtk::TreeSelection#mode=.
- type: The selection mode (GtkSelectionMode)
- Returns: self
set_select_function {|selection, model, path, path_currentry_selected| ... }
-
Sets the selection block. If set, this block is called before any node is selected or unselected, giving some control over which nodes are selected. The select block should return true if the state of the node may be toggled, and false if the state of the node should be left unchanged.
- {|selection, model, path, path_currentry_selected| ... }: the selection block
- selection: A Gtk::TreeSelection
- model: A Gtk::TreeModel being viewed
- path: The Gtk::TreePath of the row in question
- path_currently_selected: true, if the path is currently selected
- Returns : true, if the selection state of the row can be toggled
- Returns: self
- {|selection, model, path, path_currentry_selected| ... }: the selection block
tree_view
-
Returns the tree view associated with selection.
- Returns: A Gtk::TreeView
selected
-
Gets iter to the currently selected node if selection is set to Gtk::SELECTION_SINGLE or Gtk::SELECTION_BROWSE. iter may be nil if you just want to test if selection has any selected nodes. This method will not work if you use selection is Gtk::SELECTION_MULTIPLE.
- Returns: The Gtk::TreeIter, or nil
selected_each {|model, path, iter| ... }
-
Calls a block for each selected node.
- {|model, path, iter| ... }: The block to call for each selected node.
data : user data to pass to the function.
- model: A Gtk::TreeModel being viewed
- path: The Gtk::TreePath of the row in question
- iter: A Gtk::TreeIter pointing to a selected row
- Returns: self
select_path(path)
-
Select the row at path.
- path : The Gtk::TreePath to be selected.
- Returns: self
unselect_path(path)
-
Unselects the row at path.
- Returns: The Gtk::TreePath to be unselected.
path_is_selected?
-
Returns true if the row pointed to by path is currently selected. If path does not point to a valid location, false is returned.
- path: A Gtk::TreePath to check selection on.
- Returns: true if path is selected.
select_iter(iter)
-
Selects the specified iterator.
- iter: The Gtk::TreeIter to be selected
- Returns: self
unselect_iter(iter)
-
Unselects the specified iterator.
- iter: The Gtk::TreeIter to be unselected
- Returns: self
iter_is_selected?(iter)
-
Returns true if the row pointed to by path is currently selected.
- iter: A valid Gtk::TreeIter
- Returns: true, if iter is selected
select_all
-
Selects all the nodes. selection is must be set to Gtk::SELECTION_MULTIPLE mode.
- Returns: self
unselect_all
-
Unselects all the nodes.
- Returns: self
select_range(start_path, end_path)
-
Selects a range of nodes, determined by start_path and end_path inclusive.
- start_path: The initial node of the range.
- end_path: The final node of the range.
- Returns: self
Signals
changed: self
-
Emitted whenever the selection has (possibly) changed. Please note that this signal is mostly a hint. It may only be emitted once when a range of rows are selected, and it may occasionally be emitted when nothing has happened.
- self: Gtk::TreeSelection
Parola chiave:
Referenze:[Gtk::TreeView] [Gtk::TreeViewColumn] [Gtk::TreeSelection]