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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// from webkit2gtk-gir-files
// DO NOT EDIT
use crate::ContextMenu;
use crate::ContextMenuAction;
use glib::object::IsA;
use glib::translate::*;
use std::fmt;
glib::wrapper! {
/// One item of a [`ContextMenu`][crate::ContextMenu].
///
/// The [`ContextMenu`][crate::ContextMenu] is composed of [`ContextMenuItem`][crate::ContextMenuItem]<!--
/// -->s. These items can be created from a `GtkAction`, from a
/// [`ContextMenuAction`][crate::ContextMenuAction] or from a [`ContextMenuAction`][crate::ContextMenuAction] and a
/// label. These [`ContextMenuAction`][crate::ContextMenuAction]<!-- -->s denote stock actions
/// for the items. You can also create separators and submenus.
///
/// # Implements
///
/// [`ContextMenuItemExt`][trait@crate::prelude::ContextMenuItemExt], [`trait@glib::ObjectExt`]
#[doc(alias = "WebKitContextMenuItem")]
pub struct ContextMenuItem(Object<ffi::WebKitContextMenuItem, ffi::WebKitContextMenuItemClass>);
match fn {
type_ => || ffi::webkit_context_menu_item_get_type(),
}
}
impl ContextMenuItem {
pub const NONE: Option<&'static ContextMenuItem> = None;
/// Creates a new [`ContextMenuItem`][crate::ContextMenuItem] for the given `action` and `label`.
///
/// On activation
/// `target` will be passed as parameter to the callback.
/// ## `action`
/// a [`gio::Action`][crate::gio::Action]
/// ## `label`
/// the menu item label text
/// ## `target`
/// a [`glib::Variant`][struct@crate::glib::Variant] to use as the action target
///
/// # Returns
///
/// the newly created [`ContextMenuItem`][crate::ContextMenuItem] object.
#[cfg(any(feature = "v2_18", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_18")))]
#[doc(alias = "webkit_context_menu_item_new_from_gaction")]
#[doc(alias = "new_from_gaction")]
pub fn from_gaction(
action: &impl IsA<gio::Action>,
label: &str,
target: Option<&glib::Variant>,
) -> ContextMenuItem {
assert_initialized_main_thread!();
unsafe {
from_glib_none(ffi::webkit_context_menu_item_new_from_gaction(
action.as_ref().to_glib_none().0,
label.to_glib_none().0,
target.to_glib_none().0,
))
}
}
/// Creates a new [`ContextMenuItem`][crate::ContextMenuItem] for the given stock action.
///
/// Stock actions are handled automatically by WebKit so that, for example,
/// when a menu item created with a [`ContextMenuAction::Stop`][crate::ContextMenuAction::Stop] is
/// activated the action associated will be handled by WebKit and the current
/// load operation will be stopped. You can get the [`gio::Action`][crate::gio::Action] of a
/// [`ContextMenuItem`][crate::ContextMenuItem] created with a [`ContextMenuAction`][crate::ContextMenuAction] with
/// [`ContextMenuItemExt::gaction()`][crate::prelude::ContextMenuItemExt::gaction()] and connect to the `GSimpleAction::activate` signal
/// to be notified when the item is activated, but you can't prevent the associated
/// action from being performed.
/// ## `action`
/// a [`ContextMenuAction`][crate::ContextMenuAction] stock action
///
/// # Returns
///
/// the newly created [`ContextMenuItem`][crate::ContextMenuItem] object.
#[doc(alias = "webkit_context_menu_item_new_from_stock_action")]
#[doc(alias = "new_from_stock_action")]
pub fn from_stock_action(action: ContextMenuAction) -> ContextMenuItem {
assert_initialized_main_thread!();
unsafe {
from_glib_none(ffi::webkit_context_menu_item_new_from_stock_action(
action.into_glib(),
))
}
}
/// Creates a new [`ContextMenuItem`][crate::ContextMenuItem] for the given stock action using the given `label`.
///
/// Stock actions have a predefined label, this method can be used to create a
/// [`ContextMenuItem`][crate::ContextMenuItem] for a [`ContextMenuAction`][crate::ContextMenuAction] but using a custom label.
/// ## `action`
/// a [`ContextMenuAction`][crate::ContextMenuAction] stock action
/// ## `label`
/// a custom label text to use instead of the predefined one
///
/// # Returns
///
/// the newly created [`ContextMenuItem`][crate::ContextMenuItem] object.
#[doc(alias = "webkit_context_menu_item_new_from_stock_action_with_label")]
#[doc(alias = "new_from_stock_action_with_label")]
pub fn from_stock_action_with_label(action: ContextMenuAction, label: &str) -> ContextMenuItem {
assert_initialized_main_thread!();
unsafe {
from_glib_none(
ffi::webkit_context_menu_item_new_from_stock_action_with_label(
action.into_glib(),
label.to_glib_none().0,
),
)
}
}
/// Creates a new [`ContextMenuItem`][crate::ContextMenuItem] representing a separator.
///
/// # Returns
///
/// the newly created [`ContextMenuItem`][crate::ContextMenuItem] object.
#[doc(alias = "webkit_context_menu_item_new_separator")]
pub fn new_separator() -> ContextMenuItem {
assert_initialized_main_thread!();
unsafe { from_glib_none(ffi::webkit_context_menu_item_new_separator()) }
}
/// Creates a new [`ContextMenuItem`][crate::ContextMenuItem] using the given `label` with a submenu.
/// ## `label`
/// the menu item label text
/// ## `submenu`
/// a [`ContextMenu`][crate::ContextMenu] to set
///
/// # Returns
///
/// the newly created [`ContextMenuItem`][crate::ContextMenuItem] object.
#[doc(alias = "webkit_context_menu_item_new_with_submenu")]
#[doc(alias = "new_with_submenu")]
pub fn with_submenu(label: &str, submenu: &impl IsA<ContextMenu>) -> ContextMenuItem {
skip_assert_initialized!();
unsafe {
from_glib_none(ffi::webkit_context_menu_item_new_with_submenu(
label.to_glib_none().0,
submenu.as_ref().to_glib_none().0,
))
}
}
}
/// Trait containing all [`struct@ContextMenuItem`] methods.
///
/// # Implementors
///
/// [`ContextMenuItem`][struct@crate::ContextMenuItem]
pub trait ContextMenuItemExt: 'static {
/// Gets the action associated to `self` as a [`gio::Action`][crate::gio::Action].
///
/// # Returns
///
/// the [`gio::Action`][crate::gio::Action] associated to the [`ContextMenuItem`][crate::ContextMenuItem],
/// or [`None`] if `self` is a separator.
#[cfg(any(feature = "v2_18", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_18")))]
#[doc(alias = "webkit_context_menu_item_get_gaction")]
#[doc(alias = "get_gaction")]
fn gaction(&self) -> Option<gio::Action>;
/// Gets the [`ContextMenuAction`][crate::ContextMenuAction] of `self`.
///
/// If the [`ContextMenuItem`][crate::ContextMenuItem] was not
/// created for a stock action [`ContextMenuAction::Custom`][crate::ContextMenuAction::Custom] will be
/// returned. If the [`ContextMenuItem`][crate::ContextMenuItem] is a separator [`ContextMenuAction::NoAction`][crate::ContextMenuAction::NoAction]
/// will be returned.
///
/// # Returns
///
/// the [`ContextMenuAction`][crate::ContextMenuAction] of `self`
#[doc(alias = "webkit_context_menu_item_get_stock_action")]
#[doc(alias = "get_stock_action")]
fn stock_action(&self) -> ContextMenuAction;
/// Gets the submenu of `self`.
///
/// # Returns
///
/// the [`ContextMenu`][crate::ContextMenu] representing the submenu of
/// `self` or [`None`] if `self` doesn't have a submenu.
#[doc(alias = "webkit_context_menu_item_get_submenu")]
#[doc(alias = "get_submenu")]
fn submenu(&self) -> Option<ContextMenu>;
/// Checks whether `self` is a separator.
///
/// # Returns
///
/// [`true`] is `self` is a separator or [`false`] otherwise
#[doc(alias = "webkit_context_menu_item_is_separator")]
fn is_separator(&self) -> bool;
/// Sets or replaces the `self` submenu.
///
/// If `submenu` is [`None`] the current
/// submenu of `self` is removed.
/// ## `submenu`
/// a [`ContextMenu`][crate::ContextMenu]
#[doc(alias = "webkit_context_menu_item_set_submenu")]
fn set_submenu(&self, submenu: Option<&impl IsA<ContextMenu>>);
}
impl<O: IsA<ContextMenuItem>> ContextMenuItemExt for O {
#[cfg(any(feature = "v2_18", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_18")))]
fn gaction(&self) -> Option<gio::Action> {
unsafe {
from_glib_none(ffi::webkit_context_menu_item_get_gaction(
self.as_ref().to_glib_none().0,
))
}
}
fn stock_action(&self) -> ContextMenuAction {
unsafe {
from_glib(ffi::webkit_context_menu_item_get_stock_action(
self.as_ref().to_glib_none().0,
))
}
}
fn submenu(&self) -> Option<ContextMenu> {
unsafe {
from_glib_none(ffi::webkit_context_menu_item_get_submenu(
self.as_ref().to_glib_none().0,
))
}
}
fn is_separator(&self) -> bool {
unsafe {
from_glib(ffi::webkit_context_menu_item_is_separator(
self.as_ref().to_glib_none().0,
))
}
}
fn set_submenu(&self, submenu: Option<&impl IsA<ContextMenu>>) {
unsafe {
ffi::webkit_context_menu_item_set_submenu(
self.as_ref().to_glib_none().0,
submenu.map(|p| p.as_ref()).to_glib_none().0,
);
}
}
}
impl fmt::Display for ContextMenuItem {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("ContextMenuItem")
}
}