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
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

#[cfg(any(feature = "v2_18", feature = "dox"))]
use gio;
#[cfg(any(feature = "v2_18", feature = "dox"))]
use glib;
use glib::object::IsA;
use glib::translate::*;
use std::fmt;
use webkit2_sys;
use ContextMenu;
use ContextMenuAction;

glib_wrapper! {
    pub struct ContextMenuItem(Object<webkit2_sys::WebKitContextMenuItem, webkit2_sys::WebKitContextMenuItemClass, ContextMenuItemClass>);

    match fn {
        get_type => || webkit2_sys::webkit_context_menu_item_get_type(),
    }
}

impl ContextMenuItem {
    //#[cfg_attr(feature = "v2_18", deprecated)]
    //pub fn new(action: /*Ignored*/&gtk::Action) -> ContextMenuItem {
    //    unsafe { TODO: call webkit2_sys:webkit_context_menu_item_new() }
    //}

    #[cfg(any(feature = "v2_18", feature = "dox"))]
    pub fn from_gaction<P: IsA<gio::Action>>(action: &P, label: &str, target: Option<&glib::Variant>) -> ContextMenuItem {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_none(webkit2_sys::webkit_context_menu_item_new_from_gaction(action.as_ref().to_glib_none().0, label.to_glib_none().0, target.to_glib_none().0))
        }
    }

    pub fn from_stock_action(action: ContextMenuAction) -> ContextMenuItem {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_none(webkit2_sys::webkit_context_menu_item_new_from_stock_action(action.to_glib()))
        }
    }

    pub fn from_stock_action_with_label(action: ContextMenuAction, label: &str) -> ContextMenuItem {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_none(webkit2_sys::webkit_context_menu_item_new_from_stock_action_with_label(action.to_glib(), label.to_glib_none().0))
        }
    }

    pub fn new_separator() -> ContextMenuItem {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_none(webkit2_sys::webkit_context_menu_item_new_separator())
        }
    }

    pub fn with_submenu<P: IsA<ContextMenu>>(label: &str, submenu: &P) -> ContextMenuItem {
        skip_assert_initialized!();
        unsafe {
            from_glib_none(webkit2_sys::webkit_context_menu_item_new_with_submenu(label.to_glib_none().0, submenu.as_ref().to_glib_none().0))
        }
    }
}

pub const NONE_CONTEXT_MENU_ITEM: Option<&ContextMenuItem> = None;

pub trait ContextMenuItemExt: 'static {
    //#[cfg_attr(feature = "v2_18", deprecated)]
    //fn get_action(&self) -> /*Ignored*/Option<gtk::Action>;

    #[cfg(any(feature = "v2_18", feature = "dox"))]
    fn get_gaction(&self) -> Option<gio::Action>;

    fn get_stock_action(&self) -> ContextMenuAction;

    fn get_submenu(&self) -> Option<ContextMenu>;

    fn is_separator(&self) -> bool;

    fn set_submenu<P: IsA<ContextMenu>>(&self, submenu: Option<&P>);
}

impl<O: IsA<ContextMenuItem>> ContextMenuItemExt for O {
    //fn get_action(&self) -> /*Ignored*/Option<gtk::Action> {
    //    unsafe { TODO: call webkit2_sys:webkit_context_menu_item_get_action() }
    //}

    #[cfg(any(feature = "v2_18", feature = "dox"))]
    fn get_gaction(&self) -> Option<gio::Action> {
        unsafe {
            from_glib_none(webkit2_sys::webkit_context_menu_item_get_gaction(self.as_ref().to_glib_none().0))
        }
    }

    fn get_stock_action(&self) -> ContextMenuAction {
        unsafe {
            from_glib(webkit2_sys::webkit_context_menu_item_get_stock_action(self.as_ref().to_glib_none().0))
        }
    }

    fn get_submenu(&self) -> Option<ContextMenu> {
        unsafe {
            from_glib_none(webkit2_sys::webkit_context_menu_item_get_submenu(self.as_ref().to_glib_none().0))
        }
    }

    fn is_separator(&self) -> bool {
        unsafe {
            from_glib(webkit2_sys::webkit_context_menu_item_is_separator(self.as_ref().to_glib_none().0))
        }
    }

    fn set_submenu<P: IsA<ContextMenu>>(&self, submenu: Option<&P>) {
        unsafe {
            webkit2_sys::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 {
        write!(f, "ContextMenuItem")
    }
}