Helixoft Blog

Peter Macej - lead developer of VSdocman - talks about Visual Studio tips and automation

Changing Documents Tabs Order in VS 2005

VS 2005 introduced new feature which confuses many people. Newly opened documents are placed in reverse order - to the left of already opened pages and not to the right as it used to be in VS 2002/2003 and as we know it from majority of programs that use tabbed interface. Existing documents are scrolled to the right. See MS Suggestion Page to see what I'm talking about.

Some people love this new feature while some hate it. MS has its arguments for this new design, see for example this forum. There are however reasons for traditional way too. For example, our VSdocman's Comment Editor can be placed as tabbed document.

Comment editor as tabbed document

Usually, user wants to have it on constant position and doesn't want it to be scrolled away. And of course, the biggest reason is personal attitude. I personally would appreciate if there was an option to turn this behavior on or off.

I searched for some add-in or macro that fixes this but couldn't find anything. So I tried to fix it myself. I must say that I haven't found a way how to do it perfectly with macro or add-in. You would probably need to create VSIP package. Despite this fact I created a macro that solves this problem. It causes VS 2005 to open new documents or tabbed tool windows to the right. It has the following issues:

  • Short flickering when new document is opened. It's because all existing document windows are redrawn.
  • After opening new document, VS forgets the order in which the documents had focus.
  • It ignores the order of documents if you manually moved them (drag-and-drop) to another position.

To create and apply this macro:

  1. Go to menu Tools - Macros - Macros IDE...
  2. In the Macros IDE Class View navigate to MyMacros - {} MyMacros - EnvironmentEvents. Open (double-click) EnvironmentEvents.
  3. Paste this code inside module (just before End Module line):
        Private timer As System.Threading.Timer
        Private ideTitle As String = Nothing
        Declare Auto Function SetWindowText Lib "user32" (ByVal hWnd As System.IntPtr, _
        ByVal lpstring As String) As Boolean
        '''<summary>Called when any window in VS gets activated.</summary>
        '''<param name="GotFocus">Window that got focus.</param>
        '''<param name="LostFocus">Window that lost focus.</param>
        Private Sub WindowEvents_WindowActivated(ByVal GotFocus As EnvDTE.Window, ByVal LostFocus As EnvDTE.Window) Handles WindowEvents.WindowActivated
                If timer Is Nothing Then
                    ' Create timer which refreshes the caption because
                    ' IDE resets the caption very often
                    Dim autoEvent As New System.Threading.AutoResetEvent(False)
                    Dim timerDelegate As System.Threading.TimerCallback = _
                        AddressOf tick
                    timer = New System.Threading.Timer(timerDelegate, autoEvent, 0, 200)
                End If
                If GotFocus.Document Is Nothing Then
                    ideTitle = Nothing
                    ideTitle = GotFocus.Document.FullName
                End If
            Catch ex As System.Exception
            End Try
        End Sub
        '''<summary>Called by timer.</summary>
        Public Sub tick(ByVal state As Object)
                If Not ideTitle Is Nothing Then
                End If
            Catch ex As System.Exception
            End Try
        End Sub
        '''<summary>Shows the title in main window.</summary>
        Private Sub showTitle(ByVal title As String)
            SetWindowText(DTE.MainWindow.HWnd, ideTitle & " - " & DTE.Name)
        End Sub
  4. That's all. Close macro IDE and restart VS.

How it works This macro is slightly different than macros I already described because it handles VS events. To do so, you must write it in special module: EnvironmentEvents. In this case we handle WindowEvents.WindowActivated event. We check if there was new tabbed window opened. If yes, we hide all old windows and then show them again (by setting Visible property). This will cause that they will appear to the left so the new document will be the right-most one.

As I wrote, this is not perfect solution but you can experiment with it. Let us know if you find something better.

# Peter Macej 2005-12-27 10:58
In fact, new files are displayed to the right only if there is room to show the tab. If not, VS doesn't show tabs that do not fit in the parent frame and you can see them only in Active Files drop-down list. So in this case, if you open new document, it is placed to the left. It seems it is not easy or even possible to change built-in tabs handling.

Comments are now closed for this entry


Start generating your .NET documentation now!
Free, fully functional trial