示例#1
0
        public XEditNetChildForm(UserControl editorRegion) : this()
        {
            editorRegion.AutoScroll = true;
            editorRegion.BackColor  = System.Drawing.Color.White;
            editorRegion.Dock       = System.Windows.Forms.DockStyle.Fill;
            editorRegion.Location   = new System.Drawing.Point(232, 44);
            editorRegion.Name       = "editor";
            editorRegion.Size       = new System.Drawing.Size(368, 458);
            editorRegion.TabIndex   = 6;

            this.editorRegion = editorRegion;

            Editor.ChangeAttributesActivated += new XEditNet.InterfaceActivationEventHandler(ChangeAttributesActivated);
            Editor.ChangeElementActivated    += new XEditNet.InterfaceActivationEventHandler(ChangeElementActivated);
            Editor.InsertElementActivated    += new XEditNet.InterfaceActivationEventHandler(InsertElementActivated);

            this.elementChangePanel.Editor   = Editor;
            this.elementInsertPanel.Editor   = Editor;
            this.attributeChangePanel.Editor = Editor;
            this.quickFixPanel.Editor        = Editor;

            if (editorRegion != null)
            {
                int index = Controls.IndexOf(menuBar1);
                Controls.Add(editorRegion);
                Controls.SetChildIndex(editorRegion, index);
            }

            UpdateMenu();

            ControlUtil.AddImage(quickFixImageList, typeof(XEditNetChildForm), "images.btnBack.bmp");
            ControlUtil.AddImage(quickFixImageList, typeof(XEditNetChildForm), "images.btnNext.bmp");
        }
示例#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;
                }
            }
        }