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); }
private void FileTemplateSelectFromList(object sender, System.Windows.Input.MouseButtonEventArgs e) { if (_solution == null) { ResharperHelper.AppendLineToOutputWindow(_solution.Locks, "Unable to identify current solution."); DisplayLoadProjectTip(); return; } var project = _solution.GetAllCodeProjects().FirstOrDefault(); if (project == null) { ResharperHelper.AppendLineToOutputWindow(_solution.Locks, "Unable to identify a code project."); DisplayLoadProjectTip(); return; } var scope = _scopeManager.EnumerateRealScopePoints(new TemplateAcceptanceContext(new ProjectFolderWithLocation(project))); scope = scope.Distinct().Where(s => s is InLanguageSpecificProject).ToList(); var template = _templatesUiHelper.ChooseTemplate( FileTemplatesManager.Instance.QuickListSupports, scope, project.ToDataContext(), TemplateApplicability.File); if (template != null) { ((TextBox)sender).Text = template.Description; } }
private void FileTemplateSelectFromList(object sender, System.Windows.Input.MouseButtonEventArgs e) { Template template = null; if (_solution == null) { ResharperHelper.AppendLineToOutputWindow("Unable to identify current solution."); DisplayLoadProjectTip(); return; } var project = _solution.GetAllCodeProjects().FirstOrDefault(); if (project == null) { ResharperHelper.AppendLineToOutputWindow("Unable to identify a code project."); DisplayLoadProjectTip(); return; } var scope = _scopeManager.EnumerateRealScopePoints(new TemplateAcceptanceContext(new ProjectFolderWithLocation(project))); scope = scope.Distinct().Where(s => s is InLanguageSpecificProject).ToList(); using ( var templateDialog = new TemplateChooserDialog(_lifetime, FileTemplatesManager.Instance.QuickListSupports, scope, project.ToDataContext(), TemplateApplicability.File)) { if (templateDialog.ShowDialog(_application.MainWindow.GetActiveWindow()) != DialogResult.OK) { return; } template = templateDialog.Template; } if (template != null) { ((TextBox)sender).Text = template.Description; } }