gtk4/auto/shortcut_action.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, ShortcutActionFlags, Widget};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 /// Encodes an action that can be triggered by a keyboard shortcut.
10 ///
11 /// `GtkShortcutActions` contain functions that allow easy presentation
12 /// to end users as well as being printed for debugging.
13 ///
14 /// All `GtkShortcutActions` are immutable, you can only specify their
15 /// properties during construction. If you want to change a action, you
16 /// have to replace it with a new one. If you need to pass arguments to
17 /// an action, these are specified by the higher-level [`Shortcut`][crate::Shortcut] object.
18 ///
19 /// To activate a [`ShortcutAction`][crate::ShortcutAction] manually, [`ShortcutActionExt::activate()`][crate::prelude::ShortcutActionExt::activate()]
20 /// can be called.
21 ///
22 /// GTK provides various actions:
23 ///
24 /// - [`MnemonicAction`][crate::MnemonicAction]: a shortcut action that calls
25 /// gtk_widget_mnemonic_activate()
26 /// - [`CallbackAction`][crate::CallbackAction]: a shortcut action that invokes
27 /// a given callback
28 /// - [`SignalAction`][crate::SignalAction]: a shortcut action that emits a
29 /// given signal
30 /// - [`ActivateAction`][crate::ActivateAction]: a shortcut action that calls
31 /// gtk_widget_activate()
32 /// - [`NamedAction`][crate::NamedAction]: a shortcut action that calls
33 /// gtk_widget_activate_action()
34 /// - [`NothingAction`][crate::NothingAction]: a shortcut action that does nothing
35 ///
36 /// This is an Abstract Base Class, you cannot instantiate it.
37 ///
38 /// # Implements
39 ///
40 /// [`ShortcutActionExt`][trait@crate::prelude::ShortcutActionExt], [`trait@glib::ObjectExt`]
41 #[doc(alias = "GtkShortcutAction")]
42 pub struct ShortcutAction(Object<ffi::GtkShortcutAction, ffi::GtkShortcutActionClass>);
43
44 match fn {
45 type_ => || ffi::gtk_shortcut_action_get_type(),
46 }
47}
48
49impl ShortcutAction {
50 pub const NONE: Option<&'static ShortcutAction> = None;
51
52 /// Tries to parse the given string into an action.
53 ///
54 /// On success, the parsed action is returned. When parsing
55 /// failed, [`None`] is returned.
56 ///
57 /// The accepted strings are:
58 ///
59 /// - `nothing`, for [`NothingAction`][crate::NothingAction]
60 /// - `activate`, for [`ActivateAction`][crate::ActivateAction]
61 /// - `mnemonic-activate`, for [`MnemonicAction`][crate::MnemonicAction]
62 /// - `action(NAME)`, for a [`NamedAction`][crate::NamedAction] for the action named `NAME`
63 /// - `signal(NAME)`, for a [`SignalAction`][crate::SignalAction] for the signal `NAME`
64 /// ## `string`
65 /// the string to parse
66 ///
67 /// # Returns
68 ///
69 /// a new [`ShortcutAction`][crate::ShortcutAction]
70 #[doc(alias = "gtk_shortcut_action_parse_string")]
71 pub fn parse_string(string: &str) -> Option<ShortcutAction> {
72 assert_initialized_main_thread!();
73 unsafe {
74 from_glib_full(ffi::gtk_shortcut_action_parse_string(
75 string.to_glib_none().0,
76 ))
77 }
78 }
79}
80
81impl std::fmt::Display for ShortcutAction {
82 #[inline]
83 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
84 f.write_str(&ShortcutActionExt::to_str(self))
85 }
86}
87
88/// Trait containing all [`struct@ShortcutAction`] methods.
89///
90/// # Implementors
91///
92/// [`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]
93pub trait ShortcutActionExt: IsA<ShortcutAction> + 'static {
94 /// Activates the action on the @widget with the given @args.
95 ///
96 /// Note that some actions ignore the passed in @flags, @widget or @args.
97 ///
98 /// Activation of an action can fail for various reasons. If the action
99 /// is not supported by the @widget, if the @args don't match the action
100 /// or if the activation otherwise had no effect, [`false`] will be returned.
101 /// ## `flags`
102 /// flags to activate with
103 /// ## `widget`
104 /// Target of the activation
105 /// ## `args`
106 /// arguments to pass
107 ///
108 /// # Returns
109 ///
110 /// [`true`] if this action was activated successfully
111 #[doc(alias = "gtk_shortcut_action_activate")]
112 fn activate(
113 &self,
114 flags: ShortcutActionFlags,
115 widget: &impl IsA<Widget>,
116 args: Option<&glib::Variant>,
117 ) -> bool {
118 unsafe {
119 from_glib(ffi::gtk_shortcut_action_activate(
120 self.as_ref().to_glib_none().0,
121 flags.into_glib(),
122 widget.as_ref().to_glib_none().0,
123 args.to_glib_none().0,
124 ))
125 }
126 }
127
128 /// Prints the given action into a human-readable string.
129 ///
130 /// This is a small wrapper around `Gtk::ShortcutAction::print()`
131 /// to help when debugging.
132 ///
133 /// # Returns
134 ///
135 /// a new string
136 #[doc(alias = "gtk_shortcut_action_to_string")]
137 #[doc(alias = "to_string")]
138 fn to_str(&self) -> glib::GString {
139 unsafe {
140 from_glib_full(ffi::gtk_shortcut_action_to_string(
141 self.as_ref().to_glib_none().0,
142 ))
143 }
144 }
145}
146
147impl<O: IsA<ShortcutAction>> ShortcutActionExt for O {}