// ------------------------------------------------------------------- /// <summary> /// Populates the tree with the current solution and the projects /// loaded in the solution. /// </summary> private void PopulateTree() { string solutionDir, solutionFile, solutionUser; IVsSolution solution = VsShellUtils.GetSolution(serviceProvider); solution.GetSolutionInfo(out solutionDir, out solutionFile, out solutionUser); string solutionName = Path.GetFileNameWithoutExtension(solutionFile); TreeNode root = new TreeNode( String.Format(Messages.SolutionPlaceholder, solutionName)); root.Tag = solution; treeView.Nodes.Add(root); if (FindSolutionInSelection(solution)) { root.Checked = true; } foreach (HierarchyItem item in VsShellUtils.GetLoadedProjects(solution)) { AddHierarchyItemToNode(item, root); } treeView.ExpandAll(); }
// ------------------------------------------------------------------- /// <summary> /// Collects the current solution loaded into Visual Studio and invokes /// the submission wizard. /// </summary> private void SubmitSolution_Invoked(object sender, EventArgs e) { IVsSolution solution = VsShellUtils.GetSolution(this); if (solution != null) { ISubmittableItem[] items = { new SubmittableSolution(solution) }; ShowSubmissionWizard(items); } }
// ------------------------------------------------------------------- /// <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> /// Appends to a selection list the submittable item in the given node, /// if it is checked. /// </summary> /// <remarks> /// This method handles nested elements -- if the parent of an item is /// checked, that means that all of its children are as well, so only /// the parent needs to be added to the selection. If a parent node is /// not checked, then we recursively look at its children to determine /// if any of them need to be added to the selection. /// </remarks> /// <param name="items"> /// The list that will be built up to contain the selection. /// </param> /// <param name="node"> /// The node to possibly add to the selection. /// </param> private void AppendSelectionFromNode(List <ISubmittableItem> items, TreeNode node) { if (node.Checked) { string solutionDir, solutionFile, solutionUser; IVsSolution solution = VsShellUtils.GetSolution(serviceProvider); solution.GetSolutionInfo(out solutionDir, out solutionFile, out solutionUser); ISubmittableItem item = null; if (node.Tag is IVsSolution) { item = new SubmittableSolution((IVsSolution)node.Tag); } else if (node.Tag is HierarchyItem) { HierarchyItem hierarchy = (HierarchyItem)node.Tag; item = new SubmittableProject(solutionDir, hierarchy); } if (item != null) { items.Add(item); } } else { foreach (TreeNode child in node.Nodes) { AppendSelectionFromNode(items, child); } } }