sourceview5/auto/
snippet_context.rs1use crate::ffi;
7use glib::{
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "GtkSourceSnippetContext")]
16 pub struct SnippetContext(Object<ffi::GtkSourceSnippetContext, ffi::GtkSourceSnippetContextClass>);
17
18 match fn {
19 type_ => || ffi::gtk_source_snippet_context_get_type(),
20 }
21}
22
23impl SnippetContext {
24 #[doc(alias = "gtk_source_snippet_context_new")]
25 pub fn new() -> SnippetContext {
26 assert_initialized_main_thread!();
27 unsafe { from_glib_full(ffi::gtk_source_snippet_context_new()) }
28 }
29
30 #[doc(alias = "gtk_source_snippet_context_clear_variables")]
31 pub fn clear_variables(&self) {
32 unsafe {
33 ffi::gtk_source_snippet_context_clear_variables(self.to_glib_none().0);
34 }
35 }
36
37 #[doc(alias = "gtk_source_snippet_context_expand")]
38 pub fn expand(&self, input: &str) -> glib::GString {
39 unsafe {
40 from_glib_full(ffi::gtk_source_snippet_context_expand(
41 self.to_glib_none().0,
42 input.to_glib_none().0,
43 ))
44 }
45 }
46
47 #[doc(alias = "gtk_source_snippet_context_get_variable")]
48 #[doc(alias = "get_variable")]
49 pub fn variable(&self, key: &str) -> Option<glib::GString> {
50 unsafe {
51 from_glib_none(ffi::gtk_source_snippet_context_get_variable(
52 self.to_glib_none().0,
53 key.to_glib_none().0,
54 ))
55 }
56 }
57
58 #[doc(alias = "gtk_source_snippet_context_set_constant")]
59 pub fn set_constant(&self, key: &str, value: &str) {
60 unsafe {
61 ffi::gtk_source_snippet_context_set_constant(
62 self.to_glib_none().0,
63 key.to_glib_none().0,
64 value.to_glib_none().0,
65 );
66 }
67 }
68
69 #[doc(alias = "gtk_source_snippet_context_set_line_prefix")]
70 pub fn set_line_prefix(&self, line_prefix: &str) {
71 unsafe {
72 ffi::gtk_source_snippet_context_set_line_prefix(
73 self.to_glib_none().0,
74 line_prefix.to_glib_none().0,
75 );
76 }
77 }
78
79 #[doc(alias = "gtk_source_snippet_context_set_tab_width")]
80 pub fn set_tab_width(&self, tab_width: i32) {
81 unsafe {
82 ffi::gtk_source_snippet_context_set_tab_width(self.to_glib_none().0, tab_width);
83 }
84 }
85
86 #[doc(alias = "gtk_source_snippet_context_set_use_spaces")]
87 pub fn set_use_spaces(&self, use_spaces: bool) {
88 unsafe {
89 ffi::gtk_source_snippet_context_set_use_spaces(
90 self.to_glib_none().0,
91 use_spaces.into_glib(),
92 );
93 }
94 }
95
96 #[doc(alias = "gtk_source_snippet_context_set_variable")]
97 pub fn set_variable(&self, key: &str, value: &str) {
98 unsafe {
99 ffi::gtk_source_snippet_context_set_variable(
100 self.to_glib_none().0,
101 key.to_glib_none().0,
102 value.to_glib_none().0,
103 );
104 }
105 }
106
107 #[doc(alias = "changed")]
108 pub fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
109 unsafe extern "C" fn changed_trampoline<F: Fn(&SnippetContext) + 'static>(
110 this: *mut ffi::GtkSourceSnippetContext,
111 f: glib::ffi::gpointer,
112 ) {
113 let f: &F = &*(f as *const F);
114 f(&from_glib_borrow(this))
115 }
116 unsafe {
117 let f: Box_<F> = Box_::new(f);
118 connect_raw(
119 self.as_ptr() as *mut _,
120 b"changed\0".as_ptr() as *const _,
121 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
122 changed_trampoline::<F> as *const (),
123 )),
124 Box_::into_raw(f),
125 )
126 }
127 }
128}
129
130impl Default for SnippetContext {
131 fn default() -> Self {
132 Self::new()
133 }
134}