gio/auto/
simple_action.rs1use gio_sys;
6use glib;
7use glib::object::ObjectType as ObjectType_;
8use glib::signal::connect_raw;
9use glib::signal::SignalHandlerId;
10use glib::translate::*;
11use glib_sys;
12use std::boxed::Box as Box_;
13use std::fmt;
14use std::mem::transmute;
15use Action;
16
17glib_wrapper! {
18 pub struct SimpleAction(Object<gio_sys::GSimpleAction, SimpleActionClass>) @implements Action;
19
20 match fn {
21 get_type => || gio_sys::g_simple_action_get_type(),
22 }
23}
24
25impl SimpleAction {
26 pub fn new(name: &str, parameter_type: Option<&glib::VariantTy>) -> SimpleAction {
27 unsafe {
28 from_glib_full(gio_sys::g_simple_action_new(
29 name.to_glib_none().0,
30 parameter_type.to_glib_none().0,
31 ))
32 }
33 }
34
35 pub fn new_stateful(
36 name: &str,
37 parameter_type: Option<&glib::VariantTy>,
38 state: &glib::Variant,
39 ) -> SimpleAction {
40 unsafe {
41 from_glib_full(gio_sys::g_simple_action_new_stateful(
42 name.to_glib_none().0,
43 parameter_type.to_glib_none().0,
44 state.to_glib_none().0,
45 ))
46 }
47 }
48
49 pub fn set_enabled(&self, enabled: bool) {
50 unsafe {
51 gio_sys::g_simple_action_set_enabled(self.to_glib_none().0, enabled.to_glib());
52 }
53 }
54
55 pub fn set_state(&self, value: &glib::Variant) {
56 unsafe {
57 gio_sys::g_simple_action_set_state(self.to_glib_none().0, value.to_glib_none().0);
58 }
59 }
60
61 #[cfg(any(feature = "v2_44", feature = "dox"))]
62 pub fn set_state_hint(&self, state_hint: Option<&glib::Variant>) {
63 unsafe {
64 gio_sys::g_simple_action_set_state_hint(
65 self.to_glib_none().0,
66 state_hint.to_glib_none().0,
67 );
68 }
69 }
70
71 pub fn connect_activate<F: Fn(&SimpleAction, Option<&glib::Variant>) + 'static>(
72 &self,
73 f: F,
74 ) -> SignalHandlerId {
75 unsafe extern "C" fn activate_trampoline<
76 F: Fn(&SimpleAction, Option<&glib::Variant>) + 'static,
77 >(
78 this: *mut gio_sys::GSimpleAction,
79 parameter: *mut glib_sys::GVariant,
80 f: glib_sys::gpointer,
81 ) {
82 let f: &F = &*(f as *const F);
83 f(
84 &from_glib_borrow(this),
85 Option::<glib::Variant>::from_glib_borrow(parameter).as_ref(),
86 )
87 }
88 unsafe {
89 let f: Box_<F> = Box_::new(f);
90 connect_raw(
91 self.as_ptr() as *mut _,
92 b"activate\0".as_ptr() as *const _,
93 Some(transmute(activate_trampoline::<F> as usize)),
94 Box_::into_raw(f),
95 )
96 }
97 }
98
99 pub fn connect_change_state<F: Fn(&SimpleAction, Option<&glib::Variant>) + 'static>(
100 &self,
101 f: F,
102 ) -> SignalHandlerId {
103 unsafe extern "C" fn change_state_trampoline<
104 F: Fn(&SimpleAction, Option<&glib::Variant>) + 'static,
105 >(
106 this: *mut gio_sys::GSimpleAction,
107 value: *mut glib_sys::GVariant,
108 f: glib_sys::gpointer,
109 ) {
110 let f: &F = &*(f as *const F);
111 f(
112 &from_glib_borrow(this),
113 Option::<glib::Variant>::from_glib_borrow(value).as_ref(),
114 )
115 }
116 unsafe {
117 let f: Box_<F> = Box_::new(f);
118 connect_raw(
119 self.as_ptr() as *mut _,
120 b"change-state\0".as_ptr() as *const _,
121 Some(transmute(change_state_trampoline::<F> as usize)),
122 Box_::into_raw(f),
123 )
124 }
125 }
126
127 pub fn connect_property_enabled_notify<F: Fn(&SimpleAction) + 'static>(
128 &self,
129 f: F,
130 ) -> SignalHandlerId {
131 unsafe extern "C" fn notify_enabled_trampoline<F: Fn(&SimpleAction) + 'static>(
132 this: *mut gio_sys::GSimpleAction,
133 _param_spec: glib_sys::gpointer,
134 f: glib_sys::gpointer,
135 ) {
136 let f: &F = &*(f as *const F);
137 f(&from_glib_borrow(this))
138 }
139 unsafe {
140 let f: Box_<F> = Box_::new(f);
141 connect_raw(
142 self.as_ptr() as *mut _,
143 b"notify::enabled\0".as_ptr() as *const _,
144 Some(transmute(notify_enabled_trampoline::<F> as usize)),
145 Box_::into_raw(f),
146 )
147 }
148 }
149
150 pub fn connect_property_state_type_notify<F: Fn(&SimpleAction) + 'static>(
151 &self,
152 f: F,
153 ) -> SignalHandlerId {
154 unsafe extern "C" fn notify_state_type_trampoline<F: Fn(&SimpleAction) + 'static>(
155 this: *mut gio_sys::GSimpleAction,
156 _param_spec: glib_sys::gpointer,
157 f: glib_sys::gpointer,
158 ) {
159 let f: &F = &*(f as *const F);
160 f(&from_glib_borrow(this))
161 }
162 unsafe {
163 let f: Box_<F> = Box_::new(f);
164 connect_raw(
165 self.as_ptr() as *mut _,
166 b"notify::state-type\0".as_ptr() as *const _,
167 Some(transmute(notify_state_type_trampoline::<F> as usize)),
168 Box_::into_raw(f),
169 )
170 }
171 }
172}
173
174impl fmt::Display for SimpleAction {
175 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
176 write!(f, "SimpleAction")
177 }
178}