1use gdk_pixbuf;
6use glib::object::Cast;
7use glib::object::IsA;
8use glib::signal::connect_raw;
9use glib::signal::SignalHandlerId;
10use glib::translate::*;
11use glib::StaticType;
12use glib::ToValue;
13use glib::Value;
14use glib_sys;
15use gobject_sys;
16use gtk;
17use gtk_source_sys;
18use std::boxed::Box as Box_;
19use std::fmt;
20use std::mem::transmute;
21#[cfg(any(feature = "v3_10", feature = "dox"))]
22use CompletionActivation;
23use CompletionProvider;
24
25glib_wrapper! {
26 pub struct CompletionWords(Object<gtk_source_sys::GtkSourceCompletionWords, gtk_source_sys::GtkSourceCompletionWordsClass, CompletionWordsClass>) @implements CompletionProvider;
27
28 match fn {
29 get_type => || gtk_source_sys::gtk_source_completion_words_get_type(),
30 }
31}
32
33impl CompletionWords {
34 pub fn new(name: Option<&str>, icon: Option<&gdk_pixbuf::Pixbuf>) -> CompletionWords {
35 assert_initialized_main_thread!();
36 unsafe {
37 from_glib_full(gtk_source_sys::gtk_source_completion_words_new(
38 name.to_glib_none().0,
39 icon.to_glib_none().0,
40 ))
41 }
42 }
43}
44
45#[derive(Clone, Default)]
46pub struct CompletionWordsBuilder {
47 #[cfg(any(feature = "v3_10", feature = "dox"))]
48 activation: Option<CompletionActivation>,
49 icon: Option<gdk_pixbuf::Pixbuf>,
50 interactive_delay: Option<i32>,
51 minimum_word_size: Option<u32>,
52 name: Option<String>,
53 priority: Option<i32>,
54 proposals_batch_size: Option<u32>,
55 scan_batch_size: Option<u32>,
56}
57
58impl CompletionWordsBuilder {
59 pub fn new() -> Self {
60 Self::default()
61 }
62
63 pub fn build(self) -> CompletionWords {
64 let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
65 #[cfg(any(feature = "v3_10", feature = "dox"))]
66 {
67 if let Some(ref activation) = self.activation {
68 properties.push(("activation", activation));
69 }
70 }
71 if let Some(ref icon) = self.icon {
72 properties.push(("icon", icon));
73 }
74 if let Some(ref interactive_delay) = self.interactive_delay {
75 properties.push(("interactive-delay", interactive_delay));
76 }
77 if let Some(ref minimum_word_size) = self.minimum_word_size {
78 properties.push(("minimum-word-size", minimum_word_size));
79 }
80 if let Some(ref name) = self.name {
81 properties.push(("name", name));
82 }
83 if let Some(ref priority) = self.priority {
84 properties.push(("priority", priority));
85 }
86 if let Some(ref proposals_batch_size) = self.proposals_batch_size {
87 properties.push(("proposals-batch-size", proposals_batch_size));
88 }
89 if let Some(ref scan_batch_size) = self.scan_batch_size {
90 properties.push(("scan-batch-size", scan_batch_size));
91 }
92 glib::Object::new(CompletionWords::static_type(), &properties)
93 .expect("object new")
94 .downcast()
95 .expect("downcast")
96 }
97
98 #[cfg(any(feature = "v3_10", feature = "dox"))]
99 pub fn activation(mut self, activation: CompletionActivation) -> Self {
100 self.activation = Some(activation);
101 self
102 }
103
104 pub fn icon(mut self, icon: &gdk_pixbuf::Pixbuf) -> Self {
105 self.icon = Some(icon.clone());
106 self
107 }
108
109 pub fn interactive_delay(mut self, interactive_delay: i32) -> Self {
110 self.interactive_delay = Some(interactive_delay);
111 self
112 }
113
114 pub fn minimum_word_size(mut self, minimum_word_size: u32) -> Self {
115 self.minimum_word_size = Some(minimum_word_size);
116 self
117 }
118
119 pub fn name(mut self, name: &str) -> Self {
120 self.name = Some(name.to_string());
121 self
122 }
123
124 pub fn priority(mut self, priority: i32) -> Self {
125 self.priority = Some(priority);
126 self
127 }
128
129 pub fn proposals_batch_size(mut self, proposals_batch_size: u32) -> Self {
130 self.proposals_batch_size = Some(proposals_batch_size);
131 self
132 }
133
134 pub fn scan_batch_size(mut self, scan_batch_size: u32) -> Self {
135 self.scan_batch_size = Some(scan_batch_size);
136 self
137 }
138}
139
140pub const NONE_COMPLETION_WORDS: Option<&CompletionWords> = None;
141
142pub trait CompletionWordsExt: 'static {
143 fn register<P: IsA<gtk::TextBuffer>>(&self, buffer: &P);
144
145 fn unregister<P: IsA<gtk::TextBuffer>>(&self, buffer: &P);
146
147 #[cfg(any(feature = "v3_10", feature = "dox"))]
148 fn set_property_activation(&self, activation: CompletionActivation);
149
150 fn set_property_icon(&self, icon: Option<&gdk_pixbuf::Pixbuf>);
151
152 fn set_property_interactive_delay(&self, interactive_delay: i32);
153
154 fn get_property_minimum_word_size(&self) -> u32;
155
156 fn set_property_minimum_word_size(&self, minimum_word_size: u32);
157
158 fn set_property_name(&self, name: Option<&str>);
159
160 fn set_property_priority(&self, priority: i32);
161
162 fn get_property_proposals_batch_size(&self) -> u32;
163
164 fn set_property_proposals_batch_size(&self, proposals_batch_size: u32);
165
166 fn get_property_scan_batch_size(&self) -> u32;
167
168 fn set_property_scan_batch_size(&self, scan_batch_size: u32);
169
170 #[cfg(any(feature = "v3_10", feature = "dox"))]
171 fn connect_property_activation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
172
173 fn connect_property_icon_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
174
175 fn connect_property_interactive_delay_notify<F: Fn(&Self) + 'static>(
176 &self,
177 f: F,
178 ) -> SignalHandlerId;
179
180 fn connect_property_minimum_word_size_notify<F: Fn(&Self) + 'static>(
181 &self,
182 f: F,
183 ) -> SignalHandlerId;
184
185 fn connect_property_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
186
187 fn connect_property_priority_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
188
189 fn connect_property_proposals_batch_size_notify<F: Fn(&Self) + 'static>(
190 &self,
191 f: F,
192 ) -> SignalHandlerId;
193
194 fn connect_property_scan_batch_size_notify<F: Fn(&Self) + 'static>(
195 &self,
196 f: F,
197 ) -> SignalHandlerId;
198}
199
200impl<O: IsA<CompletionWords>> CompletionWordsExt for O {
201 fn register<P: IsA<gtk::TextBuffer>>(&self, buffer: &P) {
202 unsafe {
203 gtk_source_sys::gtk_source_completion_words_register(
204 self.as_ref().to_glib_none().0,
205 buffer.as_ref().to_glib_none().0,
206 );
207 }
208 }
209
210 fn unregister<P: IsA<gtk::TextBuffer>>(&self, buffer: &P) {
211 unsafe {
212 gtk_source_sys::gtk_source_completion_words_unregister(
213 self.as_ref().to_glib_none().0,
214 buffer.as_ref().to_glib_none().0,
215 );
216 }
217 }
218
219 #[cfg(any(feature = "v3_10", feature = "dox"))]
220 fn set_property_activation(&self, activation: CompletionActivation) {
221 unsafe {
222 gobject_sys::g_object_set_property(
223 self.to_glib_none().0 as *mut gobject_sys::GObject,
224 b"activation\0".as_ptr() as *const _,
225 Value::from(&activation).to_glib_none().0,
226 );
227 }
228 }
229
230 fn set_property_icon(&self, icon: Option<&gdk_pixbuf::Pixbuf>) {
231 unsafe {
232 gobject_sys::g_object_set_property(
233 self.to_glib_none().0 as *mut gobject_sys::GObject,
234 b"icon\0".as_ptr() as *const _,
235 Value::from(icon).to_glib_none().0,
236 );
237 }
238 }
239
240 fn set_property_interactive_delay(&self, interactive_delay: i32) {
241 unsafe {
242 gobject_sys::g_object_set_property(
243 self.to_glib_none().0 as *mut gobject_sys::GObject,
244 b"interactive-delay\0".as_ptr() as *const _,
245 Value::from(&interactive_delay).to_glib_none().0,
246 );
247 }
248 }
249
250 fn get_property_minimum_word_size(&self) -> u32 {
251 unsafe {
252 let mut value = Value::from_type(<u32 as StaticType>::static_type());
253 gobject_sys::g_object_get_property(
254 self.to_glib_none().0 as *mut gobject_sys::GObject,
255 b"minimum-word-size\0".as_ptr() as *const _,
256 value.to_glib_none_mut().0,
257 );
258 value
259 .get()
260 .expect("Return Value for property `minimum-word-size` getter")
261 .unwrap()
262 }
263 }
264
265 fn set_property_minimum_word_size(&self, minimum_word_size: u32) {
266 unsafe {
267 gobject_sys::g_object_set_property(
268 self.to_glib_none().0 as *mut gobject_sys::GObject,
269 b"minimum-word-size\0".as_ptr() as *const _,
270 Value::from(&minimum_word_size).to_glib_none().0,
271 );
272 }
273 }
274
275 fn set_property_name(&self, name: Option<&str>) {
276 unsafe {
277 gobject_sys::g_object_set_property(
278 self.to_glib_none().0 as *mut gobject_sys::GObject,
279 b"name\0".as_ptr() as *const _,
280 Value::from(name).to_glib_none().0,
281 );
282 }
283 }
284
285 fn set_property_priority(&self, priority: i32) {
286 unsafe {
287 gobject_sys::g_object_set_property(
288 self.to_glib_none().0 as *mut gobject_sys::GObject,
289 b"priority\0".as_ptr() as *const _,
290 Value::from(&priority).to_glib_none().0,
291 );
292 }
293 }
294
295 fn get_property_proposals_batch_size(&self) -> u32 {
296 unsafe {
297 let mut value = Value::from_type(<u32 as StaticType>::static_type());
298 gobject_sys::g_object_get_property(
299 self.to_glib_none().0 as *mut gobject_sys::GObject,
300 b"proposals-batch-size\0".as_ptr() as *const _,
301 value.to_glib_none_mut().0,
302 );
303 value
304 .get()
305 .expect("Return Value for property `proposals-batch-size` getter")
306 .unwrap()
307 }
308 }
309
310 fn set_property_proposals_batch_size(&self, proposals_batch_size: u32) {
311 unsafe {
312 gobject_sys::g_object_set_property(
313 self.to_glib_none().0 as *mut gobject_sys::GObject,
314 b"proposals-batch-size\0".as_ptr() as *const _,
315 Value::from(&proposals_batch_size).to_glib_none().0,
316 );
317 }
318 }
319
320 fn get_property_scan_batch_size(&self) -> u32 {
321 unsafe {
322 let mut value = Value::from_type(<u32 as StaticType>::static_type());
323 gobject_sys::g_object_get_property(
324 self.to_glib_none().0 as *mut gobject_sys::GObject,
325 b"scan-batch-size\0".as_ptr() as *const _,
326 value.to_glib_none_mut().0,
327 );
328 value
329 .get()
330 .expect("Return Value for property `scan-batch-size` getter")
331 .unwrap()
332 }
333 }
334
335 fn set_property_scan_batch_size(&self, scan_batch_size: u32) {
336 unsafe {
337 gobject_sys::g_object_set_property(
338 self.to_glib_none().0 as *mut gobject_sys::GObject,
339 b"scan-batch-size\0".as_ptr() as *const _,
340 Value::from(&scan_batch_size).to_glib_none().0,
341 );
342 }
343 }
344
345 #[cfg(any(feature = "v3_10", feature = "dox"))]
346 fn connect_property_activation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
347 unsafe extern "C" fn notify_activation_trampoline<P, F: Fn(&P) + 'static>(
348 this: *mut gtk_source_sys::GtkSourceCompletionWords,
349 _param_spec: glib_sys::gpointer,
350 f: glib_sys::gpointer,
351 ) where
352 P: IsA<CompletionWords>,
353 {
354 let f: &F = &*(f as *const F);
355 f(&CompletionWords::from_glib_borrow(this).unsafe_cast_ref())
356 }
357 unsafe {
358 let f: Box_<F> = Box_::new(f);
359 connect_raw(
360 self.as_ptr() as *mut _,
361 b"notify::activation\0".as_ptr() as *const _,
362 Some(transmute::<_, unsafe extern "C" fn()>(
363 notify_activation_trampoline::<Self, F> as *const (),
364 )),
365 Box_::into_raw(f),
366 )
367 }
368 }
369
370 fn connect_property_icon_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
371 unsafe extern "C" fn notify_icon_trampoline<P, F: Fn(&P) + 'static>(
372 this: *mut gtk_source_sys::GtkSourceCompletionWords,
373 _param_spec: glib_sys::gpointer,
374 f: glib_sys::gpointer,
375 ) where
376 P: IsA<CompletionWords>,
377 {
378 let f: &F = &*(f as *const F);
379 f(&CompletionWords::from_glib_borrow(this).unsafe_cast_ref())
380 }
381 unsafe {
382 let f: Box_<F> = Box_::new(f);
383 connect_raw(
384 self.as_ptr() as *mut _,
385 b"notify::icon\0".as_ptr() as *const _,
386 Some(transmute::<_, unsafe extern "C" fn()>(
387 notify_icon_trampoline::<Self, F> as *const (),
388 )),
389 Box_::into_raw(f),
390 )
391 }
392 }
393
394 fn connect_property_interactive_delay_notify<F: Fn(&Self) + 'static>(
395 &self,
396 f: F,
397 ) -> SignalHandlerId {
398 unsafe extern "C" fn notify_interactive_delay_trampoline<P, F: Fn(&P) + 'static>(
399 this: *mut gtk_source_sys::GtkSourceCompletionWords,
400 _param_spec: glib_sys::gpointer,
401 f: glib_sys::gpointer,
402 ) where
403 P: IsA<CompletionWords>,
404 {
405 let f: &F = &*(f as *const F);
406 f(&CompletionWords::from_glib_borrow(this).unsafe_cast_ref())
407 }
408 unsafe {
409 let f: Box_<F> = Box_::new(f);
410 connect_raw(
411 self.as_ptr() as *mut _,
412 b"notify::interactive-delay\0".as_ptr() as *const _,
413 Some(transmute::<_, unsafe extern "C" fn()>(
414 notify_interactive_delay_trampoline::<Self, F> as *const (),
415 )),
416 Box_::into_raw(f),
417 )
418 }
419 }
420
421 fn connect_property_minimum_word_size_notify<F: Fn(&Self) + 'static>(
422 &self,
423 f: F,
424 ) -> SignalHandlerId {
425 unsafe extern "C" fn notify_minimum_word_size_trampoline<P, F: Fn(&P) + 'static>(
426 this: *mut gtk_source_sys::GtkSourceCompletionWords,
427 _param_spec: glib_sys::gpointer,
428 f: glib_sys::gpointer,
429 ) where
430 P: IsA<CompletionWords>,
431 {
432 let f: &F = &*(f as *const F);
433 f(&CompletionWords::from_glib_borrow(this).unsafe_cast_ref())
434 }
435 unsafe {
436 let f: Box_<F> = Box_::new(f);
437 connect_raw(
438 self.as_ptr() as *mut _,
439 b"notify::minimum-word-size\0".as_ptr() as *const _,
440 Some(transmute::<_, unsafe extern "C" fn()>(
441 notify_minimum_word_size_trampoline::<Self, F> as *const (),
442 )),
443 Box_::into_raw(f),
444 )
445 }
446 }
447
448 fn connect_property_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
449 unsafe extern "C" fn notify_name_trampoline<P, F: Fn(&P) + 'static>(
450 this: *mut gtk_source_sys::GtkSourceCompletionWords,
451 _param_spec: glib_sys::gpointer,
452 f: glib_sys::gpointer,
453 ) where
454 P: IsA<CompletionWords>,
455 {
456 let f: &F = &*(f as *const F);
457 f(&CompletionWords::from_glib_borrow(this).unsafe_cast_ref())
458 }
459 unsafe {
460 let f: Box_<F> = Box_::new(f);
461 connect_raw(
462 self.as_ptr() as *mut _,
463 b"notify::name\0".as_ptr() as *const _,
464 Some(transmute::<_, unsafe extern "C" fn()>(
465 notify_name_trampoline::<Self, F> as *const (),
466 )),
467 Box_::into_raw(f),
468 )
469 }
470 }
471
472 fn connect_property_priority_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
473 unsafe extern "C" fn notify_priority_trampoline<P, F: Fn(&P) + 'static>(
474 this: *mut gtk_source_sys::GtkSourceCompletionWords,
475 _param_spec: glib_sys::gpointer,
476 f: glib_sys::gpointer,
477 ) where
478 P: IsA<CompletionWords>,
479 {
480 let f: &F = &*(f as *const F);
481 f(&CompletionWords::from_glib_borrow(this).unsafe_cast_ref())
482 }
483 unsafe {
484 let f: Box_<F> = Box_::new(f);
485 connect_raw(
486 self.as_ptr() as *mut _,
487 b"notify::priority\0".as_ptr() as *const _,
488 Some(transmute::<_, unsafe extern "C" fn()>(
489 notify_priority_trampoline::<Self, F> as *const (),
490 )),
491 Box_::into_raw(f),
492 )
493 }
494 }
495
496 fn connect_property_proposals_batch_size_notify<F: Fn(&Self) + 'static>(
497 &self,
498 f: F,
499 ) -> SignalHandlerId {
500 unsafe extern "C" fn notify_proposals_batch_size_trampoline<P, F: Fn(&P) + 'static>(
501 this: *mut gtk_source_sys::GtkSourceCompletionWords,
502 _param_spec: glib_sys::gpointer,
503 f: glib_sys::gpointer,
504 ) where
505 P: IsA<CompletionWords>,
506 {
507 let f: &F = &*(f as *const F);
508 f(&CompletionWords::from_glib_borrow(this).unsafe_cast_ref())
509 }
510 unsafe {
511 let f: Box_<F> = Box_::new(f);
512 connect_raw(
513 self.as_ptr() as *mut _,
514 b"notify::proposals-batch-size\0".as_ptr() as *const _,
515 Some(transmute::<_, unsafe extern "C" fn()>(
516 notify_proposals_batch_size_trampoline::<Self, F> as *const (),
517 )),
518 Box_::into_raw(f),
519 )
520 }
521 }
522
523 fn connect_property_scan_batch_size_notify<F: Fn(&Self) + 'static>(
524 &self,
525 f: F,
526 ) -> SignalHandlerId {
527 unsafe extern "C" fn notify_scan_batch_size_trampoline<P, F: Fn(&P) + 'static>(
528 this: *mut gtk_source_sys::GtkSourceCompletionWords,
529 _param_spec: glib_sys::gpointer,
530 f: glib_sys::gpointer,
531 ) where
532 P: IsA<CompletionWords>,
533 {
534 let f: &F = &*(f as *const F);
535 f(&CompletionWords::from_glib_borrow(this).unsafe_cast_ref())
536 }
537 unsafe {
538 let f: Box_<F> = Box_::new(f);
539 connect_raw(
540 self.as_ptr() as *mut _,
541 b"notify::scan-batch-size\0".as_ptr() as *const _,
542 Some(transmute::<_, unsafe extern "C" fn()>(
543 notify_scan_batch_size_trampoline::<Self, F> as *const (),
544 )),
545 Box_::into_raw(f),
546 )
547 }
548 }
549}
550
551impl fmt::Display for CompletionWords {
552 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
553 write!(f, "CompletionWords")
554 }
555}