1use crate::{CompressionType, Encoding, 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 = "GtkSourceFile")]
16 pub struct File(Object<ffi::GtkSourceFile, ffi::GtkSourceFileClass>);
17
18 match fn {
19 type_ => || ffi::gtk_source_file_get_type(),
20 }
21}
22
23impl File {
24 pub const NONE: Option<&'static File> = None;
25
26 #[doc(alias = "gtk_source_file_new")]
27 pub fn new() -> File {
28 assert_initialized_main_thread!();
29 unsafe { from_glib_full(ffi::gtk_source_file_new()) }
30 }
31
32 pub fn builder() -> FileBuilder {
37 FileBuilder::new()
38 }
39}
40
41impl Default for File {
42 fn default() -> Self {
43 Self::new()
44 }
45}
46
47#[must_use = "The builder must be built to be used"]
52pub struct FileBuilder {
53 builder: glib::object::ObjectBuilder<'static, File>,
54}
55
56impl FileBuilder {
57 fn new() -> Self {
58 Self {
59 builder: glib::object::Object::builder(),
60 }
61 }
62
63 pub fn location(self, location: &impl IsA<gio::File>) -> Self {
64 Self {
65 builder: self.builder.property("location", location.clone().upcast()),
66 }
67 }
68
69 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
72 pub fn build(self) -> File {
73 assert_initialized_main_thread!();
74 self.builder.build()
75 }
76}
77
78pub trait SourceFileExt: IsA<File> + 'static {
79 #[doc(alias = "gtk_source_file_check_file_on_disk")]
80 fn check_file_on_disk(&self) {
81 unsafe {
82 ffi::gtk_source_file_check_file_on_disk(self.as_ref().to_glib_none().0);
83 }
84 }
85
86 #[doc(alias = "gtk_source_file_get_compression_type")]
87 #[doc(alias = "get_compression_type")]
88 #[doc(alias = "compression-type")]
89 fn compression_type(&self) -> CompressionType {
90 unsafe {
91 from_glib(ffi::gtk_source_file_get_compression_type(
92 self.as_ref().to_glib_none().0,
93 ))
94 }
95 }
96
97 #[doc(alias = "gtk_source_file_get_encoding")]
98 #[doc(alias = "get_encoding")]
99 fn encoding(&self) -> Encoding {
100 unsafe {
101 from_glib_none(ffi::gtk_source_file_get_encoding(
102 self.as_ref().to_glib_none().0,
103 ))
104 }
105 }
106
107 #[doc(alias = "gtk_source_file_get_location")]
108 #[doc(alias = "get_location")]
109 fn location(&self) -> gio::File {
110 unsafe {
111 from_glib_none(ffi::gtk_source_file_get_location(
112 self.as_ref().to_glib_none().0,
113 ))
114 }
115 }
116
117 #[doc(alias = "gtk_source_file_get_newline_type")]
118 #[doc(alias = "get_newline_type")]
119 #[doc(alias = "newline-type")]
120 fn newline_type(&self) -> NewlineType {
121 unsafe {
122 from_glib(ffi::gtk_source_file_get_newline_type(
123 self.as_ref().to_glib_none().0,
124 ))
125 }
126 }
127
128 #[doc(alias = "gtk_source_file_is_deleted")]
129 fn is_deleted(&self) -> bool {
130 unsafe {
131 from_glib(ffi::gtk_source_file_is_deleted(
132 self.as_ref().to_glib_none().0,
133 ))
134 }
135 }
136
137 #[doc(alias = "gtk_source_file_is_externally_modified")]
138 fn is_externally_modified(&self) -> bool {
139 unsafe {
140 from_glib(ffi::gtk_source_file_is_externally_modified(
141 self.as_ref().to_glib_none().0,
142 ))
143 }
144 }
145
146 #[doc(alias = "gtk_source_file_is_local")]
147 fn is_local(&self) -> bool {
148 unsafe {
149 from_glib(ffi::gtk_source_file_is_local(
150 self.as_ref().to_glib_none().0,
151 ))
152 }
153 }
154
155 #[doc(alias = "gtk_source_file_is_readonly")]
156 fn is_readonly(&self) -> bool {
157 unsafe {
158 from_glib(ffi::gtk_source_file_is_readonly(
159 self.as_ref().to_glib_none().0,
160 ))
161 }
162 }
163
164 #[doc(alias = "gtk_source_file_set_location")]
165 #[doc(alias = "location")]
166 fn set_location(&self, location: Option<&impl IsA<gio::File>>) {
167 unsafe {
168 ffi::gtk_source_file_set_location(
169 self.as_ref().to_glib_none().0,
170 location.map(|p| p.as_ref()).to_glib_none().0,
171 );
172 }
173 }
174
175 #[doc(alias = "gtk_source_file_set_mount_operation_factory")]
176 fn set_mount_operation_factory<P: Fn(&File) -> gio::MountOperation + 'static>(
177 &self,
178 callback: P,
179 ) {
180 let callback_data: Box_<P> = Box_::new(callback);
181 unsafe extern "C" fn callback_func<P: Fn(&File) -> gio::MountOperation + 'static>(
182 file: *mut ffi::GtkSourceFile,
183 userdata: glib::ffi::gpointer,
184 ) -> *mut gio::ffi::GMountOperation {
185 unsafe {
186 let file = from_glib_borrow(file);
187 let callback = &*(userdata as *mut P);
188 (*callback)(&file)
189 .to_glib_none()
191 .0
192 }
193 }
194 let callback = Some(callback_func::<P> as _);
195 unsafe extern "C" fn notify_func<P: Fn(&File) -> gio::MountOperation + 'static>(
196 data: glib::ffi::gpointer,
197 ) {
198 unsafe {
199 let _callback = Box_::from_raw(data as *mut P);
200 }
201 }
202 let destroy_call3 = Some(notify_func::<P> as _);
203 let super_callback0: Box_<P> = callback_data;
204 unsafe {
205 ffi::gtk_source_file_set_mount_operation_factory(
206 self.as_ref().to_glib_none().0,
207 callback,
208 Box_::into_raw(super_callback0) as *mut _,
209 destroy_call3,
210 );
211 }
212 }
213
214 #[doc(alias = "read-only")]
215 fn is_read_only(&self) -> bool {
216 ObjectExt::property(self.as_ref(), "read-only")
217 }
218
219 #[doc(alias = "compression-type")]
220 fn connect_compression_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
221 unsafe extern "C" fn notify_compression_type_trampoline<
222 P: IsA<File>,
223 F: Fn(&P) + 'static,
224 >(
225 this: *mut ffi::GtkSourceFile,
226 _param_spec: glib::ffi::gpointer,
227 f: glib::ffi::gpointer,
228 ) {
229 unsafe {
230 let f: &F = &*(f as *const F);
231 f(File::from_glib_borrow(this).unsafe_cast_ref())
232 }
233 }
234 unsafe {
235 let f: Box_<F> = Box_::new(f);
236 connect_raw(
237 self.as_ptr() as *mut _,
238 c"notify::compression-type".as_ptr(),
239 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
240 notify_compression_type_trampoline::<Self, F> as *const (),
241 )),
242 Box_::into_raw(f),
243 )
244 }
245 }
246
247 #[doc(alias = "encoding")]
248 fn connect_encoding_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
249 unsafe extern "C" fn notify_encoding_trampoline<P: IsA<File>, F: Fn(&P) + 'static>(
250 this: *mut ffi::GtkSourceFile,
251 _param_spec: glib::ffi::gpointer,
252 f: glib::ffi::gpointer,
253 ) {
254 unsafe {
255 let f: &F = &*(f as *const F);
256 f(File::from_glib_borrow(this).unsafe_cast_ref())
257 }
258 }
259 unsafe {
260 let f: Box_<F> = Box_::new(f);
261 connect_raw(
262 self.as_ptr() as *mut _,
263 c"notify::encoding".as_ptr(),
264 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
265 notify_encoding_trampoline::<Self, F> as *const (),
266 )),
267 Box_::into_raw(f),
268 )
269 }
270 }
271
272 #[doc(alias = "location")]
273 fn connect_location_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
274 unsafe extern "C" fn notify_location_trampoline<P: IsA<File>, F: Fn(&P) + 'static>(
275 this: *mut ffi::GtkSourceFile,
276 _param_spec: glib::ffi::gpointer,
277 f: glib::ffi::gpointer,
278 ) {
279 unsafe {
280 let f: &F = &*(f as *const F);
281 f(File::from_glib_borrow(this).unsafe_cast_ref())
282 }
283 }
284 unsafe {
285 let f: Box_<F> = Box_::new(f);
286 connect_raw(
287 self.as_ptr() as *mut _,
288 c"notify::location".as_ptr(),
289 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
290 notify_location_trampoline::<Self, F> as *const (),
291 )),
292 Box_::into_raw(f),
293 )
294 }
295 }
296
297 #[doc(alias = "newline-type")]
298 fn connect_newline_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
299 unsafe extern "C" fn notify_newline_type_trampoline<P: IsA<File>, F: Fn(&P) + 'static>(
300 this: *mut ffi::GtkSourceFile,
301 _param_spec: glib::ffi::gpointer,
302 f: glib::ffi::gpointer,
303 ) {
304 unsafe {
305 let f: &F = &*(f as *const F);
306 f(File::from_glib_borrow(this).unsafe_cast_ref())
307 }
308 }
309 unsafe {
310 let f: Box_<F> = Box_::new(f);
311 connect_raw(
312 self.as_ptr() as *mut _,
313 c"notify::newline-type".as_ptr(),
314 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
315 notify_newline_type_trampoline::<Self, F> as *const (),
316 )),
317 Box_::into_raw(f),
318 )
319 }
320 }
321
322 #[doc(alias = "read-only")]
323 fn connect_read_only_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
324 unsafe extern "C" fn notify_read_only_trampoline<P: IsA<File>, F: Fn(&P) + 'static>(
325 this: *mut ffi::GtkSourceFile,
326 _param_spec: glib::ffi::gpointer,
327 f: glib::ffi::gpointer,
328 ) {
329 unsafe {
330 let f: &F = &*(f as *const F);
331 f(File::from_glib_borrow(this).unsafe_cast_ref())
332 }
333 }
334 unsafe {
335 let f: Box_<F> = Box_::new(f);
336 connect_raw(
337 self.as_ptr() as *mut _,
338 c"notify::read-only".as_ptr(),
339 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
340 notify_read_only_trampoline::<Self, F> as *const (),
341 )),
342 Box_::into_raw(f),
343 )
344 }
345 }
346}
347
348impl<O: IsA<File>> SourceFileExt for O {}