3

In Visual Studio 2017 it is possible to work in a mode ‘Folder View’. This is the mode that runs when opening folder (File – Open – Folder...). You can also switch to it using the 'Solution Explorer' (switching from a 'Solution View' to 'Folder View').

Is it possible to programmatically determine (and if so, then how) what mode is enabled at the moment?

I saw the IVsSolutionEvents7 interface, which contains methods that are called, for example, when opening or closing a folder (File – Open – Folder / Close Folder), but have not found anything that would help in addressing the problem described above.

Thanks in advance for your help.

Sergey Vasiliev
  • 803
  • 8
  • 19

1 Answers1

3

You can use __VSPROPID7.VSPROPID_IsInOpenFolderMode on an IVsSolution reference, with a code like this:

var solution = (IVsSolution)ServiceProvider.GetService(typeof(SVsSolution));

// __VSPROPID7 needs Microsoft.VisualStudio.Shell.Interop.15.0.DesignTime.dll nuget
// folderMode will be a boolean
solution.GetProperty((int)__VSPROPID7.VSPROPID_IsInOpenFolderMode, out object folderMode);
Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
  • Thanks! Is it possible to detect switching between the ‘Folder view’ and ‘Solution view’ modes? – Sergey Vasiliev Feb 28 '18 at 16:49
  • @Nightwalker - You can cast solution into a IVsSolution7 and use its OpenFolder method. https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.shell.interop.ivssolution7.openfolder – Simon Mourier Feb 28 '18 at 17:02
  • 1
    Perhaps, I wasn't clear enough. I meant that I wanted to track the moment of user switching from ‘Folder View’ to ‘Solution View’. May be there are interfaces for this, in which the methods are defined, whose call occurs right when switching the modes. For example, in 'IVsSolutionEvents7' there are methods 'OnAfterOpenFolder' and 'OnBeforeCloseFolder', which are called when opening/closing a folder, but not when switching the mode in 'SolutionExplorer'. – Sergey Vasiliev Mar 01 '18 at 06:57
  • @Nightwalker - There are all the other IVsSolutionEvents that you can use, OnAfterOpenSolution, OnAfterCloseSolution. – Simon Mourier Mar 01 '18 at 07:25
  • 1
    These methods aren't called when switching from the mode 'Solution View' to 'Folder View' and vice versa. – Sergey Vasiliev Mar 02 '18 at 13:57