Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable MRU behavior in VS2013 upon tab close

I have already remapped ctl+tab and ctl+shift+tab to Window.NextTab and Window.PreviousTab.

But when I call File.Close, Visual Studio 2013 still uses MRU to decide which tab to bring to the foreground, which usually results in focus jumping somewhere unepxected. I would like to change this behavior so that the tab right after the just-closed one (to the right in the tab well) is brought to the foreground (if it exists). This would make VS's behavior match that of ff, chrome, notepad++ etc.

I've tried a bunch of extensions, and while many of them change or create their own next / previous tab functions, none seems to make a new version of File.Close.

Does anyone know if this is possible or the identity of any extensions which do it?

like image 552
fastmultiplication Avatar asked Aug 26 '15 22:08

fastmultiplication


1 Answers

You can use the following command created in Visual Commander instead of File.Close to activate next tab after close:

public class C : VisualCommanderExt.ICommand
{
    public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package) 
    {
        dte = DTE;
        if (IsCommandAvailable("Window.NextTab"))
        {
            DTE.ExecuteCommand("Window.NextTab");
            DTE.ExecuteCommand("Window.PreviousTab");
        }
        if (IsCommandAvailable("File.Close"))
            DTE.ExecuteCommand("File.Close");
    }

    private bool IsCommandAvailable(string commandName)
    {
        EnvDTE80.Commands2 commands = dte.Commands as EnvDTE80.Commands2;
        if (commands == null)
            return false;

        EnvDTE.Command command = commands.Item(commandName, 0);
        if (command == null)
            return false;

        return command.IsAvailable;
    }

    private EnvDTE80.DTE2 dte;
}

Update A probably better implementation that prevents potential visual side effects:

public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package) 
{
    dte = DTE;
    if (IsCommandAvailable("Window.NextTab"))
    {
        EnvDTE.Window w = DTE.ActiveWindow;
        DTE.ExecuteCommand("Window.NextTab");
        w.Close();
    }
    else if (IsCommandAvailable("File.Close"))
        DTE.ExecuteCommand("File.Close");
}
like image 200
Sergey Vlasov Avatar answered Nov 15 '22 06:11

Sergey Vlasov