gtk4/auto/
string_sorter.rs1#[cfg(feature = "v4_10")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
7use crate::Collation;
8use crate::{Expression, Sorter, ffi};
9use glib::{
10 prelude::*,
11 signal::{SignalHandlerId, connect_raw},
12 translate::*,
13};
14use std::boxed::Box as Box_;
15
16glib::wrapper! {
17 #[doc(alias = "GtkStringSorter")]
56 pub struct StringSorter(Object<ffi::GtkStringSorter, ffi::GtkStringSorterClass>) @extends Sorter;
57
58 match fn {
59 type_ => || ffi::gtk_string_sorter_get_type(),
60 }
61}
62
63impl StringSorter {
64 #[doc(alias = "gtk_string_sorter_new")]
76 pub fn new(expression: Option<impl AsRef<Expression>>) -> StringSorter {
77 assert_initialized_main_thread!();
78 unsafe {
79 from_glib_full(ffi::gtk_string_sorter_new(
80 expression
81 .map(|p| p.as_ref().clone().upcast())
82 .into_glib_ptr(),
83 ))
84 }
85 }
86
87 pub fn builder() -> StringSorterBuilder {
92 StringSorterBuilder::new()
93 }
94
95 #[cfg(feature = "v4_10")]
101 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
102 #[doc(alias = "gtk_string_sorter_get_collation")]
103 #[doc(alias = "get_collation")]
104 pub fn collation(&self) -> Collation {
105 unsafe { from_glib(ffi::gtk_string_sorter_get_collation(self.to_glib_none().0)) }
106 }
107
108 #[doc(alias = "gtk_string_sorter_get_expression")]
114 #[doc(alias = "get_expression")]
115 pub fn expression(&self) -> Option<Expression> {
116 unsafe { from_glib_none(ffi::gtk_string_sorter_get_expression(self.to_glib_none().0)) }
117 }
118
119 #[doc(alias = "gtk_string_sorter_get_ignore_case")]
125 #[doc(alias = "get_ignore_case")]
126 #[doc(alias = "ignore-case")]
127 pub fn ignores_case(&self) -> bool {
128 unsafe {
129 from_glib(ffi::gtk_string_sorter_get_ignore_case(
130 self.to_glib_none().0,
131 ))
132 }
133 }
134
135 #[cfg(feature = "v4_10")]
139 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
140 #[doc(alias = "gtk_string_sorter_set_collation")]
141 #[doc(alias = "collation")]
142 pub fn set_collation(&self, collation: Collation) {
143 unsafe {
144 ffi::gtk_string_sorter_set_collation(self.to_glib_none().0, collation.into_glib());
145 }
146 }
147
148 #[doc(alias = "gtk_string_sorter_set_expression")]
154 #[doc(alias = "expression")]
155 pub fn set_expression(&self, expression: Option<impl AsRef<Expression>>) {
156 unsafe {
157 ffi::gtk_string_sorter_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_sorter_set_ignore_case")]
168 #[doc(alias = "ignore-case")]
169 pub fn set_ignore_case(&self, ignore_case: bool) {
170 unsafe {
171 ffi::gtk_string_sorter_set_ignore_case(self.to_glib_none().0, ignore_case.into_glib());
172 }
173 }
174
175 #[cfg(feature = "v4_10")]
176 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
177 #[doc(alias = "collation")]
178 pub fn connect_collation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
179 unsafe extern "C" fn notify_collation_trampoline<F: Fn(&StringSorter) + 'static>(
180 this: *mut ffi::GtkStringSorter,
181 _param_spec: glib::ffi::gpointer,
182 f: glib::ffi::gpointer,
183 ) {
184 unsafe {
185 let f: &F = &*(f as *const F);
186 f(&from_glib_borrow(this))
187 }
188 }
189 unsafe {
190 let f: Box_<F> = Box_::new(f);
191 connect_raw(
192 self.as_ptr() as *mut _,
193 c"notify::collation".as_ptr() as *const _,
194 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
195 notify_collation_trampoline::<F> as *const (),
196 )),
197 Box_::into_raw(f),
198 )
199 }
200 }
201
202 #[doc(alias = "expression")]
203 pub fn connect_expression_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
204 unsafe extern "C" fn notify_expression_trampoline<F: Fn(&StringSorter) + 'static>(
205 this: *mut ffi::GtkStringSorter,
206 _param_spec: glib::ffi::gpointer,
207 f: glib::ffi::gpointer,
208 ) {
209 unsafe {
210 let f: &F = &*(f as *const F);
211 f(&from_glib_borrow(this))
212 }
213 }
214 unsafe {
215 let f: Box_<F> = Box_::new(f);
216 connect_raw(
217 self.as_ptr() as *mut _,
218 c"notify::expression".as_ptr() as *const _,
219 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
220 notify_expression_trampoline::<F> as *const (),
221 )),
222 Box_::into_raw(f),
223 )
224 }
225 }
226
227 #[doc(alias = "ignore-case")]
228 pub fn connect_ignore_case_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
229 unsafe extern "C" fn notify_ignore_case_trampoline<F: Fn(&StringSorter) + 'static>(
230 this: *mut ffi::GtkStringSorter,
231 _param_spec: glib::ffi::gpointer,
232 f: glib::ffi::gpointer,
233 ) {
234 unsafe {
235 let f: &F = &*(f as *const F);
236 f(&from_glib_borrow(this))
237 }
238 }
239 unsafe {
240 let f: Box_<F> = Box_::new(f);
241 connect_raw(
242 self.as_ptr() as *mut _,
243 c"notify::ignore-case".as_ptr() as *const _,
244 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
245 notify_ignore_case_trampoline::<F> as *const (),
246 )),
247 Box_::into_raw(f),
248 )
249 }
250 }
251}
252
253impl Default for StringSorter {
254 fn default() -> Self {
255 glib::object::Object::new::<Self>()
256 }
257}
258
259#[must_use = "The builder must be built to be used"]
264pub struct StringSorterBuilder {
265 builder: glib::object::ObjectBuilder<'static, StringSorter>,
266}
267
268impl StringSorterBuilder {
269 fn new() -> Self {
270 Self {
271 builder: glib::object::Object::builder(),
272 }
273 }
274
275 #[cfg(feature = "v4_10")]
283 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
284 pub fn collation(self, collation: Collation) -> Self {
285 Self {
286 builder: self.builder.property("collation", collation),
287 }
288 }
289
290 pub fn expression(self, expression: impl AsRef<Expression>) -> Self {
292 Self {
293 builder: self
294 .builder
295 .property("expression", expression.as_ref().clone()),
296 }
297 }
298
299 pub fn ignore_case(self, ignore_case: bool) -> Self {
301 Self {
302 builder: self.builder.property("ignore-case", ignore_case),
303 }
304 }
305
306 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
309 pub fn build(self) -> StringSorter {
310 assert_initialized_main_thread!();
311 self.builder.build()
312 }
313}