Skip to main content

sourceview5/auto/
file_saver.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from
3// from gir-files (https://github.com/gtk-rs/gir-files)
4// DO NOT EDIT
5
6use crate::{Buffer, CompressionType, Encoding, File, FileSaverFlags, NewlineType, ffi};
7use glib::{
8    prelude::*,
9    signal::{SignalHandlerId, connect_raw},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    #[doc(alias = "GtkSourceFileSaver")]
16    pub struct FileSaver(Object<ffi::GtkSourceFileSaver, ffi::GtkSourceFileSaverClass>);
17
18    match fn {
19        type_ => || ffi::gtk_source_file_saver_get_type(),
20    }
21}
22
23impl FileSaver {
24    #[doc(alias = "gtk_source_file_saver_new")]
25    pub fn new(buffer: &impl IsA<Buffer>, file: &impl IsA<File>) -> FileSaver {
26        skip_assert_initialized!();
27        unsafe {
28            from_glib_full(ffi::gtk_source_file_saver_new(
29                buffer.as_ref().to_glib_none().0,
30                file.as_ref().to_glib_none().0,
31            ))
32        }
33    }
34
35    #[doc(alias = "gtk_source_file_saver_new_with_target")]
36    #[doc(alias = "new_with_target")]
37    pub fn with_target(
38        buffer: &impl IsA<Buffer>,
39        file: &impl IsA<File>,
40        target_location: &impl IsA<gio::File>,
41    ) -> FileSaver {
42        skip_assert_initialized!();
43        unsafe {
44            from_glib_full(ffi::gtk_source_file_saver_new_with_target(
45                buffer.as_ref().to_glib_none().0,
46                file.as_ref().to_glib_none().0,
47                target_location.as_ref().to_glib_none().0,
48            ))
49        }
50    }
51
52    // rustdoc-stripper-ignore-next
53    /// Creates a new builder-pattern struct instance to construct [`FileSaver`] objects.
54    ///
55    /// This method returns an instance of [`FileSaverBuilder`](crate::builders::FileSaverBuilder) which can be used to create [`FileSaver`] objects.
56    pub fn builder() -> FileSaverBuilder {
57        FileSaverBuilder::new()
58    }
59
60    #[doc(alias = "gtk_source_file_saver_get_buffer")]
61    #[doc(alias = "get_buffer")]
62    pub fn buffer(&self) -> Buffer {
63        unsafe { from_glib_none(ffi::gtk_source_file_saver_get_buffer(self.to_glib_none().0)) }
64    }
65
66    #[doc(alias = "gtk_source_file_saver_get_compression_type")]
67    #[doc(alias = "get_compression_type")]
68    #[doc(alias = "compression-type")]
69    pub fn compression_type(&self) -> CompressionType {
70        unsafe {
71            from_glib(ffi::gtk_source_file_saver_get_compression_type(
72                self.to_glib_none().0,
73            ))
74        }
75    }
76
77    #[doc(alias = "gtk_source_file_saver_get_encoding")]
78    #[doc(alias = "get_encoding")]
79    pub fn encoding(&self) -> Encoding {
80        unsafe {
81            from_glib_none(ffi::gtk_source_file_saver_get_encoding(
82                self.to_glib_none().0,
83            ))
84        }
85    }
86
87    #[doc(alias = "gtk_source_file_saver_get_file")]
88    #[doc(alias = "get_file")]
89    pub fn file(&self) -> File {
90        unsafe { from_glib_none(ffi::gtk_source_file_saver_get_file(self.to_glib_none().0)) }
91    }
92
93    #[doc(alias = "gtk_source_file_saver_get_flags")]
94    #[doc(alias = "get_flags")]
95    pub fn flags(&self) -> FileSaverFlags {
96        unsafe { from_glib(ffi::gtk_source_file_saver_get_flags(self.to_glib_none().0)) }
97    }
98
99    #[doc(alias = "gtk_source_file_saver_get_location")]
100    #[doc(alias = "get_location")]
101    pub fn location(&self) -> gio::File {
102        unsafe {
103            from_glib_none(ffi::gtk_source_file_saver_get_location(
104                self.to_glib_none().0,
105            ))
106        }
107    }
108
109    #[doc(alias = "gtk_source_file_saver_get_newline_type")]
110    #[doc(alias = "get_newline_type")]
111    #[doc(alias = "newline-type")]
112    pub fn newline_type(&self) -> NewlineType {
113        unsafe {
114            from_glib(ffi::gtk_source_file_saver_get_newline_type(
115                self.to_glib_none().0,
116            ))
117        }
118    }
119
120    #[doc(alias = "gtk_source_file_saver_set_compression_type")]
121    #[doc(alias = "compression-type")]
122    pub fn set_compression_type(&self, compression_type: CompressionType) {
123        unsafe {
124            ffi::gtk_source_file_saver_set_compression_type(
125                self.to_glib_none().0,
126                compression_type.into_glib(),
127            );
128        }
129    }
130
131    #[doc(alias = "gtk_source_file_saver_set_encoding")]
132    #[doc(alias = "encoding")]
133    pub fn set_encoding(&self, encoding: Option<&Encoding>) {
134        unsafe {
135            ffi::gtk_source_file_saver_set_encoding(
136                self.to_glib_none().0,
137                encoding.to_glib_none().0,
138            );
139        }
140    }
141
142    #[doc(alias = "gtk_source_file_saver_set_flags")]
143    #[doc(alias = "flags")]
144    pub fn set_flags(&self, flags: FileSaverFlags) {
145        unsafe {
146            ffi::gtk_source_file_saver_set_flags(self.to_glib_none().0, flags.into_glib());
147        }
148    }
149
150    #[doc(alias = "gtk_source_file_saver_set_newline_type")]
151    #[doc(alias = "newline-type")]
152    pub fn set_newline_type(&self, newline_type: NewlineType) {
153        unsafe {
154            ffi::gtk_source_file_saver_set_newline_type(
155                self.to_glib_none().0,
156                newline_type.into_glib(),
157            );
158        }
159    }
160
161    #[doc(alias = "compression-type")]
162    pub fn connect_compression_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
163        unsafe extern "C" fn notify_compression_type_trampoline<F: Fn(&FileSaver) + 'static>(
164            this: *mut ffi::GtkSourceFileSaver,
165            _param_spec: glib::ffi::gpointer,
166            f: glib::ffi::gpointer,
167        ) {
168            unsafe {
169                let f: &F = &*(f as *const F);
170                f(&from_glib_borrow(this))
171            }
172        }
173        unsafe {
174            let f: Box_<F> = Box_::new(f);
175            connect_raw(
176                self.as_ptr() as *mut _,
177                c"notify::compression-type".as_ptr(),
178                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
179                    notify_compression_type_trampoline::<F> as *const (),
180                )),
181                Box_::into_raw(f),
182            )
183        }
184    }
185
186    #[doc(alias = "encoding")]
187    pub fn connect_encoding_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
188        unsafe extern "C" fn notify_encoding_trampoline<F: Fn(&FileSaver) + 'static>(
189            this: *mut ffi::GtkSourceFileSaver,
190            _param_spec: glib::ffi::gpointer,
191            f: glib::ffi::gpointer,
192        ) {
193            unsafe {
194                let f: &F = &*(f as *const F);
195                f(&from_glib_borrow(this))
196            }
197        }
198        unsafe {
199            let f: Box_<F> = Box_::new(f);
200            connect_raw(
201                self.as_ptr() as *mut _,
202                c"notify::encoding".as_ptr(),
203                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
204                    notify_encoding_trampoline::<F> as *const (),
205                )),
206                Box_::into_raw(f),
207            )
208        }
209    }
210
211    #[doc(alias = "flags")]
212    pub fn connect_flags_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
213        unsafe extern "C" fn notify_flags_trampoline<F: Fn(&FileSaver) + 'static>(
214            this: *mut ffi::GtkSourceFileSaver,
215            _param_spec: glib::ffi::gpointer,
216            f: glib::ffi::gpointer,
217        ) {
218            unsafe {
219                let f: &F = &*(f as *const F);
220                f(&from_glib_borrow(this))
221            }
222        }
223        unsafe {
224            let f: Box_<F> = Box_::new(f);
225            connect_raw(
226                self.as_ptr() as *mut _,
227                c"notify::flags".as_ptr(),
228                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
229                    notify_flags_trampoline::<F> as *const (),
230                )),
231                Box_::into_raw(f),
232            )
233        }
234    }
235
236    #[doc(alias = "newline-type")]
237    pub fn connect_newline_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
238        unsafe extern "C" fn notify_newline_type_trampoline<F: Fn(&FileSaver) + 'static>(
239            this: *mut ffi::GtkSourceFileSaver,
240            _param_spec: glib::ffi::gpointer,
241            f: glib::ffi::gpointer,
242        ) {
243            unsafe {
244                let f: &F = &*(f as *const F);
245                f(&from_glib_borrow(this))
246            }
247        }
248        unsafe {
249            let f: Box_<F> = Box_::new(f);
250            connect_raw(
251                self.as_ptr() as *mut _,
252                c"notify::newline-type".as_ptr(),
253                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
254                    notify_newline_type_trampoline::<F> as *const (),
255                )),
256                Box_::into_raw(f),
257            )
258        }
259    }
260}
261
262impl Default for FileSaver {
263    fn default() -> Self {
264        glib::object::Object::new::<Self>()
265    }
266}
267
268// rustdoc-stripper-ignore-next
269/// A [builder-pattern] type to construct [`FileSaver`] objects.
270///
271/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
272#[must_use = "The builder must be built to be used"]
273pub struct FileSaverBuilder {
274    builder: glib::object::ObjectBuilder<'static, FileSaver>,
275}
276
277impl FileSaverBuilder {
278    fn new() -> Self {
279        Self {
280            builder: glib::object::Object::builder(),
281        }
282    }
283
284    pub fn buffer(self, buffer: &impl IsA<Buffer>) -> Self {
285        Self {
286            builder: self.builder.property("buffer", buffer.clone().upcast()),
287        }
288    }
289
290    pub fn compression_type(self, compression_type: CompressionType) -> Self {
291        Self {
292            builder: self.builder.property("compression-type", compression_type),
293        }
294    }
295
296    pub fn encoding(self, encoding: &Encoding) -> Self {
297        Self {
298            builder: self.builder.property("encoding", encoding),
299        }
300    }
301
302    pub fn file(self, file: &impl IsA<File>) -> Self {
303        Self {
304            builder: self.builder.property("file", file.clone().upcast()),
305        }
306    }
307
308    pub fn flags(self, flags: FileSaverFlags) -> Self {
309        Self {
310            builder: self.builder.property("flags", flags),
311        }
312    }
313
314    pub fn location(self, location: &impl IsA<gio::File>) -> Self {
315        Self {
316            builder: self.builder.property("location", location.clone().upcast()),
317        }
318    }
319
320    pub fn newline_type(self, newline_type: NewlineType) -> Self {
321        Self {
322            builder: self.builder.property("newline-type", newline_type),
323        }
324    }
325
326    // rustdoc-stripper-ignore-next
327    /// Build the [`FileSaver`].
328    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
329    pub fn build(self) -> FileSaver {
330        assert_initialized_main_thread!();
331        self.builder.build()
332    }
333}