1use gio_sys;
6use glib::object::IsA;
7use glib::translate::*;
8use std::fmt;
9use Action;
10
11glib_wrapper! {
12 pub struct ActionMap(Interface<gio_sys::GActionMap>);
13
14 match fn {
15 get_type => || gio_sys::g_action_map_get_type(),
16 }
17}
18
19pub const NONE_ACTION_MAP: Option<&ActionMap> = None;
20
21pub trait ActionMapExt: 'static {
22 fn add_action<P: IsA<Action>>(&self, action: &P);
23
24 fn lookup_action(&self, action_name: &str) -> Option<Action>;
27
28 fn remove_action(&self, action_name: &str);
29}
30
31impl<O: IsA<ActionMap>> ActionMapExt for O {
32 fn add_action<P: IsA<Action>>(&self, action: &P) {
33 unsafe {
34 gio_sys::g_action_map_add_action(
35 self.as_ref().to_glib_none().0,
36 action.as_ref().to_glib_none().0,
37 );
38 }
39 }
40
41 fn lookup_action(&self, action_name: &str) -> Option<Action> {
46 unsafe {
47 from_glib_none(gio_sys::g_action_map_lookup_action(
48 self.as_ref().to_glib_none().0,
49 action_name.to_glib_none().0,
50 ))
51 }
52 }
53
54 fn remove_action(&self, action_name: &str) {
55 unsafe {
56 gio_sys::g_action_map_remove_action(
57 self.as_ref().to_glib_none().0,
58 action_name.to_glib_none().0,
59 );
60 }
61 }
62}
63
64impl fmt::Display for ActionMap {
65 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
66 write!(f, "ActionMap")
67 }
68}