1use crate::{SnippetContext, ffi};
7use glib::{
8 prelude::*,
9 signal::{SignalHandlerId, connect_raw},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "GtkSourceSnippetChunk")]
16 pub struct SnippetChunk(Object<ffi::GtkSourceSnippetChunk, ffi::GtkSourceSnippetChunkClass>);
17
18 match fn {
19 type_ => || ffi::gtk_source_snippet_chunk_get_type(),
20 }
21}
22
23impl SnippetChunk {
24 #[doc(alias = "gtk_source_snippet_chunk_new")]
25 pub fn new() -> SnippetChunk {
26 assert_initialized_main_thread!();
27 unsafe { from_glib_none(ffi::gtk_source_snippet_chunk_new()) }
28 }
29
30 pub fn builder() -> SnippetChunkBuilder {
35 SnippetChunkBuilder::new()
36 }
37
38 #[doc(alias = "gtk_source_snippet_chunk_copy")]
39 #[must_use]
40 pub fn copy(&self) -> SnippetChunk {
41 unsafe { from_glib_full(ffi::gtk_source_snippet_chunk_copy(self.to_glib_none().0)) }
42 }
43
44 #[doc(alias = "gtk_source_snippet_chunk_get_context")]
45 #[doc(alias = "get_context")]
46 pub fn context(&self) -> SnippetContext {
47 unsafe {
48 from_glib_none(ffi::gtk_source_snippet_chunk_get_context(
49 self.to_glib_none().0,
50 ))
51 }
52 }
53
54 #[doc(alias = "gtk_source_snippet_chunk_get_focus_position")]
55 #[doc(alias = "get_focus_position")]
56 #[doc(alias = "focus-position")]
57 pub fn focus_position(&self) -> i32 {
58 unsafe { ffi::gtk_source_snippet_chunk_get_focus_position(self.to_glib_none().0) }
59 }
60
61 #[doc(alias = "gtk_source_snippet_chunk_get_spec")]
62 #[doc(alias = "get_spec")]
63 pub fn spec(&self) -> Option<glib::GString> {
64 unsafe {
65 from_glib_none(ffi::gtk_source_snippet_chunk_get_spec(
66 self.to_glib_none().0,
67 ))
68 }
69 }
70
71 #[doc(alias = "gtk_source_snippet_chunk_get_text")]
72 #[doc(alias = "get_text")]
73 pub fn text(&self) -> glib::GString {
74 unsafe {
75 from_glib_none(ffi::gtk_source_snippet_chunk_get_text(
76 self.to_glib_none().0,
77 ))
78 }
79 }
80
81 #[doc(alias = "gtk_source_snippet_chunk_get_text_set")]
82 #[doc(alias = "get_text_set")]
83 #[doc(alias = "text-set")]
84 pub fn is_text_set(&self) -> bool {
85 unsafe {
86 from_glib(ffi::gtk_source_snippet_chunk_get_text_set(
87 self.to_glib_none().0,
88 ))
89 }
90 }
91
92 #[doc(alias = "gtk_source_snippet_chunk_get_tooltip_text")]
93 #[doc(alias = "get_tooltip_text")]
94 #[doc(alias = "tooltip-text")]
95 pub fn tooltip_text(&self) -> glib::GString {
96 unsafe {
97 from_glib_none(ffi::gtk_source_snippet_chunk_get_tooltip_text(
98 self.to_glib_none().0,
99 ))
100 }
101 }
102
103 #[doc(alias = "gtk_source_snippet_chunk_set_context")]
104 #[doc(alias = "context")]
105 pub fn set_context(&self, context: &SnippetContext) {
106 unsafe {
107 ffi::gtk_source_snippet_chunk_set_context(
108 self.to_glib_none().0,
109 context.to_glib_none().0,
110 );
111 }
112 }
113
114 #[doc(alias = "gtk_source_snippet_chunk_set_focus_position")]
115 #[doc(alias = "focus-position")]
116 pub fn set_focus_position(&self, focus_position: i32) {
117 unsafe {
118 ffi::gtk_source_snippet_chunk_set_focus_position(self.to_glib_none().0, focus_position);
119 }
120 }
121
122 #[doc(alias = "gtk_source_snippet_chunk_set_spec")]
123 #[doc(alias = "spec")]
124 pub fn set_spec(&self, spec: &str) {
125 unsafe {
126 ffi::gtk_source_snippet_chunk_set_spec(self.to_glib_none().0, spec.to_glib_none().0);
127 }
128 }
129
130 #[doc(alias = "gtk_source_snippet_chunk_set_text")]
131 #[doc(alias = "text")]
132 pub fn set_text(&self, text: &str) {
133 unsafe {
134 ffi::gtk_source_snippet_chunk_set_text(self.to_glib_none().0, text.to_glib_none().0);
135 }
136 }
137
138 #[doc(alias = "gtk_source_snippet_chunk_set_text_set")]
139 #[doc(alias = "text-set")]
140 pub fn set_text_set(&self, text_set: bool) {
141 unsafe {
142 ffi::gtk_source_snippet_chunk_set_text_set(self.to_glib_none().0, text_set.into_glib());
143 }
144 }
145
146 #[doc(alias = "gtk_source_snippet_chunk_set_tooltip_text")]
147 #[doc(alias = "tooltip-text")]
148 pub fn set_tooltip_text(&self, tooltip_text: &str) {
149 unsafe {
150 ffi::gtk_source_snippet_chunk_set_tooltip_text(
151 self.to_glib_none().0,
152 tooltip_text.to_glib_none().0,
153 );
154 }
155 }
156
157 #[doc(alias = "context")]
158 pub fn connect_context_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
159 unsafe extern "C" fn notify_context_trampoline<F: Fn(&SnippetChunk) + 'static>(
160 this: *mut ffi::GtkSourceSnippetChunk,
161 _param_spec: glib::ffi::gpointer,
162 f: glib::ffi::gpointer,
163 ) {
164 unsafe {
165 let f: &F = &*(f as *const F);
166 f(&from_glib_borrow(this))
167 }
168 }
169 unsafe {
170 let f: Box_<F> = Box_::new(f);
171 connect_raw(
172 self.as_ptr() as *mut _,
173 c"notify::context".as_ptr(),
174 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
175 notify_context_trampoline::<F> as *const (),
176 )),
177 Box_::into_raw(f),
178 )
179 }
180 }
181
182 #[doc(alias = "focus-position")]
183 pub fn connect_focus_position_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
184 unsafe extern "C" fn notify_focus_position_trampoline<F: Fn(&SnippetChunk) + 'static>(
185 this: *mut ffi::GtkSourceSnippetChunk,
186 _param_spec: glib::ffi::gpointer,
187 f: glib::ffi::gpointer,
188 ) {
189 unsafe {
190 let f: &F = &*(f as *const F);
191 f(&from_glib_borrow(this))
192 }
193 }
194 unsafe {
195 let f: Box_<F> = Box_::new(f);
196 connect_raw(
197 self.as_ptr() as *mut _,
198 c"notify::focus-position".as_ptr(),
199 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
200 notify_focus_position_trampoline::<F> as *const (),
201 )),
202 Box_::into_raw(f),
203 )
204 }
205 }
206
207 #[doc(alias = "spec")]
208 pub fn connect_spec_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
209 unsafe extern "C" fn notify_spec_trampoline<F: Fn(&SnippetChunk) + 'static>(
210 this: *mut ffi::GtkSourceSnippetChunk,
211 _param_spec: glib::ffi::gpointer,
212 f: glib::ffi::gpointer,
213 ) {
214 unsafe {
215 let f: &F = &*(f as *const F);
216 f(&from_glib_borrow(this))
217 }
218 }
219 unsafe {
220 let f: Box_<F> = Box_::new(f);
221 connect_raw(
222 self.as_ptr() as *mut _,
223 c"notify::spec".as_ptr(),
224 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
225 notify_spec_trampoline::<F> as *const (),
226 )),
227 Box_::into_raw(f),
228 )
229 }
230 }
231
232 #[doc(alias = "text")]
233 pub fn connect_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
234 unsafe extern "C" fn notify_text_trampoline<F: Fn(&SnippetChunk) + 'static>(
235 this: *mut ffi::GtkSourceSnippetChunk,
236 _param_spec: glib::ffi::gpointer,
237 f: glib::ffi::gpointer,
238 ) {
239 unsafe {
240 let f: &F = &*(f as *const F);
241 f(&from_glib_borrow(this))
242 }
243 }
244 unsafe {
245 let f: Box_<F> = Box_::new(f);
246 connect_raw(
247 self.as_ptr() as *mut _,
248 c"notify::text".as_ptr(),
249 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
250 notify_text_trampoline::<F> as *const (),
251 )),
252 Box_::into_raw(f),
253 )
254 }
255 }
256
257 #[doc(alias = "text-set")]
258 pub fn connect_text_set_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
259 unsafe extern "C" fn notify_text_set_trampoline<F: Fn(&SnippetChunk) + 'static>(
260 this: *mut ffi::GtkSourceSnippetChunk,
261 _param_spec: glib::ffi::gpointer,
262 f: glib::ffi::gpointer,
263 ) {
264 unsafe {
265 let f: &F = &*(f as *const F);
266 f(&from_glib_borrow(this))
267 }
268 }
269 unsafe {
270 let f: Box_<F> = Box_::new(f);
271 connect_raw(
272 self.as_ptr() as *mut _,
273 c"notify::text-set".as_ptr(),
274 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
275 notify_text_set_trampoline::<F> as *const (),
276 )),
277 Box_::into_raw(f),
278 )
279 }
280 }
281
282 #[doc(alias = "tooltip-text")]
283 pub fn connect_tooltip_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
284 unsafe extern "C" fn notify_tooltip_text_trampoline<F: Fn(&SnippetChunk) + 'static>(
285 this: *mut ffi::GtkSourceSnippetChunk,
286 _param_spec: glib::ffi::gpointer,
287 f: glib::ffi::gpointer,
288 ) {
289 unsafe {
290 let f: &F = &*(f as *const F);
291 f(&from_glib_borrow(this))
292 }
293 }
294 unsafe {
295 let f: Box_<F> = Box_::new(f);
296 connect_raw(
297 self.as_ptr() as *mut _,
298 c"notify::tooltip-text".as_ptr(),
299 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
300 notify_tooltip_text_trampoline::<F> as *const (),
301 )),
302 Box_::into_raw(f),
303 )
304 }
305 }
306}
307
308impl Default for SnippetChunk {
309 fn default() -> Self {
310 Self::new()
311 }
312}
313
314#[must_use = "The builder must be built to be used"]
319pub struct SnippetChunkBuilder {
320 builder: glib::object::ObjectBuilder<'static, SnippetChunk>,
321}
322
323impl SnippetChunkBuilder {
324 fn new() -> Self {
325 Self {
326 builder: glib::object::Object::builder(),
327 }
328 }
329
330 pub fn context(self, context: &SnippetContext) -> Self {
331 Self {
332 builder: self.builder.property("context", context.clone()),
333 }
334 }
335
336 pub fn focus_position(self, focus_position: i32) -> Self {
337 Self {
338 builder: self.builder.property("focus-position", focus_position),
339 }
340 }
341
342 pub fn spec(self, spec: impl Into<glib::GString>) -> Self {
343 Self {
344 builder: self.builder.property("spec", spec.into()),
345 }
346 }
347
348 pub fn text(self, text: impl Into<glib::GString>) -> Self {
349 Self {
350 builder: self.builder.property("text", text.into()),
351 }
352 }
353
354 pub fn text_set(self, text_set: bool) -> Self {
355 Self {
356 builder: self.builder.property("text-set", text_set),
357 }
358 }
359
360 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
361 Self {
362 builder: self.builder.property("tooltip-text", tooltip_text.into()),
363 }
364 }
365
366 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
369 pub fn build(self) -> SnippetChunk {
370 assert_initialized_main_thread!();
371 self.builder.build()
372 }
373}