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

use crate::{ffi, View};
use glib::{prelude::*, translate::*};

glib::wrapper! {
    /// Auto-indentation interface.
    ///
    /// By default, [`View`][crate::View] can auto-indent as you type when
    /// [`auto-indent`][struct@crate::View#auto-indent] is enabled. The indentation simply copies the
    /// previous lines indentation.
    ///
    /// This can be changed by implementing [`Indenter`][crate::Indenter] and setting the
    /// [`indenter`][struct@crate::View#indenter] property.
    ///
    /// Implementors of this interface should implement both
    /// `vfunc::Indenter::is_trigger` and `vfunc::Indenter::indent`.
    ///
    /// `vfunc::Indenter::is_trigger` is called upon key-press to
    /// determine of the key press should trigger an indentation.  The default
    /// implementation of the interface checks to see if the key was
    /// `Gdk::KEY_Return` or `Gdk::KEY_KP_Enter` without [`gdk::ModifierType::SHIFT_MASK`][crate::gdk::ModifierType::SHIFT_MASK] set.
    ///
    /// `vfunc::Indenter::indent` is called after text has been
    /// inserted into [`Buffer`][crate::Buffer] when
    /// `vfunc::Indenter::is_trigger` returned [`true`]. The [`gtk::TextIter`][crate::gtk::TextIter]
    /// is placed directly after the inserted character or characters.
    ///
    /// It may be beneficial to move the insertion mark using
    /// [`TextBufferExtManual::select_range()`][crate::gtk::prelude::TextBufferExtManual::select_range()] depending on how the indenter changes
    /// the indentation.
    ///
    /// All changes are encapsulated within a single user action so that the
    /// user may undo them using standard undo/redo accelerators.
    ///
    /// # Implements
    ///
    /// [`IndenterExt`][trait@crate::prelude::IndenterExt]
    #[doc(alias = "GtkSourceIndenter")]
    pub struct Indenter(Interface<ffi::GtkSourceIndenter, ffi::GtkSourceIndenterInterface>);

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

impl Indenter {
    pub const NONE: Option<&'static Indenter> = None;
}

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::Indenter>> Sealed for T {}
}

/// Trait containing all [`struct@Indenter`] methods.
///
/// # Implementors
///
/// [`Indenter`][struct@crate::Indenter]
pub trait IndenterExt: IsA<Indenter> + sealed::Sealed + 'static {
    //#[doc(alias = "gtk_source_indenter_indent")]
    //fn indent(&self, view: &impl IsA<View>, iter: /*Unimplemented*/gtk::TextIter) {
    //    unsafe { TODO: call ffi:gtk_source_indenter_indent() }
    //}

    /// 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::SHIFT_MASK`][crate::gdk::ModifierType::SHIFT_MASK] 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.
    /// ## `view`
    /// a #GtkSourceView
    /// ## `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(
        &self,
        view: &impl IsA<View>,
        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.into_glib(),
                keyval,
            ))
        }
    }
}

impl<O: IsA<Indenter>> IndenterExt for O {}