Example #1
0
 protected override void OnExec()
 {
     if (template.IsVisibleFromContextMenu)
     {
         IConfigurationService configService =
             (IConfigurationService)ServiceProvider.GetService(typeof(IConfigurationService), true);
         if (template.Kind == TemplateKind.Project)
         {
             IVsSolution3             solution = (IVsSolution3)ServiceProvider.GetService(typeof(SVsSolution), true);
             IVsBrowseProjectLocation browseProjectLocation = null;
             uint cnpvdeFlags = (uint)(__VSCREATENEWPROJVIADLGEXFLAGS.VNPVDE_ALWAYSADDTOSOLUTION | __VSCREATENEWPROJVIADLGEXFLAGS.VNPVDE_ADDNESTEDTOSELECTION);
             //browseProjectLocation = this;
             //cnpvdeFlags |= (uint)(__VSCREATENEWPROJVIADLGEXFLAGS.VNPVDE_OVERRIDEBROWSEBUTTON);
             solution.CreateNewProjectViaDlgEx(Microsoft.Practices.RecipeFramework.VisualStudio.Properties.Resources.IDD_ADDPROJECTDLG,
                                               null,
                                               configService.CurrentPackage.Caption,
                                               this.template.Name,
                                               null,
                                               cnpvdeFlags,
                                               browseProjectLocation);
         }
         else if (template.Kind == TemplateKind.ProjectItem)
         {
             uint                  itemid            = 0;
             IVsProject            vsProject         = DteHelper.GetCurrentSelection(this.ServiceProvider, out itemid) as IVsProject;
             IVsAddProjectItemDlg2 addProjectItemDlg =
                 (IVsAddProjectItemDlg2)ServiceProvider.GetService(typeof(SVsAddProjectItemDlg), true);
             __VSADDITEMFLAGS addItemsFlags = __VSADDITEMFLAGS.VSADDITEM_AddNewItems | __VSADDITEMFLAGS.VSADDITEM_SuggestTemplateName;
             Guid             projectGuid   = this.template.ProjectFactory;
             string           location      = String.Empty;
             string           filter        = String.Empty;
             int dontShowAgain = VSConstantsEx.TRUE;
             addProjectItemDlg.AddProjectItemDlgTitled(itemid,
                                                       ref projectGuid,
                                                       vsProject,
                                                       (uint)addItemsFlags,
                                                       null,
                                                       configService.CurrentPackage.Caption,
                                                       this.template.Name,
                                                       ref location,
                                                       ref filter,
                                                       out dontShowAgain);
         }
     }
 }
Example #2
0
        public static bool AddProjectDialog(
            IServiceProvider provider,
            string title,
            string templateName)
        {
            Guard.ArgumentNotNull(provider, "provider");
            Guard.ArgumentNotNullOrEmptyString(title, "title");
            Guard.ArgumentNotNullOrEmptyString(templateName, "templateName");

            try
            {
                IVsSolution solution = provider.GetService(typeof(IVsSolution)) as IVsSolution;
                uint        pitemid  = 0;
                using (HierarchyNode hierarchy = new HierarchyNode(solution, DteHelper2.GetCurrentSelection(provider, out pitemid)))
                {
                    if (hierarchy.IsSolution)
                    {
                        string       templatePath = null;// (hierarchy.Hierarchy as EnvDTE.Solution).TemplatePath;
                        IVsSolution3 sln          = (IVsSolution3)hierarchy.Hierarchy;
                        ErrorHandler.ThrowOnFailure(sln.CreateNewProjectViaDlgEx(
                                                        title, templatePath, "Visual C#", templateName, null, (uint)__VSCREATENEWPROJVIADLGEXFLAGS.VNPVDE_ALWAYSADDTOSOLUTION, null));
                    }
                }
                return(true);
            }
            catch (COMException comEx)
            {
                if (comEx.ErrorCode != VSConstants.OLE_E_PROMPTSAVECANCELLED)
                {
                    Logger.Write(comEx);
                }
            }
            catch (Exception error)
            {
                Logger.Write(error);
            }
            return(false);
        }
 public int CreateNewProjectViaDlgEx(string pszDlgTitle, string pszTemplateDir, string pszExpand, string pszSelect, string pszHelpTopic, uint cnpvdeFlags, IVsBrowseProjectLocation pBrowse)
 {
     return(_solution.CreateNewProjectViaDlgEx(pszDlgTitle, pszTemplateDir, pszExpand, pszSelect, pszHelpTopic, cnpvdeFlags, pBrowse));
 }