Feb 15

Shortcuts vereinfachen das Leben gerade bei so mächtigen Tools wie dem Visual Studio 2008. Da ich allerdings meine paar Standards nutze und bei den anderen immer wieder suchen muss habe ich ein kleines Macro gefunden welches mir alle  aktuellen Shortcuts in eine html Datei exportiert. Wenn es noch interessiert der sollte weiter lesen.
 


 
   1:  Imports System
   2:  Imports EnvDTE
   3:  Imports EnvDTE90
   4:  Imports System.Diagnostics
   5:   
   6:   
   7:  Public Module ShowVisualStudio2008Shortcuts
   8:   
   9:   
  10:      Public Sub ListShortcutsInHTML()
  11:   
  12:   
  13:          'Declare a StreamWriter
  14:          Dim s As New System.IO.FileStream("c:\\VisualStudio2008ShortCuts.html", _
  15:               IO.FileMode.OpenOrCreate)
  16:          Dim sw As System.IO.StreamWriter
  17:          sw = New System.IO.StreamWriter(s)
  18:   
  19:   
  20:          'Write the beginning HTML
  21:          WriteHTMLStart(sw)
  22:   
  23:   
  24:          ' Add a row for each keyboard shortcut
  25:          For Each c As EnvDTE.Command In DTE.Commands
  26:   
  27:   
  28:              If c.Name <> "" Then
  29:                  Dim bindings As System.Array
  30:                  bindings = CType(c.Bindings, System.Array)
  31:   
  32:   
  33:                  For i As Integer = 0 To bindings.Length - 1
  34:                      sw.WriteLine("<tr>")
  35:                      sw.WriteLine("<td>" + c.Name + "</td>")
  36:                      sw.WriteLine("<td>" + bindings(i) + "</td>")
  37:                      sw.WriteLine("</tr>")
  38:                  Next i
  39:              End If
  40:          Next
  41:   
  42:   
  43:          'Write the end HTML
  44:          WriteHTMLEnd(sw)
  45:   
  46:   
  47:          'Flush and close the stream
  48:          sw.Flush()
  49:          sw.Close()
  50:      End Sub
  51:   
  52:   
  53:   
  54:   
  55:      Public Sub WriteHTMLStart(ByVal sw As System.IO.StreamWriter)
  56:          sw.WriteLine("<html>")
  57:          sw.WriteLine("<head>")
  58:          sw.WriteLine("<title>")
  59:          sw.WriteLine("Visual Studio Keyboard Shortcuts")
  60:          sw.WriteLine("</title>")
  61:          sw.WriteLine("</head>")
  62:          sw.WriteLine("<body>")
  63:          sw.WriteLine("<h1>Visual Studio 2005 Keyboard Shortcuts</h1>")
  64:          sw.WriteLine("<font size=""2"" face=""Verdana"">")
  65:          sw.WriteLine("<table border=""1"">")
  66:          sw.WriteLine("<tr BGCOLOR=""#018FFF""><td align=""center"">" & _
  67:                       "<b>Command</b></td><td align=""center"">" & _
  68:                       "<b>Shortcut</b></td></tr>")
  69:      End Sub
  70:   
  71:   
  72:   
  73:   
  74:      Public Sub WriteHTMLEnd(ByVal sw As System.IO.StreamWriter)
  75:          sw.WriteLine("</table>")
  76:          sw.WriteLine("</font>")
  77:          sw.WriteLine("</body>")
  78:          sw.WriteLine("</html>")
  79:      End Sub
  80:   
  81:   
  82:  End Module

Das Macro funktioniert auch in VS 2005. Den passenden Artikel dazu gibt es hier:
http://www.rene-paschold.de/post/Alle-Shortcuts-im-Visual-Studio-2005-anzeigen.aspx

Tags:

Kommentare

Dennis

Posted on Donnerstag, 25 Februar 2010 00:01

I adjusted your script a little for my purpose, maybe someone else finds the tweaks intersing as well.



Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics

Public Module ShowVisualStudio2008Shortcuts

    Public Sub ListShortcutsInHTML()

        'Declare Even-Odd-parameter
        Dim Even As Boolean
        Even = False

        'Declare a StreamWriter
        Dim s As New System.IO.FileStream("c:\\VisualStudio2008ShortCuts.html", IO.FileMode.OpenOrCreate)
        Dim sw As System.IO.StreamWriter
        sw = New System.IO.StreamWriter(s)

        'Write the beginning HTML
        WriteHTMLStart(sw)

        ' Add a row for each keyboard shortcut
        For Each c As EnvDTE.Command In DTE.Commands

            If c.Name <> "" Then
                Dim bindings As System.Array
                bindings = CType(c.Bindings, System.Array)

                If bindings.Length > 0 Then
                    For i As Integer = 0 To bindings.Length - 1
                        sw.Write("<tr class=""")
                        ' Set the CSS class "Even" for all even rows and "Odd" respective for all odd rows
                        If Even Then
                            sw.Write("Even")
                        Else
                            sw.Write("Odd")
                        End If
                        sw.WriteLine(""">")

                        'Add this cell only for the first time call of this particular array and add rowspan if neccessary
                        If i = 0 Then
                            sw.Write("<td")

                            If bindings.Length > 1 Then
                                sw.Write(" rowspan=""" + bindings.Length.ToString() + """ ")
                            End If
                            sw.WriteLine(">" + c.Name + "</td>")
                        End If

                        sw.WriteLine("<td>" + bindings(i) + "</td>")
                        sw.WriteLine("</tr>")
                    Next i
                    Even = Not Even
                End If
            End If
        Next

        'Write the end HTML
        WriteHTMLEnd(sw)

        'Flush and close the stream
        sw.Flush()
        sw.Close()
    End Sub

    Public Sub WriteHTMLStart(ByVal sw As System.IO.StreamWriter)
        sw.WriteLine("<html>")
        sw.WriteLine("<head>")
        sw.WriteLine("<meta http-equiv=""content-type"" content=""text/html; charset=ISO-8859-1"" />")
        sw.WriteLine("<title>")
        sw.WriteLine("Visual Studio Keyboard Shortcuts")
        sw.WriteLine("</title>")
        sw.WriteLine("<style type=""text/css"">")
        sw.WriteLine(".Odd { background-color:LightGrey }")
        sw.WriteLine(".Even { background-colorLaughingarkGrey }")
        sw.WriteLine("</style>")
        sw.WriteLine("</head>")
        sw.WriteLine("<body>")
        sw.WriteLine("<h1>Visual Studio 2008 Keyboard Shortcuts</h1>")
        sw.WriteLine("<font size=""2"" face=""Verdana"">")
        sw.WriteLine("<table border=""1"">")
        sw.WriteLine("<tr BGCOLOR=""#018FFF""><td align=""center"">" & _
          "<b>Command</b></td><td align=""center"">" & _
          "<b>Shortcut</b></td></tr>")
    End Sub

    Public Sub WriteHTMLEnd(ByVal sw As System.IO.StreamWriter)
        sw.WriteLine("</table>")
        sw.WriteLine("</font>")
        sw.WriteLine("</body>")
        sw.WriteLine("</html>")
    End Sub
End Module