private ToolStripMenuItem MenuToToolStripMenuItem(LightMenu m)
        {
            var temp = new ToolStripMenuItem(m.Text);

            if (m.Items != null)
            {
                m.PropertyChanged += (sender, args) =>
                                        {
                                            LogTo.Debug("Property changed: {0}", args.PropertyName);
                                            if (args.PropertyName != "Items")
                                                return;

                                            LogTo.Debug("Regenerating ToolStripMenuItems for menu {0}", m.Text);

                                            temp.DropDownItems.Clear();
                                            foreach (var item in m.Items)
                                                temp.DropDownItems.Add(MenuToToolStripMenuItem(item));
                                        };

                if(m.PullRight)
                    temp.Alignment = ToolStripItemAlignment.Right;

                foreach (var item in m.Items)
                    temp.DropDownItems.Add(MenuToToolStripMenuItem(item));
            }

            temp.Click += m.FireClicked;
            temp.Checked = m.Checked;
            if (m.Highlight)
                temp.BackColor = Color.Aqua;

            m.PropertyChanged += (sender, args) =>
                                     {
                                         LogTo.Debug("Property changed: {0}", args.PropertyName);
                                         if (args.PropertyName != "Checked")
                                             return;
                                         if (m.Checked != temp.Checked)
                                             temp.Checked = m.Checked;
                                     };
            temp.DropDownItemClicked += (sender, args) => m.FireItemClicked(sender, args.ClickedItem.Text);
            temp.DropDownOpening += m.FireItemListOpening;

            return temp;
        }
Exemplo n.º 2
0
        private void SetItems()
        {
            _menu.Items.Clear();
            _devicePaths = _dataDevice.Devices;
            _deviceNames = _dataDevice.ListAvailableDevices().ToArray();

            var menus = new List<LightMenu>();
            foreach (var value in _deviceNames)
            {
                var newMenu = new LightMenu(value);
                if (value.Contains("0x04D8, 0xF745"))
                    newMenu.Highlight = true;
                menus.Add(newMenu);
            }

            _menu.AddRange(menus);

            UpdateCheckedStates(PropertyName);
        }