libpanel/auto/menu_manager.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from
3// from gir-files (https://github.com/gtk-rs/gir-files.git)
4// DO NOT EDIT
5
6use crate::ffi;
7#[cfg(feature = "v1_4")]
8#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
9use glib::prelude::*;
10use glib::translate::*;
11
12glib::wrapper! {
13 /// The goal of [`MenuManager`][crate::MenuManager] is to simplify the process of merging multiple
14 /// GtkBuilder .ui files containing menus into a single representation of the
15 /// application menus. Additionally, it provides the ability to "unmerge"
16 /// previously merged menus.
17 ///
18 /// This allows for an application to have plugins which seemlessly extends
19 /// the core application menus.
20 ///
21 /// Implementation notes:
22 ///
23 /// To make this work, we don't use the GMenu instances created by a GtkBuilder
24 /// instance. Instead, we create the menus ourself and recreate section and
25 /// submenu links. This allows the [`MenuManager`][crate::MenuManager] to be in full control of
26 /// the generated menus.
27 ///
28 /// [`menu_by_id()`][Self::menu_by_id()] will always return a [`gio::Menu`][crate::gio::Menu], however
29 /// that menu may contain no children until something has extended it later
30 /// on during the application process.
31 ///
32 /// # Implements
33 ///
34 /// [`trait@glib::ObjectExt`]
35 #[doc(alias = "PanelMenuManager")]
36 pub struct MenuManager(Object<ffi::PanelMenuManager, ffi::PanelMenuManagerClass>);
37
38 match fn {
39 type_ => || ffi::panel_menu_manager_get_type(),
40 }
41}
42
43impl MenuManager {
44 #[doc(alias = "panel_menu_manager_new")]
45 pub fn new() -> MenuManager {
46 assert_initialized_main_thread!();
47 unsafe { from_glib_full(ffi::panel_menu_manager_new()) }
48 }
49
50 /// Locates a menu item that matches `id` and sets the position within
51 /// the resulting [`gio::Menu`][crate::gio::Menu] to `position`.
52 ///
53 /// If no match is found, [`None`] is returned.
54 /// ## `id`
55 /// the identifier of the menu item
56 ///
57 /// # Returns
58 ///
59 /// a [`gio::Menu`][crate::gio::Menu] if successful; otherwise
60 /// [`None`] and `position` is unset.
61 ///
62 /// ## `position`
63 /// the position within the resulting menu
64 #[cfg(feature = "v1_4")]
65 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
66 #[doc(alias = "panel_menu_manager_find_item_by_id")]
67 pub fn find_item_by_id(&self, id: &str) -> (Option<gio::Menu>, u32) {
68 unsafe {
69 let mut position = std::mem::MaybeUninit::uninit();
70 let ret = from_glib_none(ffi::panel_menu_manager_find_item_by_id(
71 self.to_glib_none().0,
72 id.to_glib_none().0,
73 position.as_mut_ptr(),
74 ));
75 (ret, position.assume_init())
76 }
77 }
78
79 ///
80 /// # Returns
81 ///
82 /// A [`gio::Menu`][crate::gio::Menu].
83 #[cfg(feature = "v1_4")]
84 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
85 #[doc(alias = "panel_menu_manager_get_menu_by_id")]
86 #[doc(alias = "get_menu_by_id")]
87 pub fn menu_by_id(&self, menu_id: &str) -> gio::Menu {
88 unsafe {
89 from_glib_none(ffi::panel_menu_manager_get_menu_by_id(
90 self.to_glib_none().0,
91 menu_id.to_glib_none().0,
92 ))
93 }
94 }
95
96 /// Gets the known menu ids as a string array.
97 #[cfg(feature = "v1_4")]
98 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
99 #[doc(alias = "panel_menu_manager_get_menu_ids")]
100 #[doc(alias = "get_menu_ids")]
101 pub fn menu_ids(&self) -> Vec<glib::GString> {
102 unsafe {
103 FromGlibPtrContainer::from_glib_none(ffi::panel_menu_manager_get_menu_ids(
104 self.to_glib_none().0,
105 ))
106 }
107 }
108
109 /// Note that `menu_model` is not retained, a copy of it is made.
110 /// ## `menu_id`
111 /// the identifier of the menu
112 /// ## `menu_model`
113 /// the menu model to merge
114 ///
115 /// # Returns
116 ///
117 /// the merge-id which can be used with [`remove()`][Self::remove()]
118 #[cfg(feature = "v1_4")]
119 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
120 #[doc(alias = "panel_menu_manager_merge")]
121 pub fn merge(&self, menu_id: &str, menu_model: &impl IsA<gio::MenuModel>) -> u32 {
122 unsafe {
123 ffi::panel_menu_manager_merge(
124 self.to_glib_none().0,
125 menu_id.to_glib_none().0,
126 menu_model.as_ref().to_glib_none().0,
127 )
128 }
129 }
130
131 /// This removes items from menus that were added as part of a previous
132 /// menu merge. Use the value returned from [`merge()`][Self::merge()] as
133 /// the `merge_id`.
134 /// ## `merge_id`
135 /// A previously registered merge id
136 #[cfg(feature = "v1_4")]
137 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
138 #[doc(alias = "panel_menu_manager_remove")]
139 pub fn remove(&self, merge_id: u32) {
140 unsafe {
141 ffi::panel_menu_manager_remove(self.to_glib_none().0, merge_id);
142 }
143 }
144
145 /// Overwrites an attribute for a menu that was created by
146 /// [`MenuManager`][crate::MenuManager].
147 ///
148 /// This can be useful when you want to update an attribute such as
149 /// "accel" when an accelerator has changed due to user mappings.
150 /// ## `menu`
151 /// the menu that was retreived with [`menu_by_id()`][Self::menu_by_id()]
152 /// ## `position`
153 /// the index of the item in the menu
154 /// ## `attribute`
155 /// the attribute to change
156 /// ## `value`
157 /// the new value for the attribute
158 #[cfg(feature = "v1_4")]
159 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
160 #[doc(alias = "panel_menu_manager_set_attribute_string")]
161 pub fn set_attribute_string(
162 &self,
163 menu: &gio::Menu,
164 position: u32,
165 attribute: &str,
166 value: &str,
167 ) {
168 unsafe {
169 ffi::panel_menu_manager_set_attribute_string(
170 self.to_glib_none().0,
171 menu.to_glib_none().0,
172 position,
173 attribute.to_glib_none().0,
174 value.to_glib_none().0,
175 );
176 }
177 }
178}
179
180impl Default for MenuManager {
181 fn default() -> Self {
182 Self::new()
183 }
184}