Is there a way to specify a summary of the default values ​​in Visual Studio 2008 so that the file opens with the members crashing by default?

What I would like to do is have VS2008, when I open the code file, by default all members of the classes / interfaces are collapsed (including, in particular, any XML documentation and comments).

I don’t want to use regions at all.

I would also like to use ctrl + m, ctrl + l chord to switch all outline elements (for example, if everything is collapsed, I would like it to expand all members, but not XML comments or documentation).

Possible? How?

+7
visual-studio outlining
source share
4 answers

Yes for part 1.

Not sure about part 2.

In order for VS2008 to automatically open files in the Collapsed state, you need to create an addin to run "Edit.CollapsetoDefinition" when you open each document.

This is not too complicated. The hard part seems to be that you need to run the code a few milliseconds after the document is really open, so you need to use the thread pool for this.

  • Create an Addin project for VS2008.
  • Add this code (see below) to the end of the OnConnection method of the Connect class.
switch (connectMode) { case ext_ConnectMode.ext_cm_UISetup: case ext_ConnectMode.ext_cm_Startup: //Do nothing OnStartup will be called once IDE is initialised. break; case ext_ConnectMode.ext_cm_AfterStartup: //The addin was started post startup so we need to call its initialisation manually InitialiseHandlers(); break; } 
  1. Add this method to the Connect class.
 private void InitialiseHandlers() { this._openHandler = new OnOpenHandler(_applicationObject); } 
  1. Add a call to InitialiseHandlers () in the OnStartupComplete method of the Connect class.
 public void OnStartupComplete(ref Array custom) { InitialiseHandlers(); } 
  1. Add this class to the project.
 using System; using System.Collections.Generic; using System.Text; using EnvDTE80; using EnvDTE; using System.Threading; namespace Collapser { internal class OnOpenHandler { DTE2 _application = null; EnvDTE.Events events = null; EnvDTE.DocumentEvents docEvents = null; internal OnOpenHandler(DTE2 application) { _application = application; events = _application.Events; docEvents = events.get_DocumentEvents(null); docEvents.DocumentOpened +=new _dispDocumentEvents_DocumentOpenedEventHandler(OnOpenHandler_DocumentOpened); } void OnOpenHandler_DocumentOpened(EnvDTE.Document document) { if (_application.Debugger.CurrentMode != dbgDebugMode.dbgBreakMode) { ThreadPool.QueueUserWorkItem(new WaitCallback(Collapse)); } } private void Collapse(object o) { System.Threading.Thread.Sleep(150); _application.ExecuteCommand("Edit.CollapsetoDefinitions", ""); } } } 

And now all open files should be completely collapsed.

+5
source share

It would be much easier to use Visual Studio macros to do the same. Editing the EnvironmentEvents macro in MyMacros and adding a handler for DocumentEvents.DocumentOpened with:
DTE.ExecuteCommand ("Edit.CollapsetoDefinitions")

0
source share

I tried to develop some kind of Visual Basic code for the macro myself, borrowing from different places and could not get anything to work. So what have I done? Why, I asked a question on StackOverflow, of course! Having received the answer, I added the proposed code to my EnvironmentEvents macro, and now, when I open the CS files, in about a second all my definitions collapse. :)

0
source share

A quick way to collapse all expositions of definition functions is to click: Contextmenu * button (next to the right mouse button) *, L, O

I use it all the time. If there is a real hotkey for this, tell me :)

0
source share

All Articles