internal void AddNewTemplateNode(ToolStripDropDown dropDown)
 {
     foreach (ToolStripItem item in dropDown.Items)
     {
         if (item is DesignerToolStripControlHost)
         {
             this.typeHereNode = (DesignerToolStripControlHost) item;
         }
     }
     if (this.typeHereNode != null)
     {
         dropDown.Items.Remove(this.typeHereNode);
     }
     this.typeHereTemplateNode = new ToolStripTemplateNode(base.Component, System.Design.SR.GetString("ToolStripDesignerTemplateNodeEnterText"), null);
     int width = this.typeHereTemplateNode.EditorToolStrip.Width;
     this.typeHereNode = new DesignerToolStripControlHost(this.typeHereTemplateNode.EditorToolStrip);
     this.typeHereTemplateNode.ControlHost = this.typeHereNode;
     this.typeHereNode.AutoSize = false;
     this.typeHereNode.Width = width;
     dropDown.Items.Add(this.typeHereNode);
 }
        /// <summary>
        ///  This function is called on the service when the PBRSFORWARD gets the first WM_CHAR message.
        /// </summary>
        public void HandleKeyChar()
        {
            if (_toolDesigner != null || _toolItemDesigner != null)
            {
                if (_toolDesigner != null)
                {
                    _toolDesigner.ShowEditNode(false);
                }
                else if (_toolItemDesigner != null)
                {
                    if (_toolItemDesigner is ToolStripMenuItemDesigner menuDesigner)
                    {
                        ISelectionService selService = (ISelectionService)_sp.GetService(typeof(ISelectionService));
                        if (selService != null)
                        {
                            object comp = selService.PrimarySelection;
                            if (comp is null)
                            {
                                comp = ToolStripKeyBoardService.SelectedDesignerControl;
                            }

                            DesignerToolStripControlHost designerItem = comp as DesignerToolStripControlHost;
                            if (designerItem != null || comp is ToolStripDropDown)
                            {
                                menuDesigner.EditTemplateNode(false);
                            }
                            else
                            {
                                menuDesigner.ShowEditNode(false);
                            }
                        }
                    }
                    else
                    {
                        _toolItemDesigner.ShowEditNode(false);
                    }
                }
            }
        }
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         this.disposed = true;
         if (this.items != null)
         {
             this.items = null;
         }
         if (this.undoEngine != null)
         {
             this.undoEngine.Undoing -= new EventHandler(this.OnUndoing);
             this.undoEngine.Undone -= new EventHandler(this.OnUndone);
         }
         if (this.componentChangeSvc != null)
         {
             this.componentChangeSvc.ComponentRemoved -= new ComponentEventHandler(this.ComponentChangeSvc_ComponentRemoved);
             this.componentChangeSvc.ComponentRemoving -= new ComponentEventHandler(this.ComponentChangeSvc_ComponentRemoving);
             this.componentChangeSvc.ComponentAdded -= new ComponentEventHandler(this.ComponentChangeSvc_ComponentAdded);
             this.componentChangeSvc.ComponentAdding -= new ComponentEventHandler(this.ComponentChangeSvc_ComponentAdding);
             this.componentChangeSvc.ComponentChanged -= new ComponentChangedEventHandler(this.ComponentChangeSvc_ComponentChanged);
         }
         if (this._selectionSvc != null)
         {
             this._selectionSvc.SelectionChanged -= new EventHandler(this.selSvc_SelectionChanged);
             this._selectionSvc.SelectionChanging -= new EventHandler(this.selSvc_SelectionChanging);
             this._selectionSvc = null;
         }
         base.EnableDragDrop(false);
         if (this.editManager != null)
         {
             this.editManager.CloseManager();
             this.editManager = null;
         }
         if (this.tn != null)
         {
             this.tn.RollBack();
             this.tn.CloseEditor();
             this.tn = null;
         }
         if (this._miniToolStrip != null)
         {
             this._miniToolStrip.Dispose();
             this._miniToolStrip = null;
         }
         if (this.editorNode != null)
         {
             this.editorNode.Dispose();
             this.editorNode = null;
         }
         if (this.ToolStrip != null)
         {
             this.ToolStrip.OverflowButton.DropDown.Closing -= new ToolStripDropDownClosingEventHandler(this.OnOverflowDropDownClosing);
             this.ToolStrip.OverflowButton.DropDownOpening -= new EventHandler(this.OnOverFlowDropDownOpening);
             this.ToolStrip.OverflowButton.DropDownOpened -= new EventHandler(this.OnOverFlowDropDownOpened);
             this.ToolStrip.OverflowButton.DropDownClosed -= new EventHandler(this.OnOverFlowDropDownClosed);
             this.ToolStrip.OverflowButton.DropDown.Resize -= new EventHandler(this.OnOverflowDropDownResize);
             this.ToolStrip.OverflowButton.DropDown.Paint -= new PaintEventHandler(this.OnOverFlowDropDownPaint);
             this.ToolStrip.Move -= new EventHandler(this.OnToolStripMove);
             this.ToolStrip.VisibleChanged -= new EventHandler(this.OnToolStripVisibleChanged);
             this.ToolStrip.ItemAdded -= new ToolStripItemEventHandler(this.OnItemAdded);
             this.ToolStrip.Resize -= new EventHandler(this.ToolStrip_Resize);
             this.ToolStrip.DockChanged -= new EventHandler(this.ToolStrip_Resize);
             this.ToolStrip.LayoutCompleted -= new EventHandler(this.ToolStrip_LayoutCompleted);
         }
         if (this.toolStripContextMenu != null)
         {
             this.toolStripContextMenu.Dispose();
             this.toolStripContextMenu = null;
         }
         this.RemoveBodyGlyphsForOverflow();
         if (this.ToolStrip.OverflowButton.DropDown.Visible)
         {
             this.ToolStrip.OverflowButton.HideDropDown();
         }
         if (this.toolStripAdornerWindowService != null)
         {
             this.toolStripAdornerWindowService = null;
         }
     }
     base.Dispose(disposing);
 }
 internal void AddNewTemplateNode(System.Windows.Forms.ToolStrip wb)
 {
     this.tn = new ToolStripTemplateNode(base.Component, System.Design.SR.GetString("ToolStripDesignerTemplateNodeEnterText"), null);
     this._miniToolStrip = this.tn.EditorToolStrip;
     int width = this.tn.EditorToolStrip.Width;
     this.editorNode = new DesignerToolStripControlHost(this.tn.EditorToolStrip);
     this.tn.ControlHost = this.editorNode;
     this.editorNode.Width = width;
     this.ToolStrip.Items.Add(this.editorNode);
     this.editorNode.Visible = false;
 }
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (this.selSvc != null)
         {
             this.selSvc.SelectionChanged -= new EventHandler(this.OnSelectionChanged);
         }
         if (this.undoEngine != null)
         {
             this.undoEngine.Undoing -= new EventHandler(this.OnUndoing);
             this.undoEngine.Undone -= new EventHandler(this.OnUndone);
         }
         if (this.MenuItem != null)
         {
             this.MenuItem.DropDown.Hide();
             this.UnHookEvents();
         }
         if (this.toolStripAdornerWindowService != null)
         {
             this.toolStripAdornerWindowService = null;
         }
         IComponentChangeService service = (IComponentChangeService) this.GetService(typeof(IComponentChangeService));
         if (service != null)
         {
             service.ComponentRemoved -= new ComponentEventHandler(this.ComponentChangeSvc_ComponentRemoved);
             service.ComponentRemoving -= new ComponentEventHandler(this.ComponentChangeSvc_ComponentRemoving);
             service.ComponentAdding -= new ComponentEventHandler(this.ComponentChangeSvc_ComponentAdding);
             service.ComponentAdded -= new ComponentEventHandler(this.ComponentChangeSvc_ComponentAdded);
         }
         if (this.typeHereTemplateNode != null)
         {
             this.typeHereTemplateNode.RollBack();
             this.typeHereTemplateNode.CloseEditor();
             this.typeHereTemplateNode = null;
         }
         if (this.typeHereNode != null)
         {
             this.typeHereNode.Dispose();
             this.typeHereNode = null;
         }
         if (this.commitedTemplateNode != null)
         {
             this.commitedTemplateNode.RollBack();
             this.commitedTemplateNode.CloseEditor();
             this.commitedTemplateNode = null;
         }
         if (this.commitedEditorNode != null)
         {
             this.commitedEditorNode.Dispose();
             this.commitedEditorNode = null;
         }
         if (this.parentItem != null)
         {
             this.parentItem = null;
         }
     }
     base.Dispose(disposing);
 }
 private void CreateDummyMenuItem(ToolStripItem item, string text, Image image)
 {
     this.commitedTemplateNode = new ToolStripTemplateNode(base.Component, text, image);
     this.commitedTemplateNode.ActiveItem = item;
     int width = this.commitedTemplateNode.EditorToolStrip.Width;
     this.commitedEditorNode = new DesignerToolStripControlHost(this.commitedTemplateNode.EditorToolStrip);
     this.commitedEditorNode.AutoSize = false;
     this.commitedEditorNode.Width = width;
 }
 private void RollBack()
 {
     if (this.commitedEditorNode != null)
     {
         int index = this.MenuItem.DropDownItems.IndexOf(this.commitedEditorNode);
         ToolStripDropDownItem item = (ToolStripDropDownItem) this.MenuItem.DropDownItems[index + 1];
         if (item != null)
         {
             item.Visible = true;
         }
         this.MenuItem.DropDown.Items.Remove(this.commitedEditorNode);
         if (this.commitedTemplateNode != null)
         {
             this.commitedTemplateNode.RollBack();
             this.commitedTemplateNode.CloseEditor();
             this.commitedTemplateNode = null;
         }
         if (this.commitedEditorNode != null)
         {
             this.commitedEditorNode.Dispose();
             this.commitedEditorNode = null;
         }
     }
 }
 internal void RemoveTypeHereNode(ToolStripDropDownItem ownerItem)
 {
     Rectangle bounds = ownerItem.DropDown.Bounds;
     if ((ownerItem.DropDownItems.Count > 0) && (ownerItem.DropDownItems[0] is DesignerToolStripControlHost))
     {
         ownerItem.DropDownItems.RemoveAt(0);
     }
     if ((this.typeHereTemplateNode != null) && this.typeHereTemplateNode.Active)
     {
         this.typeHereTemplateNode.RollBack();
         this.typeHereTemplateNode.CloseEditor();
         this.typeHereTemplateNode = null;
     }
     if (this.typeHereNode != null)
     {
         this.typeHereNode.Dispose();
         this.typeHereNode = null;
     }
     if (this.toolStripAdornerWindowService != null)
     {
         this.toolStripAdornerWindowService.Invalidate(bounds);
     }
 }
 internal override void CommitEdit(System.Type type, string text, bool commit, bool enterKeyPressed, bool tabKeyPressed)
 {
     base.IsEditorActive = false;
     if (!(this.MenuItem.Owner is ToolStripDropDown) && (base.Editor != null))
     {
         base.CommitEdit(type, text, commit, enterKeyPressed, tabKeyPressed);
         return;
     }
     if (!commit)
     {
         if (this.commitedEditorNode != null)
         {
             this.MenuItem.DropDown.SuspendLayout();
             bool flag2 = base.dummyItemAdded;
             base.dummyItemAdded = false;
             int index = this.MenuItem.DropDownItems.IndexOf(this.commitedEditorNode);
             ToolStripItem item4 = this.MenuItem.DropDownItems[index + 1];
             this.MenuItem.DropDown.Items.Remove(this.commitedEditorNode);
             item4.Visible = true;
             if (this.commitedTemplateNode != null)
             {
                 this.commitedTemplateNode.CloseEditor();
                 this.commitedTemplateNode = null;
             }
             if (this.commitedEditorNode != null)
             {
                 this.commitedEditorNode.Dispose();
                 this.commitedEditorNode = null;
             }
             if (flag2)
             {
                 this.MenuItem.DropDownItems.Remove(item4);
                 try
                 {
                     this.designerHost.DestroyComponent(item4);
                 }
                 catch
                 {
                     if (this.newMenuItemTransaction != null)
                     {
                         try
                         {
                             this.newMenuItemTransaction.Cancel();
                         }
                         catch
                         {
                         }
                         this.newMenuItemTransaction = null;
                     }
                 }
                 item4 = null;
             }
             this.MenuItem.DropDown.ResumeLayout();
             if (item4 != null)
             {
                 this.AddItemBodyGlyph(item4);
             }
             if (flag2)
             {
                 SelectionManager service = (SelectionManager) this.GetService(typeof(SelectionManager));
                 service.NeedRefresh = false;
                 if (this.newMenuItemTransaction != null)
                 {
                     try
                     {
                         base.dummyItemAdded = true;
                         this.newMenuItemTransaction.Cancel();
                         this.newMenuItemTransaction = null;
                         if (this.MenuItem.DropDownItems.Count == 0)
                         {
                             this.CreatetypeHereNode();
                         }
                     }
                     finally
                     {
                         base.dummyItemAdded = false;
                     }
                 }
                 flag2 = false;
             }
             this.MenuItem.DropDown.PerformLayout();
         }
         return;
     }
     int dummyIndex = -1;
     bool dummyItemAdded = base.dummyItemAdded;
     base.dummyItemAdded = false;
     this.MenuItem.DropDown.SuspendLayout();
     if (this.commitedEditorNode != null)
     {
         dummyIndex = this.MenuItem.DropDownItems.IndexOf(this.commitedEditorNode);
         ToolStripItem component = this.MenuItem.DropDownItems[dummyIndex + 1];
         this.MenuItem.DropDown.Items.Remove(this.commitedEditorNode);
         if (this.commitedTemplateNode != null)
         {
             this.commitedTemplateNode.CloseEditor();
             this.commitedTemplateNode = null;
         }
         if (this.commitedEditorNode != null)
         {
             this.commitedEditorNode.Dispose();
             this.commitedEditorNode = null;
         }
         if (text == "-")
         {
             ToolStripItemDesigner designer = this.designerHost.GetDesigner(component) as ToolStripItemDesigner;
             if (designer == null)
             {
                 goto Label_028C;
             }
             try
             {
                 try
                 {
                     component = designer.MorphCurrentItem(typeof(ToolStripSeparator));
                     this.RemoveItemBodyGlyph(component);
                 }
                 catch
                 {
                     if (this.newMenuItemTransaction != null)
                     {
                         try
                         {
                             this.newMenuItemTransaction.Cancel();
                         }
                         catch
                         {
                         }
                         this.newMenuItemTransaction = null;
                     }
                 }
                 goto Label_028C;
             }
             finally
             {
                 if (this.newMenuItemTransaction != null)
                 {
                     this.newMenuItemTransaction.Commit();
                     this.newMenuItemTransaction = null;
                 }
             }
         }
         if (dummyItemAdded)
         {
             try
             {
                 try
                 {
                     base.dummyItemAdded = true;
                     this.CreateNewItem(type, dummyIndex, text);
                     this.designerHost.DestroyComponent(component);
                     if (enterKeyPressed)
                     {
                         this.typeHereNode.SelectControl();
                     }
                 }
                 catch
                 {
                     if (this.newMenuItemTransaction != null)
                     {
                         try
                         {
                             this.newMenuItemTransaction.Cancel();
                         }
                         catch
                         {
                         }
                         this.newMenuItemTransaction = null;
                     }
                 }
                 goto Label_028C;
             }
             finally
             {
                 if (this.newMenuItemTransaction != null)
                 {
                     this.newMenuItemTransaction.Commit();
                     this.newMenuItemTransaction = null;
                 }
                 base.dummyItemAdded = false;
             }
         }
         component.Visible = true;
         DesignerTransaction transaction = this.designerHost.CreateTransaction(System.Design.SR.GetString("ToolStripItemPropertyChangeTransaction"));
         try
         {
             PropertyDescriptor descriptor = TypeDescriptor.GetProperties(component)["Text"];
             string str = (string) descriptor.GetValue(component);
             if ((descriptor != null) && (text != str))
             {
                 descriptor.SetValue(component, text);
             }
         }
         catch
         {
             if (transaction != null)
             {
                 transaction.Cancel();
                 transaction = null;
             }
         }
         finally
         {
             if (transaction != null)
             {
                 transaction.Commit();
                 transaction = null;
             }
         }
     }
     else
     {
         dummyIndex = this.MenuItem.DropDownItems.IndexOf(this.typeHereNode);
         try
         {
             base.dummyItemAdded = true;
             this.CreateNewItem(type, dummyIndex, text);
         }
         finally
         {
             base.dummyItemAdded = false;
         }
         this.typeHereNode.SelectControl();
     }
 Label_028C:
     this.MenuItem.DropDown.ResumeLayout(true);
     this.MenuItem.DropDown.PerformLayout();
     this.ResetGlyphs(this.MenuItem);
     if (this.selSvc != null)
     {
         if (enterKeyPressed)
         {
             ToolStripItem item2 = null;
             if (((this.MenuItem.DropDownDirection == ToolStripDropDownDirection.AboveLeft) || (this.MenuItem.DropDownDirection == ToolStripDropDownDirection.AboveRight)) && (dummyIndex >= 1))
             {
                 item2 = this.MenuItem.DropDownItems[dummyIndex - 1];
             }
             else
             {
                 item2 = this.MenuItem.DropDownItems[dummyIndex + 1];
             }
             if (this.KeyboardHandlingService != null)
             {
                 if (item2 != null)
                 {
                     ToolStripDropDownItem item3 = this.MenuItem.DropDownItems[dummyIndex] as ToolStripDropDownItem;
                     if (item3 != null)
                     {
                         item3.HideDropDown();
                     }
                 }
                 if (item2 == this.typeHereNode)
                 {
                     this.KeyboardHandlingService.SelectedDesignerControl = item2;
                     this.selSvc.SetSelectedComponents(null, SelectionTypes.Replace);
                 }
                 else
                 {
                     this.KeyboardHandlingService.SelectedDesignerControl = null;
                     this.selSvc.SetSelectedComponents(new object[] { item2 });
                 }
             }
         }
         else if (tabKeyPressed)
         {
             this.selSvc.SetSelectedComponents(new object[] { this.MenuItem.DropDownItems[dummyIndex] }, SelectionTypes.Replace);
         }
     }
 }