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
// 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::View;
use glib::object::IsA;
use glib::translate::*;
use std::fmt;

glib::wrapper! {
    pub struct Indenter(Interface<ffi::GtkSourceIndenter, ffi::GtkSourceIndenterInterface>);

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

pub const NONE_INDENTER: Option<&Indenter> = None;

/// Trait containing all `Indenter` methods.
///
/// Feature: `v5_0`
///
/// # Implementors
///
/// [`Indenter`](struct.Indenter.html)
pub trait IndenterExt: 'static {
    //#[doc(alias = "gtk_source_indenter_indent")]
    //fn indent<P: IsA<View>>(&self, view: &P, iter: /*Unimplemented*/gtk::TextIter);

    /// This function is used to determine if a key pressed should cause the
    /// indenter to automatically indent.
    ///
    /// The default implementation of this virtual method will check to see
    /// if `keyval` is `GDK_KEY_Return` or `GDK_KEY_KP_Enter` and `state` does
    /// not have `gdk::ModifierType::ShiftMask` set. This is to allow the user to avoid
    /// indentation when Shift+Return is pressed. Other indenters may want
    /// to copy this behavior to provide a consistent experience to users.
    ///
    /// Feature: `v5_0`
    ///
    /// ## `view`
    /// a `View`
    /// ## `location`
    /// the location where `ch` is to be inserted
    /// ## `state`
    /// modifier state for the insertion
    /// ## `keyval`
    /// the keyval pressed such as `GDK_KEY_Return`
    ///
    /// # Returns
    ///
    /// `true` if indentation should be automatically triggered;
    ///  otherwise `false` and no indentation will be performed.
    #[doc(alias = "gtk_source_indenter_is_trigger")]
    fn is_trigger<P: IsA<View>>(
        &self,
        view: &P,
        location: &gtk::TextIter,
        state: gdk::ModifierType,
        keyval: u32,
    ) -> bool;
}

impl<O: IsA<Indenter>> IndenterExt for O {
    //fn indent<P: IsA<View>>(&self, view: &P, iter: /*Unimplemented*/gtk::TextIter) {
    //    unsafe { TODO: call ffi:gtk_source_indenter_indent() }
    //}

    fn is_trigger<P: IsA<View>>(
        &self,
        view: &P,
        location: &gtk::TextIter,
        state: gdk::ModifierType,
        keyval: u32,
    ) -> bool {
        unsafe {
            from_glib(ffi::gtk_source_indenter_is_trigger(
                self.as_ref().to_glib_none().0,
                view.as_ref().to_glib_none().0,
                location.to_glib_none().0,
                state.to_glib(),
                keyval,
            ))
        }
    }
}

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