[go: up one dir, main page]

gio/auto/
action.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::ffi;
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    #[doc(alias = "GAction")]
15    pub struct Action(Interface<ffi::GAction, ffi::GActionInterface>);
16
17    match fn {
18        type_ => || ffi::g_action_get_type(),
19    }
20}
21
22impl Action {
23    pub const NONE: Option<&'static Action> = None;
24
25    #[doc(alias = "g_action_name_is_valid")]
26    pub fn name_is_valid(action_name: &str) -> bool {
27        unsafe { from_glib(ffi::g_action_name_is_valid(action_name.to_glib_none().0)) }
28    }
29
30    #[doc(alias = "g_action_parse_detailed_name")]
31    pub fn parse_detailed_name(
32        detailed_name: &str,
33    ) -> Result<(glib::GString, Option<glib::Variant>), glib::Error> {
34        unsafe {
35            let mut action_name = std::ptr::null_mut();
36            let mut target_value = std::ptr::null_mut();
37            let mut error = std::ptr::null_mut();
38            let is_ok = ffi::g_action_parse_detailed_name(
39                detailed_name.to_glib_none().0,
40                &mut action_name,
41                &mut target_value,
42                &mut error,
43            );
44            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
45            if error.is_null() {
46                Ok((from_glib_full(action_name), from_glib_full(target_value)))
47            } else {
48                Err(from_glib_full(error))
49            }
50        }
51    }
52
53    #[doc(alias = "g_action_print_detailed_name")]
54    pub fn print_detailed_name(
55        action_name: &str,
56        target_value: Option<&glib::Variant>,
57    ) -> glib::GString {
58        unsafe {
59            from_glib_full(ffi::g_action_print_detailed_name(
60                action_name.to_glib_none().0,
61                target_value.to_glib_none().0,
62            ))
63        }
64    }
65}
66
67mod sealed {
68    pub trait Sealed {}
69    impl<T: super::IsA<super::Action>> Sealed for T {}
70}
71
72pub trait ActionExt: IsA<Action> + sealed::Sealed + 'static {
73    #[doc(alias = "g_action_activate")]
74    fn activate(&self, parameter: Option<&glib::Variant>) {
75        unsafe {
76            ffi::g_action_activate(self.as_ref().to_glib_none().0, parameter.to_glib_none().0);
77        }
78    }
79
80    #[doc(alias = "g_action_change_state")]
81    fn change_state(&self, value: &glib::Variant) {
82        unsafe {
83            ffi::g_action_change_state(self.as_ref().to_glib_none().0, value.to_glib_none().0);
84        }
85    }
86
87    #[doc(alias = "g_action_get_enabled")]
88    #[doc(alias = "get_enabled")]
89    #[doc(alias = "enabled")]
90    fn is_enabled(&self) -> bool {
91        unsafe { from_glib(ffi::g_action_get_enabled(self.as_ref().to_glib_none().0)) }
92    }
93
94    #[doc(alias = "g_action_get_name")]
95    #[doc(alias = "get_name")]
96    fn name(&self) -> glib::GString {
97        unsafe { from_glib_none(ffi::g_action_get_name(self.as_ref().to_glib_none().0)) }
98    }
99
100    #[doc(alias = "g_action_get_parameter_type")]
101    #[doc(alias = "get_parameter_type")]
102    #[doc(alias = "parameter-type")]
103    fn parameter_type(&self) -> Option<glib::VariantType> {
104        unsafe {
105            from_glib_none(ffi::g_action_get_parameter_type(
106                self.as_ref().to_glib_none().0,
107            ))
108        }
109    }
110
111    #[doc(alias = "g_action_get_state")]
112    #[doc(alias = "get_state")]
113    fn state(&self) -> Option<glib::Variant> {
114        unsafe { from_glib_full(ffi::g_action_get_state(self.as_ref().to_glib_none().0)) }
115    }
116
117    #[doc(alias = "g_action_get_state_hint")]
118    #[doc(alias = "get_state_hint")]
119    fn state_hint(&self) -> Option<glib::Variant> {
120        unsafe { from_glib_full(ffi::g_action_get_state_hint(self.as_ref().to_glib_none().0)) }
121    }
122
123    #[doc(alias = "g_action_get_state_type")]
124    #[doc(alias = "get_state_type")]
125    #[doc(alias = "state-type")]
126    fn state_type(&self) -> Option<glib::VariantType> {
127        unsafe { from_glib_none(ffi::g_action_get_state_type(self.as_ref().to_glib_none().0)) }
128    }
129
130    #[doc(alias = "enabled")]
131    fn connect_enabled_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
132        unsafe extern "C" fn notify_enabled_trampoline<P: IsA<Action>, F: Fn(&P) + 'static>(
133            this: *mut ffi::GAction,
134            _param_spec: glib::ffi::gpointer,
135            f: glib::ffi::gpointer,
136        ) {
137            let f: &F = &*(f as *const F);
138            f(Action::from_glib_borrow(this).unsafe_cast_ref())
139        }
140        unsafe {
141            let f: Box_<F> = Box_::new(f);
142            connect_raw(
143                self.as_ptr() as *mut _,
144                b"notify::enabled\0".as_ptr() as *const _,
145                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
146                    notify_enabled_trampoline::<Self, F> as *const (),
147                )),
148                Box_::into_raw(f),
149            )
150        }
151    }
152
153    #[doc(alias = "name")]
154    fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
155        unsafe extern "C" fn notify_name_trampoline<P: IsA<Action>, F: Fn(&P) + 'static>(
156            this: *mut ffi::GAction,
157            _param_spec: glib::ffi::gpointer,
158            f: glib::ffi::gpointer,
159        ) {
160            let f: &F = &*(f as *const F);
161            f(Action::from_glib_borrow(this).unsafe_cast_ref())
162        }
163        unsafe {
164            let f: Box_<F> = Box_::new(f);
165            connect_raw(
166                self.as_ptr() as *mut _,
167                b"notify::name\0".as_ptr() as *const _,
168                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
169                    notify_name_trampoline::<Self, F> as *const (),
170                )),
171                Box_::into_raw(f),
172            )
173        }
174    }
175
176    #[doc(alias = "parameter-type")]
177    fn connect_parameter_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
178        unsafe extern "C" fn notify_parameter_type_trampoline<
179            P: IsA<Action>,
180            F: Fn(&P) + 'static,
181        >(
182            this: *mut ffi::GAction,
183            _param_spec: glib::ffi::gpointer,
184            f: glib::ffi::gpointer,
185        ) {
186            let f: &F = &*(f as *const F);
187            f(Action::from_glib_borrow(this).unsafe_cast_ref())
188        }
189        unsafe {
190            let f: Box_<F> = Box_::new(f);
191            connect_raw(
192                self.as_ptr() as *mut _,
193                b"notify::parameter-type\0".as_ptr() as *const _,
194                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
195                    notify_parameter_type_trampoline::<Self, F> as *const (),
196                )),
197                Box_::into_raw(f),
198            )
199        }
200    }
201
202    #[doc(alias = "state")]
203    fn connect_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
204        unsafe extern "C" fn notify_state_trampoline<P: IsA<Action>, F: Fn(&P) + 'static>(
205            this: *mut ffi::GAction,
206            _param_spec: glib::ffi::gpointer,
207            f: glib::ffi::gpointer,
208        ) {
209            let f: &F = &*(f as *const F);
210            f(Action::from_glib_borrow(this).unsafe_cast_ref())
211        }
212        unsafe {
213            let f: Box_<F> = Box_::new(f);
214            connect_raw(
215                self.as_ptr() as *mut _,
216                b"notify::state\0".as_ptr() as *const _,
217                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
218                    notify_state_trampoline::<Self, F> as *const (),
219                )),
220                Box_::into_raw(f),
221            )
222        }
223    }
224
225    #[doc(alias = "state-type")]
226    fn connect_state_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
227        unsafe extern "C" fn notify_state_type_trampoline<P: IsA<Action>, F: Fn(&P) + 'static>(
228            this: *mut ffi::GAction,
229            _param_spec: glib::ffi::gpointer,
230            f: glib::ffi::gpointer,
231        ) {
232            let f: &F = &*(f as *const F);
233            f(Action::from_glib_borrow(this).unsafe_cast_ref())
234        }
235        unsafe {
236            let f: Box_<F> = Box_::new(f);
237            connect_raw(
238                self.as_ptr() as *mut _,
239                b"notify::state-type\0".as_ptr() as *const _,
240                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
241                    notify_state_type_trampoline::<Self, F> as *const (),
242                )),
243                Box_::into_raw(f),
244            )
245        }
246    }
247}
248
249impl<O: IsA<Action>> ActionExt for O {}