mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-14 13:44:47 +00:00
implement BrowserWindow-API functions
This commit is contained in:
53
ElectronNET.API/Extensions/MenuItemExtensions.cs
Normal file
53
ElectronNET.API/Extensions/MenuItemExtensions.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using ElectronNET.API.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace ElectronNET.API.Extensions
|
||||
{
|
||||
internal static class MenuItemExtensions
|
||||
{
|
||||
public static MenuItem[] AddMenuItemsId(this MenuItem[] menuItems)
|
||||
{
|
||||
for (int index = 0; index < menuItems.Length; index++)
|
||||
{
|
||||
var menuItem = menuItems[index];
|
||||
if (menuItem?.Submenu?.Length > 0)
|
||||
{
|
||||
AddMenuItemsId(menuItem.Submenu);
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(menuItem.Role) &&
|
||||
string.IsNullOrEmpty(menuItem.Id))
|
||||
{
|
||||
menuItem.Id = Guid.NewGuid().ToString();
|
||||
}
|
||||
}
|
||||
|
||||
return menuItems;
|
||||
}
|
||||
|
||||
public static MenuItem GetMenuItem(this List<MenuItem> menuItems, string id)
|
||||
{
|
||||
MenuItem result = new MenuItem();
|
||||
|
||||
foreach (var item in menuItems)
|
||||
{
|
||||
if (item.Id == id)
|
||||
{
|
||||
result = item;
|
||||
}
|
||||
else if (item?.Submenu?.Length > 0)
|
||||
{
|
||||
var menuItem = GetMenuItem(item.Submenu.ToList(), id);
|
||||
if (menuItem.Id == id)
|
||||
{
|
||||
result = menuItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user