gio/auto/menu.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, MenuItem, MenuModel};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 /// `GMenu` is a simple implementation of [`MenuModel`][crate::MenuModel].
10 /// You populate a `GMenu` by adding [`MenuItem`][crate::MenuItem] instances to it.
11 ///
12 /// There are some convenience functions to allow you to directly
13 /// add items (avoiding [`MenuItem`][crate::MenuItem]) for the common cases. To add
14 /// a regular item, use [`insert()`][Self::insert()]. To add a section, use
15 /// [`insert_section()`][Self::insert_section()]. To add a submenu, use
16 /// [`insert_submenu()`][Self::insert_submenu()].
17 ///
18 /// # Implements
19 ///
20 /// [`MenuModelExt`][trait@crate::prelude::MenuModelExt], [`trait@glib::ObjectExt`]
21 #[doc(alias = "GMenu")]
22 pub struct Menu(Object<ffi::GMenu>) @extends MenuModel;
23
24 match fn {
25 type_ => || ffi::g_menu_get_type(),
26 }
27}
28
29impl Menu {
30 /// Creates a new #GMenu.
31 ///
32 /// The new menu has no items.
33 ///
34 /// # Returns
35 ///
36 /// a new #GMenu
37 #[doc(alias = "g_menu_new")]
38 pub fn new() -> Menu {
39 unsafe { from_glib_full(ffi::g_menu_new()) }
40 }
41
42 /// Convenience function for appending a normal menu item to the end of
43 /// @self. Combine g_menu_item_new() and g_menu_insert_item() for a more
44 /// flexible alternative.
45 /// ## `label`
46 /// the section label, or [`None`]
47 /// ## `detailed_action`
48 /// the detailed action string, or [`None`]
49 #[doc(alias = "g_menu_append")]
50 pub fn append(&self, label: Option<&str>, detailed_action: Option<&str>) {
51 unsafe {
52 ffi::g_menu_append(
53 self.to_glib_none().0,
54 label.to_glib_none().0,
55 detailed_action.to_glib_none().0,
56 );
57 }
58 }
59
60 /// Appends @item to the end of @self.
61 ///
62 /// See g_menu_insert_item() for more information.
63 /// ## `item`
64 /// a #GMenuItem to append
65 #[doc(alias = "g_menu_append_item")]
66 pub fn append_item(&self, item: &MenuItem) {
67 unsafe {
68 ffi::g_menu_append_item(self.to_glib_none().0, item.to_glib_none().0);
69 }
70 }
71
72 /// Convenience function for appending a section menu item to the end of
73 /// @self. Combine g_menu_item_new_section() and g_menu_insert_item() for a
74 /// more flexible alternative.
75 /// ## `label`
76 /// the section label, or [`None`]
77 /// ## `section`
78 /// a #GMenuModel with the items of the section
79 #[doc(alias = "g_menu_append_section")]
80 pub fn append_section(&self, label: Option<&str>, section: &impl IsA<MenuModel>) {
81 unsafe {
82 ffi::g_menu_append_section(
83 self.to_glib_none().0,
84 label.to_glib_none().0,
85 section.as_ref().to_glib_none().0,
86 );
87 }
88 }
89
90 /// Convenience function for appending a submenu menu item to the end of
91 /// @self. Combine g_menu_item_new_submenu() and g_menu_insert_item() for a
92 /// more flexible alternative.
93 /// ## `label`
94 /// the section label, or [`None`]
95 /// ## `submenu`
96 /// a #GMenuModel with the items of the submenu
97 #[doc(alias = "g_menu_append_submenu")]
98 pub fn append_submenu(&self, label: Option<&str>, submenu: &impl IsA<MenuModel>) {
99 unsafe {
100 ffi::g_menu_append_submenu(
101 self.to_glib_none().0,
102 label.to_glib_none().0,
103 submenu.as_ref().to_glib_none().0,
104 );
105 }
106 }
107
108 /// Marks @self as frozen.
109 ///
110 /// After the menu is frozen, it is an error to attempt to make any
111 /// changes to it. In effect this means that the #GMenu API must no
112 /// longer be used.
113 ///
114 /// This function causes g_menu_model_is_mutable() to begin returning
115 /// [`false`], which has some positive performance implications.
116 #[doc(alias = "g_menu_freeze")]
117 pub fn freeze(&self) {
118 unsafe {
119 ffi::g_menu_freeze(self.to_glib_none().0);
120 }
121 }
122
123 /// Convenience function for inserting a normal menu item into @self.
124 /// Combine g_menu_item_new() and g_menu_insert_item() for a more flexible
125 /// alternative.
126 /// ## `position`
127 /// the position at which to insert the item
128 /// ## `label`
129 /// the section label, or [`None`]
130 /// ## `detailed_action`
131 /// the detailed action string, or [`None`]
132 #[doc(alias = "g_menu_insert")]
133 pub fn insert(&self, position: i32, label: Option<&str>, detailed_action: Option<&str>) {
134 unsafe {
135 ffi::g_menu_insert(
136 self.to_glib_none().0,
137 position,
138 label.to_glib_none().0,
139 detailed_action.to_glib_none().0,
140 );
141 }
142 }
143
144 /// Inserts @item into @self.
145 ///
146 /// The "insertion" is actually done by copying all of the attribute and
147 /// link values of @item and using them to form a new item within @self.
148 /// As such, @item itself is not really inserted, but rather, a menu item
149 /// that is exactly the same as the one presently described by @item.
150 ///
151 /// This means that @item is essentially useless after the insertion
152 /// occurs. Any changes you make to it are ignored unless it is inserted
153 /// again (at which point its updated values will be copied).
154 ///
155 /// You should probably just free @item once you're done.
156 ///
157 /// There are many convenience functions to take care of common cases.
158 /// See g_menu_insert(), g_menu_insert_section() and
159 /// g_menu_insert_submenu() as well as "prepend" and "append" variants of
160 /// each of these functions.
161 /// ## `position`
162 /// the position at which to insert the item
163 /// ## `item`
164 /// the #GMenuItem to insert
165 #[doc(alias = "g_menu_insert_item")]
166 pub fn insert_item(&self, position: i32, item: &MenuItem) {
167 unsafe {
168 ffi::g_menu_insert_item(self.to_glib_none().0, position, item.to_glib_none().0);
169 }
170 }
171
172 /// Convenience function for inserting a section menu item into @self.
173 /// Combine g_menu_item_new_section() and g_menu_insert_item() for a more
174 /// flexible alternative.
175 /// ## `position`
176 /// the position at which to insert the item
177 /// ## `label`
178 /// the section label, or [`None`]
179 /// ## `section`
180 /// a #GMenuModel with the items of the section
181 #[doc(alias = "g_menu_insert_section")]
182 pub fn insert_section(
183 &self,
184 position: i32,
185 label: Option<&str>,
186 section: &impl IsA<MenuModel>,
187 ) {
188 unsafe {
189 ffi::g_menu_insert_section(
190 self.to_glib_none().0,
191 position,
192 label.to_glib_none().0,
193 section.as_ref().to_glib_none().0,
194 );
195 }
196 }
197
198 /// Convenience function for inserting a submenu menu item into @self.
199 /// Combine g_menu_item_new_submenu() and g_menu_insert_item() for a more
200 /// flexible alternative.
201 /// ## `position`
202 /// the position at which to insert the item
203 /// ## `label`
204 /// the section label, or [`None`]
205 /// ## `submenu`
206 /// a #GMenuModel with the items of the submenu
207 #[doc(alias = "g_menu_insert_submenu")]
208 pub fn insert_submenu(
209 &self,
210 position: i32,
211 label: Option<&str>,
212 submenu: &impl IsA<MenuModel>,
213 ) {
214 unsafe {
215 ffi::g_menu_insert_submenu(
216 self.to_glib_none().0,
217 position,
218 label.to_glib_none().0,
219 submenu.as_ref().to_glib_none().0,
220 );
221 }
222 }
223
224 /// Convenience function for prepending a normal menu item to the start
225 /// of @self. Combine g_menu_item_new() and g_menu_insert_item() for a more
226 /// flexible alternative.
227 /// ## `label`
228 /// the section label, or [`None`]
229 /// ## `detailed_action`
230 /// the detailed action string, or [`None`]
231 #[doc(alias = "g_menu_prepend")]
232 pub fn prepend(&self, label: Option<&str>, detailed_action: Option<&str>) {
233 unsafe {
234 ffi::g_menu_prepend(
235 self.to_glib_none().0,
236 label.to_glib_none().0,
237 detailed_action.to_glib_none().0,
238 );
239 }
240 }
241
242 /// Prepends @item to the start of @self.
243 ///
244 /// See g_menu_insert_item() for more information.
245 /// ## `item`
246 /// a #GMenuItem to prepend
247 #[doc(alias = "g_menu_prepend_item")]
248 pub fn prepend_item(&self, item: &MenuItem) {
249 unsafe {
250 ffi::g_menu_prepend_item(self.to_glib_none().0, item.to_glib_none().0);
251 }
252 }
253
254 /// Convenience function for prepending a section menu item to the start
255 /// of @self. Combine g_menu_item_new_section() and g_menu_insert_item() for
256 /// a more flexible alternative.
257 /// ## `label`
258 /// the section label, or [`None`]
259 /// ## `section`
260 /// a #GMenuModel with the items of the section
261 #[doc(alias = "g_menu_prepend_section")]
262 pub fn prepend_section(&self, label: Option<&str>, section: &impl IsA<MenuModel>) {
263 unsafe {
264 ffi::g_menu_prepend_section(
265 self.to_glib_none().0,
266 label.to_glib_none().0,
267 section.as_ref().to_glib_none().0,
268 );
269 }
270 }
271
272 /// Convenience function for prepending a submenu menu item to the start
273 /// of @self. Combine g_menu_item_new_submenu() and g_menu_insert_item() for
274 /// a more flexible alternative.
275 /// ## `label`
276 /// the section label, or [`None`]
277 /// ## `submenu`
278 /// a #GMenuModel with the items of the submenu
279 #[doc(alias = "g_menu_prepend_submenu")]
280 pub fn prepend_submenu(&self, label: Option<&str>, submenu: &impl IsA<MenuModel>) {
281 unsafe {
282 ffi::g_menu_prepend_submenu(
283 self.to_glib_none().0,
284 label.to_glib_none().0,
285 submenu.as_ref().to_glib_none().0,
286 );
287 }
288 }
289
290 /// Removes an item from the menu.
291 ///
292 /// @position gives the index of the item to remove.
293 ///
294 /// It is an error if position is not in range the range from 0 to one
295 /// less than the number of items in the menu.
296 ///
297 /// It is not possible to remove items by identity since items are added
298 /// to the menu simply by copying their links and attributes (ie:
299 /// identity of the item itself is not preserved).
300 /// ## `position`
301 /// the position of the item to remove
302 #[doc(alias = "g_menu_remove")]
303 pub fn remove(&self, position: i32) {
304 unsafe {
305 ffi::g_menu_remove(self.to_glib_none().0, position);
306 }
307 }
308
309 /// Removes all items in the menu.
310 #[doc(alias = "g_menu_remove_all")]
311 pub fn remove_all(&self) {
312 unsafe {
313 ffi::g_menu_remove_all(self.to_glib_none().0);
314 }
315 }
316}
317
318impl Default for Menu {
319 fn default() -> Self {
320 Self::new()
321 }
322}