libadwaita/auto/
shortcuts_item.rs1use crate::ffi;
7use glib::{
8 prelude::*,
9 signal::{SignalHandlerId, connect_raw},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "AdwShortcutsItem")]
16 pub struct ShortcutsItem(Object<ffi::AdwShortcutsItem, ffi::AdwShortcutsItemClass>);
17
18 match fn {
19 type_ => || ffi::adw_shortcuts_item_get_type(),
20 }
21}
22
23impl ShortcutsItem {
24 #[doc(alias = "adw_shortcuts_item_new")]
25 pub fn new(title: &str, accelerator: &str) -> ShortcutsItem {
26 assert_initialized_main_thread!();
27 unsafe {
28 from_glib_full(ffi::adw_shortcuts_item_new(
29 title.to_glib_none().0,
30 accelerator.to_glib_none().0,
31 ))
32 }
33 }
34
35 #[doc(alias = "adw_shortcuts_item_new_from_action")]
36 #[doc(alias = "new_from_action")]
37 pub fn from_action(title: &str, action_name: &str) -> ShortcutsItem {
38 assert_initialized_main_thread!();
39 unsafe {
40 from_glib_full(ffi::adw_shortcuts_item_new_from_action(
41 title.to_glib_none().0,
42 action_name.to_glib_none().0,
43 ))
44 }
45 }
46
47 #[doc(alias = "adw_shortcuts_item_get_accelerator")]
48 #[doc(alias = "get_accelerator")]
49 pub fn accelerator(&self) -> glib::GString {
50 unsafe {
51 from_glib_none(ffi::adw_shortcuts_item_get_accelerator(
52 self.to_glib_none().0,
53 ))
54 }
55 }
56
57 #[doc(alias = "adw_shortcuts_item_get_action_name")]
58 #[doc(alias = "get_action_name")]
59 #[doc(alias = "action-name")]
60 pub fn action_name(&self) -> glib::GString {
61 unsafe {
62 from_glib_none(ffi::adw_shortcuts_item_get_action_name(
63 self.to_glib_none().0,
64 ))
65 }
66 }
67
68 #[doc(alias = "adw_shortcuts_item_get_direction")]
69 #[doc(alias = "get_direction")]
70 pub fn direction(&self) -> gtk::TextDirection {
71 unsafe { from_glib(ffi::adw_shortcuts_item_get_direction(self.to_glib_none().0)) }
72 }
73
74 #[doc(alias = "adw_shortcuts_item_get_subtitle")]
75 #[doc(alias = "get_subtitle")]
76 pub fn subtitle(&self) -> glib::GString {
77 unsafe { from_glib_none(ffi::adw_shortcuts_item_get_subtitle(self.to_glib_none().0)) }
78 }
79
80 #[doc(alias = "adw_shortcuts_item_get_title")]
81 #[doc(alias = "get_title")]
82 pub fn title(&self) -> glib::GString {
83 unsafe { from_glib_none(ffi::adw_shortcuts_item_get_title(self.to_glib_none().0)) }
84 }
85
86 #[doc(alias = "adw_shortcuts_item_set_accelerator")]
87 #[doc(alias = "accelerator")]
88 pub fn set_accelerator(&self, accelerator: &str) {
89 unsafe {
90 ffi::adw_shortcuts_item_set_accelerator(
91 self.to_glib_none().0,
92 accelerator.to_glib_none().0,
93 );
94 }
95 }
96
97 #[doc(alias = "adw_shortcuts_item_set_action_name")]
98 #[doc(alias = "action-name")]
99 pub fn set_action_name(&self, action_name: &str) {
100 unsafe {
101 ffi::adw_shortcuts_item_set_action_name(
102 self.to_glib_none().0,
103 action_name.to_glib_none().0,
104 );
105 }
106 }
107
108 #[doc(alias = "adw_shortcuts_item_set_direction")]
109 #[doc(alias = "direction")]
110 pub fn set_direction(&self, direction: gtk::TextDirection) {
111 unsafe {
112 ffi::adw_shortcuts_item_set_direction(self.to_glib_none().0, direction.into_glib());
113 }
114 }
115
116 #[doc(alias = "adw_shortcuts_item_set_subtitle")]
117 #[doc(alias = "subtitle")]
118 pub fn set_subtitle(&self, subtitle: &str) {
119 unsafe {
120 ffi::adw_shortcuts_item_set_subtitle(self.to_glib_none().0, subtitle.to_glib_none().0);
121 }
122 }
123
124 #[doc(alias = "adw_shortcuts_item_set_title")]
125 #[doc(alias = "title")]
126 pub fn set_title(&self, title: &str) {
127 unsafe {
128 ffi::adw_shortcuts_item_set_title(self.to_glib_none().0, title.to_glib_none().0);
129 }
130 }
131
132 #[cfg(feature = "v1_8")]
133 #[cfg_attr(docsrs, doc(cfg(feature = "v1_8")))]
134 #[doc(alias = "accelerator")]
135 pub fn connect_accelerator_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
136 unsafe extern "C" fn notify_accelerator_trampoline<F: Fn(&ShortcutsItem) + 'static>(
137 this: *mut ffi::AdwShortcutsItem,
138 _param_spec: glib::ffi::gpointer,
139 f: glib::ffi::gpointer,
140 ) {
141 unsafe {
142 let f: &F = &*(f as *const F);
143 f(&from_glib_borrow(this))
144 }
145 }
146 unsafe {
147 let f: Box_<F> = Box_::new(f);
148 connect_raw(
149 self.as_ptr() as *mut _,
150 c"notify::accelerator".as_ptr(),
151 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
152 notify_accelerator_trampoline::<F> as *const (),
153 )),
154 Box_::into_raw(f),
155 )
156 }
157 }
158
159 #[cfg(feature = "v1_8")]
160 #[cfg_attr(docsrs, doc(cfg(feature = "v1_8")))]
161 #[doc(alias = "action-name")]
162 pub fn connect_action_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
163 unsafe extern "C" fn notify_action_name_trampoline<F: Fn(&ShortcutsItem) + 'static>(
164 this: *mut ffi::AdwShortcutsItem,
165 _param_spec: glib::ffi::gpointer,
166 f: glib::ffi::gpointer,
167 ) {
168 unsafe {
169 let f: &F = &*(f as *const F);
170 f(&from_glib_borrow(this))
171 }
172 }
173 unsafe {
174 let f: Box_<F> = Box_::new(f);
175 connect_raw(
176 self.as_ptr() as *mut _,
177 c"notify::action-name".as_ptr(),
178 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
179 notify_action_name_trampoline::<F> as *const (),
180 )),
181 Box_::into_raw(f),
182 )
183 }
184 }
185
186 #[cfg(feature = "v1_8")]
187 #[cfg_attr(docsrs, doc(cfg(feature = "v1_8")))]
188 #[doc(alias = "direction")]
189 pub fn connect_direction_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
190 unsafe extern "C" fn notify_direction_trampoline<F: Fn(&ShortcutsItem) + 'static>(
191 this: *mut ffi::AdwShortcutsItem,
192 _param_spec: glib::ffi::gpointer,
193 f: glib::ffi::gpointer,
194 ) {
195 unsafe {
196 let f: &F = &*(f as *const F);
197 f(&from_glib_borrow(this))
198 }
199 }
200 unsafe {
201 let f: Box_<F> = Box_::new(f);
202 connect_raw(
203 self.as_ptr() as *mut _,
204 c"notify::direction".as_ptr(),
205 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
206 notify_direction_trampoline::<F> as *const (),
207 )),
208 Box_::into_raw(f),
209 )
210 }
211 }
212
213 #[cfg(feature = "v1_8")]
214 #[cfg_attr(docsrs, doc(cfg(feature = "v1_8")))]
215 #[doc(alias = "subtitle")]
216 pub fn connect_subtitle_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
217 unsafe extern "C" fn notify_subtitle_trampoline<F: Fn(&ShortcutsItem) + 'static>(
218 this: *mut ffi::AdwShortcutsItem,
219 _param_spec: glib::ffi::gpointer,
220 f: glib::ffi::gpointer,
221 ) {
222 unsafe {
223 let f: &F = &*(f as *const F);
224 f(&from_glib_borrow(this))
225 }
226 }
227 unsafe {
228 let f: Box_<F> = Box_::new(f);
229 connect_raw(
230 self.as_ptr() as *mut _,
231 c"notify::subtitle".as_ptr(),
232 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
233 notify_subtitle_trampoline::<F> as *const (),
234 )),
235 Box_::into_raw(f),
236 )
237 }
238 }
239
240 #[cfg(feature = "v1_8")]
241 #[cfg_attr(docsrs, doc(cfg(feature = "v1_8")))]
242 #[doc(alias = "title")]
243 pub fn connect_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
244 unsafe extern "C" fn notify_title_trampoline<F: Fn(&ShortcutsItem) + 'static>(
245 this: *mut ffi::AdwShortcutsItem,
246 _param_spec: glib::ffi::gpointer,
247 f: glib::ffi::gpointer,
248 ) {
249 unsafe {
250 let f: &F = &*(f as *const F);
251 f(&from_glib_borrow(this))
252 }
253 }
254 unsafe {
255 let f: Box_<F> = Box_::new(f);
256 connect_raw(
257 self.as_ptr() as *mut _,
258 c"notify::title".as_ptr(),
259 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
260 notify_title_trampoline::<F> as *const (),
261 )),
262 Box_::into_raw(f),
263 )
264 }
265 }
266}