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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
// 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 crate::SnippetContext;
use glib::object::Cast;
use glib::object::ObjectType as ObjectType_;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use glib::StaticType;
use glib::ToValue;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;

glib::wrapper! {
    pub struct SnippetChunk(Object<ffi::GtkSourceSnippetChunk, ffi::GtkSourceSnippetChunkClass>);

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

impl SnippetChunk {
    /// Create a new `SnippetChunk` that can be added to
    /// a `Snippet`.
    ///
    /// Feature: `v5_0`
    ///
    #[cfg(any(feature = "v5_0", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v5_0")))]
    #[doc(alias = "gtk_source_snippet_chunk_new")]
    pub fn new() -> SnippetChunk {
        assert_initialized_main_thread!();
        unsafe { from_glib_none(ffi::gtk_source_snippet_chunk_new()) }
    }

    /// Copies the source snippet.
    ///
    /// Feature: `v5_0`
    ///
    ///
    /// # Returns
    ///
    /// A `SnippetChunk`
    #[cfg(any(feature = "v5_0", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v5_0")))]
    #[doc(alias = "gtk_source_snippet_chunk_copy")]
    pub fn copy(&self) -> Option<SnippetChunk> {
        unsafe { from_glib_full(ffi::gtk_source_snippet_chunk_copy(self.to_glib_none().0)) }
    }

    /// Gets the context for the snippet insertion.
    ///
    /// Feature: `v5_0`
    ///
    ///
    /// # Returns
    ///
    /// A `SnippetContext`
    #[cfg(any(feature = "v5_0", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v5_0")))]
    #[doc(alias = "gtk_source_snippet_chunk_get_context")]
    pub fn get_context(&self) -> Option<SnippetContext> {
        unsafe {
            from_glib_none(ffi::gtk_source_snippet_chunk_get_context(
                self.to_glib_none().0,
            ))
        }
    }

    /// Gets the `SnippetChunk:focus-position`.
    ///
    /// The focus-position is used to determine how many tabs it takes for the
    /// snippet to advanced to this chunk.
    ///
    /// A focus-position of zero will be the last focus position of the snippet
    /// and snippet editing ends when it has been reached.
    ///
    /// A focus-position of -1 means the chunk cannot be focused by the user.
    ///
    /// Feature: `v5_0`
    ///
    ///
    /// # Returns
    ///
    /// the focus-position
    #[cfg(any(feature = "v5_0", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v5_0")))]
    #[doc(alias = "gtk_source_snippet_chunk_get_focus_position")]
    pub fn get_focus_position(&self) -> i32 {
        unsafe { ffi::gtk_source_snippet_chunk_get_focus_position(self.to_glib_none().0) }
    }

    /// Gets the specification for the chunk.
    ///
    /// The specification is evaluated for variables when other chunks are edited
    /// within the snippet context. If the user has changed the text, the
    /// `SnippetChunk:text` and `SnippetChunk:text-set` properties
    /// are updated.
    ///
    /// Feature: `v5_0`
    ///
    ///
    /// # Returns
    ///
    /// the specification, if any
    #[cfg(any(feature = "v5_0", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v5_0")))]
    #[doc(alias = "gtk_source_snippet_chunk_get_spec")]
    pub fn get_spec(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::gtk_source_snippet_chunk_get_spec(
                self.to_glib_none().0,
            ))
        }
    }

    /// Gets the `SnippetChunk:text` property.
    ///
    /// The text property is updated when the user edits the text of the chunk.
    /// If it has not been edited, the `SnippetChunk:spec` property is
    /// returned.
    ///
    /// Feature: `v5_0`
    ///
    ///
    /// # Returns
    ///
    /// the text of the chunk
    #[cfg(any(feature = "v5_0", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v5_0")))]
    #[doc(alias = "gtk_source_snippet_chunk_get_text")]
    pub fn get_text(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::gtk_source_snippet_chunk_get_text(
                self.to_glib_none().0,
            ))
        }
    }

    /// Gets the `SnippetChunk:text-set` property.
    ///
    /// This is typically set when the user has edited a snippet chunk.
    ///
    /// Feature: `v5_0`
    ///
    #[cfg(any(feature = "v5_0", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v5_0")))]
    #[doc(alias = "gtk_source_snippet_chunk_get_text_set")]
    pub fn get_text_set(&self) -> bool {
        unsafe {
            from_glib(ffi::gtk_source_snippet_chunk_get_text_set(
                self.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "gtk_source_snippet_chunk_get_tooltip_text")]
    pub fn get_tooltip_text(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::gtk_source_snippet_chunk_get_tooltip_text(
                self.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "gtk_source_snippet_chunk_set_context")]
    pub fn set_context(&self, context: &SnippetContext) {
        unsafe {
            ffi::gtk_source_snippet_chunk_set_context(
                self.to_glib_none().0,
                context.to_glib_none().0,
            );
        }
    }

    /// Sets the `SnippetChunk:focus-position` property.
    ///
    /// The focus-position is used to determine how many tabs it takes for the
    /// snippet to advanced to this chunk.
    ///
    /// A focus-position of zero will be the last focus position of the snippet
    /// and snippet editing ends when it has been reached.
    ///
    /// A focus-position of -1 means the chunk cannot be focused by the user.
    ///
    /// Feature: `v5_0`
    ///
    /// ## `focus_position`
    /// the focus-position
    #[cfg(any(feature = "v5_0", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v5_0")))]
    #[doc(alias = "gtk_source_snippet_chunk_set_focus_position")]
    pub fn set_focus_position(&self, focus_position: i32) {
        unsafe {
            ffi::gtk_source_snippet_chunk_set_focus_position(self.to_glib_none().0, focus_position);
        }
    }

    /// Sets the specification for the chunk.
    ///
    /// The specification is evaluated for variables when other chunks are edited
    /// within the snippet context. If the user has changed the text, the
    /// `SnippetChunk:text` and `SnippetChunk:text-set` properties
    /// are updated.
    ///
    /// Feature: `v5_0`
    ///
    /// ## `spec`
    /// the new specification for the chunk
    #[cfg(any(feature = "v5_0", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v5_0")))]
    #[doc(alias = "gtk_source_snippet_chunk_set_spec")]
    pub fn set_spec(&self, spec: &str) {
        unsafe {
            ffi::gtk_source_snippet_chunk_set_spec(self.to_glib_none().0, spec.to_glib_none().0);
        }
    }

    /// Sets the text for the snippet chunk.
    ///
    /// This is usually used by the snippet engine to update the text, but may
    /// be useful when creating custom snippets to avoid expansion of any
    /// specification.
    ///
    /// Feature: `v5_0`
    ///
    /// ## `text`
    /// the text of the property
    #[cfg(any(feature = "v5_0", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v5_0")))]
    #[doc(alias = "gtk_source_snippet_chunk_set_text")]
    pub fn set_text(&self, text: &str) {
        unsafe {
            ffi::gtk_source_snippet_chunk_set_text(self.to_glib_none().0, text.to_glib_none().0);
        }
    }

    /// Sets the `SnippetChunk:text-set` property.
    ///
    /// This is typically set when the user has edited a snippet chunk by the
    /// snippet engine.
    ///
    /// Feature: `v5_0`
    ///
    /// ## `text_set`
    /// the property value
    #[cfg(any(feature = "v5_0", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v5_0")))]
    #[doc(alias = "gtk_source_snippet_chunk_set_text_set")]
    pub fn set_text_set(&self, text_set: bool) {
        unsafe {
            ffi::gtk_source_snippet_chunk_set_text_set(self.to_glib_none().0, text_set.to_glib());
        }
    }

    #[doc(alias = "gtk_source_snippet_chunk_set_tooltip_text")]
    pub fn set_tooltip_text(&self, tooltip_text: &str) {
        unsafe {
            ffi::gtk_source_snippet_chunk_set_tooltip_text(
                self.to_glib_none().0,
                tooltip_text.to_glib_none().0,
            );
        }
    }

    pub fn get_property_context(&self) -> Option<SnippetContext> {
        unsafe {
            let mut value = glib::Value::from_type(<SnippetContext as StaticType>::static_type());
            glib::gobject_ffi::g_object_get_property(
                self.as_ptr() as *mut glib::gobject_ffi::GObject,
                b"context\0".as_ptr() as *const _,
                value.to_glib_none_mut().0,
            );
            value
                .get()
                .expect("Return Value for property `context` getter")
        }
    }

    pub fn get_property_focus_position(&self) -> i32 {
        unsafe {
            let mut value = glib::Value::from_type(<i32 as StaticType>::static_type());
            glib::gobject_ffi::g_object_get_property(
                self.as_ptr() as *mut glib::gobject_ffi::GObject,
                b"focus-position\0".as_ptr() as *const _,
                value.to_glib_none_mut().0,
            );
            value
                .get()
                .expect("Return Value for property `focus-position` getter")
                .unwrap()
        }
    }

    pub fn set_property_focus_position(&self, focus_position: i32) {
        unsafe {
            glib::gobject_ffi::g_object_set_property(
                self.as_ptr() as *mut glib::gobject_ffi::GObject,
                b"focus-position\0".as_ptr() as *const _,
                glib::Value::from(&focus_position).to_glib_none().0,
            );
        }
    }

    pub fn get_property_spec(&self) -> Option<glib::GString> {
        unsafe {
            let mut value = glib::Value::from_type(<glib::GString as StaticType>::static_type());
            glib::gobject_ffi::g_object_get_property(
                self.as_ptr() as *mut glib::gobject_ffi::GObject,
                b"spec\0".as_ptr() as *const _,
                value.to_glib_none_mut().0,
            );
            value
                .get()
                .expect("Return Value for property `spec` getter")
        }
    }

    pub fn set_property_spec(&self, spec: Option<&str>) {
        unsafe {
            glib::gobject_ffi::g_object_set_property(
                self.as_ptr() as *mut glib::gobject_ffi::GObject,
                b"spec\0".as_ptr() as *const _,
                glib::Value::from(spec).to_glib_none().0,
            );
        }
    }

    pub fn get_property_text(&self) -> Option<glib::GString> {
        unsafe {
            let mut value = glib::Value::from_type(<glib::GString as StaticType>::static_type());
            glib::gobject_ffi::g_object_get_property(
                self.as_ptr() as *mut glib::gobject_ffi::GObject,
                b"text\0".as_ptr() as *const _,
                value.to_glib_none_mut().0,
            );
            value
                .get()
                .expect("Return Value for property `text` getter")
        }
    }

    pub fn set_property_text(&self, text: Option<&str>) {
        unsafe {
            glib::gobject_ffi::g_object_set_property(
                self.as_ptr() as *mut glib::gobject_ffi::GObject,
                b"text\0".as_ptr() as *const _,
                glib::Value::from(text).to_glib_none().0,
            );
        }
    }

    pub fn get_property_text_set(&self) -> bool {
        unsafe {
            let mut value = glib::Value::from_type(<bool as StaticType>::static_type());
            glib::gobject_ffi::g_object_get_property(
                self.as_ptr() as *mut glib::gobject_ffi::GObject,
                b"text-set\0".as_ptr() as *const _,
                value.to_glib_none_mut().0,
            );
            value
                .get()
                .expect("Return Value for property `text-set` getter")
                .unwrap()
        }
    }

    pub fn set_property_text_set(&self, text_set: bool) {
        unsafe {
            glib::gobject_ffi::g_object_set_property(
                self.as_ptr() as *mut glib::gobject_ffi::GObject,
                b"text-set\0".as_ptr() as *const _,
                glib::Value::from(&text_set).to_glib_none().0,
            );
        }
    }

    pub fn connect_property_context_notify<F: Fn(&SnippetChunk) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_context_trampoline<F: Fn(&SnippetChunk) + 'static>(
            this: *mut ffi::GtkSourceSnippetChunk,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::context\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_context_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    pub fn connect_property_focus_position_notify<F: Fn(&SnippetChunk) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_focus_position_trampoline<F: Fn(&SnippetChunk) + 'static>(
            this: *mut ffi::GtkSourceSnippetChunk,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::focus-position\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_focus_position_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    pub fn connect_property_spec_notify<F: Fn(&SnippetChunk) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_spec_trampoline<F: Fn(&SnippetChunk) + 'static>(
            this: *mut ffi::GtkSourceSnippetChunk,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::spec\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_spec_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    pub fn connect_property_text_notify<F: Fn(&SnippetChunk) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_text_trampoline<F: Fn(&SnippetChunk) + 'static>(
            this: *mut ffi::GtkSourceSnippetChunk,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::text\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_text_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    pub fn connect_property_text_set_notify<F: Fn(&SnippetChunk) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_text_set_trampoline<F: Fn(&SnippetChunk) + 'static>(
            this: *mut ffi::GtkSourceSnippetChunk,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::text-set\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_text_set_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    pub fn connect_property_tooltip_text_notify<F: Fn(&SnippetChunk) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_tooltip_text_trampoline<F: Fn(&SnippetChunk) + 'static>(
            this: *mut ffi::GtkSourceSnippetChunk,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::tooltip-text\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_tooltip_text_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

#[cfg(any(feature = "v5_0", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v5_0")))]
impl Default for SnippetChunk {
    fn default() -> Self {
        Self::new()
    }
}

#[derive(Clone, Default)]
pub struct SnippetChunkBuilder {
    context: Option<SnippetContext>,
    focus_position: Option<i32>,
    spec: Option<String>,
    text: Option<String>,
    text_set: Option<bool>,
    tooltip_text: Option<String>,
}

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

    pub fn build(self) -> SnippetChunk {
        let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
        if let Some(ref context) = self.context {
            properties.push(("context", context));
        }
        if let Some(ref focus_position) = self.focus_position {
            properties.push(("focus-position", focus_position));
        }
        if let Some(ref spec) = self.spec {
            properties.push(("spec", spec));
        }
        if let Some(ref text) = self.text {
            properties.push(("text", text));
        }
        if let Some(ref text_set) = self.text_set {
            properties.push(("text-set", text_set));
        }
        if let Some(ref tooltip_text) = self.tooltip_text {
            properties.push(("tooltip-text", tooltip_text));
        }
        let ret = glib::Object::new::<SnippetChunk>(&properties).expect("object new");
        ret
    }

    pub fn context(mut self, context: &SnippetContext) -> Self {
        self.context = Some(context.clone());
        self
    }

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

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

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

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

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

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