Exemple #1
0
 internal DesignerActionUIService(IServiceProvider serviceProvider)
 {
     this.serviceProvider = serviceProvider;
     if (serviceProvider != null)
     {
         this.serviceProvider = serviceProvider;
         ((IDesignerHost)serviceProvider.GetService(typeof(IDesignerHost))).AddService(typeof(DesignerActionUIService), this);
         this.designerActionService = serviceProvider.GetService(typeof(DesignerActionService)) as DesignerActionService;
     }
 }
 internal DesignerActionUIService(IServiceProvider serviceProvider)
 {
     _serviceProvider = serviceProvider;
     if (serviceProvider != null)
     {
         _serviceProvider = serviceProvider;
         IDesignerHost host = (IDesignerHost)serviceProvider.GetService(typeof(IDesignerHost));
         host.AddService(typeof(DesignerActionUIService), this);
         _designerActionService = serviceProvider.GetService(typeof(DesignerActionService)) as DesignerActionService;
         Debug.Assert(_designerActionService != null, "we should have created and registered the DAService first");
     }
 }
 public DesignerActionUI(IServiceProvider serviceProvider, Adorner containerAdorner)
 {
     this.serviceProvider = serviceProvider;
     this.designerActionAdorner = containerAdorner;
     this.behaviorService = (BehaviorService) serviceProvider.GetService(typeof(BehaviorService));
     this.menuCommandService = (IMenuCommandService) serviceProvider.GetService(typeof(IMenuCommandService));
     this.selSvc = (ISelectionService) serviceProvider.GetService(typeof(ISelectionService));
     if ((this.behaviorService != null) && (this.selSvc != null))
     {
         this.designerActionService = (DesignerActionService) serviceProvider.GetService(typeof(DesignerActionService));
         if (this.designerActionService == null)
         {
             this.designerActionService = new DesignerActionService(serviceProvider);
             this.disposeActionService = true;
         }
         this.designerActionUIService = (DesignerActionUIService) serviceProvider.GetService(typeof(DesignerActionUIService));
         if (this.designerActionUIService == null)
         {
             this.designerActionUIService = new DesignerActionUIService(serviceProvider);
             this.disposeActionUIService = true;
         }
         this.designerActionUIService.DesignerActionUIStateChange += new DesignerActionUIStateChangeEventHandler(this.OnDesignerActionUIStateChange);
         this.designerActionService.DesignerActionListsChanged += new DesignerActionListsChangedEventHandler(this.OnDesignerActionsChanged);
         this.lastPanelComponent = null;
         IComponentChangeService service = (IComponentChangeService) serviceProvider.GetService(typeof(IComponentChangeService));
         if (service != null)
         {
             service.ComponentChanged += new ComponentChangedEventHandler(this.OnComponentChanged);
         }
         if (this.menuCommandService != null)
         {
             this.cmdShowDesignerActions = new MenuCommand(new EventHandler(this.OnKeyShowDesignerActions), MenuCommands.KeyInvokeSmartTag);
             this.menuCommandService.AddCommand(this.cmdShowDesignerActions);
         }
         this.uiService = (IUIService) serviceProvider.GetService(typeof(IUIService));
         if (this.uiService != null)
         {
             this.mainParentWindow = this.uiService.GetDialogOwnerWindow();
         }
         this.componentToGlyph = new Hashtable();
         this.marshalingControl = new Control();
         this.marshalingControl.CreateControl();
     }
 }
        /// <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);
            }
        }
 public virtual void Initialize(IComponent component)
 {
     ControlDesigner.VerifyInitializeArgument(component, typeof(TemplateControl));
     this._component = component;
     IServiceContainer container = (IServiceContainer) this.GetService(typeof(IServiceContainer));
     if (container != null)
     {
         this._urlResolutionService = this.CreateUrlResolutionService();
         if (this._urlResolutionService != null)
         {
             container.AddService(typeof(IUrlResolutionService), this._urlResolutionService);
         }
         this._designerActionService = this.CreateDesignerActionService(this._component.Site);
         this._designerActionUIService = new DesignerActionUIService(this._component.Site);
         ServiceCreatorCallback callback = new ServiceCreatorCallback(this.OnCreateService);
         container.AddService(typeof(IImplicitResourceProvider), callback);
     }
     IPropertyValueUIService service = (IPropertyValueUIService) this.GetService(typeof(IPropertyValueUIService));
     if (service != null)
     {
         service.AddPropertyValueUIHandler(new PropertyValueUIHandler(this.OnGetUIValueItem));
     }
 }
 public void Dispose()
 {
     if (this.marshalingControl != null)
     {
         this.marshalingControl.Dispose();
         this.marshalingControl = null;
     }
     if (this.serviceProvider != null)
     {
         IComponentChangeService service = (IComponentChangeService) this.serviceProvider.GetService(typeof(IComponentChangeService));
         if (service != null)
         {
             service.ComponentChanged -= new ComponentChangedEventHandler(this.OnComponentChanged);
         }
         if (this.cmdShowDesignerActions != null)
         {
             IMenuCommandService service2 = (IMenuCommandService) this.serviceProvider.GetService(typeof(IMenuCommandService));
             if (service2 != null)
             {
                 service2.RemoveCommand(this.cmdShowDesignerActions);
             }
         }
     }
     this.serviceProvider = null;
     this.behaviorService = null;
     this.selSvc = null;
     if (this.designerActionService != null)
     {
         this.designerActionService.DesignerActionListsChanged -= new DesignerActionListsChangedEventHandler(this.OnDesignerActionsChanged);
         if (this.disposeActionService)
         {
             this.designerActionService.Dispose();
         }
     }
     this.designerActionService = null;
     if (this.designerActionUIService != null)
     {
         this.designerActionUIService.DesignerActionUIStateChange -= new DesignerActionUIStateChangeEventHandler(this.OnDesignerActionUIStateChange);
         if (this.disposeActionUIService)
         {
             this.designerActionUIService.Dispose();
         }
     }
     this.designerActionUIService = null;
     this.designerActionAdorner = null;
 }
Exemple #7
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);
            }
        }