/// <summary> /// Must run on main UI thread /// </summary> public static void PrintoutKeyboardShortcut(bool showOutputPane, string macroName, string keyboardShortcut) { IEnvDteWrapper dte = Shell.Instance.GetComponent <IEnvDteWrapper>(); try { IEnvDteCommand command = dte.Commands.TryGetCommand(macroName); if (command != null) { object[] currentBindings = command.Bindings; if (currentBindings.Length > 0) { //if (currentBindings[0].ToString() == keyboardShortcut) foreach (object t in currentBindings) { GetOutputWindowPane(dte, "TestCop", showOutputPane).OutputString( $"TestCop keyboard shortcut for '{macroName}' is set to '{t}'\n"); } return; } GetOutputWindowPane(dte, "TestCop", showOutputPane).OutputString( $"Within Visual Studio - please map testCop keyboard shortcut for '{macroName}' to '{keyboardShortcut}'\n"); } } catch (Exception e) { GetOutputWindowPane(dte, "TestCop", showOutputPane).OutputString( "Error on setting '{0}' to '{1}. Ex={2}'\n".FormatEx(macroName, keyboardShortcut, e)); Logger.LogException(e); } }
/// <summary> /// Must run on main UI thread /// </summary> public static void AssignKeyboardShortcutIfMissing(bool showOutputPane, string macroName, string keyboardShortcut) { IEnvDteWrapper dte = Shell.Instance.GetComponent <IEnvDteWrapper>(); try { IEnvDteCommand command = dte.Commands.TryGetCommand(macroName); if (command != null) { object[] currentBindings = command.Bindings; if (currentBindings.Length > 0) { foreach (object t in currentBindings) { Logger.LogMessage( $"Note that the TestCop keyboard shortcut for '{macroName}' is already set to '{t}'\n"); //GetOutputWindowPane(dte, "TestCop", showOutputPane).OutputString($"TestCop keyboard shortcut for '{macroName}' is already set to '{currentBindings[i]}'\n"); } return; } command.Bindings = string.IsNullOrEmpty(keyboardShortcut) ? new object[] { } : new object[] { keyboardShortcut }; Logger.LogMessage($"TestCop is setting keyboard shortcut for '{macroName}' to '{keyboardShortcut}'\n"); GetOutputWindowPane(dte, "TestCop", showOutputPane).OutputString( $"TestCop is setting keyboard shortcut for '{macroName}' to '{keyboardShortcut}'\n" ); } } catch (Exception e) { GetOutputWindowPane(dte, "TestCop", showOutputPane).OutputString( "Error on setting '{0}' to '{1}. Ex={2}'\n".FormatEx(macroName, keyboardShortcut, e)); Logger.LogException(e); } }