webkit2gtk/auto/
context_menu_item.rs1#![allow(deprecated)]
5
6use crate::{ContextMenu, ContextMenuAction};
7use glib::{prelude::*, translate::*};
8
9glib::wrapper! {
10 #[doc(alias = "WebKitContextMenuItem")]
11 pub struct ContextMenuItem(Object<ffi::WebKitContextMenuItem, ffi::WebKitContextMenuItemClass>);
12
13 match fn {
14 type_ => || ffi::webkit_context_menu_item_get_type(),
15 }
16}
17
18impl ContextMenuItem {
19 pub const NONE: Option<&'static ContextMenuItem> = None;
20
21 #[cfg(feature = "v2_18")]
29 #[cfg_attr(docsrs, doc(cfg(feature = "v2_18")))]
30 #[doc(alias = "webkit_context_menu_item_new_from_gaction")]
31 #[doc(alias = "new_from_gaction")]
32 pub fn from_gaction(
33 action: &impl IsA<gio::Action>,
34 label: &str,
35 target: Option<&glib::Variant>,
36 ) -> ContextMenuItem {
37 assert_initialized_main_thread!();
38 unsafe {
39 from_glib_none(ffi::webkit_context_menu_item_new_from_gaction(
40 action.as_ref().to_glib_none().0,
41 label.to_glib_none().0,
42 target.to_glib_none().0,
43 ))
44 }
45 }
46
47 #[doc(alias = "webkit_context_menu_item_new_from_stock_action")]
48 #[doc(alias = "new_from_stock_action")]
49 pub fn from_stock_action(action: ContextMenuAction) -> ContextMenuItem {
50 assert_initialized_main_thread!();
51 unsafe {
52 from_glib_none(ffi::webkit_context_menu_item_new_from_stock_action(
53 action.into_glib(),
54 ))
55 }
56 }
57
58 #[doc(alias = "webkit_context_menu_item_new_from_stock_action_with_label")]
59 #[doc(alias = "new_from_stock_action_with_label")]
60 pub fn from_stock_action_with_label(action: ContextMenuAction, label: &str) -> ContextMenuItem {
61 assert_initialized_main_thread!();
62 unsafe {
63 from_glib_none(
64 ffi::webkit_context_menu_item_new_from_stock_action_with_label(
65 action.into_glib(),
66 label.to_glib_none().0,
67 ),
68 )
69 }
70 }
71
72 #[doc(alias = "webkit_context_menu_item_new_separator")]
73 pub fn new_separator() -> ContextMenuItem {
74 assert_initialized_main_thread!();
75 unsafe { from_glib_none(ffi::webkit_context_menu_item_new_separator()) }
76 }
77
78 #[doc(alias = "webkit_context_menu_item_new_with_submenu")]
79 #[doc(alias = "new_with_submenu")]
80 pub fn with_submenu(label: &str, submenu: &impl IsA<ContextMenu>) -> ContextMenuItem {
81 skip_assert_initialized!();
82 unsafe {
83 from_glib_none(ffi::webkit_context_menu_item_new_with_submenu(
84 label.to_glib_none().0,
85 submenu.as_ref().to_glib_none().0,
86 ))
87 }
88 }
89}
90
91mod sealed {
92 pub trait Sealed {}
93 impl<T: super::IsA<super::ContextMenuItem>> Sealed for T {}
94}
95
96pub trait ContextMenuItemExt: IsA<ContextMenuItem> + sealed::Sealed + 'static {
97 #[cfg(feature = "v2_18")]
106 #[cfg_attr(docsrs, doc(cfg(feature = "v2_18")))]
107 #[doc(alias = "webkit_context_menu_item_get_gaction")]
108 #[doc(alias = "get_gaction")]
109 fn gaction(&self) -> Option<gio::Action> {
110 unsafe {
111 from_glib_none(ffi::webkit_context_menu_item_get_gaction(
112 self.as_ref().to_glib_none().0,
113 ))
114 }
115 }
116
117 #[doc(alias = "webkit_context_menu_item_get_stock_action")]
118 #[doc(alias = "get_stock_action")]
119 fn stock_action(&self) -> ContextMenuAction {
120 unsafe {
121 from_glib(ffi::webkit_context_menu_item_get_stock_action(
122 self.as_ref().to_glib_none().0,
123 ))
124 }
125 }
126
127 #[doc(alias = "webkit_context_menu_item_get_submenu")]
128 #[doc(alias = "get_submenu")]
129 fn submenu(&self) -> Option<ContextMenu> {
130 unsafe {
131 from_glib_none(ffi::webkit_context_menu_item_get_submenu(
132 self.as_ref().to_glib_none().0,
133 ))
134 }
135 }
136
137 #[doc(alias = "webkit_context_menu_item_is_separator")]
138 fn is_separator(&self) -> bool {
139 unsafe {
140 from_glib(ffi::webkit_context_menu_item_is_separator(
141 self.as_ref().to_glib_none().0,
142 ))
143 }
144 }
145
146 #[doc(alias = "webkit_context_menu_item_set_submenu")]
147 fn set_submenu(&self, submenu: Option<&impl IsA<ContextMenu>>) {
148 unsafe {
149 ffi::webkit_context_menu_item_set_submenu(
150 self.as_ref().to_glib_none().0,
151 submenu.map(|p| p.as_ref()).to_glib_none().0,
152 );
153 }
154 }
155}
156
157impl<O: IsA<ContextMenuItem>> ContextMenuItemExt for O {}