// ------------------------------------------------------ /// <summary> /// Called to update the status of the "Generate New Suite" command /// before it is displayed. /// </summary> /// <param name="sender"> /// The sender of the event. /// </param> /// <param name="e"> /// An <code>EventArgs</code> object. /// </param> private void GenerateTests_BeforeQueryStatus(object sender, EventArgs e) { OleMenuCommand command = (OleMenuCommand)sender; HierarchyItem[] selection = VsShellUtils.GetCurrentSelection(this); // Don't support test generation if more than one file is // selected. if (selection.Length > 1) { command.Supported = false; return; } ProjectItem item = selection[0].GetExtObjectAs <ProjectItem>(); if (item == null) { command.Supported = false; return; } VCFileCodeModel codeModel = (VCFileCodeModel)item.FileCodeModel; // Don't support test generation if the file contains unit tests // already. if (codeModel == null) { command.Supported = false; return; } else { foreach (VCCodeClass klass in codeModel.Classes) { if (klass.Bases.Count > 0 && Constants.CxxTestSuiteClassRegex.IsMatch( klass.Bases.Item(1).Name)) { command.Supported = false; return; } } } command.Supported = true; }
// ------------------------------------------------------------------- /// <summary> /// Collects the projects that are currently selected in the Solution /// Explorer and invokes the submission wizard. /// </summary> private void SubmitProject_Invoked(object sender, EventArgs e) { HierarchyItem[] selectedItems = VsShellUtils.GetCurrentSelection(this); List <ISubmittableItem> submittables = new List <ISubmittableItem>(); IVsSolution solution = VsShellUtils.GetSolution(this); string solutionDir, solutionFile, solutionUser; solution.GetSolutionInfo(out solutionDir, out solutionFile, out solutionUser); if (selectedItems.Length > 0) { foreach (HierarchyItem selectedItem in selectedItems) { if (selectedItem.IsProject) { submittables.Add(new SubmittableProject(solutionDir, selectedItem)); } } // Handle subprojects here by filtering them out of the list // if their parent project is also in the list? // If the selection includes all of the projects in the // solution, then just make the solution itself the current // selection. IEnumerable <HierarchyItem> allProjects = VsShellUtils.GetLoadedProjects(solution); if (AreAllProjectsInSubmittables(allProjects, submittables)) { submittables.Clear(); submittables.Add(new SubmittableSolution(solution)); } if (submittables.Count > 0) { ShowSubmissionWizard(submittables.ToArray()); } } }
// ------------------------------------------------------ /// <summary> /// Called when the "Generate New Suite" command is invoked. /// </summary> /// <param name="sender"> /// The sender of the event. /// </param> /// <param name="e"> /// An <code>EventArgs</code> object. /// </param> private void GenerateTests_Invoked(object sender, EventArgs e) { HierarchyItem[] selection = VsShellUtils.GetCurrentSelection(this); HierarchyItem headerUnderTest = null; if (selection.Length > 0) { headerUnderTest = selection[0]; } NewCxxTestSuiteWizard wizard = new NewCxxTestSuiteWizard(this, headerUnderTest); wizard.ShowDialog(); return; }