Why am I writing this: Your macro extracting the shortcuts caught my
attention. Where did you get it? I found one at
http://www.codinghorror.com/blog/archives/000412.html which is working
fine, but the output is missing some kind of readability (icons too
large). Is yours better?
I wrote it myself, and it's probably uglier. It's pretty much a dump only a
program could love. After it writes to the Output window I copy and paste it
into Excel and pretty it up from there.
Here (pardon the crappy formatting; blame OE):
Imports System.Collections.Generic
Friend Class KeyboardBinding
Private _chord As String = String.Empty
Public Property Chord() As String
Get
Return _chord
End Get
Set(ByVal value As String)
If value Is Nothing Then
_chord = String.Empty
Else
_chord = value
End If
End Set
End Property
Private _keystroke As String
Public Property Keystroke() As String
Get
Return _keystroke
End Get
Set(ByVal value As String)
If value Is Nothing Then
_keystroke = String.Empty
Else
_keystroke = value
End If
End Set
End Property
Private _scope As String = String.Empty
Public Property Scope() As String
Get
Return _scope
End Get
Set(ByVal value As String)
If value Is Nothing Then
_scope = String.Empty
Else
_scope = value
End If
End Set
End Property
Public Sub New()
End Sub
Public Sub New(ByVal source As String)
If source Is Nothing Then
Throw New ArgumentNullException("source")
End If
Dim scopePos As Integer = source.IndexOf("::")
If scopePos > 0 Then
_scope = source.Substring(0, scopePos)
Dim chordPos As Integer = source.IndexOf(", ", scopePos + 2)
If chordPos > 0 Then
' Yes, this is a chord
_chord = source.Substring(scopePos + 2, chordPos - scopePos - 2)
_keystroke = source.Substring(chordPos + 2)
Else
' No, this is not a chord, just a bare keystroke
_keystroke = source.Substring(scopePos + 2)
End If
End If
End Sub
End Class
Function GetOutputWindowPane(ByVal Name As String, Optional ByVal show As
Boolean = True) As OutputWindowPane
' I stole this from the Samples.Utilities module because I don't know how to
reference other modules
Dim window As Window
Dim outputWindow As OutputWindow
Dim outputWindowPane As OutputWindowPane
window = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput)
If show Then window.Visible = True
outputWindow = window.Object
Try
outputWindowPane = outputWindow.OutputWindowPanes.Item(Name)
Catch e As System.Exception
outputWindowPane = outputWindow.OutputWindowPanes.Add(Name)
End Try
outputWindowPane.Activate()
Return outputWindowPane
End Function
Sub ShowCommands()
Dim out As OutputWindowPane = GetOutputWindowPane("Commands", True)
out.Clear()
Dim cmdList As New SortedDictionary(Of String, Command)
' This counter is needed to make duplicate command names unique in the
dictionary
Dim counter As Integer = 1
For Each cmd As Command In DTE.Commands
If cmd.Name.Length > 0 Then
cmdList.Add(cmd.Name & counter.ToString("00000"), cmd)
counter += 1
End If
Next
out.OutputString(String.Format("Name{0}Scope{0}Chord{0}Keystroke{1}", vbTab,
Environment.NewLine))
For Each cmd As Command In cmdList.Values
Dim shortcuts As New List(Of KeyboardBinding)
Dim bindingObj As Object() = CType(cmd.Bindings, System.Array)
If bindingObj.Length > 0 Then
For Each sc As Object In bindingObj
Dim kb As New KeyboardBinding(sc.ToString())
out.OutputString(String.Format("{0}{5}{1}{5}{2}{5}{3}{4}", _
cmd.Name, kb.Scope, kb.Chord, kb.Keystroke, Environment.NewLine, vbTab))
Next
Else
out.OutputString(String.Format("{0}{1}", cmd.Name, Environment.NewLine))
End If
Next
End Sub