/// <summary> /// Gets the <see cref="CommandMapItem"/> for the specified command /// </summary> /// <param name="command"></param> /// <returns>The <see cref="CommandMapItem"/> or null if the command is not valid</returns> public CommandMapItem this[AnkhCommand command] { get { CommandMapItem item; if (_map.TryGetValue(command, out item)) { return(item); } else { item = new CommandMapItem(command); _map.Add(command, item); return(item); } } }
/// <summary> /// Gets the <see cref="CommandMapItem"/> for the specified command /// </summary> /// <param name="command"></param> /// <returns>The <see cref="CommandMapItem"/> or null if the command is not valid</returns> public CommandMapItem this[AnkhCommand command] { get { CommandMapItem item; if (_map.TryGetValue(command, out item)) return item; else { item = new CommandMapItem(command); _map.Add(command, item); return item; } } }
private void EnsureLoaded() { if (_assembliesToLoad.Count == 0) { return; } if (_defined.Count == 0) { foreach (AnkhCommand cmd in Enum.GetValues(typeof(AnkhCommand))) { if (cmd <= AnkhCommand.CommandFirst) { continue; } _defined.Add(cmd); } } while (_assembliesToLoad.Count > 0) { Assembly asm = _assembliesToLoad[0]; _assembliesToLoad.RemoveAt(0); _assembliesLoaded.Add(asm); foreach (Type type in asm.GetTypes()) { if (!type.IsClass || type.IsAbstract || type.IsNested || !Attribute.IsDefined(type, typeof(CommandAttribute), false)) { continue; } if (!typeof(ICommandHandler).IsAssignableFrom(type)) { continue; } ICommandHandler instance = null; foreach (CommandAttribute cmdAttr in type.GetCustomAttributes(typeof(CommandAttribute), false)) { if (cmdAttr.Context != _commandContext || !cmdAttr.Applies()) { continue; } foreach (AnkhCommand cmdInstance in cmdAttr.GetAllCommands()) { CommandMapItem item = this[cmdInstance]; if (item == null) { throw new InvalidOperationException("Invalid command " + cmdInstance.ToString()); } if (cmdAttr.LastCommand == cmdInstance) { item.DynamicMenuEnd = true; continue; } if (instance == null) { instance = (ICommandHandler)Activator.CreateInstance(type); IComponent component = instance as IComponent; if (component != null) { component.Site = CommandSite; } } Debug.Assert(item.ICommand == null || item.ICommand == instance, string.Format("No previous ICommand registered on the CommandMapItem for {0}", cmdAttr.Command)); item.ICommand = instance; // hooks all events via interface item.Availability = cmdAttr.Availability; item.HiddenWhenDisabled = cmdAttr.HideWhenDisabled; item.CommandTarget = cmdAttr.CommandTarget; item.ArgumentDefinition = cmdAttr.ArgumentDefinition ?? CalculateDefinition(cmdAttr.CommandTarget); } } } } }
internal void Prepare(CommandMapItem item) { _mapItem = item; }