1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Take a look at the license at the top of the repository in the LICENSE file.

use crate::SimpleAction;
use glib::translate::*;

impl SimpleAction {
    /// Creates a new stateful action.
    ///
    /// All future state values must have the same [`glib::VariantType`][crate::glib::VariantType] as the initial
    /// `state`.
    ///
    /// If the `state` [`glib::Variant`][struct@crate::glib::Variant] is floating, it is consumed.
    /// ## `name`
    /// the name of the action
    /// ## `parameter_type`
    /// the type of the parameter that will be passed to
    ///  handlers for the [`activate`][struct@crate::SimpleAction#activate] signal, or [`None`] for no parameter
    /// ## `state`
    /// the initial state of the action
    ///
    /// # Returns
    ///
    /// a new [`SimpleAction`][crate::SimpleAction]
    #[doc(alias = "g_simple_action_new_stateful")]
    pub fn new_stateful(
        name: &str,
        parameter_type: Option<&glib::VariantTy>,
        state: glib::Variant,
    ) -> SimpleAction {
        unsafe {
            from_glib_full(ffi::g_simple_action_new_stateful(
                name.to_glib_none().0,
                parameter_type.to_glib_none().0,
                state.to_glib_none().0,
            ))
        }
    }

    /// Sets the state of the action.
    ///
    /// This directly updates the 'state' property to the given value.
    ///
    /// This should only be called by the implementor of the action. Users
    /// of the action should not attempt to directly modify the 'state'
    /// property. Instead, they should call [`ActionExt::change_state()`][crate::prelude::ActionExt::change_state()] to
    /// request the change.
    ///
    /// If the `value` GVariant is floating, it is consumed.
    /// ## `value`
    /// the new [`glib::Variant`][struct@crate::glib::Variant] for the state
    #[doc(alias = "g_simple_action_set_state")]
    pub fn set_state(&self, value: glib::Variant) {
        unsafe {
            ffi::g_simple_action_set_state(self.to_glib_none().0, value.to_glib_none().0);
        }
    }

    /// Sets the state hint for the action.
    ///
    /// See [`ActionExt::state_hint()`][crate::prelude::ActionExt::state_hint()] for more information about
    /// action state hints.
    /// ## `state_hint`
    /// a [`glib::Variant`][struct@crate::glib::Variant] representing the state hint
    #[doc(alias = "g_simple_action_set_state_hint")]
    pub fn set_state_hint(&self, state_hint: Option<glib::Variant>) {
        unsafe {
            ffi::g_simple_action_set_state_hint(self.to_glib_none().0, state_hint.to_glib_none().0);
        }
    }
}