1use crate::{ffi, CompletionProvider};
7use glib::{
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "GtkSourceCompletionWords")]
16 pub struct CompletionWords(Object<ffi::GtkSourceCompletionWords, ffi::GtkSourceCompletionWordsClass>) @implements CompletionProvider;
17
18 match fn {
19 type_ => || ffi::gtk_source_completion_words_get_type(),
20 }
21}
22
23impl CompletionWords {
24 pub const NONE: Option<&'static CompletionWords> = None;
25
26 #[doc(alias = "gtk_source_completion_words_new")]
27 pub fn new(title: Option<&str>) -> CompletionWords {
28 assert_initialized_main_thread!();
29 unsafe { from_glib_full(ffi::gtk_source_completion_words_new(title.to_glib_none().0)) }
30 }
31
32 pub fn builder() -> CompletionWordsBuilder {
37 CompletionWordsBuilder::new()
38 }
39}
40
41impl Default for CompletionWords {
42 fn default() -> Self {
43 glib::object::Object::new::<Self>()
44 }
45}
46
47#[must_use = "The builder must be built to be used"]
52pub struct CompletionWordsBuilder {
53 builder: glib::object::ObjectBuilder<'static, CompletionWords>,
54}
55
56impl CompletionWordsBuilder {
57 fn new() -> Self {
58 Self {
59 builder: glib::object::Object::builder(),
60 }
61 }
62
63 pub fn minimum_word_size(self, minimum_word_size: u32) -> Self {
64 Self {
65 builder: self
66 .builder
67 .property("minimum-word-size", minimum_word_size),
68 }
69 }
70
71 pub fn priority(self, priority: i32) -> Self {
72 Self {
73 builder: self.builder.property("priority", priority),
74 }
75 }
76
77 pub fn proposals_batch_size(self, proposals_batch_size: u32) -> Self {
78 Self {
79 builder: self
80 .builder
81 .property("proposals-batch-size", proposals_batch_size),
82 }
83 }
84
85 pub fn scan_batch_size(self, scan_batch_size: u32) -> Self {
86 Self {
87 builder: self.builder.property("scan-batch-size", scan_batch_size),
88 }
89 }
90
91 pub fn title(self, title: impl Into<glib::GString>) -> Self {
92 Self {
93 builder: self.builder.property("title", title.into()),
94 }
95 }
96
97 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
100 pub fn build(self) -> CompletionWords {
101 assert_initialized_main_thread!();
102 self.builder.build()
103 }
104}
105
106pub trait CompletionWordsExt: IsA<CompletionWords> + 'static {
107 #[doc(alias = "gtk_source_completion_words_register")]
108 fn register(&self, buffer: &impl IsA<gtk::TextBuffer>) {
109 unsafe {
110 ffi::gtk_source_completion_words_register(
111 self.as_ref().to_glib_none().0,
112 buffer.as_ref().to_glib_none().0,
113 );
114 }
115 }
116
117 #[doc(alias = "gtk_source_completion_words_unregister")]
118 fn unregister(&self, buffer: &impl IsA<gtk::TextBuffer>) {
119 unsafe {
120 ffi::gtk_source_completion_words_unregister(
121 self.as_ref().to_glib_none().0,
122 buffer.as_ref().to_glib_none().0,
123 );
124 }
125 }
126
127 #[doc(alias = "minimum-word-size")]
128 fn minimum_word_size(&self) -> u32 {
129 ObjectExt::property(self.as_ref(), "minimum-word-size")
130 }
131
132 #[doc(alias = "minimum-word-size")]
133 fn set_minimum_word_size(&self, minimum_word_size: u32) {
134 ObjectExt::set_property(self.as_ref(), "minimum-word-size", minimum_word_size)
135 }
136
137 fn priority(&self) -> i32 {
138 ObjectExt::property(self.as_ref(), "priority")
139 }
140
141 fn set_priority(&self, priority: i32) {
142 ObjectExt::set_property(self.as_ref(), "priority", priority)
143 }
144
145 #[doc(alias = "proposals-batch-size")]
146 fn proposals_batch_size(&self) -> u32 {
147 ObjectExt::property(self.as_ref(), "proposals-batch-size")
148 }
149
150 #[doc(alias = "proposals-batch-size")]
151 fn set_proposals_batch_size(&self, proposals_batch_size: u32) {
152 ObjectExt::set_property(self.as_ref(), "proposals-batch-size", proposals_batch_size)
153 }
154
155 #[doc(alias = "scan-batch-size")]
156 fn scan_batch_size(&self) -> u32 {
157 ObjectExt::property(self.as_ref(), "scan-batch-size")
158 }
159
160 #[doc(alias = "scan-batch-size")]
161 fn set_scan_batch_size(&self, scan_batch_size: u32) {
162 ObjectExt::set_property(self.as_ref(), "scan-batch-size", scan_batch_size)
163 }
164
165 fn set_title(&self, title: Option<&str>) {
166 ObjectExt::set_property(self.as_ref(), "title", title)
167 }
168
169 #[doc(alias = "minimum-word-size")]
170 fn connect_minimum_word_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
171 unsafe extern "C" fn notify_minimum_word_size_trampoline<
172 P: IsA<CompletionWords>,
173 F: Fn(&P) + 'static,
174 >(
175 this: *mut ffi::GtkSourceCompletionWords,
176 _param_spec: glib::ffi::gpointer,
177 f: glib::ffi::gpointer,
178 ) {
179 let f: &F = &*(f as *const F);
180 f(CompletionWords::from_glib_borrow(this).unsafe_cast_ref())
181 }
182 unsafe {
183 let f: Box_<F> = Box_::new(f);
184 connect_raw(
185 self.as_ptr() as *mut _,
186 c"notify::minimum-word-size".as_ptr() as *const _,
187 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
188 notify_minimum_word_size_trampoline::<Self, F> as *const (),
189 )),
190 Box_::into_raw(f),
191 )
192 }
193 }
194
195 #[doc(alias = "priority")]
196 fn connect_priority_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
197 unsafe extern "C" fn notify_priority_trampoline<
198 P: IsA<CompletionWords>,
199 F: Fn(&P) + 'static,
200 >(
201 this: *mut ffi::GtkSourceCompletionWords,
202 _param_spec: glib::ffi::gpointer,
203 f: glib::ffi::gpointer,
204 ) {
205 let f: &F = &*(f as *const F);
206 f(CompletionWords::from_glib_borrow(this).unsafe_cast_ref())
207 }
208 unsafe {
209 let f: Box_<F> = Box_::new(f);
210 connect_raw(
211 self.as_ptr() as *mut _,
212 c"notify::priority".as_ptr() as *const _,
213 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
214 notify_priority_trampoline::<Self, F> as *const (),
215 )),
216 Box_::into_raw(f),
217 )
218 }
219 }
220
221 #[doc(alias = "proposals-batch-size")]
222 fn connect_proposals_batch_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
223 unsafe extern "C" fn notify_proposals_batch_size_trampoline<
224 P: IsA<CompletionWords>,
225 F: Fn(&P) + 'static,
226 >(
227 this: *mut ffi::GtkSourceCompletionWords,
228 _param_spec: glib::ffi::gpointer,
229 f: glib::ffi::gpointer,
230 ) {
231 let f: &F = &*(f as *const F);
232 f(CompletionWords::from_glib_borrow(this).unsafe_cast_ref())
233 }
234 unsafe {
235 let f: Box_<F> = Box_::new(f);
236 connect_raw(
237 self.as_ptr() as *mut _,
238 c"notify::proposals-batch-size".as_ptr() as *const _,
239 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
240 notify_proposals_batch_size_trampoline::<Self, F> as *const (),
241 )),
242 Box_::into_raw(f),
243 )
244 }
245 }
246
247 #[doc(alias = "scan-batch-size")]
248 fn connect_scan_batch_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
249 unsafe extern "C" fn notify_scan_batch_size_trampoline<
250 P: IsA<CompletionWords>,
251 F: Fn(&P) + 'static,
252 >(
253 this: *mut ffi::GtkSourceCompletionWords,
254 _param_spec: glib::ffi::gpointer,
255 f: glib::ffi::gpointer,
256 ) {
257 let f: &F = &*(f as *const F);
258 f(CompletionWords::from_glib_borrow(this).unsafe_cast_ref())
259 }
260 unsafe {
261 let f: Box_<F> = Box_::new(f);
262 connect_raw(
263 self.as_ptr() as *mut _,
264 c"notify::scan-batch-size".as_ptr() as *const _,
265 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
266 notify_scan_batch_size_trampoline::<Self, F> as *const (),
267 )),
268 Box_::into_raw(f),
269 )
270 }
271 }
272
273 #[doc(alias = "title")]
274 fn connect_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
275 unsafe extern "C" fn notify_title_trampoline<
276 P: IsA<CompletionWords>,
277 F: Fn(&P) + 'static,
278 >(
279 this: *mut ffi::GtkSourceCompletionWords,
280 _param_spec: glib::ffi::gpointer,
281 f: glib::ffi::gpointer,
282 ) {
283 let f: &F = &*(f as *const F);
284 f(CompletionWords::from_glib_borrow(this).unsafe_cast_ref())
285 }
286 unsafe {
287 let f: Box_<F> = Box_::new(f);
288 connect_raw(
289 self.as_ptr() as *mut _,
290 c"notify::title".as_ptr() as *const _,
291 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
292 notify_title_trampoline::<Self, F> as *const (),
293 )),
294 Box_::into_raw(f),
295 )
296 }
297 }
298}
299
300impl<O: IsA<CompletionWords>> CompletionWordsExt for O {}