Skip to main content

gio/auto/
menu_item.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::{Icon, MenuModel, ffi};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9    /// #GMenuItem is an opaque structure type.  You must access it using the
10    /// functions below.
11    ///
12    /// # Implements
13    ///
14    /// [`trait@glib::ObjectExt`]
15    #[doc(alias = "GMenuItem")]
16    pub struct MenuItem(Object<ffi::GMenuItem>);
17
18    match fn {
19        type_ => || ffi::g_menu_item_get_type(),
20    }
21}
22
23impl MenuItem {
24    /// Creates a new #GMenuItem.
25    ///
26    /// If @label is non-[`None`] it is used to set the "label" attribute of the
27    /// new item.
28    ///
29    /// If @detailed_action is non-[`None`] it is used to set the "action" and
30    /// possibly the "target" attribute of the new item.  See
31    /// g_menu_item_set_detailed_action() for more information.
32    /// ## `label`
33    /// the section label, or [`None`]
34    /// ## `detailed_action`
35    /// the detailed action string, or [`None`]
36    ///
37    /// # Returns
38    ///
39    /// a new #GMenuItem
40    #[doc(alias = "g_menu_item_new")]
41    pub fn new(label: Option<&str>, detailed_action: Option<&str>) -> MenuItem {
42        unsafe {
43            from_glib_full(ffi::g_menu_item_new(
44                label.to_glib_none().0,
45                detailed_action.to_glib_none().0,
46            ))
47        }
48    }
49
50    /// Creates a #GMenuItem as an exact copy of an existing menu item in a
51    /// #GMenuModel.
52    ///
53    /// @item_index must be valid (ie: be sure to call
54    /// g_menu_model_get_n_items() first).
55    /// ## `model`
56    /// a #GMenuModel
57    /// ## `item_index`
58    /// the index of an item in @model
59    ///
60    /// # Returns
61    ///
62    /// a new #GMenuItem.
63    #[doc(alias = "g_menu_item_new_from_model")]
64    #[doc(alias = "new_from_model")]
65    pub fn from_model(model: &impl IsA<MenuModel>, item_index: i32) -> MenuItem {
66        unsafe {
67            from_glib_full(ffi::g_menu_item_new_from_model(
68                model.as_ref().to_glib_none().0,
69                item_index,
70            ))
71        }
72    }
73
74    ///
75    /// ]|
76    /// ## `label`
77    /// the section label, or [`None`]
78    /// ## `section`
79    /// a #GMenuModel with the items of the section
80    ///
81    /// # Returns
82    ///
83    /// a new #GMenuItem
84    #[doc(alias = "g_menu_item_new_section")]
85    pub fn new_section(label: Option<&str>, section: &impl IsA<MenuModel>) -> MenuItem {
86        unsafe {
87            from_glib_full(ffi::g_menu_item_new_section(
88                label.to_glib_none().0,
89                section.as_ref().to_glib_none().0,
90            ))
91        }
92    }
93
94    /// Creates a new #GMenuItem representing a submenu.
95    ///
96    /// This is a convenience API around g_menu_item_new() and
97    /// g_menu_item_set_submenu().
98    /// ## `label`
99    /// the section label, or [`None`]
100    /// ## `submenu`
101    /// a #GMenuModel with the items of the submenu
102    ///
103    /// # Returns
104    ///
105    /// a new #GMenuItem
106    #[doc(alias = "g_menu_item_new_submenu")]
107    pub fn new_submenu(label: Option<&str>, submenu: &impl IsA<MenuModel>) -> MenuItem {
108        unsafe {
109            from_glib_full(ffi::g_menu_item_new_submenu(
110                label.to_glib_none().0,
111                submenu.as_ref().to_glib_none().0,
112            ))
113        }
114    }
115
116    //#[doc(alias = "g_menu_item_get_attribute")]
117    //#[doc(alias = "get_attribute")]
118    //pub fn is_attribute(&self, attribute: &str, format_string: &str, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) -> bool {
119    //    unsafe { TODO: call ffi:g_menu_item_get_attribute() }
120    //}
121
122    /// Queries the named @attribute on @self.
123    ///
124    /// If @expected_type is specified and the attribute does not have this
125    /// type, [`None`] is returned.  [`None`] is also returned if the attribute
126    /// simply does not exist.
127    /// ## `attribute`
128    /// the attribute name to query
129    /// ## `expected_type`
130    /// the expected type of the attribute
131    ///
132    /// # Returns
133    ///
134    /// the attribute value, or [`None`]
135    #[doc(alias = "g_menu_item_get_attribute_value")]
136    #[doc(alias = "get_attribute_value")]
137    pub fn attribute_value(
138        &self,
139        attribute: &str,
140        expected_type: Option<&glib::VariantTy>,
141    ) -> Option<glib::Variant> {
142        unsafe {
143            from_glib_full(ffi::g_menu_item_get_attribute_value(
144                self.to_glib_none().0,
145                attribute.to_glib_none().0,
146                expected_type.to_glib_none().0,
147            ))
148        }
149    }
150
151    /// Queries the named @link on @self.
152    /// ## `link`
153    /// the link name to query
154    ///
155    /// # Returns
156    ///
157    /// the link, or [`None`]
158    #[doc(alias = "g_menu_item_get_link")]
159    #[doc(alias = "get_link")]
160    pub fn link(&self, link: &str) -> Option<MenuModel> {
161        unsafe {
162            from_glib_full(ffi::g_menu_item_get_link(
163                self.to_glib_none().0,
164                link.to_glib_none().0,
165            ))
166        }
167    }
168
169    //#[doc(alias = "g_menu_item_set_action_and_target")]
170    //pub fn set_action_and_target(&self, action: Option<&str>, format_string: Option<&str>, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) {
171    //    unsafe { TODO: call ffi:g_menu_item_set_action_and_target() }
172    //}
173
174    /// Sets or unsets the "action" and "target" attributes of @self.
175    ///
176    /// If @action is [`None`] then both the "action" and "target" attributes
177    /// are unset (and @target_value is ignored).
178    ///
179    /// If @action is non-[`None`] then the "action" attribute is set.  The
180    /// "target" attribute is then set to the value of @target_value if it is
181    /// non-[`None`] or unset otherwise.
182    ///
183    /// Normal menu items (ie: not submenu, section or other custom item
184    /// types) are expected to have the "action" attribute set to identify
185    /// the action that they are associated with.  The state type of the
186    /// action help to determine the disposition of the menu item.  See
187    /// #GAction and #GActionGroup for an overview of actions.
188    ///
189    /// In general, clicking on the menu item will result in activation of
190    /// the named action with the "target" attribute given as the parameter
191    /// to the action invocation.  If the "target" attribute is not set then
192    /// the action is invoked with no parameter.
193    ///
194    /// If the action has no state then the menu item is usually drawn as a
195    /// plain menu item (ie: with no additional decoration).
196    ///
197    /// If the action has a boolean state then the menu item is usually drawn
198    /// as a toggle menu item (ie: with a checkmark or equivalent
199    /// indication).  The item should be marked as 'toggled' or 'checked'
200    /// when the boolean state is [`true`].
201    ///
202    /// If the action has a string state then the menu item is usually drawn
203    /// as a radio menu item (ie: with a radio bullet or equivalent
204    /// indication).  The item should be marked as 'selected' when the string
205    /// state is equal to the value of the @target property.
206    ///
207    /// See g_menu_item_set_action_and_target() or
208    /// g_menu_item_set_detailed_action() for two equivalent calls that are
209    /// probably more convenient for most uses.
210    /// ## `action`
211    /// the name of the action for this item
212    /// ## `target_value`
213    /// a #GVariant to use as the action target
214    #[doc(alias = "g_menu_item_set_action_and_target_value")]
215    pub fn set_action_and_target_value(
216        &self,
217        action: Option<&str>,
218        target_value: Option<&glib::Variant>,
219    ) {
220        unsafe {
221            ffi::g_menu_item_set_action_and_target_value(
222                self.to_glib_none().0,
223                action.to_glib_none().0,
224                target_value.to_glib_none().0,
225            );
226        }
227    }
228
229    //#[doc(alias = "g_menu_item_set_attribute")]
230    //pub fn set_attribute(&self, attribute: &str, format_string: Option<&str>, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) {
231    //    unsafe { TODO: call ffi:g_menu_item_set_attribute() }
232    //}
233
234    /// Sets or unsets an attribute on @self.
235    ///
236    /// The attribute to set or unset is specified by @attribute. This
237    /// can be one of the standard attribute names [`MENU_ATTRIBUTE_LABEL`][crate::MENU_ATTRIBUTE_LABEL],
238    /// [`MENU_ATTRIBUTE_ACTION`][crate::MENU_ATTRIBUTE_ACTION], [`MENU_ATTRIBUTE_TARGET`][crate::MENU_ATTRIBUTE_TARGET], or a custom
239    /// attribute name.
240    /// Attribute names are restricted to lowercase characters, numbers
241    /// and '-'. Furthermore, the names must begin with a lowercase character,
242    /// must not end with a '-', and must not contain consecutive dashes.
243    ///
244    /// must consist only of lowercase
245    /// ASCII characters, digits and '-'.
246    ///
247    /// If @value is non-[`None`] then it is used as the new value for the
248    /// attribute.  If @value is [`None`] then the attribute is unset. If
249    /// the @value #GVariant is floating, it is consumed.
250    ///
251    /// See also g_menu_item_set_attribute() for a more convenient way to do
252    /// the same.
253    /// ## `attribute`
254    /// the attribute to set
255    /// ## `value`
256    /// a #GVariant to use as the value, or [`None`]
257    #[doc(alias = "g_menu_item_set_attribute_value")]
258    pub fn set_attribute_value(&self, attribute: &str, value: Option<&glib::Variant>) {
259        unsafe {
260            ffi::g_menu_item_set_attribute_value(
261                self.to_glib_none().0,
262                attribute.to_glib_none().0,
263                value.to_glib_none().0,
264            );
265        }
266    }
267
268    /// Sets the "action" and possibly the "target" attribute of @self.
269    ///
270    /// The format of @detailed_action is the same format parsed by
271    /// g_action_parse_detailed_name().
272    ///
273    /// See g_menu_item_set_action_and_target() or
274    /// g_menu_item_set_action_and_target_value() for more flexible (but
275    /// slightly less convenient) alternatives.
276    ///
277    /// See also g_menu_item_set_action_and_target_value() for a description of
278    /// the semantics of the action and target attributes.
279    /// ## `detailed_action`
280    /// the "detailed" action string
281    #[doc(alias = "g_menu_item_set_detailed_action")]
282    pub fn set_detailed_action(&self, detailed_action: &str) {
283        unsafe {
284            ffi::g_menu_item_set_detailed_action(
285                self.to_glib_none().0,
286                detailed_action.to_glib_none().0,
287            );
288        }
289    }
290
291    /// Sets (or unsets) the icon on @self.
292    ///
293    /// This call is the same as calling g_icon_serialize() and using the
294    /// result as the value to g_menu_item_set_attribute_value() for
295    /// [`MENU_ATTRIBUTE_ICON`][crate::MENU_ATTRIBUTE_ICON].
296    ///
297    /// This API is only intended for use with "noun" menu items; things like
298    /// bookmarks or applications in an "Open With" menu.  Don't use it on
299    /// menu items corresponding to verbs (eg: stock icons for 'Save' or
300    /// 'Quit').
301    ///
302    /// If @icon is [`None`] then the icon is unset.
303    /// ## `icon`
304    /// a #GIcon, or [`None`]
305    #[doc(alias = "g_menu_item_set_icon")]
306    pub fn set_icon(&self, icon: &impl IsA<Icon>) {
307        unsafe {
308            ffi::g_menu_item_set_icon(self.to_glib_none().0, icon.as_ref().to_glib_none().0);
309        }
310    }
311
312    /// Sets or unsets the "label" attribute of @self.
313    ///
314    /// If @label is non-[`None`] it is used as the label for the menu item.  If
315    /// it is [`None`] then the label attribute is unset.
316    /// ## `label`
317    /// the label to set, or [`None`] to unset
318    #[doc(alias = "g_menu_item_set_label")]
319    pub fn set_label(&self, label: Option<&str>) {
320        unsafe {
321            ffi::g_menu_item_set_label(self.to_glib_none().0, label.to_glib_none().0);
322        }
323    }
324
325    /// Creates a link from @self to @model if non-[`None`], or unsets it.
326    ///
327    /// Links are used to establish a relationship between a particular menu
328    /// item and another menu.  For example, [`MENU_LINK_SUBMENU`][crate::MENU_LINK_SUBMENU] is used to
329    /// associate a submenu with a particular menu item, and [`MENU_LINK_SECTION`][crate::MENU_LINK_SECTION]
330    /// is used to create a section. Other types of link can be used, but there
331    /// is no guarantee that clients will be able to make sense of them.
332    /// Link types are restricted to lowercase characters, numbers
333    /// and '-'. Furthermore, the names must begin with a lowercase character,
334    /// must not end with a '-', and must not contain consecutive dashes.
335    /// ## `link`
336    /// type of link to establish or unset
337    /// ## `model`
338    /// the #GMenuModel to link to (or [`None`] to unset)
339    #[doc(alias = "g_menu_item_set_link")]
340    pub fn set_link(&self, link: &str, model: Option<&impl IsA<MenuModel>>) {
341        unsafe {
342            ffi::g_menu_item_set_link(
343                self.to_glib_none().0,
344                link.to_glib_none().0,
345                model.map(|p| p.as_ref()).to_glib_none().0,
346            );
347        }
348    }
349
350    /// Sets or unsets the "section" link of @self to @section.
351    ///
352    /// The effect of having one menu appear as a section of another is
353    /// exactly as it sounds: the items from @section become a direct part of
354    /// the menu that @self is added to.  See g_menu_item_new_section()
355    /// for more information about what it means for a menu item to be a
356    /// section.
357    /// ## `section`
358    /// a #GMenuModel, or [`None`]
359    #[doc(alias = "g_menu_item_set_section")]
360    pub fn set_section(&self, section: Option<&impl IsA<MenuModel>>) {
361        unsafe {
362            ffi::g_menu_item_set_section(
363                self.to_glib_none().0,
364                section.map(|p| p.as_ref()).to_glib_none().0,
365            );
366        }
367    }
368
369    /// Sets or unsets the "submenu" link of @self to @submenu.
370    ///
371    /// If @submenu is non-[`None`], it is linked to.  If it is [`None`] then the
372    /// link is unset.
373    ///
374    /// The effect of having one menu appear as a submenu of another is
375    /// exactly as it sounds.
376    /// ## `submenu`
377    /// a #GMenuModel, or [`None`]
378    #[doc(alias = "g_menu_item_set_submenu")]
379    pub fn set_submenu(&self, submenu: Option<&impl IsA<MenuModel>>) {
380        unsafe {
381            ffi::g_menu_item_set_submenu(
382                self.to_glib_none().0,
383                submenu.map(|p| p.as_ref()).to_glib_none().0,
384            );
385        }
386    }
387}