/// <summary>
        ///  Ensures that the verb list has been created.
        /// </summary>
        protected void EnsureVerbs()
        {
            // We apply global verbs only if the base component is the
            // currently selected object.
            //
            bool useGlobalVerbs = false;

            if (_currentVerbs is null && _serviceProvider != null)
            {
                Hashtable buildVerbs = null;
                ArrayList verbsOrder;

                if (_selectionService is null)
                {
                    _selectionService = GetService(typeof(ISelectionService)) as ISelectionService;

                    if (_selectionService != null)
                    {
                        _selectionService.SelectionChanging += new EventHandler(OnSelectionChanging);
                    }
                }

                int verbCount = 0;
                DesignerVerbCollection localVerbs          = null;
                DesignerVerbCollection designerActionVerbs = new DesignerVerbCollection(); // we instanciate this one here...
                IDesignerHost          designerHost        = GetService(typeof(IDesignerHost)) as IDesignerHost;

                if (_selectionService != null && designerHost != null && _selectionService.SelectionCount == 1)
                {
                    object selectedComponent = _selectionService.PrimarySelection;
                    if (selectedComponent is IComponent &&
                        !TypeDescriptor.GetAttributes(selectedComponent).Contains(InheritanceAttribute.InheritedReadOnly))
                    {
                        useGlobalVerbs = (selectedComponent == designerHost.RootComponent);

                        // LOCAL VERBS
                        IDesigner designer = designerHost.GetDesigner((IComponent)selectedComponent);
                        if (designer != null)
                        {
                            localVerbs = designer.Verbs;
                            if (localVerbs != null)
                            {
                                verbCount      += localVerbs.Count;
                                _verbSourceType = selectedComponent.GetType();
                            }
                            else
                            {
                                _verbSourceType = null;
                            }
                        }

                        // DesignerAction Verbs
                        DesignerActionService daSvc = GetService(typeof(DesignerActionService)) as DesignerActionService;
                        if (daSvc != null)
                        {
                            DesignerActionListCollection actionLists = daSvc.GetComponentActions(selectedComponent as IComponent);
                            if (actionLists != null)
                            {
                                foreach (DesignerActionList list in actionLists)
                                {
                                    DesignerActionItemCollection dai = list.GetSortedActionItems();
                                    if (dai != null)
                                    {
                                        for (int i = 0; i < dai.Count; i++)
                                        {
                                            DesignerActionMethodItem dami = dai[i] as DesignerActionMethodItem;
                                            if (dami != null && dami.IncludeAsDesignerVerb)
                                            {
                                                EventHandler handler = new EventHandler(dami.Invoke);
                                                DesignerVerb verb    = new DesignerVerb(dami.DisplayName, handler);
                                                designerActionVerbs.Add(verb);
                                                verbCount++;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                // GLOBAL VERBS
                if (useGlobalVerbs && _globalVerbs is null)
                {
                    useGlobalVerbs = false;
                }

                if (useGlobalVerbs)
                {
                    verbCount += _globalVerbs.Count;
                }

                // merge all
                buildVerbs = new Hashtable(verbCount, StringComparer.OrdinalIgnoreCase);
                verbsOrder = new ArrayList(verbCount);

                // PRIORITY ORDER FROM HIGH TO LOW: LOCAL VERBS - DESIGNERACTION VERBS - GLOBAL VERBS
                if (useGlobalVerbs)
                {
                    for (int i = 0; i < _globalVerbs.Count; i++)
                    {
                        string key = ((DesignerVerb)_globalVerbs[i]).Text;
                        buildVerbs[key] = verbsOrder.Add(_globalVerbs[i]);
                    }
                }

                if (designerActionVerbs.Count > 0)
                {
                    for (int i = 0; i < designerActionVerbs.Count; i++)
                    {
                        string key = designerActionVerbs[i].Text;
                        buildVerbs[key] = verbsOrder.Add(designerActionVerbs[i]);
                    }
                }

                if (localVerbs != null && localVerbs.Count > 0)
                {
                    for (int i = 0; i < localVerbs.Count; i++)
                    {
                        string key = localVerbs[i].Text;
                        buildVerbs[key] = verbsOrder.Add(localVerbs[i]);
                    }
                }

                // look for duplicate, prepare the result table
                DesignerVerb[] result = new DesignerVerb[buildVerbs.Count];
                int            j      = 0;
                for (int i = 0; i < verbsOrder.Count; i++)
                {
                    DesignerVerb value = (DesignerVerb)verbsOrder[i];
                    string       key   = value.Text;
                    if ((int)buildVerbs[key] == i)
                    { // there's not been a duplicate for this entry
                        result[j] = value;
                        j++;
                    }
                }

                _currentVerbs = new DesignerVerbCollection(result);
            }
        }
Exemple #2
0
        protected void EnsureVerbs()
        {
            bool flag = false;

            if ((this._currentVerbs == null) && (this._serviceProvider != null))
            {
                Hashtable hashtable = null;
                if (this._selectionService == null)
                {
                    this._selectionService = this.GetService(typeof(ISelectionService)) as ISelectionService;
                    if (this._selectionService != null)
                    {
                        this._selectionService.SelectionChanging += new EventHandler(this.OnSelectionChanging);
                    }
                }
                int capacity = 0;
                DesignerVerbCollection verbs  = null;
                DesignerVerbCollection verbs2 = new DesignerVerbCollection();
                IDesignerHost          host   = this.GetService(typeof(IDesignerHost)) as IDesignerHost;
                if (((this._selectionService != null) && (host != null)) && (this._selectionService.SelectionCount == 1))
                {
                    object primarySelection = this._selectionService.PrimarySelection;
                    if ((primarySelection is IComponent) && !TypeDescriptor.GetAttributes(primarySelection).Contains(InheritanceAttribute.InheritedReadOnly))
                    {
                        flag = primarySelection == host.RootComponent;
                        IDesigner designer = host.GetDesigner((IComponent)primarySelection);
                        if (designer != null)
                        {
                            verbs = designer.Verbs;
                            if (verbs != null)
                            {
                                capacity            += verbs.Count;
                                this._verbSourceType = primarySelection.GetType();
                            }
                            else
                            {
                                this._verbSourceType = null;
                            }
                        }
                        DesignerActionService service = this.GetService(typeof(DesignerActionService)) as DesignerActionService;
                        if (service != null)
                        {
                            DesignerActionListCollection componentActions = service.GetComponentActions(primarySelection as IComponent);
                            if (componentActions != null)
                            {
                                foreach (DesignerActionList list2 in componentActions)
                                {
                                    DesignerActionItemCollection sortedActionItems = list2.GetSortedActionItems();
                                    if (sortedActionItems != null)
                                    {
                                        for (int j = 0; j < sortedActionItems.Count; j++)
                                        {
                                            DesignerActionMethodItem item = sortedActionItems[j] as DesignerActionMethodItem;
                                            if ((item != null) && item.IncludeAsDesignerVerb)
                                            {
                                                EventHandler handler = new EventHandler(item.Invoke);
                                                DesignerVerb verb    = new DesignerVerb(item.DisplayName, handler);
                                                verbs2.Add(verb);
                                                capacity++;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if (flag && (this._globalVerbs == null))
                {
                    flag = false;
                }
                if (flag)
                {
                    capacity += this._globalVerbs.Count;
                }
                hashtable = new Hashtable(capacity, StringComparer.OrdinalIgnoreCase);
                ArrayList list = new ArrayList(capacity);
                if (flag)
                {
                    for (int k = 0; k < this._globalVerbs.Count; k++)
                    {
                        string text = ((DesignerVerb)this._globalVerbs[k]).Text;
                        hashtable[text] = list.Add(this._globalVerbs[k]);
                    }
                }
                if (verbs2.Count > 0)
                {
                    for (int m = 0; m < verbs2.Count; m++)
                    {
                        string str2 = verbs2[m].Text;
                        hashtable[str2] = list.Add(verbs2[m]);
                    }
                }
                if ((verbs != null) && (verbs.Count > 0))
                {
                    for (int n = 0; n < verbs.Count; n++)
                    {
                        string str3 = verbs[n].Text;
                        hashtable[str3] = list.Add(verbs[n]);
                    }
                }
                DesignerVerb[] verbArray = new DesignerVerb[hashtable.Count];
                int            index     = 0;
                for (int i = 0; i < list.Count; i++)
                {
                    DesignerVerb verb2 = (DesignerVerb)list[i];
                    string       str4  = verb2.Text;
                    if (((int)hashtable[str4]) == i)
                    {
                        verbArray[index] = verb2;
                        index++;
                    }
                }
                this._currentVerbs = new DesignerVerbCollection(verbArray);
            }
        }