Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the background colour of the toolbars and menus in Visual Studio depending on the path (branch) of the loaded solution?

I often have more than one copy of Visual Studio open looking at different branches of our software. The branch name is mapped to the folder in the file system that contains the solution file.

I wish to be able quickly tell the branch I am on, in a way that is hard to avoid seeing!

like image 459
Ian Ringrose Avatar asked Jul 20 '11 10:07

Ian Ringrose


People also ask

Which toolbar is used to change the background color?

Answer: To change the background of your graph, click in the space between the plot area and the edge of your graph. Then, click the Drawing toolbar's Fill Color tool and select a color from the palette. As soon as you do, Excel changes the background of your chart, filling it with the color you selected.


2 Answers

I don't think it's possible to conditionally change the menu/toolbar colors in Visual Studio based on the currently loaded solution. The nifty Visual Studio Color Theme Editor does give you a way to change the color scheme of the entire environment, but it doesn't support the kind of fine-grained control that you're looking for. All instances of Visual Studio will have the same color scheme applied to them.

The only thing I know of that might do what you want is Microsoft's Productivity Power Tools extension. Among dozens of features (most all of which you can turn off if you don't like them or they conflict with other extensions that you already have installed), it also supports extensive customization of the tabs (what they term the "Tab Well UI").

Specifically, it allows you to "color tabs according to their project or according to regular expressions":

This option permits tabs to be colored according to the project they belong to. This is particularly useful when sorting tabs by project, as it allows you to immediately identify different groups of project documents. You can also configure regular expressions and assign a color to each one. If the name of a tab matches the configured regular expression, it will be colored with the assigned color.

Here's a sample screenshot of some random tabs open, sorted and colored by project:

I haven't personally tried configuring this to work with multiple simultaneous instances of Visual Studio, but I've been using it for a few weeks now (albeit with the regular expression-style highlighting, rather than by project), and it seems to be reasonably stable and configurable. I like being able to distinguish between the various types of open files at a glance.

like image 139
Cody Gray Avatar answered Nov 15 '22 04:11

Cody Gray


If you heavily work with branches, one of the most frustrating error you can do is modify the wrong branch. I have a project composed by several solution each one containing different UI Projects, each one using WCF as back end but released as separate software. Whenever we do a release of a new version of one of the UI we create a branch, so we can support hotfix, SP, etc.

A simple solution is creating a Visual Studio Macro (http://www.helixoft.com/blog/archives/32) that uses a Regex to parse the fullpath of the solution file, searching for a specific folder structure that identify a Branch. Here is the full code:

Declare Auto Function SetWindowText Lib "user32" (ByVal hWnd As System.IntPtr, _
                                                  ByVal lpstring As String) As Boolean


Private Sub showTitle(ByVal title As String)
    SetWindowText(New System.IntPtr(DTE.MainWindow.HWnd), title & " - " & DTE.Name)
End Sub


Private Sub SolutionEvents_Opened() Handles SolutionEvents.Opened
    Dim m As Match = Regex.Match( _
        DTE.Solution.FullName, _
        "Branch.*\\(?<project>.*)\\(?<branch>.*)\\(?<sln>.*)\.sln", _
        RegexOptions.IgnoreCase)
    If (m.Success) Then
        Dim project As String = m.Groups("project").Value
        Dim version As String = m.Groups("branch").Value
        Dim sln As String = m.Groups("sln").Value
        showTitle(String.Format("BRANCH [{0}] - Project {1} - {2}", _
                                version, project, sln))

    End If
End Sub

You need to paste this code in the Macros editor, opened from Tools –> Macros –> Macros IDE

From the opened editor you just double click on MyMacros, expand the EnvironmentEvents, and you can add your code to every handler supported from Visual Studio.

If you look at the code, I’ve simply put a regex that permits me to parse the typical branch path structure I have on my projects, where I have Branch\someothertext\nameoftheproject\branchnumber\solutionfile.sln.

HTH Cheers, Tarun

like image 36
Tarun Arora Avatar answered Nov 15 '22 04:11

Tarun Arora