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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT

use crate::ffi;
use glib::{prelude::*, translate::*};

glib::wrapper! {
    /// Mark object for [`Buffer`][crate::Buffer].
    ///
    /// A [`Mark`][crate::Mark] marks a position in the text where you want to display
    /// additional info. It is based on [`gtk::TextMark`][crate::gtk::TextMark] and thus is still valid after
    /// the text has changed though its position may change.
    ///
    /// [`Mark`][crate::Mark]s are organized in categories which you have to set
    /// when you create the mark. Each category can have a priority, a pixbuf and
    /// other associated attributes. See [`ViewExt::set_mark_attributes()`][crate::prelude::ViewExt::set_mark_attributes()].
    /// The pixbuf will be displayed in the margin at the line where the mark
    /// residents if the [`show-line-marks`][struct@crate::View#show-line-marks] property is set to [`true`]. If
    /// there are multiple marks in the same line, the pixbufs will be drawn on top
    /// of each other. The mark with the highest priority will be drawn on top.
    ///
    /// ## Properties
    ///
    ///
    /// #### `category`
    ///  The category of the [`Mark`][crate::Mark], classifies the mark and controls
    /// which pixbuf is used and with which priority it is drawn.
    ///
    /// Readable | Writeable | Construct Only
    /// <details><summary><h4>TextMark</h4></summary>
    ///
    ///
    /// #### `left-gravity`
    ///  Whether the mark has left gravity.
    ///
    /// When text is inserted at the mark’s current location, if the mark
    /// has left gravity it will be moved to the left of the newly-inserted
    /// text, otherwise to the right.
    ///
    /// Readable | Writeable | Construct Only
    ///
    ///
    /// #### `name`
    ///  The name of the mark or [`None`] if the mark is anonymous.
    ///
    /// Readable | Writeable | Construct Only
    /// </details>
    ///
    /// # Implements
    ///
    /// [`MarkExt`][trait@crate::prelude::MarkExt], [`trait@gtk::prelude::TextMarkExt`], [`trait@glib::ObjectExt`]
    #[doc(alias = "GtkSourceMark")]
    pub struct Mark(Object<ffi::GtkSourceMark, ffi::GtkSourceMarkClass>) @extends gtk::TextMark;

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

impl Mark {
    pub const NONE: Option<&'static Mark> = None;

    /// Creates a text mark.
    ///
    /// Add it to a buffer using [`TextBufferExtManual::add_mark()`][crate::gtk::prelude::TextBufferExtManual::add_mark()].
    /// If name is NULL, the mark is anonymous; otherwise, the mark can be retrieved
    /// by name using [`TextBufferExtManual::mark()`][crate::gtk::prelude::TextBufferExtManual::mark()].
    /// Normally marks are created using the utility function
    /// [`BufferExt::create_source_mark()`][crate::prelude::BufferExt::create_source_mark()].
    /// ## `name`
    /// Name of the #GtkSourceMark or [`None`]
    /// ## `category`
    /// is used to classify marks according to common characteristics
    ///   (e.g. all the marks representing a bookmark could belong to the "bookmark"
    ///   category, or all the marks representing a compilation error could belong
    ///   to "error" category).
    ///
    /// # Returns
    ///
    /// a new #GtkSourceMark that can be added using [`TextBufferExtManual::add_mark()`][crate::gtk::prelude::TextBufferExtManual::add_mark()].
    #[doc(alias = "gtk_source_mark_new")]
    pub fn new(name: Option<&str>, category: &str) -> Mark {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::gtk_source_mark_new(
                name.to_glib_none().0,
                category.to_glib_none().0,
            ))
        }
    }

    // rustdoc-stripper-ignore-next
    /// Creates a new builder-pattern struct instance to construct [`Mark`] objects.
    ///
    /// This method returns an instance of [`MarkBuilder`](crate::builders::MarkBuilder) which can be used to create [`Mark`] objects.
    pub fn builder() -> MarkBuilder {
        MarkBuilder::new()
    }
}

impl Default for Mark {
    fn default() -> Self {
        glib::object::Object::new::<Self>()
    }
}

// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`Mark`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct MarkBuilder {
    builder: glib::object::ObjectBuilder<'static, Mark>,
}

impl MarkBuilder {
    fn new() -> Self {
        Self {
            builder: glib::object::Object::builder(),
        }
    }

    /// The category of the [`Mark`][crate::Mark], classifies the mark and controls
    /// which pixbuf is used and with which priority it is drawn.
    pub fn category(self, category: impl Into<glib::GString>) -> Self {
        Self {
            builder: self.builder.property("category", category.into()),
        }
    }

    /// Whether the mark has left gravity.
    ///
    /// When text is inserted at the mark’s current location, if the mark
    /// has left gravity it will be moved to the left of the newly-inserted
    /// text, otherwise to the right.
    pub fn left_gravity(self, left_gravity: bool) -> Self {
        Self {
            builder: self.builder.property("left-gravity", left_gravity),
        }
    }

    /// The name of the mark or [`None`] if the mark is anonymous.
    pub fn name(self, name: impl Into<glib::GString>) -> Self {
        Self {
            builder: self.builder.property("name", name.into()),
        }
    }

    // rustdoc-stripper-ignore-next
    /// Build the [`Mark`].
    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
    pub fn build(self) -> Mark {
        self.builder.build()
    }
}

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::Mark>> Sealed for T {}
}

/// Trait containing all [`struct@Mark`] methods.
///
/// # Implementors
///
/// [`Mark`][struct@crate::Mark]
pub trait MarkExt: IsA<Mark> + sealed::Sealed + 'static {
    /// Returns the mark category.
    ///
    /// # Returns
    ///
    /// the category of the #GtkSourceMark.
    #[doc(alias = "gtk_source_mark_get_category")]
    #[doc(alias = "get_category")]
    fn category(&self) -> glib::GString {
        unsafe {
            from_glib_none(ffi::gtk_source_mark_get_category(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Returns the next [`Mark`][crate::Mark] in the buffer or [`None`] if the mark
    /// was not added to a buffer.
    ///
    ///  If there is no next mark, [`None`] will be returned.
    ///
    /// If @category is [`None`], looks for marks of any category.
    /// ## `category`
    /// a string specifying the mark category, or [`None`].
    ///
    /// # Returns
    ///
    /// the next #GtkSourceMark, or [`None`].
    #[doc(alias = "gtk_source_mark_next")]
    #[must_use]
    fn next(&self, category: Option<&str>) -> Option<Mark> {
        unsafe {
            from_glib_none(ffi::gtk_source_mark_next(
                self.as_ref().to_glib_none().0,
                category.to_glib_none().0,
            ))
        }
    }

    /// Returns the previous [`Mark`][crate::Mark] in the buffer or [`None`] if the mark
    /// was not added to a buffer.
    ///
    /// If there is no previous mark, [`None`] is returned.
    ///
    /// If @category is [`None`], looks for marks of any category
    /// ## `category`
    /// a string specifying the mark category, or [`None`].
    ///
    /// # Returns
    ///
    /// the previous #GtkSourceMark, or [`None`].
    #[doc(alias = "gtk_source_mark_prev")]
    #[must_use]
    fn prev(&self, category: Option<&str>) -> Option<Mark> {
        unsafe {
            from_glib_none(ffi::gtk_source_mark_prev(
                self.as_ref().to_glib_none().0,
                category.to_glib_none().0,
            ))
        }
    }
}

impl<O: IsA<Mark>> MarkExt for O {}