gtk4/auto/shortcut_trigger.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;
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 /// [`ShortcutTrigger`][crate::ShortcutTrigger] tracks how a [`Shortcut`][crate::Shortcut] should be activated.
10 ///
11 /// To find out if a [`ShortcutTrigger`][crate::ShortcutTrigger] triggers, you can call
12 /// [`ShortcutTriggerExt::trigger()`][crate::prelude::ShortcutTriggerExt::trigger()] on a [`gdk::Event`][crate::gdk::Event].
13 ///
14 /// `GtkShortcutTriggers` contain functions that allow easy presentation
15 /// to end users as well as being printed for debugging.
16 ///
17 /// All `GtkShortcutTriggers` are immutable, you can only specify their
18 /// properties during construction. If you want to change a trigger, you
19 /// have to replace it with a new one.
20 ///
21 /// This is an Abstract Base Class, you cannot instantiate it.
22 ///
23 /// # Implements
24 ///
25 /// [`ShortcutTriggerExt`][trait@crate::prelude::ShortcutTriggerExt], [`trait@glib::ObjectExt`], [`ShortcutTriggerExtManual`][trait@crate::prelude::ShortcutTriggerExtManual]
26 #[doc(alias = "GtkShortcutTrigger")]
27 pub struct ShortcutTrigger(Object<ffi::GtkShortcutTrigger, ffi::GtkShortcutTriggerClass>);
28
29 match fn {
30 type_ => || ffi::gtk_shortcut_trigger_get_type(),
31 }
32}
33
34impl ShortcutTrigger {
35 pub const NONE: Option<&'static ShortcutTrigger> = None;
36
37 /// Tries to parse the given string into a trigger.
38 ///
39 /// On success, the parsed trigger is returned.
40 /// When parsing failed, [`None`] is returned.
41 ///
42 /// The accepted strings are:
43 ///
44 /// - `never`, for [`NeverTrigger`][crate::NeverTrigger]
45 /// - a string parsed by gtk_accelerator_parse(), for a [`KeyvalTrigger`][crate::KeyvalTrigger], e.g. `<Control>C`
46 /// - underscore, followed by a single character, for [`MnemonicTrigger`][crate::MnemonicTrigger], e.g. `_l`
47 /// - two valid trigger strings, separated by a `|` character, for a
48 /// [`AlternativeTrigger`][crate::AlternativeTrigger]: `<Control>q|<Control>w`
49 ///
50 /// Note that you will have to escape the `<` and `>` characters when specifying
51 /// triggers in XML files, such as GtkBuilder ui files. Use `<` instead of
52 /// `<` and `>` instead of `>`.
53 /// ## `string`
54 /// the string to parse
55 ///
56 /// # Returns
57 ///
58 /// a new [`ShortcutTrigger`][crate::ShortcutTrigger]
59 #[doc(alias = "gtk_shortcut_trigger_parse_string")]
60 pub fn parse_string(string: &str) -> Option<ShortcutTrigger> {
61 assert_initialized_main_thread!();
62 unsafe {
63 from_glib_full(ffi::gtk_shortcut_trigger_parse_string(
64 string.to_glib_none().0,
65 ))
66 }
67 }
68}
69
70impl std::fmt::Display for ShortcutTrigger {
71 #[inline]
72 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
73 f.write_str(&ShortcutTriggerExt::to_str(self))
74 }
75}
76
77mod sealed {
78 pub trait Sealed {}
79 impl<T: super::IsA<super::ShortcutTrigger>> Sealed for T {}
80}
81
82/// Trait containing all [`struct@ShortcutTrigger`] methods.
83///
84/// # Implementors
85///
86/// [`AlternativeTrigger`][struct@crate::AlternativeTrigger], [`KeyvalTrigger`][struct@crate::KeyvalTrigger], [`MnemonicTrigger`][struct@crate::MnemonicTrigger], [`NeverTrigger`][struct@crate::NeverTrigger], [`ShortcutTrigger`][struct@crate::ShortcutTrigger]
87pub trait ShortcutTriggerExt: IsA<ShortcutTrigger> + sealed::Sealed + 'static {
88 /// Gets textual representation for the given trigger.
89 ///
90 /// This function is returning a translated string for
91 /// presentation to end users for example in menu items
92 /// or in help texts.
93 ///
94 /// The @display in use may influence the resulting string in
95 /// various forms, such as resolving hardware keycodes or by
96 /// causing display-specific modifier names.
97 ///
98 /// The form of the representation may change at any time and is
99 /// not guaranteed to stay identical.
100 /// ## `display`
101 /// [`gdk::Display`][crate::gdk::Display] to print for
102 ///
103 /// # Returns
104 ///
105 /// a new string
106 #[doc(alias = "gtk_shortcut_trigger_to_label")]
107 fn to_label(&self, display: &impl IsA<gdk::Display>) -> glib::GString {
108 unsafe {
109 from_glib_full(ffi::gtk_shortcut_trigger_to_label(
110 self.as_ref().to_glib_none().0,
111 display.as_ref().to_glib_none().0,
112 ))
113 }
114 }
115
116 /// Prints the given trigger into a human-readable string.
117 ///
118 /// This is a small wrapper around `Gtk::ShortcutTrigger::print()`
119 /// to help when debugging.
120 ///
121 /// # Returns
122 ///
123 /// a new string
124 #[doc(alias = "gtk_shortcut_trigger_to_string")]
125 #[doc(alias = "to_string")]
126 fn to_str(&self) -> glib::GString {
127 unsafe {
128 from_glib_full(ffi::gtk_shortcut_trigger_to_string(
129 self.as_ref().to_glib_none().0,
130 ))
131 }
132 }
133
134 /// Checks if the given @event triggers @self.
135 /// ## `event`
136 /// the event to check
137 /// ## `enable_mnemonics`
138 /// [`true`] if mnemonics should trigger. Usually the
139 /// value of this property is determined by checking that the passed
140 /// in @event is a Key event and has the right modifiers set.
141 ///
142 /// # Returns
143 ///
144 /// Whether the event triggered the shortcut
145 #[doc(alias = "gtk_shortcut_trigger_trigger")]
146 fn trigger(&self, event: impl AsRef<gdk::Event>, enable_mnemonics: bool) -> gdk::KeyMatch {
147 unsafe {
148 from_glib(ffi::gtk_shortcut_trigger_trigger(
149 self.as_ref().to_glib_none().0,
150 event.as_ref().to_glib_none().0,
151 enable_mnemonics.into_glib(),
152 ))
153 }
154 }
155}
156
157impl<O: IsA<ShortcutTrigger>> ShortcutTriggerExt for O {}