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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::ShortcutActionFlags;
use crate::Widget;
use glib::object::IsA;
use glib::translate::*;
use std::fmt;

glib::wrapper! {
    /// [`ShortcutAction`][crate::ShortcutAction] encodes an action that can be triggered by a
    /// keyboard shortcut.
    ///
    /// `GtkShortcutActions` contain functions that allow easy presentation
    /// to end users as well as being printed for debugging.
    ///
    /// All `GtkShortcutActions` are immutable, you can only specify their
    /// properties during construction. If you want to change a action, you
    /// have to replace it with a new one. If you need to pass arguments to
    /// an action, these are specified by the higher-level [`Shortcut`][crate::Shortcut] object.
    ///
    /// To activate a [`ShortcutAction`][crate::ShortcutAction] manually, [`ShortcutActionExt::activate()`][crate::prelude::ShortcutActionExt::activate()]
    /// can be called.
    ///
    /// GTK provides various actions:
    ///
    ///  - [`MnemonicAction`][crate::MnemonicAction]: a shortcut action that calls
    ///    gtk_widget_mnemonic_activate()
    ///  - [`CallbackAction`][crate::CallbackAction]: a shortcut action that invokes
    ///    a given callback
    ///  - [`SignalAction`][crate::SignalAction]: a shortcut action that emits a
    ///    given signal
    ///  - [`ActivateAction`][crate::ActivateAction]: a shortcut action that calls
    ///    gtk_widget_activate()
    ///  - [`NamedAction`][crate::NamedAction]: a shortcut action that calls
    ///    gtk_widget_activate_action()
    ///  - [`NothingAction`][crate::NothingAction]: a shortcut action that does nothing
    ///
    /// This is an Abstract Base Class, you cannot instantiate it.
    ///
    /// # Implements
    ///
    /// [`ShortcutActionExt`][trait@crate::prelude::ShortcutActionExt], [`trait@glib::ObjectExt`]
    #[doc(alias = "GtkShortcutAction")]
    pub struct ShortcutAction(Object<ffi::GtkShortcutAction, ffi::GtkShortcutActionClass>);

    match fn {
        type_ => || ffi::gtk_shortcut_action_get_type(),
    }
}

impl ShortcutAction {
    pub const NONE: Option<&'static ShortcutAction> = None;

    /// Tries to parse the given string into an action.
    ///
    /// On success, the parsed action is returned. When parsing
    /// failed, [`None`] is returned.
    ///
    /// The accepted strings are:
    ///
    /// - `nothing`, for [`NothingAction`][crate::NothingAction]
    /// - `activate`, for [`ActivateAction`][crate::ActivateAction]
    /// - `mnemonic-activate`, for [`MnemonicAction`][crate::MnemonicAction]
    /// - `action(NAME)`, for a [`NamedAction`][crate::NamedAction] for the action named `NAME`
    /// - `signal(NAME)`, for a [`SignalAction`][crate::SignalAction] for the signal `NAME`
    /// ## `string`
    /// the string to parse
    ///
    /// # Returns
    ///
    /// a new [`ShortcutAction`][crate::ShortcutAction]
    #[doc(alias = "gtk_shortcut_action_parse_string")]
    pub fn parse_string(string: &str) -> Option<ShortcutAction> {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::gtk_shortcut_action_parse_string(
                string.to_glib_none().0,
            ))
        }
    }
}

impl fmt::Display for ShortcutAction {
    #[inline]
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str(&ShortcutActionExt::to_str(self))
    }
}

/// Trait containing all [`struct@ShortcutAction`] methods.
///
/// # Implementors
///
/// [`ActivateAction`][struct@crate::ActivateAction], [`CallbackAction`][struct@crate::CallbackAction], [`MnemonicAction`][struct@crate::MnemonicAction], [`NamedAction`][struct@crate::NamedAction], [`NothingAction`][struct@crate::NothingAction], [`ShortcutAction`][struct@crate::ShortcutAction], [`SignalAction`][struct@crate::SignalAction]
pub trait ShortcutActionExt: 'static {
    /// Activates the action on the @widget with the given @args.
    ///
    /// Note that some actions ignore the passed in @flags, @widget or @args.
    ///
    /// Activation of an action can fail for various reasons. If the action
    /// is not supported by the @widget, if the @args don't match the action
    /// or if the activation otherwise had no effect, [`false`] will be returned.
    /// ## `flags`
    /// flags to activate with
    /// ## `widget`
    /// Target of the activation
    /// ## `args`
    /// arguments to pass
    ///
    /// # Returns
    ///
    /// [`true`] if this action was activated successfully
    #[doc(alias = "gtk_shortcut_action_activate")]
    fn activate(
        &self,
        flags: ShortcutActionFlags,
        widget: &impl IsA<Widget>,
        args: Option<&glib::Variant>,
    ) -> bool;

    /// Prints the given action into a human-readable string.
    ///
    /// This is a small wrapper around `Gtk::ShortcutAction::print()`
    /// to help when debugging.
    ///
    /// # Returns
    ///
    /// a new string
    #[doc(alias = "gtk_shortcut_action_to_string")]
    #[doc(alias = "to_string")]
    fn to_str(&self) -> glib::GString;
}

impl<O: IsA<ShortcutAction>> ShortcutActionExt for O {
    fn activate(
        &self,
        flags: ShortcutActionFlags,
        widget: &impl IsA<Widget>,
        args: Option<&glib::Variant>,
    ) -> bool {
        unsafe {
            from_glib(ffi::gtk_shortcut_action_activate(
                self.as_ref().to_glib_none().0,
                flags.into_glib(),
                widget.as_ref().to_glib_none().0,
                args.to_glib_none().0,
            ))
        }
    }

    fn to_str(&self) -> glib::GString {
        unsafe {
            from_glib_full(ffi::gtk_shortcut_action_to_string(
                self.as_ref().to_glib_none().0,
            ))
        }
    }
}