Пример #1
0
        /// <summary>
        /// build up a list of standard items separated by the custom items
        /// </summary>

        public static NewItemsContextMenuStrip GetNewItemDropDown(IComponent component, ToolStripItem currentItem, EventHandler onClick, bool convertTo, IServiceProvider serviceProvider, bool populateCustom)
        {
            NewItemsContextMenuStrip contextMenu = new NewItemsContextMenuStrip(component, currentItem, onClick, convertTo, serviceProvider);

            contextMenu.GroupOrdering.Add("StandardList");
            contextMenu.GroupOrdering.Add("CustomList");
            // plumb through the standard and custom items.
            foreach (ToolStripItem item in GetStandardItemMenuItems(component, onClick, convertTo))
            {
                contextMenu.Groups["StandardList"].Items.Add(item);
                if (convertTo)
                {
                    if (item is ItemTypeToolStripMenuItem toolItem && currentItem != null && toolItem.ItemType == currentItem.GetType())
                    {
                        toolItem.Enabled = false;
                    }
                }
            }
            if (populateCustom)
            {
                GetCustomNewItemDropDown(contextMenu, component, currentItem, onClick, convertTo, serviceProvider);
            }
            if (serviceProvider.GetService(typeof(IUIService)) is IUIService uis)
            {
                contextMenu.Renderer = (ToolStripProfessionalRenderer)uis.Styles["VsRenderer"];
                contextMenu.Font     = (Font)uis.Styles["DialogFont"];
                if (uis.Styles["VsColorPanelText"] is Color)
                {
                    contextMenu.ForeColor = (Color)uis.Styles["VsColorPanelText"];
                }
            }
            contextMenu.Populate();
            return(contextMenu);
        }
