gtk4/auto/
string_sorter.rs1#[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")]
18 pub struct StringSorter(Object<ffi::GtkStringSorter, ffi::GtkStringSorterClass>) @extends Sorter;
19
20 match fn {
21 type_ => || ffi::gtk_string_sorter_get_type(),
22 }
23}
24
25impl StringSorter {
26 #[doc(alias = "gtk_string_sorter_new")]
27 pub fn new(expression: Option<impl AsRef<Expression>>) -> StringSorter {
28 assert_initialized_main_thread!();
29 unsafe {
30 from_glib_full(ffi::gtk_string_sorter_new(
31 expression
32 .map(|p| p.as_ref().clone().upcast())
33 .into_glib_ptr(),
34 ))
35 }
36 }
37
38 pub fn builder() -> StringSorterBuilder {
43 StringSorterBuilder::new()
44 }
45
46 #[cfg(feature = "v4_10")]
47 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
48 #[doc(alias = "gtk_string_sorter_get_collation")]
49 #[doc(alias = "get_collation")]
50 pub fn collation(&self) -> Collation {
51 unsafe { from_glib(ffi::gtk_string_sorter_get_collation(self.to_glib_none().0)) }
52 }
53
54 #[doc(alias = "gtk_string_sorter_get_expression")]
55 #[doc(alias = "get_expression")]
56 pub fn expression(&self) -> Option<Expression> {
57 unsafe { from_glib_none(ffi::gtk_string_sorter_get_expression(self.to_glib_none().0)) }
58 }
59
60 #[doc(alias = "gtk_string_sorter_get_ignore_case")]
61 #[doc(alias = "get_ignore_case")]
62 #[doc(alias = "ignore-case")]
63 pub fn ignores_case(&self) -> bool {
64 unsafe {
65 from_glib(ffi::gtk_string_sorter_get_ignore_case(
66 self.to_glib_none().0,
67 ))
68 }
69 }
70
71 #[cfg(feature = "v4_10")]
72 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
73 #[doc(alias = "gtk_string_sorter_set_collation")]
74 #[doc(alias = "collation")]
75 pub fn set_collation(&self, collation: Collation) {
76 unsafe {
77 ffi::gtk_string_sorter_set_collation(self.to_glib_none().0, collation.into_glib());
78 }
79 }
80
81 #[doc(alias = "gtk_string_sorter_set_expression")]
82 #[doc(alias = "expression")]
83 pub fn set_expression(&self, expression: Option<impl AsRef<Expression>>) {
84 unsafe {
85 ffi::gtk_string_sorter_set_expression(
86 self.to_glib_none().0,
87 expression.as_ref().map(|p| p.as_ref()).to_glib_none().0,
88 );
89 }
90 }
91
92 #[doc(alias = "gtk_string_sorter_set_ignore_case")]
93 #[doc(alias = "ignore-case")]
94 pub fn set_ignore_case(&self, ignore_case: bool) {
95 unsafe {
96 ffi::gtk_string_sorter_set_ignore_case(self.to_glib_none().0, ignore_case.into_glib());
97 }
98 }
99
100 #[cfg(feature = "v4_10")]
101 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
102 #[doc(alias = "collation")]
103 pub fn connect_collation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
104 unsafe extern "C" fn notify_collation_trampoline<F: Fn(&StringSorter) + 'static>(
105 this: *mut ffi::GtkStringSorter,
106 _param_spec: glib::ffi::gpointer,
107 f: glib::ffi::gpointer,
108 ) {
109 let f: &F = &*(f as *const F);
110 f(&from_glib_borrow(this))
111 }
112 unsafe {
113 let f: Box_<F> = Box_::new(f);
114 connect_raw(
115 self.as_ptr() as *mut _,
116 c"notify::collation".as_ptr() as *const _,
117 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
118 notify_collation_trampoline::<F> as *const (),
119 )),
120 Box_::into_raw(f),
121 )
122 }
123 }
124
125 #[doc(alias = "expression")]
126 pub fn connect_expression_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
127 unsafe extern "C" fn notify_expression_trampoline<F: Fn(&StringSorter) + 'static>(
128 this: *mut ffi::GtkStringSorter,
129 _param_spec: glib::ffi::gpointer,
130 f: glib::ffi::gpointer,
131 ) {
132 let f: &F = &*(f as *const F);
133 f(&from_glib_borrow(this))
134 }
135 unsafe {
136 let f: Box_<F> = Box_::new(f);
137 connect_raw(
138 self.as_ptr() as *mut _,
139 c"notify::expression".as_ptr() as *const _,
140 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
141 notify_expression_trampoline::<F> as *const (),
142 )),
143 Box_::into_raw(f),
144 )
145 }
146 }
147
148 #[doc(alias = "ignore-case")]
149 pub fn connect_ignore_case_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
150 unsafe extern "C" fn notify_ignore_case_trampoline<F: Fn(&StringSorter) + 'static>(
151 this: *mut ffi::GtkStringSorter,
152 _param_spec: glib::ffi::gpointer,
153 f: glib::ffi::gpointer,
154 ) {
155 let f: &F = &*(f as *const F);
156 f(&from_glib_borrow(this))
157 }
158 unsafe {
159 let f: Box_<F> = Box_::new(f);
160 connect_raw(
161 self.as_ptr() as *mut _,
162 c"notify::ignore-case".as_ptr() as *const _,
163 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
164 notify_ignore_case_trampoline::<F> as *const (),
165 )),
166 Box_::into_raw(f),
167 )
168 }
169 }
170}
171
172impl Default for StringSorter {
173 fn default() -> Self {
174 glib::object::Object::new::<Self>()
175 }
176}
177
178#[must_use = "The builder must be built to be used"]
183pub struct StringSorterBuilder {
184 builder: glib::object::ObjectBuilder<'static, StringSorter>,
185}
186
187impl StringSorterBuilder {
188 fn new() -> Self {
189 Self {
190 builder: glib::object::Object::builder(),
191 }
192 }
193
194 #[cfg(feature = "v4_10")]
195 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
196 pub fn collation(self, collation: Collation) -> Self {
197 Self {
198 builder: self.builder.property("collation", collation),
199 }
200 }
201
202 pub fn expression(self, expression: impl AsRef<Expression>) -> Self {
203 Self {
204 builder: self
205 .builder
206 .property("expression", expression.as_ref().clone()),
207 }
208 }
209
210 pub fn ignore_case(self, ignore_case: bool) -> Self {
211 Self {
212 builder: self.builder.property("ignore-case", ignore_case),
213 }
214 }
215
216 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
219 pub fn build(self) -> StringSorter {
220 assert_initialized_main_thread!();
221 self.builder.build()
222 }
223}