コード例 #1
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();
            }
        }