Пример #2
0
 public static void GetCustomNewItemDropDown(NewItemsContextMenuStrip contextMenu, IComponent component, ToolStripItem currentItem, EventHandler onClick, bool convertTo, IServiceProvider serviceProvider)
 {
     foreach (ToolStripItem item in GetCustomItemMenuItems(component, onClick, convertTo, serviceProvider))
     {
         contextMenu.Groups["CustomList"].Items.Add(item);
         if (convertTo)
         {
             if (item is ItemTypeToolStripMenuItem toolItem && currentItem != null && toolItem.ItemType == currentItem.GetType())
             {
                 toolItem.Enabled = false;
             }
         }
     }
     contextMenu.Populate();
 }
        public static ToolStripDropDown GetNewItemDropDown(IComponent component, ToolStripItem currentItem, EventHandler onClick, bool convertTo, IServiceProvider serviceProvider)
        {
            NewItemsContextMenuStrip strip = new NewItemsContextMenuStrip(component, currentItem, onClick, convertTo, serviceProvider);

            strip.GroupOrdering.Add("StandardList");
            strip.GroupOrdering.Add("CustomList");
            foreach (ToolStripItem item in GetStandardItemMenuItems(component, onClick, convertTo))
            {
                strip.Groups["StandardList"].Items.Add(item);
                if (convertTo)
                {
                    ItemTypeToolStripMenuItem item2 = item as ItemTypeToolStripMenuItem;
                    if (((item2 != null) && (currentItem != null)) && (item2.ItemType == currentItem.GetType()))
                    {
                        item2.Enabled = false;
                    }
                }
            }
            foreach (ToolStripItem item3 in GetCustomItemMenuItems(component, onClick, convertTo, serviceProvider))
            {
                strip.Groups["CustomList"].Items.Add(item3);
                if (convertTo)
                {
                    ItemTypeToolStripMenuItem item4 = item3 as ItemTypeToolStripMenuItem;
                    if (((item4 != null) && (currentItem != null)) && (item4.ItemType == currentItem.GetType()))
                    {
                        item4.Enabled = false;
                    }
                }
            }
            IUIService service = serviceProvider.GetService(typeof(IUIService)) as IUIService;

            if (service != null)
            {
                strip.Renderer = (ToolStripProfessionalRenderer)service.Styles["VsRenderer"];
                strip.Font     = (Font)service.Styles["DialogFont"];
            }
            strip.Populate();
            return(strip);
        }
 public static NewItemsContextMenuStrip GetNewItemDropDown(IComponent component, ToolStripItem currentItem, EventHandler onClick, bool convertTo, IServiceProvider serviceProvider, bool populateCustom)
 {
     NewItemsContextMenuStrip contextMenu = new NewItemsContextMenuStrip(component, currentItem, onClick, convertTo, serviceProvider);
     contextMenu.GroupOrdering.Add("StandardList");
     contextMenu.GroupOrdering.Add("CustomList");
     foreach (ToolStripItem item in GetStandardItemMenuItems(component, onClick, convertTo))
     {
         contextMenu.Groups["StandardList"].Items.Add(item);
         if (convertTo)
         {
             ItemTypeToolStripMenuItem item2 = item as ItemTypeToolStripMenuItem;
             if (((item2 != null) && (currentItem != null)) && (item2.ItemType == currentItem.GetType()))
             {
                 item2.Enabled = false;
             }
         }
     }
     if (populateCustom)
     {
         GetCustomNewItemDropDown(contextMenu, component, currentItem, onClick, convertTo, serviceProvider);
     }
     IUIService service = serviceProvider.GetService(typeof(IUIService)) as IUIService;
     if (service != null)
     {
         contextMenu.Renderer = (ToolStripProfessionalRenderer) service.Styles["VsRenderer"];
         contextMenu.Font = (Font) service.Styles["DialogFont"];
         if (service.Styles["VsColorPanelText"] is System.Drawing.Color)
         {
             contextMenu.ForeColor = (System.Drawing.Color) service.Styles["VsColorPanelText"];
         }
     }
     contextMenu.Populate();
     return contextMenu;
 }
 public static void GetCustomNewItemDropDown(NewItemsContextMenuStrip contextMenu, IComponent component, ToolStripItem currentItem, EventHandler onClick, bool convertTo, IServiceProvider serviceProvider)
 {
     foreach (ToolStripItem item in GetCustomItemMenuItems(component, onClick, convertTo, serviceProvider))
     {
         contextMenu.Groups["CustomList"].Items.Add(item);
         if (convertTo)
         {
             ItemTypeToolStripMenuItem item2 = item as ItemTypeToolStripMenuItem;
             if (((item2 != null) && (currentItem != null)) && (item2.ItemType == currentItem.GetType()))
             {
                 item2.Enabled = false;
             }
         }
     }
     contextMenu.Populate();
 }
 public static ToolStripDropDown GetNewItemDropDown(IComponent component, ToolStripItem currentItem, EventHandler onClick, bool convertTo, IServiceProvider serviceProvider)
 {
     NewItemsContextMenuStrip strip = new NewItemsContextMenuStrip(component, currentItem, onClick, convertTo, serviceProvider);
     strip.GroupOrdering.Add("StandardList");
     strip.GroupOrdering.Add("CustomList");
     foreach (ToolStripItem item in GetStandardItemMenuItems(component, onClick, convertTo))
     {
         strip.Groups["StandardList"].Items.Add(item);
         if (convertTo)
         {
             ItemTypeToolStripMenuItem item2 = item as ItemTypeToolStripMenuItem;
             if (((item2 != null) && (currentItem != null)) && (item2.ItemType == currentItem.GetType()))
             {
                 item2.Enabled = false;
             }
         }
     }
     foreach (ToolStripItem item3 in GetCustomItemMenuItems(component, onClick, convertTo, serviceProvider))
     {
         strip.Groups["CustomList"].Items.Add(item3);
         if (convertTo)
         {
             ItemTypeToolStripMenuItem item4 = item3 as ItemTypeToolStripMenuItem;
             if (((item4 != null) && (currentItem != null)) && (item4.ItemType == currentItem.GetType()))
             {
                 item4.Enabled = false;
             }
         }
     }
     IUIService service = serviceProvider.GetService(typeof(IUIService)) as IUIService;
     if (service != null)
     {
         strip.Renderer = (ToolStripProfessionalRenderer) service.Styles["VsRenderer"];
         strip.Font = (Font) service.Styles["DialogFont"];
     }
     strip.Populate();
     return strip;
 }
 private void CenterLabelClick(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Right)
     {
         if ((this.KeyboardService == null) || !this.KeyboardService.TemplateNodeActive)
         {
             if (this.KeyboardService != null)
             {
                 this.KeyboardService.SelectedDesignerControl = this.controlHost;
             }
             this.SelectionService.SetSelectedComponents(null, SelectionTypes.Replace);
             if (this.BehaviorService != null)
             {
                 Point p = this.BehaviorService.ControlToAdornerWindow(this._miniToolStrip);
                 p = this.BehaviorService.AdornerWindowPointToScreen(p);
                 p.Offset(e.Location);
                 this.DesignerContextMenu.Show(p);
             }
         }
     }
     else if (this.hotRegion.Contains(e.Location) && !this.KeyboardService.TemplateNodeActive)
     {
         if (this.KeyboardService != null)
         {
             this.KeyboardService.SelectedDesignerControl = this.controlHost;
         }
         this.SelectionService.SetSelectedComponents(null, SelectionTypes.Replace);
         ToolStripDropDown contextMenu = this.contextMenu;
         if (contextMenu != null)
         {
             contextMenu.Closed -= new ToolStripDropDownClosedEventHandler(this.OnContextMenuClosed);
             contextMenu.Opened -= new EventHandler(this.OnContextMenuOpened);
             contextMenu.Dispose();
         }
         this.contextMenu = null;
         this.ShowDropDownMenu();
     }
     else
     {
         ToolStripDesigner.LastCursorPosition = Cursor.Position;
         if (this._designer is ToolStripDesigner)
         {
             if (this.KeyboardService.TemplateNodeActive)
             {
                 this.KeyboardService.ActiveTemplateNode.Commit(false, false);
             }
             if (this.SelectionService.PrimarySelection == null)
             {
                 this.SelectionService.SetSelectedComponents(new object[] { this.component }, SelectionTypes.Replace);
             }
             this.KeyboardService.SelectedDesignerControl = this.controlHost;
             this.SelectionService.SetSelectedComponents(null, SelectionTypes.Replace);
             ((ToolStripDesigner) this._designer).ShowEditNode(true);
         }
         if (this._designer is ToolStripMenuItemDesigner)
         {
             IServiceProvider site = this.component.Site;
             if (this.KeyboardService.TemplateNodeActive)
             {
                 ToolStripItem component = this.component as ToolStripItem;
                 if (component != null)
                 {
                     if (component.Visible)
                     {
                         this.KeyboardService.ActiveTemplateNode.Commit(false, false);
                     }
                     else
                     {
                         this.KeyboardService.ActiveTemplateNode.Commit(false, true);
                     }
                 }
                 else
                 {
                     this.KeyboardService.ActiveTemplateNode.Commit(false, false);
                 }
             }
             if (this._designer != null)
             {
                 ((ToolStripMenuItemDesigner) this._designer).EditTemplateNode(true);
             }
             else
             {
                 ISelectionService service = (ISelectionService) site.GetService(typeof(ISelectionService));
                 ToolStripItem primarySelection = service.PrimarySelection as ToolStripItem;
                 if ((primarySelection != null) && (this._designerHost != null))
                 {
                     ToolStripMenuItemDesigner designer = this._designerHost.GetDesigner(primarySelection) as ToolStripMenuItemDesigner;
                     if (designer != null)
                     {
                         if (!primarySelection.IsOnDropDown)
                         {
                             Rectangle glyphBounds = designer.GetGlyphBounds();
                             ToolStripDesignerUtils.GetAdjustedBounds(primarySelection, ref glyphBounds);
                             System.Windows.Forms.Design.Behavior.BehaviorService service2 = site.GetService(typeof(System.Windows.Forms.Design.Behavior.BehaviorService)) as System.Windows.Forms.Design.Behavior.BehaviorService;
                             if (service2 != null)
                             {
                                 service2.Invalidate(glyphBounds);
                             }
                         }
                         designer.EditTemplateNode(true);
                     }
                 }
             }
         }
     }
 }
 internal void ShowDropDownMenu()
 {
     if (this.addItemButton != null)
     {
         if (!this._isPopulated)
         {
             this._isPopulated = true;
             ToolStripDesignerUtils.GetCustomNewItemDropDown(this.contextMenu, this.component, null, new EventHandler(this.AddNewItemClick), false, this.component.Site);
         }
         this.addItemButton.ShowDropDown();
     }
     else if (this.BehaviorService != null)
     {
         Point p = this.BehaviorService.ControlToAdornerWindow(this._miniToolStrip);
         p = this.BehaviorService.AdornerWindowPointToScreen(p);
         Rectangle rectangle = new Rectangle(p, this._miniToolStrip.Size);
         if (this.contextMenu == null)
         {
             this._isPopulated = true;
             this.contextMenu = ToolStripDesignerUtils.GetNewItemDropDown(this.component, null, new EventHandler(this.AddNewItemClick), false, this.component.Site, true);
             this.contextMenu.Closed += new ToolStripDropDownClosedEventHandler(this.OnContextMenuClosed);
             this.contextMenu.Opened += new EventHandler(this.OnContextMenuOpened);
             this.contextMenu.Text = "ItemSelectionMenu";
         }
         else if (!this._isPopulated)
         {
             this._isPopulated = true;
             ToolStripDesignerUtils.GetCustomNewItemDropDown(this.contextMenu, this.component, null, new EventHandler(this.AddNewItemClick), false, this.component.Site);
         }
         ToolStrip component = this.component as ToolStrip;
         if (component != null)
         {
             this.contextMenu.RightToLeft = component.RightToLeft;
         }
         else
         {
             ToolStripDropDownItem item = this.component as ToolStripDropDownItem;
             if (item != null)
             {
                 this.contextMenu.RightToLeft = item.RightToLeft;
             }
         }
         this.contextMenu.Show(rectangle.X, rectangle.Y + rectangle.Height);
         this.contextMenu.Focus();
         if (this.renderer != null)
         {
             this.renderer.State = 6;
             this._miniToolStrip.Invalidate();
         }
     }
 }
 internal void CloseEditor()
 {
     if (this._miniToolStrip != null)
     {
         this.Active = false;
         if (this.lastSelection != null)
         {
             this.lastSelection.Dispose();
             this.lastSelection = null;
         }
         ToolStrip component = this.component as ToolStrip;
         if (component != null)
         {
             component.RightToLeftChanged -= new EventHandler(this.OnRightToLeftChanged);
         }
         else
         {
             ToolStripDropDownItem item = this.component as ToolStripDropDownItem;
             if (item != null)
             {
                 item.RightToLeftChanged -= new EventHandler(this.OnRightToLeftChanged);
             }
         }
         if (this.centerLabel != null)
         {
             this.centerLabel.MouseUp -= new MouseEventHandler(this.CenterLabelClick);
             this.centerLabel.MouseEnter -= new EventHandler(this.CenterLabelMouseEnter);
             this.centerLabel.MouseMove -= new MouseEventHandler(this.CenterLabelMouseMove);
             this.centerLabel.MouseLeave -= new EventHandler(this.CenterLabelMouseLeave);
             this.centerLabel.Dispose();
             this.centerLabel = null;
         }
         if (this.addItemButton != null)
         {
             this.addItemButton.MouseMove -= new MouseEventHandler(this.OnMouseMove);
             this.addItemButton.MouseUp -= new MouseEventHandler(this.OnMouseUp);
             this.addItemButton.MouseDown -= new MouseEventHandler(this.OnMouseDown);
             this.addItemButton.DropDownOpened -= new EventHandler(this.OnAddItemButtonDropDownOpened);
             this.addItemButton.DropDown.Dispose();
             this.addItemButton.Dispose();
             this.addItemButton = null;
         }
         if (this.contextMenu != null)
         {
             this.contextMenu.Closed -= new ToolStripDropDownClosedEventHandler(this.OnContextMenuClosed);
             this.contextMenu.Opened -= new EventHandler(this.OnContextMenuOpened);
             this.contextMenu = null;
         }
         this._miniToolStrip.MouseLeave -= new EventHandler(this.OnMouseLeave);
         this._miniToolStrip.Dispose();
         this._miniToolStrip = null;
         if (this._designSurface != null)
         {
             this._designSurface.Flushed -= new EventHandler(this.OnLoaderFlushed);
             this._designSurface = null;
         }
         this._designer = null;
         this.OnClosed(new EventArgs());
     }
 }
 private void SetUpToolTemplateNode(ToolStripTemplateNode owner, string text, Image image, IComponent component)
 {
     this.addItemButton = new ToolStripSplitButton();
     this.addItemButton.AutoSize = false;
     this.addItemButton.Margin = new Padding(1);
     this.addItemButton.Size = this._miniToolStrip.DisplayRectangle.Size - this.addItemButton.Margin.Size;
     this.addItemButton.DropDownButtonWidth = MINITOOLSTRIP_DROPDOWN_BUTTON_WIDTH;
     this.addItemButton.DisplayStyle = ToolStripItemDisplayStyle.Image;
     if (component is StatusStrip)
     {
         this.addItemButton.ToolTipText = System.Design.SR.GetString("ToolStripDesignerTemplateNodeSplitButtonStatusStripToolTip");
     }
     else
     {
         this.addItemButton.ToolTipText = System.Design.SR.GetString("ToolStripDesignerTemplateNodeSplitButtonToolTip");
     }
     this.addItemButton.MouseDown += new MouseEventHandler(this.OnMouseDown);
     this.addItemButton.MouseMove += new MouseEventHandler(this.OnMouseMove);
     this.addItemButton.MouseUp += new MouseEventHandler(this.OnMouseUp);
     this.addItemButton.DropDownOpened += new EventHandler(this.OnAddItemButtonDropDownOpened);
     this.contextMenu = ToolStripDesignerUtils.GetNewItemDropDown(component, null, new EventHandler(this.AddNewItemClick), false, component.Site, false);
     this.contextMenu.Text = "ItemSelectionMenu";
     this.contextMenu.Closed += new ToolStripDropDownClosedEventHandler(this.OnContextMenuClosed);
     this.contextMenu.Opened += new EventHandler(this.OnContextMenuOpened);
     this.addItemButton.DropDown = this.contextMenu;
     try
     {
         if (this.addItemButton.DropDownItems.Count > 0)
         {
             ItemTypeToolStripMenuItem item = (ItemTypeToolStripMenuItem) this.addItemButton.DropDownItems[0];
             this.addItemButton.ImageTransparentColor = Color.Lime;
             Bitmap logicalBitmap = new Bitmap(System.Drawing.BitmapSelector.GetResourceStream(typeof(ToolStripTemplateNode), "ToolStripTemplateNode.bmp"));
             if (System.Windows.Forms.DpiHelper.IsScalingRequired)
             {
                 System.Windows.Forms.DpiHelper.ScaleBitmapLogicalToDevice(ref logicalBitmap);
             }
             this.addItemButton.Image = logicalBitmap;
             this.addItemButton.DefaultItem = item;
         }
     }
     catch (Exception exception)
     {
         if (System.Windows.Forms.ClientUtils.IsCriticalException(exception))
         {
             throw;
         }
     }
     this._miniToolStrip.Items.AddRange(new ToolStripItem[] { this.addItemButton });
 }