Ejemplo n.º 1
0
        protected override async Task <bool> TryHandleCommandAsync(IProjectTree node, bool focused, long commandExecuteOptions, IntPtr variantArgIn, IntPtr variantArgOut)
        {
            if (!_projectTree.NodeCanHaveAdditions(node))
            {
                return(false);
            }

            __VSADDITEMFLAGS uiFlags = __VSADDITEMFLAGS.VSADDITEM_AddNewItems | __VSADDITEMFLAGS.VSADDITEM_SuggestTemplateName | __VSADDITEMFLAGS.VSADDITEM_AllowHiddenTreeView;

            string strBrowseLocations = _projectTree.TreeProvider.GetAddNewItemDirectory(node);

            string strFilter = string.Empty;
            await _projectVsServices.ThreadingService.SwitchToUIThread();

            IVsAddProjectItemDlg addItemDialog = _serviceProvider.GetService <IVsAddProjectItemDlg, SVsAddProjectItemDlg>();

            Assumes.Present(addItemDialog);

            Guid    addItemTemplateGuid = Guid.Empty; // Let the dialog ask the hierarchy itself
            HResult res = addItemDialog.AddProjectItemDlg(node.GetHierarchyId(), ref addItemTemplateGuid, _projectVsServices.VsProject, (uint)uiFlags,
                                                          DirName, VSResources.ClassTemplateName, ref strBrowseLocations, ref strFilter, out int iDontShowAgain);

            // Return true here regardless of whether or not the user clicked OK or they clicked Cancel. This ensures that some other
            // handler isn't called after we run.
            return(res == VSConstants.S_OK || res == VSConstants.OLE_E_PROMPTSAVECANCELLED);
        }
Ejemplo n.º 2
0
        public async Task <bool> TryHandleCommandAsync(IImmutableSet <IProjectTree> nodes, long commandId, bool focused, long commandExecuteOptions, IntPtr variantArgIn, IntPtr variantArgOut)
        {
            Requires.NotNull(nodes, nameof(nodes));

            // We only support single node selections
            if (nodes.Count != 1)
            {
                return(false);
            }

            IProjectTree node = nodes.First();

            // We only support nodes that can actually have things added to it
            if (!_projectTree.NodeCanHaveAdditions(node))
            {
                return(false);
            }

            if (TryGetTemplateDetails(commandId, out TemplateDetails result))
            {
                __VSADDITEMFLAGS uiFlags = __VSADDITEMFLAGS.VSADDITEM_AddNewItems |
                                           __VSADDITEMFLAGS.VSADDITEM_SuggestTemplateName |
                                           __VSADDITEMFLAGS.VSADDITEM_AllowHiddenTreeView;

                string strBrowseLocations = _projectTree.TreeProvider.GetAddNewItemDirectory(node);

                await _projectVsServices.ThreadingService.SwitchToUIThread();

                // Look up the resources from each package to get the strings to pass to the Add Item dialog.
                // These strings must match what is used in the template exactly, including localized versions. Rather than relying on
                // our localizations being the same as the VS repository localizations we just load the right strings using the same
                // resource IDs as the templates themselves use.
                string dirName      = _vsShell.Value.LoadPackageString(result.DirNamePackageGuid, result.DirNameResourceId);
                string templateName = _vsShell.Value.LoadPackageString(result.TemplateNamePackageGuid, result.TemplateNameResourceId);

                string  strFilter           = string.Empty;
                Guid    addItemTemplateGuid = Guid.Empty; // Let the dialog ask the hierarchy itself
                HResult res = _addItemDialog.Value.AddProjectItemDlg(node.GetHierarchyId(),
                                                                     ref addItemTemplateGuid,
                                                                     _projectVsServices.VsProject,
                                                                     (uint)uiFlags,
                                                                     dirName,
                                                                     templateName,
                                                                     ref strBrowseLocations,
                                                                     ref strFilter,
                                                                     out _);

                // Return true here regardless of whether or not the user clicked OK or they clicked Cancel. This ensures that some other
                // handler isn't called after we run.
                return(res == HResult.OK || res == HResult.Ole.PromptSaveCancelled);
            }

            return(false);
        }
Ejemplo n.º 3
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);
         }
     }
 }
Ejemplo n.º 4
0
        private async Task <bool> ShowDialogAsync(IProjectTree node, __VSADDITEMFLAGS flags, string?localizedDirectoryName = null, string?localizedTemplateName = null)
        {
            string?path = _projectTree.TreeProvider.GetAddNewItemDirectory(node);

            if (path == null)
            {
                throw new ArgumentException("Node is marked with DisableAddItemFolder or DisableAddItemRecursiveFolder, call CanAddNewOrExistingItemTo before calling this method.", nameof(node));
            }

            await _projectVsServices.ThreadingService.SwitchToUIThread();

            string filter = string.Empty;
            Guid   addItemTemplateGuid = Guid.Empty; // Let the dialog ask the hierarchy itself

            IVsAddProjectItemDlg?addProjectItemDialog = _addProjectItemDialog.Value;

            if (addProjectItemDialog == null)
            {
                return(false);
            }

            HResult result = addProjectItemDialog.AddProjectItemDlg(
                node.GetHierarchyId(),
                ref addItemTemplateGuid,
                _projectVsServices.VsProject,
                (uint)flags,
                localizedDirectoryName,
                localizedTemplateName,
                ref path,
                ref filter,
                out _);

            if (result == HResult.Ole.PromptSaveCancelled)
            {
                return(false);
            }

            if (result.Failed)
            {
                throw result.Exception !;
            }

            return(true);
        }
Ejemplo n.º 5
0
        private static int ShowAddItemDialog(SVsServiceProvider serviceProvider, IProjectTree target, IVsProject vsProject, string strBrowseLocations, AddItemAction addItemAction)
        {
#pragma warning disable RS0030 // Do not used banned APIs
            IVsAddProjectItemDlg addItemDialog = serviceProvider.GetService <IVsAddProjectItemDlg, SVsAddProjectItemDlg>();
#pragma warning restore RS0030 // Do not used banned APIs
            Assumes.Present(addItemDialog);

            __VSADDITEMFLAGS uiFlags = __VSADDITEMFLAGS.VSADDITEM_AddNewItems | __VSADDITEMFLAGS.VSADDITEM_SuggestTemplateName | __VSADDITEMFLAGS.VSADDITEM_AllowHiddenTreeView;
            if (addItemAction == AddItemAction.ExistingItem)
            {
                uiFlags = __VSADDITEMFLAGS.VSADDITEM_AddExistingItems | __VSADDITEMFLAGS.VSADDITEM_AllowMultiSelect | __VSADDITEMFLAGS.VSADDITEM_AllowStickyFilter | __VSADDITEMFLAGS.VSADDITEM_ProjectHandlesLinks;
            }

            string strFilter           = string.Empty;
            Guid   addItemTemplateGuid = Guid.Empty; // Let the dialog ask the hierarchy itself

            return(addItemDialog.AddProjectItemDlg(target.GetHierarchyId(), ref addItemTemplateGuid, vsProject, (uint)uiFlags,
                                                   null, null, ref strBrowseLocations, ref strFilter, out _));
        }