electron_sys/class/
menu.rs

1use crate::{
2    class::{BrowserWindow, MenuItem},
3    interface::PopupOptions,
4};
5use js_sys::{JsString, Object};
6use wasm_bindgen::prelude::*;
7
8#[wasm_bindgen(module = "electron")]
9extern {
10    #[wasm_bindgen(extends = Object)]
11    #[derive(Clone, Debug, Eq, PartialEq)]
12    /// Docs: http://electronjs.org/docs/api/menu
13    pub type Menu;
14
15    //*************//
16    // Constructor //
17    //*************//
18
19    #[wasm_bindgen(constructor)]
20    pub fn new() -> Menu;
21
22    //****************//
23    // Static Methods //
24    //****************//
25
26    #[wasm_bindgen(static_method_of = Menu, js_name = "buildFromTemplate")]
27    pub fn build_from_template(template: Box<[JsValue]>) -> Menu;
28
29    #[wasm_bindgen(static_method_of = Menu, js_name = "getApplicationMenu")]
30    pub fn get_application_menu(template: Box<[JsValue]>) -> Option<Menu>;
31
32    #[wasm_bindgen(static_method_of = Menu, js_name = "sendApplicationToFirstResponder")]
33    pub fn send_application_to_first_responder(action: &JsString);
34
35    #[wasm_bindgen(static_method_of = Menu, js_name = "setApplicationMenu")]
36    pub fn set_application_menu(menu: Option<Menu>);
37
38    //******************//
39    // Instance Methods //
40    //******************//
41
42    #[wasm_bindgen(method)]
43    pub fn append(this: &Menu, menu_item: &MenuItem);
44
45    #[wasm_bindgen(method, js_name = "closePopup")]
46    pub fn close_popup(this: &Menu, browser_window: Option<BrowserWindow>);
47
48    #[wasm_bindgen(method, js_name = "getMenuItemById")]
49    pub fn get_menu_item_by_id(this: &Menu, id: &str) -> MenuItem;
50
51    #[wasm_bindgen(method)]
52    pub fn insert(this: &Menu, pos: usize, menu_item: &MenuItem);
53
54    #[wasm_bindgen(method)]
55    pub fn popup(this: &Menu, options: Option<PopupOptions>);
56
57    //*********************//
58    // Instance Properties //
59    //*********************//
60
61    #[wasm_bindgen(method, getter)]
62    pub fn items(this: &Menu) -> Box<[JsValue]>;
63
64    #[wasm_bindgen(method, setter)]
65    pub fn set_items(this: &Menu, value: Box<[JsValue]>);
66}