private ContextMenuStrip GetMenuWithCompatibleConstructorIfExists(object o, IMasqueradeAs oMasquerader = null) { RDMPContextMenuStripArgs args = new RDMPContextMenuStripArgs(_activator, Tree, o); args.CurrentlyPinnedObject = CurrentlyPinned; args.Masquerader = oMasquerader ?? o as IMasqueradeAs; var objectConstructor = new ObjectConstructor(); Type oType = o.GetType(); //if we have encountered this object type before if (_cachedMenuCompatibility.ContainsKey(oType)) { Type compatibleMenu = _cachedMenuCompatibility[oType]; //we know there are no menus compatible with o if (compatibleMenu == null) { return(null); } return(ConstructMenu(objectConstructor, _cachedMenuCompatibility[oType], args, o)); } //now find the first RDMPContextMenuStrip with a compatible constructor foreach (Type menuType in _activator.RepositoryLocator.CatalogueRepository.MEF.GetTypes <RDMPContextMenuStrip>()) { if (menuType.IsAbstract || menuType.IsInterface || menuType == typeof(RDMPContextMenuStrip)) { continue; } //try constructing menu with: var menu = ConstructMenu(objectConstructor, menuType, args, o); //find first menu that's compatible if (menu != null) { if (!_cachedMenuCompatibility.ContainsKey(oType)) { _cachedMenuCompatibility.Add(oType, menu.GetType()); } return(menu); } } //we know there are no menus compatible with this type if (!_cachedMenuCompatibility.ContainsKey(oType)) { _cachedMenuCompatibility.Add(oType, null); } //there are no derrived classes with compatible constructors return(null); }
private RDMPContextMenuStrip ConstructMenu(ObjectConstructor objectConstructor, Type type, RDMPContextMenuStripArgs args, object o) { //there is a compatible menu Type known //parameter 1 must be args //parameter 2 must be object compatible Type var menu = (RDMPContextMenuStrip)objectConstructor.ConstructIfPossible(type, args, o); if (menu != null) { menu.AddCommonMenuItems(this); } return(menu); }
public ExecuteCommandShowKeywordHelp(IActivateItems activator, RDMPContextMenuStripArgs args) : base(activator) { _args = args; }
public AllServersNodeMenu(RDMPContextMenuStripArgs args, AllServersNode o) : base(args, o) { Add(new ExecuteCommandCreateNewEmptyCatalogue(args.ItemActivator)); }