private void SetChildren(IAvnAppMenu menu, ICollection <NativeMenuItemBase> children) { foreach (var i in children) { if (i is NativeMenuItem item) { AddMenuItem(item); var menuItem = _factory.CreateMenuItem(); using (var buffer = new Utf8Buffer(item.Header)) { menuItem.Title = buffer.DangerousGetHandle(); } if (item.Gesture != null) { using (var buffer = new Utf8Buffer(ConvertOSXSpecialKeyCodes(item.Gesture.Key))) { menuItem.SetGesture(buffer.DangerousGetHandle(), (AvnInputModifiers)item.Gesture.KeyModifiers); } } menuItem.SetAction(new PredicateCallback(() => { if (item.Command != null || item.HasClickHandlers) { return(item.Enabled); } return(false); }), new MenuActionCallback(() => { item.RaiseClick(); })); menu.AddItem(menuItem); if (item.Menu?.Items?.Count > 0) { var submenu = _factory.CreateMenu(); using (var buffer = new Utf8Buffer(item.Header)) { submenu.Title = buffer.DangerousGetHandle(); } menuItem.SetSubMenu(submenu); AddItemsToMenu(submenu, item.Menu?.Items); } } else if (i is NativeMenuItemSeperator seperator) { menu.AddItem(_factory.CreateMenuItemSeperator()); } } }
private __MicroComIAvnMenuItemProxy CreateNew(IAvaloniaNativeFactory factory, NativeMenuItemBase item) { var nativeItem = (__MicroComIAvnMenuItemProxy)(item is NativeMenuItemSeparator ? factory.CreateMenuItemSeparator() : factory.CreateMenuItem()); nativeItem.ManagedMenuItem = item; return nativeItem; }
private IAvnMenuItem CreateNew(IAvaloniaNativeFactory factory, NativeMenuItemBase item) { var nativeItem = item is NativeMenuItemSeperator?factory.CreateMenuItemSeperator() : factory.CreateMenuItem(); nativeItem.ManagedMenuItem = item; return(nativeItem); }