gtk4/auto/
string_filter.rs1use crate::{ffi, Expression, Filter, StringFilterMatchMode};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 #[doc(alias = "GtkStringFilter")]
15 pub struct StringFilter(Object<ffi::GtkStringFilter, ffi::GtkStringFilterClass>) @extends Filter;
16
17 match fn {
18 type_ => || ffi::gtk_string_filter_get_type(),
19 }
20}
21
22impl StringFilter {
23 #[doc(alias = "gtk_string_filter_new")]
24 pub fn new(expression: Option<impl AsRef<Expression>>) -> StringFilter {
25 assert_initialized_main_thread!();
26 unsafe {
27 from_glib_full(ffi::gtk_string_filter_new(
28 expression
29 .map(|p| p.as_ref().clone().upcast())
30 .into_glib_ptr(),
31 ))
32 }
33 }
34
35 pub fn builder() -> StringFilterBuilder {
40 StringFilterBuilder::new()
41 }
42
43 #[doc(alias = "gtk_string_filter_get_expression")]
44 #[doc(alias = "get_expression")]
45 pub fn expression(&self) -> Option<Expression> {
46 unsafe { from_glib_none(ffi::gtk_string_filter_get_expression(self.to_glib_none().0)) }
47 }
48
49 #[doc(alias = "gtk_string_filter_get_ignore_case")]
50 #[doc(alias = "get_ignore_case")]
51 #[doc(alias = "ignore-case")]
52 pub fn ignores_case(&self) -> bool {
53 unsafe {
54 from_glib(ffi::gtk_string_filter_get_ignore_case(
55 self.to_glib_none().0,
56 ))
57 }
58 }
59
60 #[doc(alias = "gtk_string_filter_get_match_mode")]
61 #[doc(alias = "get_match_mode")]
62 #[doc(alias = "match-mode")]
63 pub fn match_mode(&self) -> StringFilterMatchMode {
64 unsafe { from_glib(ffi::gtk_string_filter_get_match_mode(self.to_glib_none().0)) }
65 }
66
67 #[doc(alias = "gtk_string_filter_get_search")]
68 #[doc(alias = "get_search")]
69 pub fn search(&self) -> Option<glib::GString> {
70 unsafe { from_glib_none(ffi::gtk_string_filter_get_search(self.to_glib_none().0)) }
71 }
72
73 #[doc(alias = "gtk_string_filter_set_expression")]
74 #[doc(alias = "expression")]
75 pub fn set_expression(&self, expression: Option<impl AsRef<Expression>>) {
76 unsafe {
77 ffi::gtk_string_filter_set_expression(
78 self.to_glib_none().0,
79 expression.as_ref().map(|p| p.as_ref()).to_glib_none().0,
80 );
81 }
82 }
83
84 #[doc(alias = "gtk_string_filter_set_ignore_case")]
85 #[doc(alias = "ignore-case")]
86 pub fn set_ignore_case(&self, ignore_case: bool) {
87 unsafe {
88 ffi::gtk_string_filter_set_ignore_case(self.to_glib_none().0, ignore_case.into_glib());
89 }
90 }
91
92 #[doc(alias = "gtk_string_filter_set_match_mode")]
93 #[doc(alias = "match-mode")]
94 pub fn set_match_mode(&self, mode: StringFilterMatchMode) {
95 unsafe {
96 ffi::gtk_string_filter_set_match_mode(self.to_glib_none().0, mode.into_glib());
97 }
98 }
99
100 #[doc(alias = "gtk_string_filter_set_search")]
101 #[doc(alias = "search")]
102 pub fn set_search(&self, search: Option<&str>) {
103 unsafe {
104 ffi::gtk_string_filter_set_search(self.to_glib_none().0, search.to_glib_none().0);
105 }
106 }
107
108 #[doc(alias = "expression")]
109 pub fn connect_expression_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
110 unsafe extern "C" fn notify_expression_trampoline<F: Fn(&StringFilter) + 'static>(
111 this: *mut ffi::GtkStringFilter,
112 _param_spec: glib::ffi::gpointer,
113 f: glib::ffi::gpointer,
114 ) {
115 let f: &F = &*(f as *const F);
116 f(&from_glib_borrow(this))
117 }
118 unsafe {
119 let f: Box_<F> = Box_::new(f);
120 connect_raw(
121 self.as_ptr() as *mut _,
122 b"notify::expression\0".as_ptr() as *const _,
123 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
124 notify_expression_trampoline::<F> as *const (),
125 )),
126 Box_::into_raw(f),
127 )
128 }
129 }
130
131 #[doc(alias = "ignore-case")]
132 pub fn connect_ignore_case_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
133 unsafe extern "C" fn notify_ignore_case_trampoline<F: Fn(&StringFilter) + 'static>(
134 this: *mut ffi::GtkStringFilter,
135 _param_spec: glib::ffi::gpointer,
136 f: glib::ffi::gpointer,
137 ) {
138 let f: &F = &*(f as *const F);
139 f(&from_glib_borrow(this))
140 }
141 unsafe {
142 let f: Box_<F> = Box_::new(f);
143 connect_raw(
144 self.as_ptr() as *mut _,
145 b"notify::ignore-case\0".as_ptr() as *const _,
146 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
147 notify_ignore_case_trampoline::<F> as *const (),
148 )),
149 Box_::into_raw(f),
150 )
151 }
152 }
153
154 #[doc(alias = "match-mode")]
155 pub fn connect_match_mode_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
156 unsafe extern "C" fn notify_match_mode_trampoline<F: Fn(&StringFilter) + 'static>(
157 this: *mut ffi::GtkStringFilter,
158 _param_spec: glib::ffi::gpointer,
159 f: glib::ffi::gpointer,
160 ) {
161 let f: &F = &*(f as *const F);
162 f(&from_glib_borrow(this))
163 }
164 unsafe {
165 let f: Box_<F> = Box_::new(f);
166 connect_raw(
167 self.as_ptr() as *mut _,
168 b"notify::match-mode\0".as_ptr() as *const _,
169 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
170 notify_match_mode_trampoline::<F> as *const (),
171 )),
172 Box_::into_raw(f),
173 )
174 }
175 }
176
177 #[doc(alias = "search")]
178 pub fn connect_search_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
179 unsafe extern "C" fn notify_search_trampoline<F: Fn(&StringFilter) + 'static>(
180 this: *mut ffi::GtkStringFilter,
181 _param_spec: glib::ffi::gpointer,
182 f: glib::ffi::gpointer,
183 ) {
184 let f: &F = &*(f as *const F);
185 f(&from_glib_borrow(this))
186 }
187 unsafe {
188 let f: Box_<F> = Box_::new(f);
189 connect_raw(
190 self.as_ptr() as *mut _,
191 b"notify::search\0".as_ptr() as *const _,
192 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
193 notify_search_trampoline::<F> as *const (),
194 )),
195 Box_::into_raw(f),
196 )
197 }
198 }
199}
200
201impl Default for StringFilter {
202 fn default() -> Self {
203 glib::object::Object::new::<Self>()
204 }
205}
206
207#[must_use = "The builder must be built to be used"]
212pub struct StringFilterBuilder {
213 builder: glib::object::ObjectBuilder<'static, StringFilter>,
214}
215
216impl StringFilterBuilder {
217 fn new() -> Self {
218 Self {
219 builder: glib::object::Object::builder(),
220 }
221 }
222
223 pub fn expression(self, expression: impl AsRef<Expression>) -> Self {
224 Self {
225 builder: self
226 .builder
227 .property("expression", expression.as_ref().clone()),
228 }
229 }
230
231 pub fn ignore_case(self, ignore_case: bool) -> Self {
232 Self {
233 builder: self.builder.property("ignore-case", ignore_case),
234 }
235 }
236
237 pub fn match_mode(self, match_mode: StringFilterMatchMode) -> Self {
238 Self {
239 builder: self.builder.property("match-mode", match_mode),
240 }
241 }
242
243 pub fn search(self, search: impl Into<glib::GString>) -> Self {
244 Self {
245 builder: self.builder.property("search", search.into()),
246 }
247 }
248
249 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
252 pub fn build(self) -> StringFilter {
253 assert_initialized_main_thread!();
254 self.builder.build()
255 }
256}