Пример #1
0
        //------------------------------------------------------------------------------------------------------------------------
        private static IList <SimpleMenuItem> DescribeFilesAssociatedWithDeclaredElement(Lifetime lifetime, DocumentManager documentManager, IClrDeclaredElement declaredElement, Func <IProjectFile, Action> clickAction)
        {
            IList <SimpleMenuItem> menuItems = new List <SimpleMenuItem>();

            var projectFiles = GetProjectFiles(documentManager, declaredElement);

            foreach (var projectFile in projectFiles)
            {
                IProjectFile currentProjectFile = projectFile;
                var          np = new ProjectFileNavigationPoint(currentProjectFile);

                var result = new SimpleMenuItemForProjectItem(np.GetPresentationText()
                                                              , np.GetPresentationImage()
                                                              , ResharperHelper.ProtectActionFromReEntry(lifetime, "TestingMenuNavigation", clickAction.Invoke(projectFile))
                                                              , projectFile, declaredElement
                                                              );

                result.ShortcutText = np.GetSecondaryPresentationText();
                result.Style        = MenuItemStyle.Enabled;
                result.Tag          = projectFile.Location.FullPath;

                menuItems.Add(result);
            }
            return(menuItems);
        }
        public void CreateFileWithinProject([NotNull] TestCopProjectItem projectItem, [NotNull] string targetFile)
        {
            var desiredTemplateName = LookupTemplateName(projectItem.Project);
            var boundSettingsStore  = _settingsStore.BindToContextTransient(ContextRange.ApplicationWide);

            var context = _dataContexts.CreateOnActiveControl(_lifetime);

            var applicableFileTemplateScopes = _scopeManager.EnumerateRealScopePoints(new TemplateAcceptanceContext(new ProjectFolderWithLocation(projectItem.Project)));

            applicableFileTemplateScopes = applicableFileTemplateScopes.Distinct().Where(s => s is InLanguageSpecificProject).ToList();

            var classTemplate = _storedTemplatesProvider.EnumerateTemplates(boundSettingsStore, TemplateApplicability.File)
                                .Where(x => x.Description == desiredTemplateName &&
                                       TemplateScopeManager.TemplateIsAvailable(x, applicableFileTemplateScopes))
                                .Select(x => x)
                                .FirstOrDefault();

            if (classTemplate == null)
            {
                ResharperHelper.AppendLineToOutputWindow(string.Format("File Template for '{0}' not found with default to 'Class'", desiredTemplateName));
                classTemplate = LoadTemplateFromQuickList(context, "Class");
            }
            IProjectFolder folder = (IProjectFolder)projectItem.Project.FindProjectItemByLocation(projectItem.SubNamespaceFolder)
                                    ?? GetOrCreateProjectFolder(projectItem);

            if (folder == null)
            {
                ResharperHelper.AppendLineToOutputWindow("Error failed to create/location project folder" + projectItem.SubNamespaceFolder);
                return;
            }

            string extension = Enumerable.First(_fileExtensions.GetExtensions(projectItem.Project.ProjectProperties.DefaultLanguage.DefaultProjectFileType));

            FileTemplatesManager.Instance.CreateFileFromTemplate(targetFile + extension, new ProjectFolderWithLocation(folder), classTemplate);
        }
Пример #3
0
        //------------------------------------------------------------------------------------------------------------------------
        public static bool DeriveRelatedFileNameAndAddCreateMenus(IDataContext context, Lifetime lifetime,
                                                                  IProject project, IList <TestCopProjectItem> associatedTargetProjects, IList <SimpleMenuItem> currentMenus,
                                                                  IClrTypeName clrTypeClassName)
        {
            bool addedCreateMenuItem = false;

            if (clrTypeClassName == null)
            {
                return(false);
            }
            var baseFileName = ResharperHelper.GetBaseFileName(context, project.GetSolution());

            var  settings = TestCopSettingsManager.Instance.Settings;
            bool currentFileisTestFile = baseFileName.EndsWith(settings.TestClassSuffixes());

            foreach (var testClassSuffix in settings.GetAppropriateTestClassSuffixes(baseFileName))
            {
                var targetFile = ResharperHelper.UsingFileNameGetClassName(baseFileName).RemoveTrailing(testClassSuffix);

                if (!currentFileisTestFile)
                {
                    targetFile += testClassSuffix;
                }

                foreach (var associatedTargetProjectItem in associatedTargetProjects)
                {
                    if (currentFileisTestFile == associatedTargetProjectItem.Project.IsTestProject())
                    {
                        ResharperHelper.AppendLineToOutputWindow(
                            string.Format("Internal Error: Attempted to create '{0}' within project '{1}'"
                                          , targetFile, associatedTargetProjectItem.Project.Name));
                        continue;
                    }

                    string targetFileLocation = associatedTargetProjectItem.SubNamespaceFolder.FullPath + "\\" + targetFile;

                    if (!IsMenuItemPresentForFile(currentMenus, targetFileLocation))
                    {
                        currentMenus.AddRange(AddCreateFileMenuItem(lifetime, associatedTargetProjectItem, targetFile));
                        addedCreateMenuItem = true;
                    }
                }
            }

            return(addedCreateMenuItem);
        }
Пример #4
0
        //------------------------------------------------------------------------------------------------------------------------
        private static List <SimpleMenuItem> AddCreateFileMenuItem(Lifetime lifetime, TestCopProjectItem projectItem, string targetFile)
        {
            var menuItems = new List <SimpleMenuItem>();

            var result = new SimpleMenuItem("Create associated file"
                                            , null,
                                            ResharperHelper.ProtectActionFromReEntry(lifetime, "TestingMenuNavigation",
                                                                                     () =>
                                                                                     ResharperHelper.CreateFileWithinProject(projectItem, targetFile)));

            result.Style        = MenuItemStyle.Enabled;
            result.Icon         = UnnamedThemedIcons.Agent16x16.Id;
            result.Text         = new RichText("Create ", TextStyle.FromForeColor(Color.Green)).Append(targetFile, TextStyle.FromForeColor(TextStyle.DefaultForegroundColor));
            result.ShortcutText = new RichText("(" + projectItem.Project.GetPresentableProjectPath()
                                               +
                                               projectItem.SubNamespaceFolder.FullPath.RemoveLeading(
                                                   projectItem.Project.ProjectFileLocation.Directory.FullPath) + ")",
                                               TextStyle.FromForeColor(Color.LightGray));
            menuItems.Add(result);
            return(menuItems);
        }