gtk4/auto/
string_filter.rs1use crate::{Expression, Filter, StringFilterMatchMode, ffi};
6use glib::{
7 prelude::*,
8 signal::{SignalHandlerId, connect_raw},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 #[doc(alias = "GtkStringFilter")]
58 pub struct StringFilter(Object<ffi::GtkStringFilter, ffi::GtkStringFilterClass>) @extends Filter;
59
60 match fn {
61 type_ => || ffi::gtk_string_filter_get_type(),
62 }
63}
64
65impl StringFilter {
66 #[doc(alias = "gtk_string_filter_new")]
77 pub fn new(expression: Option<impl AsRef<Expression>>) -> StringFilter {
78 assert_initialized_main_thread!();
79 unsafe {
80 from_glib_full(ffi::gtk_string_filter_new(
81 expression
82 .map(|p| p.as_ref().clone().upcast())
83 .into_glib_ptr(),
84 ))
85 }
86 }
87
88 pub fn builder() -> StringFilterBuilder {
93 StringFilterBuilder::new()
94 }
95
96 #[doc(alias = "gtk_string_filter_get_expression")]
103 #[doc(alias = "get_expression")]
104 pub fn expression(&self) -> Option<Expression> {
105 unsafe { from_glib_none(ffi::gtk_string_filter_get_expression(self.to_glib_none().0)) }
106 }
107
108 #[doc(alias = "gtk_string_filter_get_ignore_case")]
114 #[doc(alias = "get_ignore_case")]
115 #[doc(alias = "ignore-case")]
116 pub fn ignores_case(&self) -> bool {
117 unsafe {
118 from_glib(ffi::gtk_string_filter_get_ignore_case(
119 self.to_glib_none().0,
120 ))
121 }
122 }
123
124 #[doc(alias = "gtk_string_filter_get_match_mode")]
130 #[doc(alias = "get_match_mode")]
131 #[doc(alias = "match-mode")]
132 pub fn match_mode(&self) -> StringFilterMatchMode {
133 unsafe { from_glib(ffi::gtk_string_filter_get_match_mode(self.to_glib_none().0)) }
134 }
135
136 #[doc(alias = "gtk_string_filter_get_search")]
142 #[doc(alias = "get_search")]
143 pub fn search(&self) -> Option<glib::GString> {
144 unsafe { from_glib_none(ffi::gtk_string_filter_get_search(self.to_glib_none().0)) }
145 }
146
147 #[doc(alias = "gtk_string_filter_set_expression")]
154 #[doc(alias = "expression")]
155 pub fn set_expression(&self, expression: Option<impl AsRef<Expression>>) {
156 unsafe {
157 ffi::gtk_string_filter_set_expression(
158 self.to_glib_none().0,
159 expression.as_ref().map(|p| p.as_ref()).to_glib_none().0,
160 );
161 }
162 }
163
164 #[doc(alias = "gtk_string_filter_set_ignore_case")]
168 #[doc(alias = "ignore-case")]
169 pub fn set_ignore_case(&self, ignore_case: bool) {
170 unsafe {
171 ffi::gtk_string_filter_set_ignore_case(self.to_glib_none().0, ignore_case.into_glib());
172 }
173 }
174
175 #[doc(alias = "gtk_string_filter_set_match_mode")]
179 #[doc(alias = "match-mode")]
180 pub fn set_match_mode(&self, mode: StringFilterMatchMode) {
181 unsafe {
182 ffi::gtk_string_filter_set_match_mode(self.to_glib_none().0, mode.into_glib());
183 }
184 }
185
186 #[doc(alias = "gtk_string_filter_set_search")]
190 #[doc(alias = "search")]
191 pub fn set_search(&self, search: Option<&str>) {
192 unsafe {
193 ffi::gtk_string_filter_set_search(self.to_glib_none().0, search.to_glib_none().0);
194 }
195 }
196
197 #[doc(alias = "expression")]
198 pub fn connect_expression_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
199 unsafe extern "C" fn notify_expression_trampoline<F: Fn(&StringFilter) + 'static>(
200 this: *mut ffi::GtkStringFilter,
201 _param_spec: glib::ffi::gpointer,
202 f: glib::ffi::gpointer,
203 ) {
204 unsafe {
205 let f: &F = &*(f as *const F);
206 f(&from_glib_borrow(this))
207 }
208 }
209 unsafe {
210 let f: Box_<F> = Box_::new(f);
211 connect_raw(
212 self.as_ptr() as *mut _,
213 c"notify::expression".as_ptr() as *const _,
214 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
215 notify_expression_trampoline::<F> as *const (),
216 )),
217 Box_::into_raw(f),
218 )
219 }
220 }
221
222 #[doc(alias = "ignore-case")]
223 pub fn connect_ignore_case_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
224 unsafe extern "C" fn notify_ignore_case_trampoline<F: Fn(&StringFilter) + 'static>(
225 this: *mut ffi::GtkStringFilter,
226 _param_spec: glib::ffi::gpointer,
227 f: glib::ffi::gpointer,
228 ) {
229 unsafe {
230 let f: &F = &*(f as *const F);
231 f(&from_glib_borrow(this))
232 }
233 }
234 unsafe {
235 let f: Box_<F> = Box_::new(f);
236 connect_raw(
237 self.as_ptr() as *mut _,
238 c"notify::ignore-case".as_ptr() as *const _,
239 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
240 notify_ignore_case_trampoline::<F> as *const (),
241 )),
242 Box_::into_raw(f),
243 )
244 }
245 }
246
247 #[doc(alias = "match-mode")]
248 pub fn connect_match_mode_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
249 unsafe extern "C" fn notify_match_mode_trampoline<F: Fn(&StringFilter) + 'static>(
250 this: *mut ffi::GtkStringFilter,
251 _param_spec: glib::ffi::gpointer,
252 f: glib::ffi::gpointer,
253 ) {
254 unsafe {
255 let f: &F = &*(f as *const F);
256 f(&from_glib_borrow(this))
257 }
258 }
259 unsafe {
260 let f: Box_<F> = Box_::new(f);
261 connect_raw(
262 self.as_ptr() as *mut _,
263 c"notify::match-mode".as_ptr() as *const _,
264 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
265 notify_match_mode_trampoline::<F> as *const (),
266 )),
267 Box_::into_raw(f),
268 )
269 }
270 }
271
272 #[doc(alias = "search")]
273 pub fn connect_search_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
274 unsafe extern "C" fn notify_search_trampoline<F: Fn(&StringFilter) + 'static>(
275 this: *mut ffi::GtkStringFilter,
276 _param_spec: glib::ffi::gpointer,
277 f: glib::ffi::gpointer,
278 ) {
279 unsafe {
280 let f: &F = &*(f as *const F);
281 f(&from_glib_borrow(this))
282 }
283 }
284 unsafe {
285 let f: Box_<F> = Box_::new(f);
286 connect_raw(
287 self.as_ptr() as *mut _,
288 c"notify::search".as_ptr() as *const _,
289 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
290 notify_search_trampoline::<F> as *const (),
291 )),
292 Box_::into_raw(f),
293 )
294 }
295 }
296}
297
298impl Default for StringFilter {
299 fn default() -> Self {
300 glib::object::Object::new::<Self>()
301 }
302}
303
304#[must_use = "The builder must be built to be used"]
309pub struct StringFilterBuilder {
310 builder: glib::object::ObjectBuilder<'static, StringFilter>,
311}
312
313impl StringFilterBuilder {
314 fn new() -> Self {
315 Self {
316 builder: glib::object::Object::builder(),
317 }
318 }
319
320 pub fn expression(self, expression: impl AsRef<Expression>) -> Self {
323 Self {
324 builder: self
325 .builder
326 .property("expression", expression.as_ref().clone()),
327 }
328 }
329
330 pub fn ignore_case(self, ignore_case: bool) -> Self {
332 Self {
333 builder: self.builder.property("ignore-case", ignore_case),
334 }
335 }
336
337 pub fn match_mode(self, match_mode: StringFilterMatchMode) -> Self {
339 Self {
340 builder: self.builder.property("match-mode", match_mode),
341 }
342 }
343
344 pub fn search(self, search: impl Into<glib::GString>) -> Self {
346 Self {
347 builder: self.builder.property("search", search.into()),
348 }
349 }
350
351 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
354 pub fn build(self) -> StringFilter {
355 assert_initialized_main_thread!();
356 self.builder.build()
357 }
358}