gio/auto/action_map.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, Action};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 /// `GActionMap` is an interface for action containers.
10 ///
11 /// The `GActionMap` interface is implemented by [`ActionGroup`][crate::ActionGroup]
12 /// implementations that operate by containing a number of named
13 /// [`Action`][crate::Action] instances, such as [`SimpleActionGroup`][crate::SimpleActionGroup].
14 ///
15 /// One useful application of this interface is to map the
16 /// names of actions from various action groups to unique,
17 /// prefixed names (e.g. by prepending "app." or "win.").
18 /// This is the motivation for the ‘Map’ part of the interface
19 /// name.
20 ///
21 /// # Implements
22 ///
23 /// [`ActionMapExt`][trait@crate::prelude::ActionMapExt], [`ActionMapExtManual`][trait@crate::prelude::ActionMapExtManual]
24 #[doc(alias = "GActionMap")]
25 pub struct ActionMap(Interface<ffi::GActionMap, ffi::GActionMapInterface>);
26
27 match fn {
28 type_ => || ffi::g_action_map_get_type(),
29 }
30}
31
32impl ActionMap {
33 pub const NONE: Option<&'static ActionMap> = None;
34}
35
36/// Trait containing all [`struct@ActionMap`] methods.
37///
38/// # Implementors
39///
40/// [`ActionMap`][struct@crate::ActionMap], [`Application`][struct@crate::Application], [`SimpleActionGroup`][struct@crate::SimpleActionGroup]
41pub trait ActionMapExt: IsA<ActionMap> + 'static {
42 /// Adds an action to the @self.
43 ///
44 /// If the action map already contains an action with the same name
45 /// as @action then the old action is dropped from the action map.
46 ///
47 /// The action map takes its own reference on @action.
48 /// ## `action`
49 /// a [`Action`][crate::Action]
50 #[doc(alias = "g_action_map_add_action")]
51 fn add_action(&self, action: &impl IsA<Action>) {
52 unsafe {
53 ffi::g_action_map_add_action(
54 self.as_ref().to_glib_none().0,
55 action.as_ref().to_glib_none().0,
56 );
57 }
58 }
59
60 /// Looks up the action with the name @action_name in @self.
61 ///
62 /// If no such action exists, returns `NULL`.
63 /// ## `action_name`
64 /// the name of an action
65 ///
66 /// # Returns
67 ///
68 /// a [`Action`][crate::Action]
69 #[doc(alias = "g_action_map_lookup_action")]
70 fn lookup_action(&self, action_name: &str) -> Option<Action> {
71 unsafe {
72 from_glib_none(ffi::g_action_map_lookup_action(
73 self.as_ref().to_glib_none().0,
74 action_name.to_glib_none().0,
75 ))
76 }
77 }
78
79 /// Removes the named action from the action map.
80 ///
81 /// If no action of this name is in the map then nothing happens.
82 /// ## `action_name`
83 /// the name of the action
84 #[doc(alias = "g_action_map_remove_action")]
85 fn remove_action(&self, action_name: &str) {
86 unsafe {
87 ffi::g_action_map_remove_action(
88 self.as_ref().to_glib_none().0,
89 action_name.to_glib_none().0,
90 );
91 }
92 }
93}
94
95impl<O: IsA<ActionMap>> ActionMapExt for O {}