About Me

Training

Nothin But .Net Developer Bootcamp

Navigation

Search

Categories

On this page

Archive

Blogroll

 Agile Developer Venkat's Blog
 Ayende @ Blog
 B#
 Barry Gervin's Software Architecture Perspectives
 Boy Meets World
 Brad Abrams
 Canadian Developers
 Christopher Steen
 Claritude Software News
 Clemens Vasters: Enterprise Development and Alien Abductions
 Coding Horror
 Coding in an Igloo
 Dare Obasanjo aka Carnage4Life
 Darrell Norton's Blog [MVP]
 David Hayden [MVP C#]
 Don Box's Spoutlet
 Eric Gunnerson's C# Compendium
 EZWeb guy: Jeffrey Palermo [C# MVP]
 Fear and Loathing
 Generalities & Details: Adventures in the High-tech Underbelly
 Greg Young [MVP]
 Greg's Cool [Insert Clever Name] of the Day
 IanG on Tap
 Ingo Rammer's Weblog
 ISerializable - Roy Osherove's Blog
 James Kovacs' Weblog
 Jason Haley
 Jean-Luc David
 Jeremy D. Miller -- The Shade Tree Developer
 JetBrains .NET Tools Blog
 Jimmy Nilsson's weblog
 John Bristowe's Weblog
 John Papa [MVP C#]
 Jon Skeet's Coding Blog
 JonGalloway.ToString()
 Jump the Fence or Walk Around
 Lambda the Ultimate - Programming Languages Weblog
 Larkware News
 Lutz Roeder
 Marquee de Sells: Chris's insight outlet
 Martin Fowler's Bliki
 Mike Nichols - SonOfNun Technology
 MSDN Magazine - .NET Matters
 MSDN Magazine - All Articles
 OdeToCode Blogs
 Onion Blog
 Planet TW
 Raymond Lewallen [MVP]
 Rockford Lhotka
 RodMan's Corner
 Roger Johansson's blog
 Sahil Malik - blah.winsmarts.com
 Sam Gentile's Blog
 Scott Bellware [MVP]
 Scott Hanselman's Computer Zen
 ScottGu's Blog
 secretGeek
 Service Station, by Aaron Skonnard
 Signum sine tinnitu--by Guy Kawasaki
 Stephen Toub
 Steve Eichert's Blog
 Steven Rockarts
 The Blog Ride
 The Coding Hillbilly
 The Daily WTF
 TheServerSide.net: News
 Tim Gifford
 Vance Morrison's Weblog
 you've been HAACKED

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

RSS 2.0 | Atom 1.0 | CDF

Send mail to the author(s) E-mail

Total Posts: 385
This Year: 110
This Month: 0
This Week: 0
Comments: 973

 Monday, May 26, 2008
Monday, May 26, 2008 10:19:28 PM (Mountain Standard Time, UTC-07:00) ( General )

Hot on the heels of the Toronto course completion, one of the attendees (Michael Sevestre) just emailed me with a small update that fixes the issue on trying to reapply the macro to the name of the context when it is now inheriting from a base context class.

Thanks Michael, it is greatly appreciated!!

The update is below:

Imports System

Imports System.Windows.Forms
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics

Public Module CodeEditor

    Public Sub ReplaceSpacesInTestNameWithUnderscores()
        If DTE.ActiveDocument Is Nothing Then Return
        Dim wrCS As Boolean = DTE.Properties("TextEditor", "CSharp").Item("WordWrap").Value

        Try
            DTE.Properties("TextEditor", "CSharp").Item("WordWrap").Value = False
            Dim selection As TextSelection = CType(DTE.ActiveDocument.Selection(), EnvDTE.TextSelection)
            Dim index As Integer

            selection.SelectLine()
            If selection.Text = "" Then Return

            Dim methodIndex As Integer = selection.Text.IndexOf("public void ")
            Dim classIndex As Integer = selection.Text.IndexOf("public class ")
            Dim implementIndex As Integer = selection.Text.IndexOf(":")

            If (methodIndex < 0 AndAlso classIndex < 0) Then Return

            index = CType(IIf(methodIndex >= 0, methodIndex, classIndex), Integer)

            Dim prefix As String = CType(IIf(methodIndex >= 0, "public void ", "public class "), String)
            Dim whiteSpace As String = selection.Text.Substring(0, index)
            prefix = whiteSpace + prefix

            Dim description As String = selection.Text.Replace(prefix, String.Empty)

            'Find the ":" at the end of the line if defines
            Dim suffix As String = String.Empty
            If (implementIndex >= 0) Then
                suffix = selection.Text.Substring(implementIndex).Trim()
                description = description.Replace(suffix, String.Empty)
                suffix = String.Format(" {0}", suffix)
            End If

            description = description.Trim
            Dim text As String = prefix + description.Replace(" ", "_").Replace("'", "_") + suffix + vbCrLf
            selection.Delete()
            selection.Insert(text)
            selection.LineUp()
            selection.LineUp()
            selection.SelectLine()
            If selection.Text.Trim = "{" Or selection.Text.Trim = "}" Or selection.Text.Trim = "" Then
                If selection.Text.Trim = "{" Or selection.Text.Trim = "}" Then
                    selection.Insert(selection.Text.Replace(vbCrLf, "") + vbCrLf)
                ElseIf selection.Text.Trim = "" Then
                    selection.Delete()
                End If
            End If         
            selection.EndOfLine()
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            DTE.Properties("TextEditor", "CSharp").Item("WordWrap").Value = wrCS
        End Try
    End Sub
End Module

Monday, May 26, 2008 9:12:59 PM (Mountain Standard Time, UTC-07:00)
Hi Jean-Paul,

Have you thought about replacing this macro with an autohotkey script? I have an AHK script that I use to toggle "emacs-mode" on and off whenever I hit Caps Lock. It would be pretty straightforward to do a similar thing to toggle "spec naming mode" that replaces SPACE with underscores, and you could just toggle it on and off as required.

Regards,
David

PS: What are the odds of you doing a Nothin' But .NET course down here in Sydney, Australia one day?
PPS: My apologies if there are duplicates of this comment, had trouble with the form submission.
Tuesday, May 27, 2008 5:55:06 AM (Mountain Standard Time, UTC-07:00)
Hi JP,

Could you please point me to whatever tool you use to do just the opposite of this (replacing underscores with spaces) when generating the spec report to be shared with business users?

Thanks, and keep up the awesome work.

Tom
Tom
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):