private void OnVerbStatusChanged(object sender, EventArgs args) { if (!this.reEntrantCode) { try { this.reEntrantCode = true; IComponent primarySelection = this.selSvc.PrimarySelection as IComponent; if (primarySelection != null) { IServiceContainer site = primarySelection.Site as IServiceContainer; if (site != null) { DesignerCommandSet set = (DesignerCommandSet)site.GetService(typeof(DesignerCommandSet)); foreach (DesignerVerb verb in set.Verbs) { if (verb == sender) { DesignerActionUIService service = (DesignerActionUIService)site.GetService(typeof(DesignerActionUIService)); if (service != null) { service.Refresh(primarySelection); } } } } } } finally { this.reEntrantCode = false; } } }
private void OnVerbStatusChanged(object sender, EventArgs args) { if (!_reEntrantCode) { try { _reEntrantCode = true; if (_selSvc.PrimarySelection is IComponent comp) { if (comp.Site is IServiceContainer sc) { DesignerCommandSet dcs = (DesignerCommandSet)sc.GetService(typeof(DesignerCommandSet)); foreach (DesignerVerb verb in dcs.Verbs) { if (verb == sender) { DesignerActionUIService dapUISvc = (DesignerActionUIService)sc.GetService(typeof(DesignerActionUIService)); if (dapUISvc != null) { //Debug.WriteLine("Calling refresh on component " + comp.Site.Name); dapUISvc.Refresh(comp); // we need to refresh, a verb on the current panel has changed its state } } } } } } finally { _reEntrantCode = false; } } }
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); } } } } } }