private void RefreshSelectionMenuItem()
 {
     int index = -1;
     if (this.selectionMenuItem != null)
     {
         index = this.Items.IndexOf(this.selectionMenuItem);
         base.Groups["Selection"].Items.Remove(this.selectionMenuItem);
         this.Items.Remove(this.selectionMenuItem);
     }
     ArrayList list = new ArrayList();
     int count = 0;
     ISelectionService service = this.serviceProvider.GetService(typeof(ISelectionService)) as ISelectionService;
     IDesignerHost host = this.serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost;
     if ((service != null) && (host != null))
     {
         IComponent rootComponent = host.RootComponent;
         Control primarySelection = service.PrimarySelection as Control;
         if (((primarySelection != null) && (rootComponent != null)) && (primarySelection != rootComponent))
         {
             for (Control control2 = primarySelection.Parent; control2 != null; control2 = control2.Parent)
             {
                 if (control2.Site != null)
                 {
                     list.Add(control2);
                     count++;
                 }
                 if (control2 == rootComponent)
                 {
                     break;
                 }
             }
         }
         else if (service.PrimarySelection is ToolStripItem)
         {
             ToolStripItem component = service.PrimarySelection as ToolStripItem;
             ToolStripItemDesigner designer = host.GetDesigner(component) as ToolStripItemDesigner;
             if (designer != null)
             {
                 list = designer.AddParentTree();
                 count = list.Count;
             }
         }
     }
     if (count > 0)
     {
         this.selectionMenuItem = new ToolStripMenuItem();
         IUIService service2 = this.serviceProvider.GetService(typeof(IUIService)) as IUIService;
         if (service2 != null)
         {
             this.selectionMenuItem.DropDown.Renderer = (ToolStripProfessionalRenderer) service2.Styles["VsRenderer"];
             this.selectionMenuItem.DropDown.Font = (Font) service2.Styles["DialogFont"];
         }
         this.selectionMenuItem.Text = System.Design.SR.GetString("ContextMenuSelect");
         foreach (Component component2 in list)
         {
             ToolStripMenuItem item2 = new SelectToolStripMenuItem(component2, this.serviceProvider);
             this.selectionMenuItem.DropDownItems.Add(item2);
         }
         base.Groups["Selection"].Items.Add(this.selectionMenuItem);
         if (index != -1)
         {
             this.Items.Insert(index, this.selectionMenuItem);
         }
     }
 }
Beispiel #2
0
        private void RefreshSelectionMenuItem()
        {
            int index = -1;

            if (this.selectionMenuItem != null)
            {
                index = this.Items.IndexOf(this.selectionMenuItem);
                base.Groups["Selection"].Items.Remove(this.selectionMenuItem);
                this.Items.Remove(this.selectionMenuItem);
            }
            ArrayList         list    = new ArrayList();
            int               count   = 0;
            ISelectionService service = this.serviceProvider.GetService(typeof(ISelectionService)) as ISelectionService;
            IDesignerHost     host    = this.serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost;

            if ((service != null) && (host != null))
            {
                IComponent rootComponent    = host.RootComponent;
                Control    primarySelection = service.PrimarySelection as Control;
                if (((primarySelection != null) && (rootComponent != null)) && (primarySelection != rootComponent))
                {
                    for (Control control2 = primarySelection.Parent; control2 != null; control2 = control2.Parent)
                    {
                        if (control2.Site != null)
                        {
                            list.Add(control2);
                            count++;
                        }
                        if (control2 == rootComponent)
                        {
                            break;
                        }
                    }
                }
                else if (service.PrimarySelection is ToolStripItem)
                {
                    ToolStripItem         component = service.PrimarySelection as ToolStripItem;
                    ToolStripItemDesigner designer  = host.GetDesigner(component) as ToolStripItemDesigner;
                    if (designer != null)
                    {
                        list  = designer.AddParentTree();
                        count = list.Count;
                    }
                }
            }
            if (count > 0)
            {
                this.selectionMenuItem = new ToolStripMenuItem();
                IUIService service2 = this.serviceProvider.GetService(typeof(IUIService)) as IUIService;
                if (service2 != null)
                {
                    this.selectionMenuItem.DropDown.Renderer = (ToolStripProfessionalRenderer)service2.Styles["VsRenderer"];
                    this.selectionMenuItem.DropDown.Font     = (Font)service2.Styles["DialogFont"];
                }
                this.selectionMenuItem.Text = System.Design.SR.GetString("ContextMenuSelect");
                foreach (Component component2 in list)
                {
                    ToolStripMenuItem item2 = new SelectToolStripMenuItem(component2, this.serviceProvider);
                    this.selectionMenuItem.DropDownItems.Add(item2);
                }
                base.Groups["Selection"].Items.Add(this.selectionMenuItem);
                if (index != -1)
                {
                    this.Items.Insert(index, this.selectionMenuItem);
                }
            }
        }