public SolutionViewModel(SolutionStateMachine slnMachine, WorkspaceStateMachine wsMachine, Action <string> writeLog, ISender <IRingCommand> commandQueue) { ThreadHelper.ThrowIfNotOnUIThread(); _writeLog = writeLog; _commandQueue = commandQueue; _wsMachine = wsMachine; _slnMachine = slnMachine; Configure(_slnMachine); var debugStartCmd = Dte.Commands.Item("Debug.Start"); _solutionEventsHandler = new SolutionsEventsHandler(Sln); _debuggerEventsHandler = new DebuggerEventsHandler(Debugger); _projStartDebugEvent = Dte.Events.CommandEvents["{" + VSConstants.VSStd2K + "}", (int)VSConstants.VSStd2KCmdID.PROJSTARTDEBUG]; _projStepIntoEvent = Dte.Events.CommandEvents["{" + VSConstants.VSStd2K + "}", (int)VSConstants.VSStd2KCmdID.PROJSTEPINTO]; _debugStartEvent = Dte.Events.CommandEvents[debugStartCmd.Guid, debugStartCmd.ID]; _debuggerEvents = Dte.Events.DebuggerEvents; _buildEvents = Dte.Events.BuildEvents; _buildEvents.OnBuildBegin += BuildBegin; _buildEvents.OnBuildDone += BuildDone; _buildEvents.OnBuildProjConfigBegin += ProjectBuildBegin; _buildEvents.OnBuildProjConfigDone += ProjectBuildDone; _projStepIntoEvent.BeforeExecute += DebugProjectsAdd; _projStartDebugEvent.BeforeExecute += DebugProjectsAdd; _debugStartEvent.BeforeExecute += DebugStart; _debuggerEvents.OnEnterDesignMode += DebugStop; _solutionEventsHandler.OnAfterOpen += Load; _solutionEventsHandler.OnAfterClose += Unload; _debuggerEventsHandler.OnProcessCreated += DebugProcessAdd; _debuggerEventsHandler.OnProcessRemoved += DebugRemove; _projectProcesses = new ProjectsProcesses(writeLog); //TODO: handle debug detach (probably kill detached the process - figure out how to get it - potentially get PID on creation) //TODO: handle clean up - what should happen if a project or whole solution is cleaned up? Should ring run in a degraded state (With "big exclamation marks" in the window) }
// ------------------------------------------------------ /// <summary> /// This method is called after the package is sited to perform any /// initialization that relies on Visual Studio services. /// </summary> protected override void Initialize() { base.Initialize(); // Add the command handlers for the menus and toolbars. OleMenuCommandService mcs = GetService( typeof(IMenuCommandService)) as OleMenuCommandService; if (mcs != null) { CommandID cmdID; // View / Other Windows / CxxTest Suites cmdID = new CommandID(Guids.CxxTestPackageCmdSet, (int)CommandIds.cmdidCxxTestViewWindow); mcs.AddCommand(new MenuCommand( new EventHandler(ShowCxxTestSuitesWindow_Invoked), cmdID)); // View / Other Windows / CxxTest Results cmdID = new CommandID(Guids.CxxTestPackageCmdSet, (int)CommandIds.cmdidCxxTestResultsWindow); mcs.AddCommand(new MenuCommand( new EventHandler(ShowCxxTestResultsWindow_Invoked), cmdID)); // <Solution Item> / Generate Test Suite... cmdID = new CommandID(Guids.CxxTestPackageCmdSet, (int)CommandIds.cmdidGenerateTests); mcs.AddCommand(new OleMenuCommand( new EventHandler(GenerateTests_Invoked), delegate { }, new EventHandler(GenerateTests_BeforeQueryStatus), cmdID)); } // Add the CxxTest and Dereferee includes and libraries paths to // the Visual C++ directories options if they're not already // there. AddIncludesAndLibrariesPaths(); // Initialize the solution build events listener. solutionBuildEvents = new SolutionBuildEventsHandler(); IVsSolutionBuildManager manager = (IVsSolutionBuildManager)GetService( typeof(SVsSolutionBuildManager)); manager.AdviseUpdateSolutionEvents( solutionBuildEvents, out solutionBuildCookie); // Listen for solution events. (We may want to switch this over to // VSIP interfaces in the future.) DTE dte = (DTE)GetService(typeof(DTE)); dte.Events.SolutionEvents.Opened += SolutionEvents_Opened; dte.Events.SolutionEvents.ProjectAdded += SolutionEvents_ProjectAdded; dte.Events.SolutionEvents.ProjectRemoved += SolutionEvents_ProjectRemoved; dte.Events.SolutionEvents.BeforeClosing += SolutionEvents_BeforeClosing; dte.Events.SolutionEvents.AfterClosing += SolutionEvents_AfterClosing; // Initialize the project documents tracking events handler. IVsTrackProjectDocuments2 trackDocs = GetTrackProjectDocuments(); trackProjectDocsEvents = new TrackProjectDocumentsEventsHandler(); trackDocs.AdviseTrackProjectDocumentsEvents( trackProjectDocsEvents, out trackProjectDocsCookie); // Initialize the debugger events handler. debuggerEvents = new DebuggerEventsHandler(); IVsDebugger debugger = (IVsDebugger)GetService(typeof(SVsShellDebugger)); debugger.AdviseDebuggerEvents(debuggerEvents, out debuggerCookie); }