Example #1
0
        public static MenuItem AddOrGetMenuItem(MenuItem parent, MenuGroupItem item, IMenuCommand menuCommand)
        {
            var menuItem = parent.AddOrGetMenuItem(item);

            UpdateMenuItemProperties(menuCommand, menuItem);
            return(menuItem);
        }
Example #2
0
        private MenuItem(MenuGroupItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            Name            = item.Name;
            Precedence      = item.Precedence;
            Group           = item.Group;
            GroupPrecedence = item.GroupPrecedence;

            Items = new ObservableCollection <MenuItem>();
        }
Example #3
0
        internal MenuItem AddOrGetMenuItem(MenuGroupItem item)
        {
            if (Items.Any(x => x.Name == item.Name && x.Group != item.Group))
            {
                throw new InvalidOperationException($"A menu item can only appear in one group: {item.Name} cannot be added to group {item.Group}");
            }

            var matchedItems = Items.Where(x => x.Name == item.Name && x.Group == item.Group);
            var menuItems    = matchedItems as IList <MenuItem> ?? matchedItems.ToList();

            if (!menuItems.Any())
            {
                Items.Add(new MenuItem(item));
            }
            else if (menuItems.First().Precedence != item.Precedence || menuItems.First().GroupPrecedence != item.GroupPrecedence)
            {
                throw new InvalidOperationException(
                          $"Cannot add items with different precedence {item.Precedence}/{item.GroupPrecedence} to group precedence {menuItems.First().Precedence}/{menuItems.First().GroupPrecedence}");
            }
            return(Items.Single(x => x.Name == item.Name));
        }