
Gnome::Gtk4::StringList
Description
Gnome::Gtk4::StringList is a list model that wraps an array of strings.
The objects in the model are of type Gnome::Gtk4::StringObject and have a "string" property that can be used inside expressions.
Gnome::Gtk4::StringList is well-suited for any place where you would typically use a string, but need a list model.
GtkStringList as GtkBuildable
The Gnome::Gtk4::StringList implementation of the Gnome::Gtk4::R-Buildable interface supports adding items directly using the `<items>` element and specifying `<item>` elements for each item. Each `<item>` element supports the regular translation attributes “translatable”, “context” and “comments”.
Here is a UI definition fragment specifying a Gnome::Gtk4::StringList
<object class="GtkStringList">
<items>
<item translatable="yes">Factory</item>
<item translatable="yes">Home</item>
<item translatable="yes">Subway</item>
</items>
</object>
Uml Diagram

Example
# Example use of module Gnome::Gtk4::StringList
my Gnome::Gtk4::StringList $stringlist; $stringlist .= new-stringlist([ 'a string', '2nd string']); say $stringlist.get-string(1); # Shows '2nd string'
Class initialization
new
:native-object
Create an object using a native object from an object of the same type found elsewhere. See also Gnome::N::TopLevelSupportClass.
multi method new ( N-Object() :$native-object! )
new-stringlist
Creates a new Gnome::Gtk4::StringList with the given $strings.
method new-stringlist ( Array[Str] $strings --> Gnome::Gtk4::StringList )
$strings; The strings to put in the model.
Methods
append
Appends $string to the string list.
The $string will be copied.
method append ( Str $string )
$string; the string to insert.
Example
Create an empty list and append 10 strings to it.
my Gnome::Gtk4::StringList $stringlist;
$stringlist .= new-stringlist([]);
for ^10 -> $i {
$stringlist.append("string$i");
}
say $stringlist.get-string(3); # Shows 'string3'
get-string
Gets the string that is at $position in the stringlist.
If the stringlist does not contain $position items, undefined is returned.
This function returns an Str. To get the object wrapping it, use .get-object() from R-ListModel in Gio. That object should be of type Gnome::Gtk4::StringObject.
method get-string ( UInt() $position --> Str )
$position; the position to get the string for.
Return value; the string at the given position.
remove
Removes the string at $position from the stringlist. $position must be smaller than the current length of the list.
method remove ( UInt() $position )
$position; the position of the string that is to be removed.
splice
Changes the stringlist by removing $n-removals strings and adding $additions to it.
This function is more efficient than .append() and .remove(), because it only emits the items-changed signal once for the change.
This function copies the strings in $additions.
The parameters $position and $n-removals must be correct (ie: $position + $n-removals must be less than or equal to the length of the list at the time this function is called).
method splice ( UInt() $position, UInt() $n-removals, Array[Str] $additions )
$position; the position at which to make the change.
$n-removals; the number of strings to remove.
$additions; The strings to add.
About my projects, examples and tutorials