示例#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);
        }
        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 _));
        }
示例#3
0
        private void AddNewItem(object sender, EventArgs e)
        {
            var items = GetSelectedItems().ToArray();

            if (items.Length == 1)
            {
                // Make sure we pass a folder item to the dialog. This is what the client project would
                // have done.

                var item = items[0];

                if (!item.IsFolder())
                {
                    item = item.GetParentFolder();
                }
                uint itemid = item.itemid;

                int    iDontShowAgain     = 0;
                string strBrowseLocations = "";

                Guid projectGuid = typeof(DjangoProject).GUID;

                uint uiFlags = (uint)(__VSADDITEMFLAGS.VSADDITEM_AddNewItems | __VSADDITEMFLAGS.VSADDITEM_SuggestTemplateName | __VSADDITEMFLAGS.VSADDITEM_AllowHiddenTreeView);


                IVsAddProjectItemDlg addItemDialog = (IVsAddProjectItemDlg)((System.IServiceProvider) this).GetService(typeof(IVsAddProjectItemDlg));
                string filter = "";
                // Note we pass "Web" as the default category to select. The dialog only uses it if it hasn't already saved a default value.
                string defCategory = "Web";
                string folderName  = item.Name();
                addItemDialog.AddProjectItemDlg(itemid,
                                                ref projectGuid,
                                                this,
                                                uiFlags, defCategory,
                                                null,
                                                ref strBrowseLocations,
                                                ref filter,
                                                out iDontShowAgain);
            }
        }