/// <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++; }
/// <summary> /// Adds the commands. /// </summary> internal void AddCommands() { TraceService.WriteLine("Connect::AddCommands"); 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, BitmapResourceId = 0, }; 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, BitmapResourceId = 0, }; 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, BitmapResourceId = 0, }; this.AddMenuItem(commandInfo); /*commandInfo = new VSCommandInfo { AddIn = this.AddInInstance, Name = "NinjaCoderforMvvmCrossAddServices", ButtonText = "Add Services", Tooltip = "Ninja Coder for MvvmCross Add Services", Action = this.AddServices, ParentCommand = commandBar, BitmapResourceId = 0, }; 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, BitmapResourceId = 0, }; this.AddMenuItem(commandInfo); commandInfo = new VSCommandInfo { AddIn = this.AddInInstance, Name = "NinjaCoderforMvvmCrossOptions", ButtonText = "Options", Tooltip = "Ninja Coder for MvvmCross Options", Action = this.ShowOptions, ParentCommand = commandBar, BitmapResourceId = 0 }; this.AddMenuItem(commandInfo); SettingsService settingsService = new SettingsService(); if (settingsService.ShowViewLogFileOnVisualStudioMenu) { commandInfo = new VSCommandInfo { AddIn = this.AddInInstance, Name = "NinjaCoderforMvvmCrossViewLogFile", ButtonText = "View Log File", Tooltip = "Ninja Coder for MvvmCross View Log File", Action = this.ViewLogFile, ParentCommand = commandBar, BitmapResourceId = 0 }; this.AddMenuItem(commandInfo); } if (settingsService.ShowClearLogFileOnVisualStudioMenu) { commandInfo = new VSCommandInfo { AddIn = this.AddInInstance, Name = "NinjaCoderforMvvmCrossClearLogFile", ButtonText = "Clear Log File", Tooltip = "Ninja Coder for MvvmCross Clear Log File", Action = this.ClearLogFile, ParentCommand = commandBar, BitmapResourceId = 0 }; this.AddMenuItem(commandInfo); } commandInfo = new VSCommandInfo { AddIn = this.AddInInstance, Name = "NinjaCoderforMvvmCrossAbout", ButtonText = "About", Tooltip = "Ninja Coder for MvvmCross About", Action = this.ShowAbout, ParentCommand = commandBar, BitmapResourceId = 0 }; this.AddMenuItem(commandInfo); TraceService.WriteLine("Connect::AddCommands Ended"); }
/// <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, 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, 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, BitmapResourceId = 450, }; this.AddMenuItem(commandInfo); /*commandInfo = new VSCommandInfo { AddIn = this.AddInInstance, Name = "NinjaCoderforMvvmCrossAddServices", ButtonText = "Add Services", Tooltip = "Ninja Coder for MvvmCross Add Services", Action = this.AddServices, ParentCommand = commandBar, 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, 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, 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, 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, BitmapResourceId = 0 }; this.AddMenuItem(commandInfo); TraceService.WriteLine("Connect::AddCommands Ended"); }
/// <summary> /// Add item to the menu. /// </summary> /// <param name="vsCommandInfo">The command info.</param> /// <returns>The command</returns> public 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); } }