gtk4/auto/
string_sorter.rs
1#[cfg(feature = "v4_10")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
7use crate::Collation;
8use crate::{ffi, Expression, Sorter};
9use glib::{
10 prelude::*,
11 signal::{connect_raw, SignalHandlerId},
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 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::collation\0".as_ptr() as *const _,
192 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
193 notify_collation_trampoline::<F> as *const (),
194 )),
195 Box_::into_raw(f),
196 )
197 }
198 }
199
200 #[doc(alias = "expression")]
201 pub fn connect_expression_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
202 unsafe extern "C" fn notify_expression_trampoline<F: Fn(&StringSorter) + 'static>(
203 this: *mut ffi::GtkStringSorter,
204 _param_spec: glib::ffi::gpointer,
205 f: glib::ffi::gpointer,
206 ) {
207 let f: &F = &*(f as *const F);
208 f(&from_glib_borrow(this))
209 }
210 unsafe {
211 let f: Box_<F> = Box_::new(f);
212 connect_raw(
213 self.as_ptr() as *mut _,
214 b"notify::expression\0".as_ptr() as *const _,
215 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
216 notify_expression_trampoline::<F> as *const (),
217 )),
218 Box_::into_raw(f),
219 )
220 }
221 }
222
223 #[doc(alias = "ignore-case")]
224 pub fn connect_ignore_case_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
225 unsafe extern "C" fn notify_ignore_case_trampoline<F: Fn(&StringSorter) + 'static>(
226 this: *mut ffi::GtkStringSorter,
227 _param_spec: glib::ffi::gpointer,
228 f: glib::ffi::gpointer,
229 ) {
230 let f: &F = &*(f as *const F);
231 f(&from_glib_borrow(this))
232 }
233 unsafe {
234 let f: Box_<F> = Box_::new(f);
235 connect_raw(
236 self.as_ptr() as *mut _,
237 b"notify::ignore-case\0".as_ptr() as *const _,
238 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
239 notify_ignore_case_trampoline::<F> as *const (),
240 )),
241 Box_::into_raw(f),
242 )
243 }
244 }
245}
246
247impl Default for StringSorter {
248 fn default() -> Self {
249 glib::object::Object::new::<Self>()
250 }
251}
252
253#[must_use = "The builder must be built to be used"]
258pub struct StringSorterBuilder {
259 builder: glib::object::ObjectBuilder<'static, StringSorter>,
260}
261
262impl StringSorterBuilder {
263 fn new() -> Self {
264 Self {
265 builder: glib::object::Object::builder(),
266 }
267 }
268
269 #[cfg(feature = "v4_10")]
277 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
278 pub fn collation(self, collation: Collation) -> Self {
279 Self {
280 builder: self.builder.property("collation", collation),
281 }
282 }
283
284 pub fn expression(self, expression: impl AsRef<Expression>) -> Self {
286 Self {
287 builder: self
288 .builder
289 .property("expression", expression.as_ref().clone()),
290 }
291 }
292
293 pub fn ignore_case(self, ignore_case: bool) -> Self {
295 Self {
296 builder: self.builder.property("ignore-case", ignore_case),
297 }
298 }
299
300 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
303 pub fn build(self) -> StringSorter {
304 assert_initialized_main_thread!();
305 self.builder.build()
306 }
307}