/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void MenuItemCallback(object sender, EventArgs e) { var dte = VSPackage.DteInstance; //save node name details to maintain selection in solution explorer var selectedItem = ((Array)dte.ToolWindows.SolutionExplorer.SelectedItems).Cast <UIHierarchyItem>().First(); var selectedParent = selectedItem.Collection.Parent as UIHierarchyItem; var parentNodeName = selectedParent.NodeName(); var nodeName = selectedItem.Name; var itemPath = SolutionExplorerExtensions.SelectedItemPath; var fileName = SolutionExplorerExtensions.SelectedItemPath; var projectFullName = VSPackage.DteInstance.Solution.FindProjectItem(fileName).ContainingProject.FullName; var parameterizationProject = new ParameterizationProject(projectFullName); if (parameterizationProject.Initialize()) { var projectItem = VSPackage.DteInstance.Solution.FindProjectItem(fileName); projectItem.Properties.Item("ItemType").Value = "Parameterization"; Nester.ApplyNesting(itemPath); System.Threading.Thread.Sleep(1000); dte.ToolWindows.SolutionExplorer.GetItem($"{parentNodeName}\\Parameters.xml").UIHierarchyItems.Expanded = true; dte.ToolWindows.SolutionExplorer.GetItem($"{parentNodeName}\\Parameters.xml\\{nodeName}").Select(vsUISelectionType.vsUISelectionTypeSelect); } }
/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override void Initialize() { GenerateSetParametersCommand.Initialize(this); NestCommand.Initialize(this); base.Initialize(); CoreDte = GetService(typeof(DTE)) as DTE; DteInstance = GetService(typeof(DTE)) as DTE2; Shell = GetService(typeof(SVsUIShell)) as IVsUIShell; Solution = GetService(typeof(SVsSolution)) as SVsSolution; OptionsPage = (OptionsPageGrid)GetDialogPage(typeof(OptionsPageGrid)); Nester.Initialize(DteInstance); ApplyMissingParametersCommand.Initialize(this); GenerateParametersCommand.Initialize(this); AddParameterizationTargetCommand.Initialize(this); }