Wednesday, September 30, 2009

Visual Studio: Focus on what TODO

I built this visual studio macro to help with developing large projects, where I add many TODO comments. It helps me by focusing only on the remaining todo items of any given project, closing all files without. Written for C# solutions only.


  1. Iterates through the current solution and sub-projects
  2. Opens files and looks for the string "// TODO" with RegEx
  3. Keeps files open with this string, closes files without
  4. opens and focuses the Task List, which then lists all TODO items

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Imports System.Text.RegularExpressions

Public Module OpenAll

    Sub FocusOnTODO()
        Dim solution As Solution = DTE.Solution
        For Each prj As Project In solution.Projects
            IterateProjectFiles(prj.ProjectItems)
        Next
        DTE.ExecuteCommand("View.TaskList")
    End Sub

    Private Sub IterateProjectFiles(ByVal prjItms As ProjectItems)
        For Each file As ProjectItem In prjItms
            If file.IsOpen Then
                file.Document.Close()
            End If
            If file.SubProject IsNot Nothing Then
                TestFile(file)
                IterateProjectFiles(file.ProjectItems)
            ElseIf file.ProjectItems IsNot Nothing AndAlso file.ProjectItems.Count > 0 Then
                TestFile(file)
                IterateProjectFiles(file.ProjectItems)
            Else
                TestFile(file)
            End If
        Next
    End Sub

    Private Sub TestFile(ByVal file As ProjectItem)
        DTE.ExecuteCommand("View.SolutionExplorer")
        If file.Name.EndsWith(".cs") OrElse file.Name.EndsWith(".aspx") OrElse file.Name.EndsWith(".ascx") OrElse file.Name.EndsWith(".js") Then
            file.Open()
            file.Document.Activate()
            Dim sel As TextSelection = DTE.ActiveDocument.Selection
            sel.SelectAll()
            Dim documentText As String = sel.Text
            sel.StartOfDocument()

            If (Not Regex.IsMatch(documentText, "//([ ]+)?TODO", RegexOptions.IgnoreCase)) Then
                file.Document.Close()
            End If

        End If
    End Sub

End Module

Tuesday, September 29, 2009

Sort programs by name

  1. Click Start, click All Programs, and then right-click any folder or icon.
  2. On the shortcut menu, click Sort by Name.

Tweak UI 64bit (Not Itanium)