Example #1
0
        private void AddItemsToMenu(IAvnAppMenu menu, ICollection <NativeMenuItemBase> items, bool isMainMenu = false)
        {
            foreach (var i in items)
            {
                if (i is NativeMenuItem item)
                {
                    var menuItem = _factory.CreateMenuItem();

                    AddMenuItem(item);

                    menuItem.SetAction(new PredicateCallback(() =>
                    {
                        if (item.Command != null || item.HasClickHandlers)
                        {
                            return(item.Enabled);
                        }

                        return(false);
                    }), new MenuActionCallback(() => { item.RaiseClick(); }));

                    if (item.Menu?.Items.Count > 0 || isMainMenu)
                    {
                        var subMenu = CreateSubmenu(item.Menu?.Items);

                        menuItem.SetSubMenu(subMenu);

                        using (var buffer = new Utf8Buffer(item.Header))
                        {
                            subMenu.Title = buffer.DangerousGetHandle();
                        }
                    }
                    else
                    {
                        using (var buffer = new Utf8Buffer(item.Header))
                        {
                            menuItem.Title = buffer.DangerousGetHandle();
                        }

                        if (item.Gesture != null)
                        {
                            using (var buffer = new Utf8Buffer(item.Gesture.Key.ToString().ToLower()))
                            {
                                menuItem.SetGesture(buffer.DangerousGetHandle(), (AvnInputModifiers)item.Gesture.KeyModifiers);
                            }
                        }
                    }

                    menu.AddItem(menuItem);
                }
                else if (i is NativeMenuItemSeperator seperator)
                {
                    menu.AddItem(_factory.CreateMenuItemSeperator());
                }
            }
        }
Example #2
0
        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());
                }
            }
        }