1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::Buildable;
use glib::translate::*;
use std::fmt;

glib::wrapper! {
    /// [`StringList`][crate::StringList] is a list model that wraps an array of strings.
    ///
    /// The objects in the model have a "string" property.
    ///
    /// [`StringList`][crate::StringList] is well-suited for any place where you would
    /// typically use a `char*[]`, but need a list model.
    ///
    /// # GtkStringList as GtkBuildable
    ///
    /// The [`StringList`][crate::StringList] implementation of the [`Buildable`][crate::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 [`StringList`][crate::StringList]
    ///
    /// ```xml
    /// <object class="GtkStringList">
    ///   <items>
    ///     <item translatable="yes">Factory</item>
    ///     <item translatable="yes">Home</item>
    ///     <item translatable="yes">Subway</item>
    ///   </items>
    /// </object>
    /// ```
    ///
    /// ## Properties
    ///
    ///
    /// #### `strings`
    ///  Writeable | Construct Only
    ///
    /// # Implements
    ///
    /// [`trait@glib::ObjectExt`], [`trait@gio::prelude::ListModelExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt]
    #[doc(alias = "GtkStringList")]
    pub struct StringList(Object<ffi::GtkStringList, ffi::GtkStringListClass>) @implements gio::ListModel, Buildable;

    match fn {
        type_ => || ffi::gtk_string_list_get_type(),
    }
}

impl StringList {
    /// Creates a new [`StringList`][crate::StringList] with the given @strings.
    /// ## `strings`
    /// The strings to put in the model
    ///
    /// # Returns
    ///
    /// a new [`StringList`][crate::StringList]
    #[doc(alias = "gtk_string_list_new")]
    pub fn new(strings: &[&str]) -> StringList {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(ffi::gtk_string_list_new(strings.to_glib_none().0)) }
    }

    /// Appends @string to @self.
    ///
    /// The @string will be copied. See
    /// `Gtk::StringList::take()` for a way to avoid that.
    /// ## `string`
    /// the string to insert
    #[doc(alias = "gtk_string_list_append")]
    pub fn append(&self, string: &str) {
        unsafe {
            ffi::gtk_string_list_append(self.to_glib_none().0, string.to_glib_none().0);
        }
    }

    /// Gets the string that is at @position in @self.
    ///
    /// If @self does not contain @position items, [`None`] is returned.
    ///
    /// This function returns the const char *. To get the
    /// object wrapping it, use g_list_model_get_item().
    /// ## `position`
    /// the position to get the string for
    ///
    /// # Returns
    ///
    /// the string at the given position
    #[doc(alias = "gtk_string_list_get_string")]
    #[doc(alias = "get_string")]
    pub fn string(&self, position: u32) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::gtk_string_list_get_string(
                self.to_glib_none().0,
                position,
            ))
        }
    }

    /// Removes the string at @position from @self.
    ///
    /// @position must be smaller than the current
    /// length of the list.
    /// ## `position`
    /// the position of the string that is to be removed
    #[doc(alias = "gtk_string_list_remove")]
    pub fn remove(&self, position: u32) {
        unsafe {
            ffi::gtk_string_list_remove(self.to_glib_none().0, position);
        }
    }

    /// Changes @self by removing @n_removals strings and adding @additions
    /// to it.
    ///
    /// This function is more efficient than [`append()`][Self::append()]
    /// and [`remove()`][Self::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).
    /// ## `position`
    /// the position at which to make the change
    /// ## `n_removals`
    /// the number of strings to remove
    /// ## `additions`
    /// The strings to add
    #[doc(alias = "gtk_string_list_splice")]
    pub fn splice(&self, position: u32, n_removals: u32, additions: &[&str]) {
        unsafe {
            ffi::gtk_string_list_splice(
                self.to_glib_none().0,
                position,
                n_removals,
                additions.to_glib_none().0,
            );
        }
    }
}

impl fmt::Display for StringList {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("StringList")
    }
}