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
36mod sealed {
37    pub trait Sealed {}
38    impl<T: super::IsA<super::ActionMap>> Sealed for T {}
39}
40
41/// Trait containing all [`struct@ActionMap`] methods.
42///
43/// # Implementors
44///
45/// [`ActionMap`][struct@crate::ActionMap], [`Application`][struct@crate::Application], [`SimpleActionGroup`][struct@crate::SimpleActionGroup]
46pub trait ActionMapExt: IsA<ActionMap> + sealed::Sealed + 'static {
47    /// Adds an action to the @self.
48    ///
49    /// If the action map already contains an action with the same name
50    /// as @action then the old action is dropped from the action map.
51    ///
52    /// The action map takes its own reference on @action.
53    /// ## `action`
54    /// a [`Action`][crate::Action]
55    #[doc(alias = "g_action_map_add_action")]
56    fn add_action(&self, action: &impl IsA<Action>) {
57        unsafe {
58            ffi::g_action_map_add_action(
59                self.as_ref().to_glib_none().0,
60                action.as_ref().to_glib_none().0,
61            );
62        }
63    }
64
65    /// Looks up the action with the name @action_name in @self.
66    ///
67    /// If no such action exists, returns `NULL`.
68    /// ## `action_name`
69    /// the name of an action
70    ///
71    /// # Returns
72    ///
73    /// a [`Action`][crate::Action]
74    #[doc(alias = "g_action_map_lookup_action")]
75    fn lookup_action(&self, action_name: &str) -> Option<Action> {
76        unsafe {
77            from_glib_none(ffi::g_action_map_lookup_action(
78                self.as_ref().to_glib_none().0,
79                action_name.to_glib_none().0,
80            ))
81        }
82    }
83
84    /// Removes the named action from the action map.
85    ///
86    /// If no action of this name is in the map then nothing happens.
87    /// ## `action_name`
88    /// the name of the action
89    #[doc(alias = "g_action_map_remove_action")]
90    fn remove_action(&self, action_name: &str) {
91        unsafe {
92            ffi::g_action_map_remove_action(
93                self.as_ref().to_glib_none().0,
94                action_name.to_glib_none().0,
95            );
96        }
97    }
98}
99
100impl<O: IsA<ActionMap>> ActionMapExt for O {}