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
// 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 glib::object::IsA;
use glib::translate::*;
use std::fmt;

glib::wrapper! {
    /// [`ShortcutTrigger`][crate::ShortcutTrigger] tracks how a [`Shortcut`][crate::Shortcut] should be activated.
    ///
    /// To find out if a [`ShortcutTrigger`][crate::ShortcutTrigger] triggers, you can call
    /// [`ShortcutTriggerExt::trigger()`][crate::prelude::ShortcutTriggerExt::trigger()] on a [`gdk::Event`][crate::gdk::Event].
    ///
    /// `GtkShortcutTriggers` contain functions that allow easy presentation
    /// to end users as well as being printed for debugging.
    ///
    /// All `GtkShortcutTriggers` are immutable, you can only specify their
    /// properties during construction. If you want to change a trigger, you
    /// have to replace it with a new one.
    ///
    /// This is an Abstract Base Class, you cannot instantiate it.
    ///
    /// # Implements
    ///
    /// [`ShortcutTriggerExt`][trait@crate::prelude::ShortcutTriggerExt], [`trait@glib::ObjectExt`], [`ShortcutTriggerExtManual`][trait@crate::prelude::ShortcutTriggerExtManual]
    #[doc(alias = "GtkShortcutTrigger")]
    pub struct ShortcutTrigger(Object<ffi::GtkShortcutTrigger, ffi::GtkShortcutTriggerClass>);

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

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

    /// Tries to parse the given string into a trigger.
    ///
    /// On success, the parsed trigger is returned.
    /// When parsing failed, [`None`] is returned.
    ///
    /// The accepted strings are:
    ///
    ///   - `never`, for [`NeverTrigger`][crate::NeverTrigger]
    ///   - a string parsed by gtk_accelerator_parse(), for a [`KeyvalTrigger`][crate::KeyvalTrigger], e.g. `<Control>C`
    ///   - underscore, followed by a single character, for [`MnemonicTrigger`][crate::MnemonicTrigger], e.g. `_l`
    ///   - two valid trigger strings, separated by a `|` character, for a
    ///     [`AlternativeTrigger`][crate::AlternativeTrigger]: `<Control>q|<Control>w`
    ///
    /// Note that you will have to escape the `<` and `>` characters when specifying
    /// triggers in XML files, such as GtkBuilder ui files. Use `&lt;` instead of
    /// `<` and `&gt;` instead of `>`.
    /// ## `string`
    /// the string to parse
    ///
    /// # Returns
    ///
    /// a new [`ShortcutTrigger`][crate::ShortcutTrigger]
    #[doc(alias = "gtk_shortcut_trigger_parse_string")]
    pub fn parse_string(string: &str) -> Option<ShortcutTrigger> {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::gtk_shortcut_trigger_parse_string(
                string.to_glib_none().0,
            ))
        }
    }
}

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

/// Trait containing all [`struct@ShortcutTrigger`] methods.
///
/// # Implementors
///
/// [`AlternativeTrigger`][struct@crate::AlternativeTrigger], [`KeyvalTrigger`][struct@crate::KeyvalTrigger], [`MnemonicTrigger`][struct@crate::MnemonicTrigger], [`NeverTrigger`][struct@crate::NeverTrigger], [`ShortcutTrigger`][struct@crate::ShortcutTrigger]
pub trait ShortcutTriggerExt: 'static {
    /// Gets textual representation for the given trigger.
    ///
    /// This function is returning a translated string for
    /// presentation to end users for example in menu items
    /// or in help texts.
    ///
    /// The @display in use may influence the resulting string in
    /// various forms, such as resolving hardware keycodes or by
    /// causing display-specific modifier names.
    ///
    /// The form of the representation may change at any time and is
    /// not guaranteed to stay identical.
    /// ## `display`
    /// [`gdk::Display`][crate::gdk::Display] to print for
    ///
    /// # Returns
    ///
    /// a new string
    #[doc(alias = "gtk_shortcut_trigger_to_label")]
    fn to_label(&self, display: &impl IsA<gdk::Display>) -> glib::GString;

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

    /// Checks if the given @event triggers @self.
    /// ## `event`
    /// the event to check
    /// ## `enable_mnemonics`
    /// [`true`] if mnemonics should trigger. Usually the
    ///   value of this property is determined by checking that the passed
    ///   in @event is a Key event and has the right modifiers set.
    ///
    /// # Returns
    ///
    /// Whether the event triggered the shortcut
    #[doc(alias = "gtk_shortcut_trigger_trigger")]
    fn trigger(&self, event: impl AsRef<gdk::Event>, enable_mnemonics: bool) -> gdk::KeyMatch;
}

impl<O: IsA<ShortcutTrigger>> ShortcutTriggerExt for O {
    fn to_label(&self, display: &impl IsA<gdk::Display>) -> glib::GString {
        unsafe {
            from_glib_full(ffi::gtk_shortcut_trigger_to_label(
                self.as_ref().to_glib_none().0,
                display.as_ref().to_glib_none().0,
            ))
        }
    }

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

    fn trigger(&self, event: impl AsRef<gdk::Event>, enable_mnemonics: bool) -> gdk::KeyMatch {
        unsafe {
            from_glib(ffi::gtk_shortcut_trigger_trigger(
                self.as_ref().to_glib_none().0,
                event.as_ref().to_glib_none().0,
                enable_mnemonics.into_glib(),
            ))
        }
    }
}