public DTE_Command FindCommand(string InName, DTE_Output InOutput) { EnvDTE.Command found = null; string fullName = mAddin.ProgID + "." + InName; EnvDTE.Commands commands = mMain.dte2.Commands; try { found = commands.Item(fullName, -1); } catch (Exception excp) { found = null; string xx = excp.ToString(); } if (found == null) { return(null); } else { return(new DTE_Command(mMain, found)); } }
public DTE_Commands GetCommands() { EnvDTE.Commands xx = mDte2.Commands; DTE_Commands cmds = new DTE_Commands(this, xx); return(cmds); }
/// <summary> /// Called when the AddIn is loaded. This method allows each of the commands to /// store member variables with the objects passed in and ensure that the menu /// items and commands have been properly added to the object model. /// </summary> /// <param name="application"> Root object in the application </param> /// <param name="connectMode"> 'Mode' in which the environment is starting up the addin </param> /// <param name="addIn"> Object representing this AddIn in the Object Model</param> public void OnConnection(EnvDTE._DTE application, Extensibility.ext_ConnectMode connectMode, EnvDTE.AddIn addIn) { try { m_applicationObject = (EnvDTE._DTE)application; m_addInInstance = (EnvDTE.AddIn)addIn; m_strCommandName = "AMDeleteCourse"; m_strName = AMResources.GetLocalizedString("AMDeleteCourseName"); m_strItemText = AMResources.GetLocalizedString("AMDeleteCourseItemText"); string description = AMResources.GetLocalizedString("AMDeleteCourseDescription"); EnvDTE.Commands commands = null; EnvDTE.Command command = null; _CommandBars officeCommandBars = null; CommandBar officeCommandBar = null; CommandBarControl officeCommandControl = null; CommandBar officeAcademic = null; object [] contextGuids; contextGuids = new object[] { }; commands = m_applicationObject.Commands; try { command = commands.AddNamedCommand(m_addInInstance, m_strCommandName, m_strName, description, false, 108, ref contextGuids, (int)(EnvDTE.vsCommandStatus.vsCommandStatusEnabled | EnvDTE.vsCommandStatus.vsCommandStatusSupported)); // Add the new command to the tools menu officeCommandBars = m_applicationObject.CommandBars; string amFacultyMenuItem = AMResources.GetLocalizedString("AMFacultyMenuItem"); try { officeAcademic = (CommandBar)officeCommandBars[amFacultyMenuItem]; } catch { } if (officeAcademic == null) { officeCommandBar = (CommandBar)officeCommandBars["Tools"]; officeAcademic = (CommandBar)m_applicationObject.Commands.AddCommandBar(amFacultyMenuItem, EnvDTE.vsCommandBarType.vsCommandBarTypeMenu, officeCommandBar, 1); } officeCommandControl = command.AddControl((object)officeAcademic, 1); officeCommandControl.Caption = m_strItemText; } catch { // Falling into this simply means that the command was already registered. } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Exception e = " + e.Message); } }
/// <summary> /// Adds (appends) a binding for the given shortcut /// </summary> /// <param name="commandName"></param> /// <param name="shortcutDef"></param> public void BindShortcut(string commandName, string shortcutDef) { DTE dte = (DTE)serviceProvider.GetService(typeof(DTE)); EnvDTE.Commands cmds = dte.Commands; //EnvDTE.Command shortCutCommand = DTECommands.Item(commandName); EnvDTE.Command shortCutCommand = cmds.Item(commandName); object[] newBindings = AppendKeyboardBinding(shortCutCommand, shortcutDef); shortCutCommand.Bindings = newBindings; }
/// <summary> /// Adds (appends) a binding for the given shortcut /// </summary> /// <param name="commandName"></param> /// <param name="shortcutDef"></param> public static void BindShortcut(string commandName, string shortcutDef) { // Make sure we're not using the Default keyboard mapping scheme DTE dte = (DTE)((IServiceProvider)package).GetService(typeof(DTE)); EnvDTE.Commands cmds = dte.Commands; Command cmd = cmds.Item(commandName); object[] newBindings = AppendKeyboardBinding(cmd, shortcutDef); cmd.Bindings = newBindings; }
public static Command Named(this EnvDTE.Commands commands, string canonicalName) { Command testCommand = null; foreach (Command c in commands) { if (c.Name.Equals(canonicalName)) { testCommand = c; } } return(testCommand); }
/// <summary> /// Note: Calling this is redundant if the original KeyBinding works in the vsct file. /// However, sometimes there is another command bound to the desired keybinding. /// In those cases, explicitly defining the key binding here is usually more effective. /// </summary> internal void UpdateKeyBindings() { // Make sure we're not using the Default keyboard mapping scheme DTE dte = (DTE)ServiceProvider.GetService(typeof(DTE)); Properties props = dte.Properties["Environment", "Keyboard"]; Property prop = props.Item("SchemeName"); prop.Value = "MyBindings.vsk"; EnvDTE.Commands cmds = dte.Commands; // Add a binding for ExpandSelection(TextEditor) { Command cmdToggleComment = cmds.Item("Edit.ToggleComment"); const string toggleCommentKeyBinding = "Text Editor::Ctrl+/"; cmdToggleComment.Bindings = (object)AppendKeyboardBinding(cmdToggleComment, toggleCommentKeyBinding); // Note: This overrides any key bindings already assigned to this command } // Add a binding for ExpandSelection(TextEditor) { Command cmdExpandSelection = cmds.Item("1023dc3d-550c-46b8-a3ec-c6b03431642c", 0x1022); // Edit.ExpandSelection const string expandSelectionKeyBinding = "Text Editor::Ctrl+W"; object[] newBindings = SingleKeyboardBinding(expandSelectionKeyBinding); cmdExpandSelection.Bindings = (object)newBindings; } { Command cmdToggleComment = cmds.Item("Edit.DuplicateSelection"); const string toggleCommentKeyBinding = "Text Editor::Ctrl+D"; cmdToggleComment.Bindings = AppendKeyboardBinding(cmdToggleComment, toggleCommentKeyBinding); cmdToggleComment = cmds.Item("Edit.DuplicateAndSelectOriginal"); const string toggleCommentKeyReverseBinding = "Text Editor::Ctrl+Shift+D"; cmdToggleComment.Bindings = AppendKeyboardBinding(cmdToggleComment, toggleCommentKeyReverseBinding); } // Add a binding for MoveMemberUp(TextEditor) { Command cmdMoveMemberUP = cmds.Item("Edit.MoveMemberUp", 0x1031); const string moveMemberUPKeyBinding = "Text Editor::Ctrl+Num 8"; cmdMoveMemberUP.Bindings = (object)AppendKeyboardBinding(cmdMoveMemberUP, moveMemberUPKeyBinding); } // Add a binding for MoveMemberDown(TextEditor) { Command cmdMoveMemberDown = cmds.Item("Edit.MoveMemberDown", 0x1032); const string moveMemberDownKeyBinding = "Text Editor::Ctrl+Num 2"; cmdMoveMemberDown.Bindings = (object)AppendKeyboardBinding(cmdMoveMemberDown, moveMemberDownKeyBinding); } }
// find a command in the commands collection public static EnvDTE.Command FindCommand(EnvDTE.Commands commands, string commandName) { // first find this command if it exists, then delete it System.Collections.IEnumerator enm = commands.GetEnumerator(); while (enm.MoveNext()) { Command cmd = (Command)enm.Current; if (cmd.Name == commandName) { return(cmd); } } return(null); // command not found }
/// <summary> /// Registers a command and places it on the Tools menu. /// </summary> public void OnConnection(EnvDTE._DTE application, Extensibility.ext_ConnectMode connectMode, EnvDTE.AddIn addIn) { m_applicationObject = (EnvDTE._DTE)application; m_addInInstance = (EnvDTE.AddIn)addIn; m_strCommandName = "AMRemoveCourse"; m_strName = AMResources.GetLocalizedString("AMRemoveCourseName"); m_strItemText = AMResources.GetLocalizedString("AMRemoveCourseItemText"); string strDescription = AMResources.GetLocalizedString("AMRemoveCourseDescription"); EnvDTE.Commands commands = null; EnvDTE.Command command = null; Microsoft.Office.Core._CommandBars officeCommandBars = null; Microsoft.Office.Core.CommandBar officeCommandBar = null; Microsoft.Office.Core.CommandBarControl officeCommandControl = null; Microsoft.Office.Core.CommandBar officeAcademic = null; object [] contextGuids; contextGuids = new object[] { }; commands = m_applicationObject.Commands; try { command = commands.AddNamedCommand(m_addInInstance, m_strCommandName, m_strName, strDescription, false, 108, ref contextGuids, (int)(EnvDTE.vsCommandStatus.vsCommandStatusEnabled | EnvDTE.vsCommandStatus.vsCommandStatusSupported)); // Add the new command to the tools menu officeCommandBars = m_applicationObject.CommandBars; string amStudentMenuItem = AMResources.GetLocalizedString("AMStudentMenuItem"); try { officeAcademic = (CommandBar)officeCommandBars[amStudentMenuItem]; } catch { } if (officeAcademic == null) { officeCommandBar = (CommandBar)officeCommandBars["Tools"]; officeAcademic = (CommandBar)m_applicationObject.Commands.AddCommandBar(amStudentMenuItem, EnvDTE.vsCommandBarType.vsCommandBarTypeMenu, officeCommandBar, 1); } officeCommandControl = command.AddControl((object)officeAcademic, 1); officeCommandControl.Caption = m_strItemText; } catch (System.Exception /*e*/) { // Falling into this simply means that the command was already registered. } }
public DTE_Menu AddMenuControl( string InMenuName, int InPositionInParent) { CommandBar subMenu = null; EnvDTE.Commands commands = mMain.Commandsx; subMenu = (CommandBar)commands.AddCommandBar( InMenuName, vsCommandBarType.vsCommandBarTypeMenu, mBar, InPositionInParent); return(new DTE_Menu(mMain, subMenu)); }
// add a command to the addin. // the added command will be assigned a full name from the progid of the addin. // VisualStudio will call the Exec function of the DLL of the addin when the command // is executed. // InAddinName : local name of the command within the addin. The full name is a // concat of the progid of the addin and this name. // InBitmapIx : index into collection of icon bitmaps of VisualStudio. // some values: public DTE_Command AddCommand( string InName, ButtonText InButtonText, string InToolTipText, int InBitmapIx) { int defaultCommandDisabled = 16; object[] contextUIGuid = new object[] { }; EnvDTE.Commands commands = mMain.dte2.Commands; EnvDTE.Command addedCmd = commands.AddNamedCommand( addin, InName, InButtonText.Text, InToolTipText, true, InBitmapIx, ref contextUIGuid, defaultCommandDisabled); return(new DTE_Command(mMain, addedCmd)); }
internal static bool BindingExists(string commandName, string shortcutDef) { DTE dte = (DTE)((IServiceProvider)package).GetService(typeof(DTE)); EnvDTE.Commands cmds = dte.Commands; // Find command Command cmd = cmds.Item(commandName); if (cmd == null) { return(false); } // Check if the binding is attached to it object[] existingBindings = (object[])cmd.Bindings; if (existingBindings == null) { return(false); } // Check if the keyboard binding is already there return(existingBindings.Contains(shortcutDef)); }
public static void Execute(this EnvDTE.Commands command, Enum commandId, object arg = null) { command.Raise(commandId.GetType().GUID.ToString(), Convert.ToInt32(commandId, CultureInfo.InvariantCulture), arg, IntPtr.Zero); }
public void RemoveMenuControl(DTE_Menu InSubMenu) { EnvDTE.Commands commands = mMain.Commandsx; commands.RemoveCommandBar(InSubMenu.mBar); }