/// <summary> /// Main function for wizard project. Calls the wizard- /// form and then delegates control to the CreateSolution function /// </summary> /// <param name="Application"></param> /// <param name="hwndOwner"></param> /// <param name="contextParams"></param> /// <param name="CustomParams"></param> /// <param name="retval"></param> public void Execute(object Application, int hwndOwner, ref object[] contextParams, ref object[] CustomParams, ref EnvDTE.wizardResult retval) { //System.Diagnostics.Debugger.Launch(); _DTE IDEObject = (_DTE)Application; try { FunctoidProjectWizardForm wizardForm = new FunctoidProjectWizardForm(); wizardForm.Enabled = true; if (wizardForm.ShowDialog() == DialogResult.OK) { // Retrieve the wizard data _wizardResults = wizardForm.WizardResults; _functoidParameters = wizardForm.FunctoidParameters; // Create the solution CreateSolution(IDEObject, contextParams); retval = wizardResult.wizardResultSuccess; } else { retval = wizardResult.wizardResultCancel; } } catch (Exception err) { MessageBox.Show(err.Message); retval = wizardResult.wizardResultFailure; } }
public void Execute(object Application, int hwndOwner, ref object[] contextParams, ref object[] customParams, ref EnvDTE.wizardResult retval) { try { _applicationObject = Application as DTE2; if (null == template_file_name_src) { RegistryKey vs2010 = Registry.CurrentUser.OpenSubKey("software\\jstructtool"); app_folder = vs2010.GetValue("AppFolder").ToString(); template_file_name_src = app_folder + "\\inc\\template.jst"; vs2010.Close(); } foreach (SelectedItem si in _applicationObject.SelectedItems) { VCFilter filter = si.ProjectItem.Object as VCFilter; VCProject proj = filter.project as VCProject; template_file_name_dst = contextParams[4] as string; template_file_name_dst += ".jst"; File.Copy(template_file_name_src, template_file_name_dst); if (filter.CanAddFile(template_file_name_dst)) { string text = null; using (StreamReader sr = new StreamReader(template_file_name_dst)) { text = sr.ReadToEnd(); text = text.Replace("%ns%", Path.GetFileNameWithoutExtension(template_file_name_dst)); } using (StreamWriter sw = new StreamWriter(template_file_name_dst)) { sw.Write(text); } filter.AddFile(template_file_name_dst); if (null == add_output_file) { XmlDocument doc = new XmlDocument(); doc.Load(app_folder + "\\debugconf.xml"); XmlNode add_o_file = doc.SelectSingleNode("/debug/add_output_file"); add_output_file = add_o_file.InnerText; } if ("true" == add_output_file) { filter.AddFile(proj.ProjectDirectory + "\\mjst\\" + Path.GetFileNameWithoutExtension(template_file_name_dst) + ".h"); } // open added file _applicationObject.ItemOperations.OpenFile(template_file_name_dst); } } } catch (Exception e) { MessageBox.Show(e.ToString()); } }
/// <summary> /// Main function for wizard project. Calls the wizard- /// form and then delegates control to the createsolution function /// </summary> /// <param name="Application"></param> /// <param name="hwndOwner"></param> /// <param name="ContextParams"></param> /// <param name="CustomParams"></param> /// <param name="retval"></param> public void Execute(object Application, int hwndOwner, ref object[] ContextParams, ref object[] CustomParams, ref EnvDTE.wizardResult retval) { _DTE IDEObject = (_DTE)Application; _Application = (DTE2)Application; try { PipeLineComponentWizardForm WizardForm = new PipeLineComponentWizardForm(); if (WizardForm.ShowDialog() == DialogResult.OK) { //Retrieve the wizard data _WizardResults = WizardForm.WizardResults; //_TransmitHandlerProperties = WizardForm.TransmitHandlerProperties; _DesignerProperties = WizardForm.DesignerProperties; // Default Designer Property = Enabled (boolean) if (!_DesignerProperties.ContainsKey("Enabled")) { _DesignerProperties.Add("Enabled", "bool"); } //Create the solution CreateSolution(IDEObject, ContextParams); retval = wizardResult.wizardResultSuccess; } else { retval = wizardResult.wizardResultCancel; return; } } catch (Exception err) { Trace.WriteLine(err.ToString()); MessageBox.Show(err.ToString()); retval = wizardResult.wizardResultFailure; } }
public void Execute(object Application, int hwndOwner, ref object[] contextParams, ref object[] customParams, ref EnvDTE.wizardResult retval) { try { _applicationObject = Application as DTE2; if (null == template_file_name_src_jst || null == template_file_name_src_json) { RegistryKey vs2010 = Registry.CurrentUser.OpenSubKey("software\\jstructtool"); template_file_name_src_jst = vs2010.GetValue("AppFolder").ToString() + "\\inc\\template.jst"; template_file_name_src_json = vs2010.GetValue("AppFolder").ToString() + "\\inc\\template.json"; vs2010.Close(); } foreach (SelectedItem si in _applicationObject.SelectedItems) { VCFilter filter = si.ProjectItem.Object as VCFilter; VCProject proj = filter.project as VCProject; template_file_name_dst = contextParams[4] as string; if (!template_file_name_dst.EndsWith(".json")) { template_file_name_dst += ".jst"; File.Copy(template_file_name_src_jst, template_file_name_dst); } else { File.Copy(template_file_name_src_json, template_file_name_dst); } if (filter.CanAddFile(template_file_name_dst)) { if (template_file_name_dst.EndsWith(".jst")) { string text = null; using (StreamReader sr = new StreamReader(template_file_name_dst)) { text = sr.ReadToEnd(); text = text.Replace("%struct_name%", Path.GetFileNameWithoutExtension(template_file_name_dst)); } using (StreamWriter sw = new StreamWriter(template_file_name_dst)) { sw.Write(text); } } filter.AddFile(template_file_name_dst); // open added file _applicationObject.ItemOperations.OpenFile(template_file_name_dst); if (template_file_name_dst.EndsWith(".json")) { template_file_name_dst = template_file_name_dst.Remove(template_file_name_dst.LastIndexOf(".json")) + ".jst"; filter.AddFile(template_file_name_dst); } } } } catch (Exception e) { MessageBox.Show(e.ToString()); } }
void EnvDTE.IDTWizard.Execute(object Application, int hwndOwner, ref object[] ContextParams, ref object[] CustomParams, ref EnvDTE.wizardResult retval) { IVsTemplate vsTemplate = null; try { DTE dte = new DTETemplate((DTE)Application); CustomParams[0] = Environment.ExpandEnvironmentVariables((string)CustomParams[0]); if (!Path.IsPathRooted((string)CustomParams[0]) && CustomParams.Length >= 2) { var guidancePackageName = (string)CustomParams[1]; var guidancePackageConfigurationFile = RecipeManager.GetConfigurationFile(RecipeManagerPackage.Singleton, guidancePackageName); if (!string.IsNullOrEmpty(guidancePackageConfigurationFile)) { var template = Path.Combine(Path.GetDirectoryName(guidancePackageConfigurationFile), (string)CustomParams[0]); if (File.Exists(template)) { CustomParams[0] = template; } } } string templateFileName = (string)CustomParams[0]; IVsTemplatesService templateService = (IVsTemplatesService) ServiceHelper.GetService( (IRecipeManagerService) new VsServiceProvider(Application).GetService(typeof(IRecipeManagerService)), typeof(IVsTemplatesService), this); vsTemplate = templateService.GetTemplate(templateFileName); string wizardKind = ((string)ContextParams[0]).ToUpper(CultureInfo.InvariantCulture); if (wizardKind == Constants.vsWizardNewProject) { string destDir = (string)ContextParams[2]; //Web projects can pass in an empty directory, if so don't create the dest directory. if ((new System.Uri(destDir)).IsFile) { Directory.CreateDirectory(destDir); } //If adding the project as exclusive, close the current solution then check to see if a // solution name is specified. If so, then create Ona solution with that name. if (((bool)ContextParams[4]) == true) { vsPromptResult promptResult = dte.ItemOperations.PromptToSave; if (promptResult == vsPromptResult.vsPromptResultCancelled) { retval = wizardResult.wizardResultCancel; return; } dte.Solution.Close(false); if (string.IsNullOrEmpty(((string)ContextParams[5])) == false) { dte.Solution.Create(destDir, ((string)ContextParams[5])); } ContextParams[4] = false; } // Create a new Solution Folder for the multiproject template else if (vsTemplate.VSKind == WizardRunKind.AsMultiProject) { string folderName = (string)ContextParams[1]; if (dte.SelectedItems.Count == 1) { object item = DteHelper.GetTarget(dte); if (item is Solution2) { ((Solution2)item).AddSolutionFolder(folderName); } else if (item is Project) { SolutionFolder slnFolder = (SolutionFolder)(((Project)item).Object); slnFolder.AddSolutionFolder(folderName); } } } } // Pre-fill state with context parameters. context = new System.Collections.Specialized.HybridDictionary(); // See http://msdn.microsoft.com/library/en-us/vsintro7/html/vxlrfcontextparamsenum.asp string kind = ((string)ContextParams[0]).ToUpper(); if (kind == Constants.vsWizardNewProject.ToUpper()) { FillNewProject(ContextParams, context); } else if (kind == Constants.vsWizardAddSubProject.ToUpper()) { FillAddSubProject(ContextParams, context); } else if (kind == Constants.vsWizardAddItem.ToUpper()) { FillAddItem(ContextParams, context); } IDTWizard wizard = new Microsoft.VisualStudio.TemplateWizard.Wizard(); wizard.Execute(dte, hwndOwner, ref ContextParams, ref CustomParams, ref retval); } catch (Exception ex) { retval = wizardResult.wizardResultCancel; if (!(ex is COMException) || ((COMException)ex).ErrorCode != VSConstants.E_ABORT) { ErrorHelper.Show(this.Site, ex); } } finally { Debug.Assert(UnfoldTemplate.UnfoldingTemplates.Count == 0); UnfoldTemplate.UnfoldingTemplates.Clear(); } }
/// <summary> /// Derived classes can call and override this method /// </summary> protected virtual void Execute(object Application, int hwndOwner, ref object[] ContextParams, ref object[] CustomParams, ref EnvDTE.wizardResult retval) { Execute(Application, hwndOwner, ref ContextParams, ref CustomParams, ref retval); }
// Execute is the main entry point for a project wizard. It has to follow this template. // contextParams: // 0: some GUID // 1: Project Name // 2: Project Path // 3: location of visual studio exe // 4: Create New Solution : true..... Add to existing solution: false // 5: Solution Name--- Will be empty string if not selected to create solution // 6: false // 7: "4.0" public void Execute(object Application, int hwndOwner, ref object[] contextParams, ref object[] customParams, ref EnvDTE.wizardResult retval) { try { fMain f = new fMain((string)contextParams[1]); if (f.ShowDialog() == DialogResult.OK) { // Set all our member variables based on input: //TODO: Organize and validate input this.dte = (_DTE)Application; this.wz = f.GetWizardData(); this.solutionName = (string)contextParams[5]; this.projectName = (string)contextParams[1]; this.path = (string)contextParams[2]; this.projectType = (ProjectType)wz.Type.ProjectTemplate; this.createNewSolution = (bool)contextParams[4]; // Parse project path and solution path from "path" //TODO: Can "path" be null/empty? this.projectPath = this.path; if (this.createNewSolution) { this.solutionPath = path.Substring(0, this.path.Length - this.projectName.Length - 1); } else { this.solutionPath = Path.GetDirectoryName(this.dte.Solution.FullName); } // Create a Project based on all our input: retval = createProject() ? wizardResult.wizardResultSuccess : wizardResult.wizardResultFailure; } else { retval = wizardResult.wizardResultCancel; } } catch (System.Exception ex) { MessageBox.Show("Exception: " + ex.Message, "Error"); retval = wizardResult.wizardResultBackOut; } }