/// <summary> /// Initializes a new instance of the <see cref="VsCommandExtensionAdapter"/> class with a /// specific command identifier and implementation. /// </summary> public VsCommandExtensionAdapter(CommandID id, ICommandExtension implementation) : base(OnExecute, id) { tracer = Tracer.Get(this.GetType()); this.Implementation = implementation; this.BeforeQueryStatus += this.OnBeforeQueryStatus; }
/// <summary> /// Initializes a new instance of the <see cref="VsCommandExtensionAdapter"/> class with a /// specific command identifier and implementation. /// </summary> public VsCommandExtensionAdapter(CommandID id, ICommandExtension implementation) : base(OnExecute, id) { Guard.NotNull(() => id, id); Guard.NotNull(() => implementation, implementation); this.tracer = Tracer.Get(this.GetType()); this.Implementation = implementation; this.BeforeQueryStatus += this.OnBeforeQueryStatus; }
/// <summary> /// Adds the specified command implementation to the manager, /// with the specified explicit metadata. /// </summary> /// <param name="command">The command instance, which does not need to /// be annotated with the <see cref="CommandAttribute"/> attribute since /// it's provided explicitly.</param> /// <param name="metadata">Explicit metadata to use for the command, /// instead of reflecting the <see cref="CommandAttribute"/>.</param> public void AddCommand(ICommandExtension command, CommandAttribute metadata) { Guard.NotNull(() => command, command); Guard.NotNull(() => metadata, metadata); var menuService = serviceProvider.GetService <IMenuCommandService>(); var commandId = new CommandID(new Guid(metadata.GroupId), metadata.CommandId); var existing = menuService.FindCommand(commandId); if (existing != null) { throw new ArgumentException(Strings.CommandManager.DuplicateCommand(metadata.CommandId, metadata.GroupId)); } menuService.AddCommand(new VsCommandExtensionAdapter(commandId, command)); tracer.Info(Strings.CommandManager.CommandRegistered(command.Text, command.GetType())); }
/// <summary> /// Initializes a new instance of the <see cref="VsCommandExtensionAdapter"/> class with a /// specific command identifier and implementation. /// </summary> public VsCommandExtensionAdapter( CommandID id, ICommandExtension implementation, UIContextWrapper uiContext = null, bool triggerQueryStatus = false /* for testing purposes only */) : base(OnExecute, id) { tracer = Tracer.Get(this.GetType()); this.Implementation = implementation; this.uiContext = uiContext; this.BeforeQueryStatus += this.OnBeforeQueryStatus; if (triggerQueryStatus) { OnBeforeQueryStatus(this, new EventArgs()); } }
/// <summary> /// Sets the extension of the command /// </summary> /// <param name="extension">Command extension object</param> public void SetExtension(ICommandExtension extension) { if (this.ExtensionElement == null) { var extensionElement = new XElement(EppNs.GetName("extension")); //this.CommandElement.Add(extensionElement); //fix: extension should be placed before TranId var clTRIDElement = this.ClientTranIdElement; if (clTRIDElement != null) { clTRIDElement.AddBeforeSelf(extensionElement); } else { this.CommandElement.Add(extensionElement); } } //this.ExtensionElement.RemoveAll(); extension.Fill(this.ExtensionElement); }
/// <summary> /// Adds the specified command implementation to the manager, /// with the specified explicit metadata. /// </summary> /// <param name="command">The command instance, which does not need to /// be annotated with the <see cref="CommandAttribute"/> attribute since /// it's provided explicitly.</param> /// <param name="metadata">Explicit metadata to use for the command, /// instead of reflecting the <see cref="CommandAttribute"/>.</param> public void AddCommand(ICommandExtension command, CommandAttribute metadata) { Guard.NotNull(() => command, command); Guard.NotNull(() => metadata, metadata); var menuService = serviceProvider.GetService<IMenuCommandService>(); var commandId = new CommandID(new Guid(metadata.GroupId), metadata.CommandId); var existing = menuService.FindCommand(commandId); if (existing != null) throw new ArgumentException(Strings.CommandManager.DuplicateCommand(metadata.CommandId, metadata.GroupId)); menuService.AddCommand(new VsCommandExtensionAdapter(commandId, command)); tracer.Info(Strings.CommandManager.CommandRegistered(command.Text, command.GetType())); }