Пример #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);
        }
        public static SVsServiceProvider Create(IVsAddProjectItemDlg dlg = null)
        {
            var mock = new Mock <SVsServiceProvider>();

            mock.Setup(s => s.GetService(It.IsAny <Type>())).Returns(dlg);
            return(mock.Object);
        }
Пример #3
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 _));
        }
Пример #4
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);
            }
        }
        internal AbstractAddClassProjectCommand CreateInstance(IPhysicalProjectTree projectTree = null, IUnconfiguredProjectVsServices projectVsServices = null, Shell.SVsServiceProvider serviceProvider = null, IProjectTreeProvider provider = null, IVsAddProjectItemDlg dlg = null)
        {
            projectTree       = projectTree ?? IPhysicalProjectTreeFactory.Create(provider);
            projectVsServices = projectVsServices ?? IUnconfiguredProjectVsServicesFactory.Implement(threadingServiceCreator: () => IProjectThreadingServiceFactory.Create());
            serviceProvider   = serviceProvider ?? SVsServiceProviderFactory.Create(dlg);

            return(CreateInstance(projectTree, projectVsServices, serviceProvider));
        }
        internal AbstractAddItemCommandHandler CreateInstance(IPhysicalProjectTree projectTree = null, IUnconfiguredProjectVsServices projectVsServices = null, IProjectTreeProvider provider = null, IVsAddProjectItemDlg addItemDialog = null, string capability = null)
        {
            var configuredProject = ConfiguredProjectFactory.Create(IProjectCapabilitiesScopeFactory.Create(new string[] { capability ?? TestAddItemCommand.Capability }));

            projectTree       = projectTree ?? IPhysicalProjectTreeFactory.Create(provider);
            projectVsServices = projectVsServices ??
                                IUnconfiguredProjectVsServicesFactory.Implement(
                threadingServiceCreator: () => IProjectThreadingServiceFactory.Create()
                );
            var addItemDialogService = IVsUIServiceFactory.Create <SVsAddProjectItemDlg, IVsAddProjectItemDlg>(addItemDialog);

            string result      = "DirName";
            var    vsShellMock = new Mock <IVsShell>();

            vsShellMock.Setup(x => x.LoadPackageString(ref It.Ref <Guid> .IsAny, (uint)TestAddItemCommand.ResourceIds.DirName, out result)).Returns(0);
            result = "TemplateName";
            vsShellMock.Setup(x => x.LoadPackageString(ref It.Ref <Guid> .IsAny, (uint)TestAddItemCommand.ResourceIds.TemplateName, out result)).Returns(0);

            var vsShellService = IVsUIServiceFactory.Create <SVsShell, IVsShell>(vsShellMock.Object);

            return(new TestAddItemCommand(configuredProject, projectTree, projectVsServices, addItemDialogService, vsShellService));
        }
Пример #7
0
        internal AbstractAddClassProjectCommand CreateInstance(IPhysicalProjectTree projectTree = null, IUnconfiguredProjectVsServices projectVsServices = null, IProjectTreeProvider provider = null, IVsAddProjectItemDlg addItemDialog = null)
        {
            projectTree       = projectTree ?? IPhysicalProjectTreeFactory.Create(provider);
            projectVsServices = projectVsServices ?? IUnconfiguredProjectVsServicesFactory.Implement(threadingServiceCreator: () => IProjectThreadingServiceFactory.Create());
            var addItemDialogService = IVsUIServiceFactory.Create <SVsAddProjectItemDlg, IVsAddProjectItemDlg>(addItemDialog);

            return(CreateInstance(projectTree, projectVsServices, addItemDialogService));
        }