///-------------------------------------------------------------------------------- /// <summary>This method handles opening a solution builder solution when an output /// solution is opened.</summary> ///-------------------------------------------------------------------------------- private void CheckOpenCurrentSolution() { try { SolutionBuilderWindow window = this.FindToolWindow(typeof(SolutionBuilderWindow), 0, false) as SolutionBuilderWindow; if (window != null) { if (ApplicationObject.Solution.FullName != string.Empty) { window.Control.TreeViewModel.SolutionsFolder.CheckOpenCurrentSolution(System.IO.Path.GetDirectoryName(ApplicationObject.Solution.FullName)); IVsWindowFrame frame = window.Frame as IVsWindowFrame; if (frame == null) { throw new COMException(this.GetResourceString("@102")); } // Bring the tool window to the front and give it focus ErrorHandler.ThrowOnFailure(frame.Show()); } } } catch (System.Exception ex) { // put exception message in output pane SolutionBuilderPane.OutputString(ex.Message); } }
///-------------------------------------------------------------------------------- /// <summary>This method launches the solution updater to update the solution.</summary> ///-------------------------------------------------------------------------------- private void UpdateSolution() { try { // Get the instance number 0 of this tool window. This window is single instance so this instance // is actually the only one. // The last flag is set to true so that if the tool window does not exists it will be created. SolutionBuilderWindow window = this.FindToolWindow(typeof(SolutionBuilderWindow), 0, false) as SolutionBuilderWindow; if (window == null) { SolutionUpdaterPane.OutputString("Please open the Solution Builder window prior to updating the solution."); } else { // wire up solution builder window events //window.Control.ProgressChanged += new SolutionBuilderControl.StatusChangeEventHandler(SolutionBuilderControl_ProgressChanged); //window.Control.StatusChanged += new SolutionBuilderControl.StatusChangeEventHandler(SolutionBuilderControl_StatusChanged); //window.Control.OutputChanged += new SolutionBuilderControl.StatusChangeEventHandler(SolutionBuilderControl_OutputChanged); //window.Control.OpenOutputSolutionRequested += new SolutionBuilderControl.SolutionEventHandler(SolutionBuilderControl_OpenOutputSolutionRequested); //window.Control.ShowSolutionDesignerRequested += new SolutionBuilderControl.SolutionEventHandler(SolutionBuilderControl_ShowSolutionDesignerRequested); // execute the solution updater SolutionUpdaterPane.Clear(); if (ApplicationObject.Solution != null && ApplicationObject.Solution.FullName != String.Empty) { string solutionDir = System.IO.Path.GetDirectoryName(ApplicationObject.Solution.FullName); SolutionViewModel solutionView = window.Control.TreeViewModel.SolutionsFolder.CheckOpenCurrentSolution(solutionDir); if (solutionView != null) { solutionView.UpdateOutputSolution(); } // put solution updater output to output pane SolutionUpdaterPane.OutputString("Solution update complete."); } } } catch (System.Exception ex) { // put exception message in output pane SolutionUpdaterPane.OutputString(ex.Message); } }
///-------------------------------------------------------------------------------- /// <summary>This method determines if visual studio can close.</summary> ///-------------------------------------------------------------------------------- public int get_CanClose(out bool pfCanClose) { pfCanClose = true; try { // cancel close if either solution designer or solution builder cannot close SolutionDesignerWindow solutionDesigner = this.FindToolWindow(typeof(SolutionDesignerWindow), 0, false) as SolutionDesignerWindow; if (solutionDesigner != null) { if (solutionDesigner.CanClose() == false) { pfCanClose = false; return(VSConstants.E_ABORT); } solutionDesigner.Control.DesignerView.CloseNoPromptAllItems(); IVsWindowFrame windowFrame = (IVsWindowFrame)solutionDesigner.Frame; windowFrame.Hide(); } SolutionBuilderWindow solutionBuilder = this.FindToolWindow(typeof(SolutionBuilderWindow), 0, false) as SolutionBuilderWindow; if (solutionBuilder != null) { if (solutionBuilder.CanClose() == false) { pfCanClose = false; return(VSConstants.E_ABORT); } solutionBuilder.Control.CloseAllSolutions(true); IVsWindowFrame windowFrame = (IVsWindowFrame)solutionBuilder.Frame; windowFrame.Hide(); } } catch (System.Exception ex) { // put exception message in output pane SolutionBuilderPane.OutputString(ex.Message); } return(VSConstants.S_OK); }
///-------------------------------------------------------------------------------- /// <summary> /// This function is called when the user clicks the menu item that shows the /// tool window. See the Initialize method to see how the menu item is associated to /// this function using the OleMenuCommandService service and the MenuCommand class. /// </summary> ///-------------------------------------------------------------------------------- private void ShowSolutionBuilderWindow(object sender, EventArgs e) { try { // show solution builder SolutionBuilderPane.Clear(); // Get the instance number 0 of this tool window. This window is single instance so this instance // is actually the only one. // The last flag is set to true so that if the tool window does not exists it will be created. SolutionBuilderWindow window = this.FindToolWindow(typeof(SolutionBuilderWindow), 0, false) as SolutionBuilderWindow; if (window == null) { window = this.CreateToolWindow(typeof(SolutionBuilderWindow), 0) as SolutionBuilderWindow; if ((null == window) || (null == window.Frame)) { throw new NotSupportedException(Resources.CanNotCreateWindow); } } // wire up solution builder window events window.Control.ProgressChanged -= SolutionBuilderControl_ProgressChanged; window.Control.ProgressChanged += new SolutionBuilderControl.StatusChangeEventHandler(SolutionBuilderControl_ProgressChanged); window.Control.StatusChanged -= SolutionBuilderControl_StatusChanged; window.Control.StatusChanged += new SolutionBuilderControl.StatusChangeEventHandler(SolutionBuilderControl_StatusChanged); window.Control.OutputChanged -= SolutionBuilderControl_OutputChanged; window.Control.OutputChanged += new SolutionBuilderControl.StatusChangeEventHandler(SolutionBuilderControl_OutputChanged); window.Control.OpenOutputSolutionRequested -= SolutionBuilderControl_OpenOutputSolutionRequested; window.Control.OpenOutputSolutionRequested += new SolutionBuilderControl.SolutionEventHandler(SolutionBuilderControl_OpenOutputSolutionRequested); window.Control.ShowSolutionDesignerRequested -= SolutionBuilderControl_ShowSolutionDesignerRequested; window.Control.ShowSolutionDesignerRequested += new SolutionBuilderControl.SolutionEventHandler(SolutionBuilderControl_ShowSolutionDesignerRequested); // show designer window ShowSolutionDesignerWindow(); // show getting started help if (window.Control.DataContext is BuilderViewModel) { (window.Control.DataContext as BuilderViewModel).ResourcesFolder.ShowGettingStartedHelp(); } // TODO: remove this later window.DesignerWindow = this.FindToolWindow(typeof(SolutionDesignerWindow), 0, false) as SolutionDesignerWindow; // if solution is already open, load it CheckOpenCurrentSolution(); IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame; Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show()); // put solution builder output to output pane SolutionBuilderPane.OutputString("Solution Builder shown."); } catch (System.Exception ex) { Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Error showing solution builder: {0}", ex.ToString())); // put exception message in output pane string message = ex.Message; System.Exception exception = ex.InnerException; while (exception != null) { message += "\r\n" + exception.Message; exception = exception.InnerException; } SolutionBuilderPane.OutputString(message); } }