Skip to main content

sourceview5/auto/
vim_im_context.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::{View, ffi};
7use glib::{
8    object::ObjectType as _,
9    prelude::*,
10    signal::{SignalHandlerId, connect_raw},
11    translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16    #[doc(alias = "GtkSourceVimIMContext")]
17    pub struct VimIMContext(Object<ffi::GtkSourceVimIMContext, ffi::GtkSourceVimIMContextClass>) @extends gtk::IMContext;
18
19    match fn {
20        type_ => || ffi::gtk_source_vim_im_context_get_type(),
21    }
22}
23
24impl VimIMContext {
25    #[doc(alias = "gtk_source_vim_im_context_new")]
26    pub fn new() -> VimIMContext {
27        assert_initialized_main_thread!();
28        unsafe {
29            gtk::IMContext::from_glib_full(ffi::gtk_source_vim_im_context_new()).unsafe_cast()
30        }
31    }
32
33    // rustdoc-stripper-ignore-next
34    /// Creates a new builder-pattern struct instance to construct [`VimIMContext`] objects.
35    ///
36    /// This method returns an instance of [`VimIMContextBuilder`](crate::builders::VimIMContextBuilder) which can be used to create [`VimIMContext`] objects.
37    pub fn builder() -> VimIMContextBuilder {
38        VimIMContextBuilder::new()
39    }
40
41    #[doc(alias = "gtk_source_vim_im_context_execute_command")]
42    pub fn execute_command(&self, command: &str) {
43        unsafe {
44            ffi::gtk_source_vim_im_context_execute_command(
45                self.to_glib_none().0,
46                command.to_glib_none().0,
47            );
48        }
49    }
50
51    #[doc(alias = "gtk_source_vim_im_context_get_command_bar_text")]
52    #[doc(alias = "get_command_bar_text")]
53    #[doc(alias = "command-bar-text")]
54    pub fn command_bar_text(&self) -> glib::GString {
55        unsafe {
56            from_glib_none(ffi::gtk_source_vim_im_context_get_command_bar_text(
57                self.to_glib_none().0,
58            ))
59        }
60    }
61
62    #[doc(alias = "gtk_source_vim_im_context_get_command_text")]
63    #[doc(alias = "get_command_text")]
64    #[doc(alias = "command-text")]
65    pub fn command_text(&self) -> glib::GString {
66        unsafe {
67            from_glib_none(ffi::gtk_source_vim_im_context_get_command_text(
68                self.to_glib_none().0,
69            ))
70        }
71    }
72
73    #[cfg(not(feature = "v5_4"))]
74    #[cfg_attr(docsrs, doc(cfg(not(feature = "v5_4"))))]
75    #[doc(alias = "command-bar-text")]
76    pub fn command_bar_text(&self) -> Option<glib::GString> {
77        ObjectExt::property(self, "command-bar-text")
78    }
79
80    #[cfg(not(feature = "v5_4"))]
81    #[cfg_attr(docsrs, doc(cfg(not(feature = "v5_4"))))]
82    #[doc(alias = "command-text")]
83    pub fn command_text(&self) -> Option<glib::GString> {
84        ObjectExt::property(self, "command-text")
85    }
86
87    #[cfg(feature = "v5_4")]
88    #[cfg_attr(docsrs, doc(cfg(feature = "v5_4")))]
89    #[doc(alias = "edit")]
90    pub fn connect_edit<F: Fn(&Self, &View, Option<&str>) + 'static>(
91        &self,
92        f: F,
93    ) -> SignalHandlerId {
94        unsafe extern "C" fn edit_trampoline<
95            F: Fn(&VimIMContext, &View, Option<&str>) + 'static,
96        >(
97            this: *mut ffi::GtkSourceVimIMContext,
98            view: *mut ffi::GtkSourceView,
99            path: *mut std::ffi::c_char,
100            f: glib::ffi::gpointer,
101        ) {
102            unsafe {
103                let f: &F = &*(f as *const F);
104                f(
105                    &from_glib_borrow(this),
106                    &from_glib_borrow(view),
107                    Option::<glib::GString>::from_glib_borrow(path)
108                        .as_ref()
109                        .as_ref()
110                        .map(|s| s.as_str()),
111                )
112            }
113        }
114        unsafe {
115            let f: Box_<F> = Box_::new(f);
116            connect_raw(
117                self.as_ptr() as *mut _,
118                c"edit".as_ptr(),
119                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
120                    edit_trampoline::<F> as *const (),
121                )),
122                Box_::into_raw(f),
123            )
124        }
125    }
126
127    #[cfg(feature = "v5_4")]
128    #[cfg_attr(docsrs, doc(cfg(feature = "v5_4")))]
129    #[doc(alias = "execute-command")]
130    pub fn connect_execute_command<F: Fn(&Self, &str) -> bool + 'static>(
131        &self,
132        f: F,
133    ) -> SignalHandlerId {
134        unsafe extern "C" fn execute_command_trampoline<
135            F: Fn(&VimIMContext, &str) -> bool + 'static,
136        >(
137            this: *mut ffi::GtkSourceVimIMContext,
138            command: *mut std::ffi::c_char,
139            f: glib::ffi::gpointer,
140        ) -> glib::ffi::gboolean {
141            unsafe {
142                let f: &F = &*(f as *const F);
143                f(
144                    &from_glib_borrow(this),
145                    &glib::GString::from_glib_borrow(command),
146                )
147                .into_glib()
148            }
149        }
150        unsafe {
151            let f: Box_<F> = Box_::new(f);
152            connect_raw(
153                self.as_ptr() as *mut _,
154                c"execute-command".as_ptr(),
155                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
156                    execute_command_trampoline::<F> as *const (),
157                )),
158                Box_::into_raw(f),
159            )
160        }
161    }
162
163    #[cfg(feature = "v5_4")]
164    #[cfg_attr(docsrs, doc(cfg(feature = "v5_4")))]
165    #[doc(alias = "format-text")]
166    pub fn connect_format_text<F: Fn(&Self, &gtk::TextIter, &gtk::TextIter) + 'static>(
167        &self,
168        f: F,
169    ) -> SignalHandlerId {
170        unsafe extern "C" fn format_text_trampoline<
171            F: Fn(&VimIMContext, &gtk::TextIter, &gtk::TextIter) + 'static,
172        >(
173            this: *mut ffi::GtkSourceVimIMContext,
174            begin: *mut gtk::ffi::GtkTextIter,
175            end: *mut gtk::ffi::GtkTextIter,
176            f: glib::ffi::gpointer,
177        ) {
178            unsafe {
179                let f: &F = &*(f as *const F);
180                f(
181                    &from_glib_borrow(this),
182                    &from_glib_borrow(begin),
183                    &from_glib_borrow(end),
184                )
185            }
186        }
187        unsafe {
188            let f: Box_<F> = Box_::new(f);
189            connect_raw(
190                self.as_ptr() as *mut _,
191                c"format-text".as_ptr(),
192                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
193                    format_text_trampoline::<F> as *const (),
194                )),
195                Box_::into_raw(f),
196            )
197        }
198    }
199
200    #[cfg(feature = "v5_4")]
201    #[cfg_attr(docsrs, doc(cfg(feature = "v5_4")))]
202    #[doc(alias = "write")]
203    pub fn connect_write<F: Fn(&Self, &View, Option<&str>) + 'static>(
204        &self,
205        f: F,
206    ) -> SignalHandlerId {
207        unsafe extern "C" fn write_trampoline<
208            F: Fn(&VimIMContext, &View, Option<&str>) + 'static,
209        >(
210            this: *mut ffi::GtkSourceVimIMContext,
211            view: *mut ffi::GtkSourceView,
212            path: *mut std::ffi::c_char,
213            f: glib::ffi::gpointer,
214        ) {
215            unsafe {
216                let f: &F = &*(f as *const F);
217                f(
218                    &from_glib_borrow(this),
219                    &from_glib_borrow(view),
220                    Option::<glib::GString>::from_glib_borrow(path)
221                        .as_ref()
222                        .as_ref()
223                        .map(|s| s.as_str()),
224                )
225            }
226        }
227        unsafe {
228            let f: Box_<F> = Box_::new(f);
229            connect_raw(
230                self.as_ptr() as *mut _,
231                c"write".as_ptr(),
232                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
233                    write_trampoline::<F> as *const (),
234                )),
235                Box_::into_raw(f),
236            )
237        }
238    }
239
240    #[doc(alias = "command-bar-text")]
241    pub fn connect_command_bar_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
242        unsafe extern "C" fn notify_command_bar_text_trampoline<F: Fn(&VimIMContext) + 'static>(
243            this: *mut ffi::GtkSourceVimIMContext,
244            _param_spec: glib::ffi::gpointer,
245            f: glib::ffi::gpointer,
246        ) {
247            unsafe {
248                let f: &F = &*(f as *const F);
249                f(&from_glib_borrow(this))
250            }
251        }
252        unsafe {
253            let f: Box_<F> = Box_::new(f);
254            connect_raw(
255                self.as_ptr() as *mut _,
256                c"notify::command-bar-text".as_ptr(),
257                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
258                    notify_command_bar_text_trampoline::<F> as *const (),
259                )),
260                Box_::into_raw(f),
261            )
262        }
263    }
264
265    #[doc(alias = "command-text")]
266    pub fn connect_command_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
267        unsafe extern "C" fn notify_command_text_trampoline<F: Fn(&VimIMContext) + 'static>(
268            this: *mut ffi::GtkSourceVimIMContext,
269            _param_spec: glib::ffi::gpointer,
270            f: glib::ffi::gpointer,
271        ) {
272            unsafe {
273                let f: &F = &*(f as *const F);
274                f(&from_glib_borrow(this))
275            }
276        }
277        unsafe {
278            let f: Box_<F> = Box_::new(f);
279            connect_raw(
280                self.as_ptr() as *mut _,
281                c"notify::command-text".as_ptr(),
282                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
283                    notify_command_text_trampoline::<F> as *const (),
284                )),
285                Box_::into_raw(f),
286            )
287        }
288    }
289}
290
291impl Default for VimIMContext {
292    fn default() -> Self {
293        Self::new()
294    }
295}
296
297// rustdoc-stripper-ignore-next
298/// A [builder-pattern] type to construct [`VimIMContext`] objects.
299///
300/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
301#[must_use = "The builder must be built to be used"]
302pub struct VimIMContextBuilder {
303    builder: glib::object::ObjectBuilder<'static, VimIMContext>,
304}
305
306impl VimIMContextBuilder {
307    fn new() -> Self {
308        Self {
309            builder: glib::object::Object::builder(),
310        }
311    }
312
313    pub fn input_hints(self, input_hints: gtk::InputHints) -> Self {
314        Self {
315            builder: self.builder.property("input-hints", input_hints),
316        }
317    }
318
319    pub fn input_purpose(self, input_purpose: gtk::InputPurpose) -> Self {
320        Self {
321            builder: self.builder.property("input-purpose", input_purpose),
322        }
323    }
324
325    // rustdoc-stripper-ignore-next
326    /// Build the [`VimIMContext`].
327    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
328    pub fn build(self) -> VimIMContext {
329        assert_initialized_main_thread!();
330        self.builder.build()
331    }
332}