/// <summary> /// Add item to the menu. /// </summary> /// <param name="vsCommandInfo">The command info.</param> protected virtual void AddMenuItem(VSCommandInfo vsCommandInfo) { TraceService.WriteLine("CommandManager::AddMenuItem Name=" + vsCommandInfo.Name); //// This try/catch block can be duplicated if you wish to add multiple commands to be handled by your Add-in, //// just make sure you also update the QueryStatus/Exec method to include the new command names. try { Commands2 commands = (Commands2)this.VSInstance.ApplicationObject.Commands; object[] context = new object[] { }; TraceService.WriteLine("CommandManager::AddMenuItem Adding command name=" + vsCommandInfo.Name); IEnumerable <Command> currentCommands = commands.Cast <Command>(); foreach (Command command in currentCommands .Where(command => command.Name == vsCommandInfo.Name)) { TraceService.WriteLine("CommandManager::AddMenuItem Deleting Command already in memory name=" + vsCommandInfo.Name); command.Delete(); break; } vsCommandInfo.Command = commands.AddNamedCommand2( vsCommandInfo.AddIn, vsCommandInfo.Name, vsCommandInfo.ButtonText, vsCommandInfo.Tooltip, vsCommandInfo.UseOfficeResources, vsCommandInfo.BitmapResourceId, ref context); vsCommandInfo.Command.AddControl(vsCommandInfo.ParentCommand, vsCommandInfo.Position); this.commandInfos.Add(vsCommandInfo); } catch (ArgumentException exception) { //// If we are here, then the exception is probably because a command with that name //// already exists. If so there is no need to recreate the command and we can //// safely ignore the exception. TraceService.WriteError("CommandManager::AddMenuItem ArgumentException"); TraceService.WriteLine("commandName=" + vsCommandInfo.Name); TraceService.WriteError("message=" + exception.Message); TraceService.WriteError("parameterName=" + exception.ParamName); TraceService.WriteError("stackTrace=" + exception.StackTrace); } }
/// <summary> /// Add item to the menu. /// </summary> /// <param name="commandInfo">The command info.</param> protected virtual void AddMenuItem(VSCommandInfo commandInfo) { TraceService.WriteLine("CommandManager::AddMenuItem Name=" + commandInfo.Name); //// This try/catch block can be duplicated if you wish to add multiple commands to be handled by your Add-in, //// just make sure you also update the QueryStatus/Exec method to include the new command names. try { Commands2 commands = (Commands2)this.VsInstance.ApplicationObject.Commands; object[] context = { }; TraceService.WriteLine("AddMenuItem name=" + commandInfo.Name); IEnumerable <Command> currentCommands = commands.Cast <Command>(); foreach (Command command in currentCommands .Where(command => command.Name.Contains(commandInfo.Name))) { TraceService.WriteLine("Deleting Command already in memory name=" + commandInfo.Name); command.Delete(); break; } TraceService.WriteLine("AddingCommand"); commandInfo.Command = commands.AddNamedCommand2( commandInfo.AddIn, commandInfo.Name, commandInfo.ButtonText, commandInfo.Tooltip, commandInfo.UseOfficeResources, commandInfo.BitmapResourceId, ref context); TraceService.WriteLine("AddControl"); commandInfo.Command.AddControl(commandInfo.ParentCommand, commandInfo.Position); TraceService.WriteLine("Added"); this.commandInfos.Add(commandInfo); } catch (Exception exception) { TraceService.WriteLine("commandName=" + commandInfo.Name); TraceService.WriteLine("message=" + exception.Message); TraceService.WriteLine("stackTrace=" + exception.StackTrace); } }
/// <summary> /// Adds the commands. /// </summary> internal void AddCommands() { TraceService.WriteLine("Connect::AddCommands Version=" + this.ApplicationVersion); CommandBar commandBar = this.AddCommandBar("Ninja Coder for MvvmCross"); VSCommandInfo commandInfo = new VSCommandInfo { AddIn = this.AddInInstance, Name = "NinjaCoderforMvvmCrossAddProjects", ButtonText = "Add Projects", Tooltip = "Ninja Coder for MvvmCross Add Projects", Action = this.BuildProjects, ParentCommand = commandBar, Position = 1, BitmapResourceId = 183, }; this.AddMenuItem(commandInfo); commandInfo = new VSCommandInfo { AddIn = this.AddInInstance, Name = "NinjaCoderforMvvmCrossAddViewModel", ButtonText = "Add ViewModel and Views", Tooltip = "Ninja Coder for MvvmCross Add ViewModel and Views", Action = this.AddViewModelAndViews, ParentCommand = commandBar, Position = 2, BitmapResourceId = 303, }; this.AddMenuItem(commandInfo); commandInfo = new VSCommandInfo { AddIn = this.AddInInstance, Name = "NinjaCoderforMvvmCrossAddPlugins", ButtonText = "Add Plugins", Tooltip = "Ninja Coder for MvvmCross Add Plugins", Action = this.AddPlugins, ParentCommand = commandBar, Position = 3, BitmapResourceId = 450, }; this.AddMenuItem(commandInfo); commandInfo = new VSCommandInfo { AddIn = this.AddInInstance, Name = "NinjaCoderforMvvmCrossAddConverters", ButtonText = "Add Converters", Tooltip = "Ninja Coder for MvvmCross Add Converters", Action = this.AddConverters, ParentCommand = commandBar, Position = 4, BitmapResourceId = 450, }; this.AddMenuItem(commandInfo); commandInfo = new VSCommandInfo { AddIn = this.AddInInstance, Name = "NinjaCoderforMvvmCrossOptions", ButtonText = "Options", Tooltip = "Ninja Coder for MvvmCross Options", Action = this.ShowOptions, ParentCommand = commandBar, Position = 5, BitmapResourceId = 642 }; this.AddMenuItem(commandInfo); commandInfo = new VSCommandInfo { AddIn = this.AddInInstance, Name = "NinjaCoderforMvvmCrossHelp", ButtonText = "Help", Tooltip = "Ninja Coder for MvvmCross Help", Action = this.ShowHelp, ParentCommand = commandBar, Position = 6, BitmapResourceId = 1954, BeginGroup = true }; this.AddMenuItem(commandInfo); commandInfo = new VSCommandInfo { AddIn = this.AddInInstance, Name = "NinjaCoderforMvvmCrossAbout", ButtonText = "About", Tooltip = "Ninja Coder for MvvmCross About", Action = this.ShowAbout, ParentCommand = commandBar, Position = 7, BitmapResourceId = 0 }; this.AddMenuItem(commandInfo); }
/// <summary> /// Add item to the menu. /// </summary> /// <param name="vsCommandInfo">The command info.</param> protected virtual void AddMenuItem(VSCommandInfo vsCommandInfo) { TraceService.WriteLine("CommandManager::AddMenuItem Name=" + vsCommandInfo.Name); //// This try/catch block can be duplicated if you wish to add multiple commands to be handled by your Add-in, //// just make sure you also update the QueryStatus/Exec method to include the new command names. try { Commands2 commands = (Commands2)this.VsInstance.ApplicationObject.Commands; object[] context = { }; TraceService.WriteLine("AddMenuItem name=" + vsCommandInfo.Name); IEnumerable<Command> currentCommands = commands.Cast<Command>(); foreach (Command command in currentCommands .Where(command => command.Name.Contains(vsCommandInfo.Name))) { TraceService.WriteLine("Deleting Command already in memory name=" + vsCommandInfo.Name); command.Delete(); break; } TraceService.WriteLine("AddingCommand"); vsCommandInfo.Command = commands.AddNamedCommand2( vsCommandInfo.AddIn, vsCommandInfo.Name, vsCommandInfo.ButtonText, vsCommandInfo.Tooltip, vsCommandInfo.UseOfficeResources, vsCommandInfo.BitmapResourceId, ref context); TraceService.WriteLine("AddControl"); vsCommandInfo.Command.AddControl(vsCommandInfo.ParentCommand, vsCommandInfo.Position); TraceService.WriteLine("Added"); this.commandInfos.Add(vsCommandInfo); } catch (Exception exception) { TraceService.WriteLine("commandName=" + vsCommandInfo.Name); TraceService.WriteLine("message=" + exception.Message); TraceService.WriteLine("stackTrace=" + exception.StackTrace); } }
/// <summary> /// Add item to the menu. /// </summary> /// <param name="vsCommandInfo">The command info.</param> protected virtual void AddMenuItem(VSCommandInfo vsCommandInfo) { TraceService.WriteLine("CommandManager::AddMenuItem Name=" + vsCommandInfo.Name); //// This try/catch block can be duplicated if you wish to add multiple commands to be handled by your Add-in, //// just make sure you also update the QueryStatus/Exec method to include the new command names. try { Commands2 commands = (Commands2)this.VSInstance.ApplicationObject.Commands; object[] context = { }; TraceService.WriteLine("CommandManager::AddMenuItem Adding command name=" + vsCommandInfo.Name); IEnumerable<Command> currentCommands = commands.Cast<Command>(); foreach (Command command in currentCommands .Where(command => command.Name == vsCommandInfo.Name)) { TraceService.WriteLine("CommandManager::AddMenuItem Deleting Command already in memory name=" + vsCommandInfo.Name); command.Delete(); break; } vsCommandInfo.Command = commands.AddNamedCommand2( vsCommandInfo.AddIn, vsCommandInfo.Name, vsCommandInfo.ButtonText, vsCommandInfo.Tooltip, vsCommandInfo.UseOfficeResources, vsCommandInfo.BitmapResourceId, ref context); vsCommandInfo.Command.AddControl(vsCommandInfo.ParentCommand, vsCommandInfo.Position); this.commandInfos.Add(vsCommandInfo); } catch (ArgumentException exception) { //// If we are here, then the exception is probably because a command with that name //// already exists. If so there is no need to recreate the command and we can //// safely ignore the exception. TraceService.WriteLine("CommandManager::AddMenuItem ArgumentException"); TraceService.WriteLine("commandName=" + vsCommandInfo.Name); TraceService.WriteLine("message=" + exception.Message); TraceService.WriteLine("parameterName=" + exception.ParamName); TraceService.WriteLine("stackTrace=" + exception.StackTrace); } }
/// <summary> /// Add item to the menu. /// </summary> /// <param name="vsCommandInfo">The command info.</param> protected override void AddMenuItem(VSCommandInfo vsCommandInfo) { vsCommandInfo.Position = this.commandPosition; base.AddMenuItem(vsCommandInfo); this.commandPosition++; }