1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT

use glib::{prelude::*, translate::*};
use std::fmt;

glib::wrapper! {
    /// The goal of [`MenuManager`][crate::MenuManager] is to simplify the process of merging multiple
    /// GtkBuilder .ui files containing menus into a single representation of the
    /// application menus. Additionally, it provides the ability to "unmerge"
    /// previously merged menus.
    ///
    /// This allows for an application to have plugins which seemlessly extends
    /// the core application menus.
    ///
    /// Implementation notes:
    ///
    /// To make this work, we don't use the GMenu instances created by a GtkBuilder
    /// instance. Instead, we create the menus ourself and recreate section and
    /// submenu links. This allows the [`MenuManager`][crate::MenuManager] to be in full control of
    /// the generated menus.
    ///
    /// [`menu_by_id()`][Self::menu_by_id()] will always return a [`gio::Menu`][crate::gio::Menu], however
    /// that menu may contain no children until something has extended it later
    /// on during the application process.
    ///
    /// # Implements
    ///
    /// [`trait@glib::ObjectExt`]
    #[doc(alias = "DzlMenuManager")]
    pub struct MenuManager(Object<ffi::DzlMenuManager, ffi::DzlMenuManagerClass>);

    match fn {
        type_ => || ffi::dzl_menu_manager_get_type(),
    }
}

impl MenuManager {
    #[doc(alias = "dzl_menu_manager_new")]
    pub fn new() -> MenuManager {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(ffi::dzl_menu_manager_new()) }
    }

    ///
    /// # Returns
    ///
    /// A [`gio::Menu`][crate::gio::Menu].
    #[doc(alias = "dzl_menu_manager_get_menu_by_id")]
    #[doc(alias = "get_menu_by_id")]
    pub fn menu_by_id(&self, menu_id: &str) -> Option<gio::Menu> {
        unsafe {
            from_glib_none(ffi::dzl_menu_manager_get_menu_by_id(
                self.to_glib_none().0,
                menu_id.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "dzl_menu_manager_merge")]
    pub fn merge(&self, menu_id: &str, model: &impl IsA<gio::MenuModel>) -> u32 {
        unsafe {
            ffi::dzl_menu_manager_merge(
                self.to_glib_none().0,
                menu_id.to_glib_none().0,
                model.as_ref().to_glib_none().0,
            )
        }
    }

    /// This removes items from menus that were added as part of a previous
    /// menu merge. Use the value returned from [`merge()`][Self::merge()] as
    /// the `merge_id`.
    /// ## `merge_id`
    /// A previously registered merge id
    #[doc(alias = "dzl_menu_manager_remove")]
    pub fn remove(&self, merge_id: u32) {
        unsafe {
            ffi::dzl_menu_manager_remove(self.to_glib_none().0, merge_id);
        }
    }
}

#[cfg(feature = "v3_26")]
#[cfg_attr(docsrs, doc(cfg(feature = "v3_26")))]
impl Default for MenuManager {
    fn default() -> Self {
        Self::new()
    }
}

impl fmt::Display for MenuManager {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("MenuManager")
    }
}