1.192 <GtkStringList>

Class: <GtkStringList>

It derives from <GObject>.

A list model that wraps an array of strings.

The objects in the model are of type <GtkStringObject> and have a "string" property that can be used inside expressions.

<GtkStringList> is well-suited for any place where you would typically use a char*[], but need a list model.

GtkStringList as GtkBuildable

The <GtkStringList> implementation of the <GtkBuildable> 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 <GtkStringList>

<object class="GtkStringList">
  <items>
    <item translatable="yes">Factory</item>
    <item translatable="yes">Home</item>
    <item translatable="yes">Subway</item>
  </items>
</object>

Properties

Property: string-list:item-type self

The type of items. See list-model:get-item-type.

Its value is a class, or a GType number.

It is read only.

Property: string-list:n-items self

The number of items. See list-model:get-n-items.

Its value is an unsigned 32-bit integer.

It is read only.

Property: string-list:strings self

The strings in the model.

Its value is a list or vector, each a string, or #f.

It can only be set when the object is made, with #:strings. It cannot be read.

Procedures

Method: string-list:append self string
Method: append self string

Appends string to self.

The string will be copied. See string-list:take for a way to avoid that.

self

Passed: a <GtkStringList>.

a <GtkStringList>

string

Passed: a string.

the string to insert

Method: string-list:find self string ⇒ %return
Method: find self string ⇒ %return

Gets the position of the string in self.

If self does not contain string item, G_MAXUINT is returned.

self

Passed: a <GtkStringList>.

a <GtkStringList>

string

Passed: a string.

the string to find

%return

Returned: an unsigned 32-bit integer.

the position of the string

Method: string-list:get-string self position ⇒ %return
Method: get-string self position ⇒ %return

Gets the string that is at position in self.

If self does not contain position items, #f is returned.

This function returns the const char *. To get the object wrapping it, use list-model:get-item.

self

Passed: a <GtkStringList>.

a <GtkStringList>

position

Passed: an unsigned 32-bit integer.

the position to get the string for

%return

Returned: a string, or #f.

the string at the given position

Procedure: string-list:new [strings] ⇒ %return

Creates a new <GtkStringList> with the given strings.

strings

Passed, or left out: a list or vector, each a string, or #f.

The strings to put in the model

%return

Returned: a <GtkStringList>.

a new <GtkStringList>

Method: string-list:remove self position
Method: remove self position

Removes the string at position from self.

position must be smaller than the current length of the list.

self

Passed: a <GtkStringList>.

a <GtkStringList>

position

Passed: an unsigned 32-bit integer.

the position of the string that is to be removed

Method: string-list:splice self position n-removals [additions]
Method: splice self position n-removals [additions]

Changes self by removing n-removals strings and adding additions to it.

This function is more efficient than string-list:append and string-list: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).

self

Passed: a <GtkStringList>.

a <GtkStringList>

position

Passed: an unsigned 32-bit integer.

the position at which to make the change

n-removals

Passed: an unsigned 32-bit integer.

the number of strings to remove

additions

Passed, or left out: a list or vector, each a string, or #f.

The strings to add

Method: string-list:take self string
Method: take self string

Adds string to self at the end, and takes ownership of it.

This variant of string-list:append is convenient for formatting strings:

gtk_string_list_take (self, g_strdup_print ("%d dollars", lots));
self

Passed: a <GtkStringList>.

a <GtkStringList>

string

Passed: a string.

the string to insert