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
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT

use glib::object::Cast;
use glib::object::IsA;
use glib::translate::*;
use glib::StaticType;
use glib::ToValue;
use std::fmt;

glib::wrapper! {
    pub struct Mark(Object<ffi::GtkSourceMark, ffi::GtkSourceMarkClass>) @extends gtk::TextMark;

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

impl Mark {
    /// Creates a text mark. Add it to a buffer using `gtk::TextBufferExt::add_mark`.
    /// If name is NULL, the mark is anonymous; otherwise, the mark can be retrieved
    /// by name using `gtk::TextBufferExt::get_mark`.
    /// Normally marks are created using the utility function
    /// `BufferExt::create_source_mark`.
    /// ## `name`
    /// Name of the `Mark`, can be NULL when not using a name
    /// ## `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 `Mark` that can be added using `gtk::TextBufferExt::add_mark`.
    #[doc(alias = "gtk_source_mark_new")]
    pub fn new(name: &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,
            ))
        }
    }
}

#[derive(Clone, Default)]
pub struct MarkBuilder {
    category: Option<String>,
    left_gravity: Option<bool>,
    name: Option<String>,
}

impl MarkBuilder {
    pub fn new() -> Self {
        Self::default()
    }

    pub fn build(self) -> Mark {
        let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
        if let Some(ref category) = self.category {
            properties.push(("category", category));
        }
        if let Some(ref left_gravity) = self.left_gravity {
            properties.push(("left-gravity", left_gravity));
        }
        if let Some(ref name) = self.name {
            properties.push(("name", name));
        }
        let ret = glib::Object::new::<Mark>(&properties).expect("object new");
        ret
    }

    pub fn category(mut self, category: &str) -> Self {
        self.category = Some(category.to_string());
        self
    }

    pub fn left_gravity(mut self, left_gravity: bool) -> Self {
        self.left_gravity = Some(left_gravity);
        self
    }

    pub fn name(mut self, name: &str) -> Self {
        self.name = Some(name.to_string());
        self
    }
}

pub const NONE_MARK: Option<&Mark> = None;

/// Trait containing all `Mark` methods.
///
/// # Implementors
///
/// [`Mark`](struct.Mark.html)
pub trait MarkExt: 'static {
    /// Returns the mark category.
    ///
    /// # Returns
    ///
    /// the category of the `Mark`.
    #[doc(alias = "gtk_source_mark_get_category")]
    fn get_category(&self) -> Option<glib::GString>;

    /// Returns the next `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 `Mark`, or `None`.
    #[doc(alias = "gtk_source_mark_next")]
    fn next(&self, category: Option<&str>) -> Option<Mark>;

    /// Returns the previous `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 `Mark`, or `None`.
    #[doc(alias = "gtk_source_mark_prev")]
    fn prev(&self, category: &str) -> Option<Mark>;
}

impl<O: IsA<Mark>> MarkExt for O {
    fn get_category(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::gtk_source_mark_get_category(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    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,
            ))
        }
    }

    fn prev(&self, category: &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 fmt::Display for Mark {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("Mark")
    }
}