Exemplo n.º 1
0
        private static void CopyItems(CefMenuModel model, MenuModelItem[] dest)
        {
            for (int i = 0; i < dest.Length; i++)
            {
                var item = new MenuModelItem
                {
                    Command = model.GetCommandIdAt(i),
                    Label   = model.GetLabelAt(i),
                    Type    = model.GetTypeAt(i),
                    Group   = model.GetGroupIdAt(i),
                    Visible = model.IsVisibleAt(i),
                    Enabled = model.IsEnabledAt(i),
                    Checked = model.IsCheckedAt(i),
                };

                CefColor color = default;
                item.Colors = new CefColor[(int)CefMenuColorType.Count];
                for (int j = 0; j < item.Colors.Length; j++)
                {
                    item.Colors[j] = model.GetColorAt(i, (CefMenuColorType)j, ref color) ? color : default;
                }

                int keycode = 0, alt = 0, ctrl = 0, shift = 0;
                if (model.GetAcceleratorAt(i, ref keycode, ref shift, ref ctrl, ref alt))
                {
                    item.Accelerator = new Accelerator {
                        KeyCode = keycode, Alt = alt != 0, Ctrl = ctrl != 0, Shift = shift != 0
                    };
                }

                if (item.Type == CefMenuItemType.Submenu)
                {
                    CefMenuModel submenu = model.GetSubMenuAt(i);
                    var          items   = new MenuModelItem[submenu.Count];
                    CopyItems(submenu, items);
                    item.SubMenu = new MenuModel(items)
                    {
                        IsSubMenu = true
                    };
                }
                dest[i] = item;
            }
        }