コード例 #1
0
 public void ShowMenu()
 {
     if (this.menuItem != null)
     {
         Control parent    = this.designMenu.Parent;
         Form    component = parent as Form;
         if (component != null)
         {
             this.parentFormDesigner = this.host.GetDesigner(component) as FormDocumentDesigner;
             if ((this.parentFormDesigner != null) && (this.parentFormDesigner.Menu != null))
             {
                 this.parentMenu = this.parentFormDesigner.Menu;
                 this.parentFormDesigner.Menu = null;
             }
         }
         this.selected           = true;
         this.designMenu.Visible = true;
         this.designMenu.BringToFront();
         this.menuItem.Visible = true;
         if ((this.currentParent != null) && (this.currentParent != this.menuItem))
         {
             ToolStripMenuItemDesigner designer = this.host.GetDesigner(this.currentParent) as ToolStripMenuItemDesigner;
             if (designer != null)
             {
                 designer.RemoveTypeHereNode(this.currentParent);
             }
         }
         this.menuItem.DropDown           = this.dropDown;
         this.menuItem.DropDown.OwnerItem = this.menuItem;
         if (this.dropDown.Items.Count > 0)
         {
             ToolStripItem[] array = new ToolStripItem[this.dropDown.Items.Count];
             this.dropDown.Items.CopyTo(array, 0);
             foreach (ToolStripItem item in array)
             {
                 if (item is DesignerToolStripControlHost)
                 {
                     this.dropDown.Items.Remove(item);
                 }
             }
         }
         ToolStripMenuItemDesigner designer2 = (ToolStripMenuItemDesigner)this.host.GetDesigner(this.menuItem);
         BehaviorService           service   = (BehaviorService)this.GetService(typeof(BehaviorService));
         if (service != null)
         {
             if ((designer2 != null) && (parent != null))
             {
                 Rectangle parentBounds = service.ControlRectInAdornerWindow(parent);
                 if (ToolStripDesigner.IsGlyphTotallyVisible(service.ControlRectInAdornerWindow(this.designMenu), parentBounds))
                 {
                     designer2.InitializeDropDown();
                 }
             }
             if (this.dummyToolStripGlyph == null)
             {
                 Point     pos    = service.ControlToAdornerWindow(this.designMenu);
                 Rectangle bounds = this.designMenu.Bounds;
                 bounds.Offset(pos);
                 this.dummyToolStripGlyph = new ControlBodyGlyph(bounds, Cursor.Current, this.menuItem, new ContextMenuStripBehavior(this.menuItem));
                 SelectionManager manager = (SelectionManager)this.GetService(typeof(SelectionManager));
                 if (manager != null)
                 {
                     manager.BodyGlyphAdorner.Glyphs.Insert(0, this.dummyToolStripGlyph);
                 }
             }
             ToolStripKeyboardHandlingService service2 = (ToolStripKeyboardHandlingService)this.GetService(typeof(ToolStripKeyboardHandlingService));
             if (service2 != null)
             {
                 int num = this.dropDown.Items.Count - 1;
                 if (num >= 0)
                 {
                     service2.SelectedDesignerControl = this.dropDown.Items[num];
                 }
             }
         }
     }
 }
コード例 #2
0
        internal virtual void CommitEdit(System.Type type, string text, bool commit, bool enterKeyPressed, bool tabKeyPressed)
        {
            System.Windows.Forms.ToolStripItem component = null;
            SelectionManager manager         = (SelectionManager)this.GetService(typeof(SelectionManager));
            BehaviorService  service         = (BehaviorService)this.GetService(typeof(BehaviorService));
            ToolStrip        immediateParent = this.ImmediateParent as ToolStrip;

            immediateParent.SuspendLayout();
            this.HideDummyNode();
            IDesignerHost     host     = (IDesignerHost)this.GetService(typeof(IDesignerHost));
            ToolStripDesigner designer = (ToolStripDesigner)host.GetDesigner(this.ToolStripItem.Owner);

            if ((designer != null) && (designer.EditManager != null))
            {
                designer.EditManager.ActivateEditor(null, false);
            }
            if ((immediateParent is MenuStrip) && (type == typeof(ToolStripSeparator)))
            {
                IDesignerHost host2 = (IDesignerHost)this.GetService(typeof(IDesignerHost));
                if (host2 != null)
                {
                    IUIService service2 = (IUIService)host2.GetService(typeof(IUIService));
                    if (service2 != null)
                    {
                        service2.ShowError(System.Design.SR.GetString("ToolStripSeparatorError"));
                        commit = false;
                        if (this.selSvc != null)
                        {
                            this.selSvc.SetSelectedComponents(new object[] { immediateParent });
                        }
                    }
                }
            }
            if (!commit)
            {
                if (this.dummyItemAdded)
                {
                    this.dummyItemAdded = false;
                    this.RemoveItem();
                    if (designer.NewItemTransaction != null)
                    {
                        designer.NewItemTransaction.Cancel();
                        designer.NewItemTransaction = null;
                    }
                }
                goto Label_0246;
            }
            if (this.dummyItemAdded)
            {
                try
                {
                    this.RemoveItem();
                    component = designer.AddNewItem(type, text, enterKeyPressed, false);
                    goto Label_020B;
                }
                finally
                {
                    if (designer.NewItemTransaction != null)
                    {
                        designer.NewItemTransaction.Commit();
                        designer.NewItemTransaction = null;
                    }
                }
            }
            DesignerTransaction transaction = host.CreateTransaction(System.Design.SR.GetString("ToolStripItemPropertyChangeTransaction"));

            try
            {
                PropertyDescriptor descriptor = TypeDescriptor.GetProperties(this.ToolStripItem)["Text"];
                string             str        = (string)descriptor.GetValue(this.ToolStripItem);
                if ((descriptor != null) && (text != str))
                {
                    descriptor.SetValue(this.ToolStripItem, text);
                }
                if (enterKeyPressed && (this.selSvc != null))
                {
                    this.SelectNextItem(this.selSvc, enterKeyPressed, designer);
                }
            }
            catch (Exception exception)
            {
                if (transaction != null)
                {
                    transaction.Cancel();
                    transaction = null;
                }
                if (manager != null)
                {
                    manager.Refresh();
                }
                if (System.Windows.Forms.ClientUtils.IsCriticalException(exception))
                {
                    throw;
                }
            }
            finally
            {
                if (transaction != null)
                {
                    transaction.Commit();
                    transaction = null;
                }
            }
Label_020B:
            this.dummyItemAdded = false;
Label_0246:
            immediateParent.ResumeLayout();
            if ((component != null) && !component.IsOnDropDown)
            {
                ToolStripDropDownItem item2 = component as ToolStripDropDownItem;
                if (item2 != null)
                {
                    Rectangle glyphBounds   = ((ToolStripItemDesigner)host.GetDesigner(component)).GetGlyphBounds();
                    Control   rootComponent = host.RootComponent as Control;
                    if ((rootComponent != null) && (service != null))
                    {
                        Rectangle parentBounds = service.ControlRectInAdornerWindow(rootComponent);
                        if (!ToolStripDesigner.IsGlyphTotallyVisible(glyphBounds, parentBounds))
                        {
                            item2.HideDropDown();
                        }
                    }
                }
            }
            if (manager != null)
            {
                manager.Refresh();
            }
        }