public void SetApplicationMenu(MenuItem[] menuItems) { menuItems.AddMenuItemsId(); BridgeConnector.Socket.Emit("menu-setApplicationMenu", JArray.FromObject(menuItems, _jsonSerializer)); _items.AddRange(menuItems); BridgeConnector.Socket.Off("menuItemClicked"); BridgeConnector.Socket.On("menuItemClicked", (id) => { MenuItem menuItem = _items.GetMenuItem(id.ToString()); menuItem?.Click(); }); }
public void Show(string image, MenuItem[] menuItems) { menuItems.AddMenuItemsId(); BridgeConnector.Socket.Emit("create-tray", image, JArray.FromObject(menuItems, _jsonSerializer)); _items.AddRange(menuItems); BridgeConnector.Socket.Off("trayMenuItemClicked"); BridgeConnector.Socket.On("trayMenuItemClicked", (id) => { MenuItem menuItem = _items.GetMenuItem(id.ToString()); menuItem?.Click(); }); }
/// <summary> /// Sets the application's dock menu. /// </summary> public void SetMenu(MenuItem[] menuItems) { menuItems.AddMenuItemsId(); BridgeConnector.Emit("dock-setMenu", JArray.FromObject(menuItems, _jsonSerializer)); _items.AddRange(menuItems); BridgeConnector.Off("dockMenuItemClicked"); BridgeConnector.On <string>("dockMenuItemClicked", (id) => { MenuItem menuItem = _items.GetMenuItem(id); menuItem?.Click(); }); }
/// <summary> /// Sets the application menu. /// </summary> /// <param name="menuItems">The menu items.</param> public void SetApplicationMenu(MenuItem[] menuItems) { _menuItems.Clear(); menuItems.AddMenuItemsId(); menuItems.AddSubmenuTypes(); BridgeConnector.Emit("menu-setApplicationMenu", JArray.FromObject(menuItems, _jsonSerializer)); _menuItems.AddRange(menuItems); BridgeConnector.Off("menuItemClicked"); BridgeConnector.On <string>("menuItemClicked", (id) => { MenuItem menuItem = _menuItems.GetMenuItem(id); menuItem.Click?.Invoke(); }); }
/// <summary> /// Sets the context menu. /// </summary> /// <param name="browserWindow">The browser window.</param> /// <param name="menuItems">The menu items.</param> public void SetContextMenu(BrowserWindow browserWindow, MenuItem[] menuItems) { menuItems.AddMenuItemsId(); menuItems.AddSubmenuTypes(); BridgeConnector.Emit("menu-setContextMenu", browserWindow.Id, JArray.FromObject(menuItems, _jsonSerializer)); if (!_contextMenuItems.ContainsKey(browserWindow.Id)) { _contextMenuItems.Add(browserWindow.Id, menuItems.ToList()); var x = _contextMenuItems.ToDictionary(kv => kv.Key, kv => kv.Value.AsReadOnly()); ContextMenuItems = new ReadOnlyDictionary <int, ReadOnlyCollection <MenuItem> >(x); } BridgeConnector.Off("contextMenuItemClicked"); BridgeConnector.On <MenuResponse>("contextMenuItemClicked", (results) => { MenuItem menuItem = _contextMenuItems[results.windowId].GetMenuItem(results.id); menuItem.Click?.Invoke(); }); }
/// <summary> /// Sets the context menu. /// </summary> /// <param name="browserWindow">The browser window.</param> /// <param name="menuItems">The menu items.</param> public void SetContextMenu(BrowserWindow browserWindow, MenuItem[] menuItems) { if (!_contextMenuItems.ContainsKey(browserWindow.Id)) { menuItems.AddMenuItemsId(); BridgeConnector.Socket.Emit("menu-setContextMenu", browserWindow.Id, JArray.FromObject(menuItems, _jsonSerializer)); _contextMenuItems.Add(browserWindow.Id, menuItems.ToList()); var x = _contextMenuItems.ToDictionary(kv => kv.Key, kv => kv.Value.AsReadOnly()); ContextMenuItems = new ReadOnlyDictionary <int, ReadOnlyCollection <MenuItem> >(x); BridgeConnector.Socket.Off("contextMenuItemClicked"); BridgeConnector.Socket.On("contextMenuItemClicked", (results) => { var id = ((JArray)results).First.ToString(); var browserWindowId = (int)((JArray)results).Last; MenuItem menuItem = _contextMenuItems[browserWindowId].GetMenuItem(id); menuItem.Click?.Invoke(); }); } }