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:
- Add this method to the Connect class.
private void InitialiseHandlers() { this._openHandler = new OnOpenHandler(_applicationObject); }
- Add a call to InitialiseHandlers () in the OnStartupComplete method of the Connect class.
public void OnStartupComplete(ref Array custom) { InitialiseHandlers(); }
- 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.
Brody
source share