Pablo Picasso
"Computers are useless. They can only give you answers."
My Latest Tweets
Tags

This will be shown to users with no Flash or Javascript.
Calendar
<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910
Disclaimer

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

Sign in

Some time ago, while reinstalling StyleCop for ReSharper, I had to restart Visual Studio in order to reload the add-in. I then realised that restarting VS actually requires quite a lot of ‘clicking’ around. First you have to exit the editor, then you need to launch Visual Studio again and finally you have to re-open the solution you were working on just before you closed the IDE. This did not seem very efficient and, a quick macro later, I had a way to restart VS easily with one single click.

Public Sub RestartVisualStudio()
    Dim solution As String = DTE.Solution.FullName
    DTE.Solution.Close(True)
 
    If String.IsNullOrEmpty(solution) Then
        solution = String.Empty
    Else
        solution = """ """ & solution
    End If
 
    Dim process As System.Diagnostics.Process = New System.Diagnostics.Process()
    Dim arguments As String = "/c start """" /high """ & DTE.FullName & solution & """ /nosplash"
    process.StartInfo = New ProcessStartInfo("cmd.exe", arguments)
    process.StartInfo.UseShellExecute = False
    process.StartInfo.CreateNoWindow = True
    process.Start()
 
    DTE.Quit()
End Sub

As restarting VS is not something I do that often, I just added a restart button on my custom toolbar.

Restart Visual Studio

Ok. I promise this is my last post on Visual Studio macros… for 2009 :)

In my previous post I mentioned that I  usually work in full screen mode with all the toolbars removed to maximise the amount of code I can see on the screen. To activate full screen mode I just type Shift + Alt + Enter. Note that you can also squeeze in that little extra space by disabling the scrollbars under Tools > Options > Text Editor.

Visual Studio scrollbars options

However after you’ve built your solution, tracked a file within Solution Explorer and inspected a class using the ReSharper File Structure window, you end up with a fairly ‘dirty’ screen.

Visual Studio dirty full screen

All that viewing space is now lost! One solution is to set all the windows to ‘Auto Hide’. However since I find this feature rather annoying (in most cases) I tend to pin down all my working windows and therefore I need another way to recover that viewing space. As usual a small macro can do the trick. The macro below simply closes any active tool window that is currently opened.

Public Sub CloseAllToolWindows()
	Dim items As EnvDTE.Windows = DTE.Windows
	Dim item As Window

	For Each item In items
		If item.Kind.Equals("Tool") And item.Visible Then
			item.Close()
		End If
	Next
End Sub

 

Once bound to a keyboard shortcut, Alt + S in my case, I can run it and enjoy my full screen again!

Full Screen Mode

As I tend to work mainly in full screen mode within Visual Studio with all toolbars closed, I use shortcuts quite extensively to execute standard IDE and ReSharper commands. Fortunately most commands already have shortcuts associated to them. However there are a few that I need to either map to new shortcuts or rebind to different key combination.

Below are my custom keyboard mappings:

Command Shortcut
Build.BuildSelection Shift + F6
Edit.LineOpenAbove Shift + Enter
Edit.ToggleWordWrap Alt + W
File.CloseAllButThis Ctrl + \
Macros.MyMacros.TBF.CloseAllToolWindows Alt + S
Macros.MyMacros.TBF.DecreaseTextEditorFontSize Alt + [
Macros.MyMacros.TBF.IncreaseTextEditorFontSize Alt + ]
Macros.MyMacros.TBF.RemoveRegions Ctrl + Shift + #
ReSharper.CollapseInSolutionExplorerAction Ctrl + `
ReSharper.Generate Alt + I
ReSharper.GotoNextErrorInSolution Alt + 0
ReSharper.MoveDown Ctrl + Left Windows, Ctrl + Down Arrow
ReSharper.MoveLeft Ctrl + Left Windows, Ctrl + Left Arrow
ReSharper.MoveRight Ctrl + Left Windows, Ctrl + Right Arrow
ReSharper.MoveUp Ctrl + Left Windows, Ctrl + Up Arrow
TestDriven.NET.RunTests F8
TestDriven.NET.RerunTests Shift + F8

 

To change your keyboard binding in Visual Studio, follow the steps below:

  1. Go to Tools > Options > Keyboard.
  2. Select the command you would like to bind to (e.g. Macros.Samples.Accessibility.DecreaseTextEditorFondSize).
  3. Select Text Editor or Global where appropriate.
  4. Enter your shortcut key (e.g. Alt + [).
  5. Click on Assign.

 Decrease text font size key binding

Once you’ve assigned all your keyboard shortcuts simply click OK and you’re done!

As I was running a macro to increase or decrease the text font size (see previous post), I noticed that the macro balloon kept on flashing in the system tray. The reason for this is that in Visual Studio 2008, a balloon tip is shown every time you run a macro, until you click on it 5 times that is. Thereafter it will be no longer visible. The problem is that your macro might be running too quickly, giving you no time to click on it. For some background on this and why it is behaving like this by design, read Stopping the “Click here balloon” by Craig Skibo.

macro_balloon  

While I sort of understand why the VS team did this, I actually don’t care much for this feature. So I thought I’ll disable it altogether. This is easily done by adding a new registry key (HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\DontShowMacrosBalloon) and setting its value to 6. Note that you will still see the spinning cassette icon in the system tray but this is a lot less intrusive.

Instead of doing this manually I wrote a macro to disable this feature as otherwise I’ll probably forget I ever done this.

' Suppresses the macros balloon.
Public Sub DontShowMacrosBalloon()
	Dim key As Microsoft.Win32.Registry Key
	Dim subKey As Microsoft.Win32.Registry Key

	key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\VisualStudio\9.0", True)
	If (Not key Is Nothing) Then
		subKey = IIf(key.OpenSubKey("DontShowMacrosBalloon") Is Nothing, key.CreateSubKey("DontShowMacrosBalloon"), key.OpenSubKey("DontShowMacrosBalloon"))
		key.SetValue("DontShowMacrosBalloon", "00000006", Microsoft.Win32.RegistryValueKind.DWord)
		subKey.Close()
		key.Close()
	End If
End Sub

Should you ever want to re-enable it, simply delete the registry key or run the macro below:

' Enables the macros balloon simply by deleting the key
Public Sub ShowMacrosBalloon()
	Dim key As Microsoft.Win32.RegistryKey

	key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\VisualStudio\9.0", True)
	If (Not key Is Nothing) Then
		key.DeleteValue("DontShowMacrosBalloon", False)
		key.Close()
	End If
End Sub

Warning
The macros above modify the Registry and therefore the usual precautions apply.

The other day I grew increasingly frustrated with the amount of code I could or rather couldn’t see on my screen at work, even when working in full screen mode. I therefore wanted to write a Visual Studio macro to zoom in and out of the text editor. However while browsing through the sample macros that come with Visual Studio 2008, I found two macros that are doing just what I wanted: DecreaseTextEditorFontSize and IncreaseTextEditorFontSize. To check whether they are installed on your machine, simply go to Tools > Macros > Macro Explorer or type in ALT + F8 and then drill down to Macros > Accessibility.

Macro Explorer: Decrease Increase Text Editor Font Size 

Here is the Visual Basic code (after I changed fontSizeIncrement from 2 to 1):

' Set the font size increment and minimum font size
Private Const fontSizeIncrement As Integer = 1
Private Const minimumSupportedEditorSize As Integer = 3

' Increases the font size used within the editor.
Public Sub IncreaseTextEditorFontSize()
	Dim textEditorFontsAndColors As Properties

	textEditorFontsAndColors = DTE.Properties(“FontsAndColors”, “TextEditor”)
	textEditorFontsAndColors.Item(“FontSize”).Value += fontSizeIncrement
End Sub

' Decreases the font size used within the editor.
Public Sub DecreaseTextEditorFontSize()
	Dim textEditorFontsAndColors As Properties
	Dim fontSize As [Property]

	textEditorFontsAndColors = DTE.Properties(“FontsAndColors”, “TextEditor”)
	fontSize = textEditorFontsAndColors.Item(“FontSize”)
	If fontSize.Value >= minimumSupportedEditorSize Then
		fontSize.Value -= fontSizeIncrement
	End If
End Sub

If you don’t have the Visual Studio samples, follow the steps below to add these two macros:

  1. Open the Macro IDE (Tools > Macros > Macro IDE or ALT + F11).
  2. In Project Explorer, right-click on My Macros and select Add New Item…
  3. In the Add New Item… dialog, choose Module, give it a name (e.g. MyModule) and click Add.
  4. Simply copy and paste the code above in the newly added module.
  5. Save and close the Macro IDE.

 Add new module

All I had to do after that was to bind these macros to a keyboard shortcut. I chose ALT + [ to decrease the text font size and ALT + ] to increase it.

 Decrease text font size key binding

Now, I can easily zoom code in and out in the Visual Studio Text Editor.