Exemplo n.º 1
0
 private MenuItemBase FindItem(ToolbarItemBaseCollection list, string part)
 {
     foreach (MenuItemBase n in list)
     {
         if (n.Text.Equals(part))
         {
             return(n);
         }
     }
     return(null);
 }
Exemplo n.º 2
0
        private void UpdateMenu()
        {
            Hashtable images     = new Hashtable();
            int       imageIndex = 0;

            foreach (CommandMapping cmd in Editor.Commands)
            {
                if (cmd.MenuPath == null)
                {
                    continue;
                }

                string fullPath = cmd.MenuPath;

                string[] parts   = fullPath.Split('/');
                string   current = "";
                int      n       = parts.Length;
                ToolbarItemBaseCollection list = menuBar1.Items;
                MenuItemBase menuNode          = null;
                foreach (string part in parts)
                {
                    n--;

                    if (part.Length == 0)
                    {
                        continue;
                    }

                    current += "/" + part;

                    if (n == 0)
                    {
                        MenuButtonItem leaf = new MenuButtonItem(part);

                        if (cmd.ImagePath != null)
                        {
                            object o = images[cmd.ImagePath];
                            if (o != null)
                            {
                                IntPtr index = (IntPtr)o;
                                leaf.Image = commandImageList.Images[index.ToInt32()];
                            }
                            else
                            {
                                if (ControlUtil.AddImage(commandImageList, typeof(XEditNetCtrl), cmd.ImagePath))
                                {
                                    leaf.Image            = commandImageList.Images[imageIndex];
                                    images[cmd.ImagePath] = new IntPtr(imageIndex++);
                                }
                            }
                        }

                        leaf.MergeIndex  = 0;
                        leaf.MergeAction = ItemMergeAction.Add;
                        if (cmd.MenuIndex != -1)
                        {
                            leaf.MergeIndex  = cmd.MenuIndex;
                            leaf.MergeAction = ItemMergeAction.Insert;
                        }
                        leaf.BeginGroup = cmd.MenuBreak;
                        leaf.Tag        = cmd;
                        leaf.Activate  += new EventHandler(DispatchCommand);

                        Shortcut[] keys = cmd.Keys;
                        if (keys.Length > 0)
                        {
                            leaf.Shortcut = keys[0];
                            if (keys.Length > 1)
                            {
                                leaf.Shortcut2 = keys[1];
                            }
                        }
                        // TODO: M: check for invalid input (button at top level)
                        menuNode.Items.Add(leaf);
                    }
                    else
                    {
                        menuNode = FindItem(list, part);
                        if (menuNode == null)
                        {
                            menuNode             = new MenuBarItem(part);
                            menuNode.MergeIndex  = -1;
                            menuNode.MergeAction = ItemMergeAction.MergeChildren;
                            menuNode.BeginGroup  = cmd.MenuBreak;

                            list.Add(menuNode);
                        }
                    }

                    list = menuNode.Items;
                }
            }
        }
Exemplo n.º 3
0
 private MenuItemBase FindItem(ToolbarItemBaseCollection list, string part)
 {
     foreach ( MenuItemBase n in list )
     {
         if ( n.Text.Equals(part) )
             return n;
     }
     return null;
 }