Beispiel #1
0
        protected virtual void GetComponentDesignerActions(IComponent component, DesignerActionListCollection actionLists)
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }
            if (actionLists == null)
            {
                throw new ArgumentNullException("actionLists");
            }
            IServiceContainer site = component.Site as IServiceContainer;

            if (site != null)
            {
                DesignerCommandSet service = (DesignerCommandSet)site.GetService(typeof(DesignerCommandSet));
                if (service != null)
                {
                    DesignerActionListCollection lists = service.ActionLists;
                    if (lists != null)
                    {
                        actionLists.AddRange(lists);
                    }
                    if (actionLists.Count == 0)
                    {
                        DesignerVerbCollection verbs = service.Verbs;
                        if ((verbs != null) && (verbs.Count != 0))
                        {
                            ArrayList list = new ArrayList();
                            bool      flag = this.componentToVerbsEventHookedUp[component] == null;
                            if (flag)
                            {
                                this.componentToVerbsEventHookedUp[component] = true;
                            }
                            foreach (DesignerVerb verb in verbs)
                            {
                                if (flag)
                                {
                                    verb.CommandChanged += new EventHandler(this.OnVerbStatusChanged);
                                }
                                if (verb.Enabled && verb.Visible)
                                {
                                    list.Add(verb);
                                }
                            }
                            if (list.Count != 0)
                            {
                                DesignerActionVerbList list2 = new DesignerActionVerbList((DesignerVerb[])list.ToArray(typeof(DesignerVerb)));
                                actionLists.Add(list2);
                            }
                        }
                    }
                    if (lists != null)
                    {
                        foreach (DesignerActionList list3 in lists)
                        {
                            DesignerActionItemCollection sortedActionItems = list3.GetSortedActionItems();
                            if ((sortedActionItems == null) || (sortedActionItems.Count == 0))
                            {
                                actionLists.Remove(list3);
                            }
                        }
                    }
                }
            }
        }
 protected virtual void GetComponentDesignerActions(IComponent component, DesignerActionListCollection actionLists)
 {
     if (component == null)
     {
         throw new ArgumentNullException("component");
     }
     if (actionLists == null)
     {
         throw new ArgumentNullException("actionLists");
     }
     IServiceContainer site = component.Site as IServiceContainer;
     if (site != null)
     {
         DesignerCommandSet service = (DesignerCommandSet) site.GetService(typeof(DesignerCommandSet));
         if (service != null)
         {
             DesignerActionListCollection lists = service.ActionLists;
             if (lists != null)
             {
                 actionLists.AddRange(lists);
             }
             if (actionLists.Count == 0)
             {
                 DesignerVerbCollection verbs = service.Verbs;
                 if ((verbs != null) && (verbs.Count != 0))
                 {
                     ArrayList list = new ArrayList();
                     bool flag = this.componentToVerbsEventHookedUp[component] == null;
                     if (flag)
                     {
                         this.componentToVerbsEventHookedUp[component] = true;
                     }
                     foreach (DesignerVerb verb in verbs)
                     {
                         if (flag)
                         {
                             verb.CommandChanged += new EventHandler(this.OnVerbStatusChanged);
                         }
                         if (verb.Enabled && verb.Visible)
                         {
                             list.Add(verb);
                         }
                     }
                     if (list.Count != 0)
                     {
                         DesignerActionVerbList list2 = new DesignerActionVerbList((DesignerVerb[]) list.ToArray(typeof(DesignerVerb)));
                         actionLists.Add(list2);
                     }
                 }
             }
             if (lists != null)
             {
                 foreach (DesignerActionList list3 in lists)
                 {
                     DesignerActionItemCollection sortedActionItems = list3.GetSortedActionItems();
                     if ((sortedActionItems == null) || (sortedActionItems.Count == 0))
                     {
                         actionLists.Remove(list3);
                     }
                 }
             }
         }
     }
 }
        protected virtual void GetComponentDesignerActions(IComponent component, DesignerActionListCollection actionLists)
        {
            if (component == null)
            {
                throw new ArgumentNullException(nameof(component));
            }

            if (actionLists == null)
            {
                throw new ArgumentNullException(nameof(actionLists));
            }

            if (component.Site is IServiceContainer sc)
            {
                DesignerCommandSet dcs = (DesignerCommandSet)sc.GetService(typeof(DesignerCommandSet));
                if (dcs != null)
                {
                    DesignerActionListCollection pullCollection = dcs.ActionLists;
                    if (pullCollection != null)
                    {
                        actionLists.AddRange(pullCollection);
                    }

                    // if we don't find any, add the verbs for this component there...
                    if (actionLists.Count == 0)
                    {
                        DesignerVerbCollection verbs = dcs.Verbs;
                        if (verbs != null && verbs.Count != 0)
                        {
                            ArrayList verbsArray   = new ArrayList();
                            bool      hookupEvents = _componentToVerbsEventHookedUp[component] == null;
                            if (hookupEvents)
                            {
                                _componentToVerbsEventHookedUp[component] = true;
                            }
                            foreach (DesignerVerb verb in verbs)
                            {
                                if (hookupEvents)
                                {
                                    //Debug.WriteLine("hooking up change event for verb " + verb.Text);
                                    verb.CommandChanged += new EventHandler(OnVerbStatusChanged);
                                }
                                if (verb.Enabled && verb.Visible)
                                {
                                    //Debug.WriteLine("adding verb to collection for panel... " + verb.Text);
                                    verbsArray.Add(verb);
                                }
                            }
                            if (verbsArray.Count != 0)
                            {
                                DesignerActionVerbList davl = new DesignerActionVerbList((DesignerVerb[])verbsArray.ToArray(typeof(DesignerVerb)));
                                actionLists.Add(davl);
                            }
                        }
                    }

                    // remove all the ones that are empty... ie GetSortedActionList returns nothing we might waste some time doing this twice but don't have much of a choice here... the panel is not yet displayed and we want to know if a non empty panel is present...
                    // NOTE: We do this AFTER the verb check that way to disable auto verb upgrading you can just return an empty actionlist collection
                    if (pullCollection != null)
                    {
                        foreach (DesignerActionList actionList in pullCollection)
                        {
                            DesignerActionItemCollection collection = actionList.GetSortedActionItems();
                            if (collection == null || collection.Count == 0)
                            {
                                actionLists.Remove(actionList);
                            }
                        }
                    }
                }
            }
        }