Example #1
0
        public IGuiMenu MergeMenus(IGuiMenu menu1, IGuiMenu menu2)
        {
            if (menu1 == null || menu1.Count == 0)
            {
                return(menu2);
            }
            if (menu2 == null || menu2.Count == 0)
            {
                return(menu1);
            }
            GuiMenu m = new GuiMenu(menu1.Name + "+" + menu2.Name);
            int     i = 0;

            while (i < menu1.Count)
            {
                m.Add(menu1.Children [i++]);
            }
            if (!m.Last().IsSeparator)
            {
                m.Add(new GuiMenuItem("mergeseparator", "-"));
            }
            i = 0;
            while (i < menu2.Count && menu2.Children [i].IsSeparator)
            {
                i++;
            }
            while (i < menu2.Count)
            {
                IGuiMenuItem itm = menu2.Children [i++];
                if (itm.IsSeparator)
                {
                    if (!m.Last().IsSeparator)
                    {
                        m.Add(itm);
                    }
                }
                else if (m.FindItem(itm.Name) == null)
                {
                    m.Add(itm);
                }
            }
            while (m.Count > 0 && m.Last().IsSeparator)
            {
                m.RemoveAt(m.Count - 1);
            }
            return(m);
        }
Example #2
0
        public IGuiMenu GetAutoContextMenu(Widget w)
        {
            GuiMenu m        = new GuiMenu("auto");
            int     sepCount = 0;

            MenuCommandDefinitions.Interfaces.Values.Where(t => t.Commands.Count > 0 && w.HasInterface(t.InterfaceType))
            .OrderBy(g => g.Commands.First().MenuItem.Rank)
            .ForEach(g => {
                g.Commands.Select(c => c.MenuItem).OrderBy(x => x.Rank)
                .ForEach(m.Add);
                m.Add(new GuiMenuItem("sep" + sepCount++, "-"));
            });

            while (m.Count > 0 && m.Last().IsSeparator)
            {
                m.RemoveAt(m.Count - 1);
            }

            return(m);
        }