com.intellij.ide.fileTemplates.FileTemplateManager Java Examples
The following examples show how to use
com.intellij.ide.fileTemplates.FileTemplateManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FileTemplateHelper.java From PackageTemplates with Apache License 2.0 | 6 votes |
private static FileTemplate getDefaultTemplatePriority(String name, FileTemplateManager projectManager, FileTemplateManager defaultManager) { FileTemplate result; // Default result = getDefaultTemplateOnly(name, projectManager, defaultManager); if (result != null) { return result; } // Project result = getProjectTemplateOnly(name, projectManager, defaultManager); if (result != null) { return result; } return null; }
Example #2
Source File: FileReferenceQuickFixProvider.java From consulo with Apache License 2.0 | 6 votes |
@Override protected String getFileText() { if (!isDirectory && myNewFileTemplateName != null) { Project project = getStartElement().getProject(); FileTemplateManager fileTemplateManager = FileTemplateManager.getInstance(project); FileTemplate template = findTemplate(fileTemplateManager); if (template != null) { try { return template.getText(fileTemplateManager.getDefaultProperties()); } catch (IOException ex) { throw new RuntimeException(ex); } } } return super.getFileText(); }
Example #3
Source File: CSharpCreateFileAction.java From consulo-csharp with Apache License 2.0 | 6 votes |
@Override @RequiredReadAction protected PsiFile createFile(String name, String templateName, final PsiDirectory dir) { FileTemplate template = FileTemplateManager.getInstance(dir.getProject()).getInternalTemplate(templateName); try { Map<String, Object> map = new HashMap<>(); map.put("psiDirectory", dir); return (PsiFile) FileTemplateUtil.createFromTemplate(template, name, map, dir, getClass().getClassLoader()); } catch(Exception e) { LOG.error(e); return null; } }
Example #4
Source File: CreateRTAction.java From react-templates-plugin with MIT License | 6 votes |
public CreateRTAction() { super(RTBundle.message("action.gui.rt.text"), RTBundle.message("action.gui.rt.description"), RTIcons.RT); // delete obsolete template ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { public void run() { // to prevent deadlocks, this code must run while not holding the ActionManager lock FileTemplateManager manager = FileTemplateManager.getDefaultInstance(); final FileTemplate template = manager.getTemplate("RTFile3"); //noinspection HardCodedStringLiteral if (template != null && template.getExtension().equals("rt")) { manager.removeTemplate(template); } } }); }
Example #5
Source File: BashTemplatesFactory.java From BashSupport with Apache License 2.0 | 6 votes |
@NotNull static PsiFile createFromTemplate(final PsiDirectory directory, String fileName, String templateName) throws IncorrectOperationException { Project project = directory.getProject(); FileTemplateManager templateManager = FileTemplateManager.getInstance(project); FileTemplate template = templateManager.getInternalTemplate(templateName); Properties properties = new Properties(templateManager.getDefaultProperties()); String templateText; try { templateText = template.getText(properties); } catch (IOException e) { throw new RuntimeException("Unable to load template for " + templateManager.internalTemplateToSubject(templateName), e); } PsiFile file = PsiFileFactory.getInstance(project).createFileFromText(fileName, BashFileType.BASH_FILE_TYPE, templateText); return (PsiFile) directory.add(file); }
Example #6
Source File: CreateFromTemplateGroup.java From consulo with Apache License 2.0 | 6 votes |
@RequiredUIAccess @Override public void update(@Nonnull AnActionEvent event) { Project project = event.getData(CommonDataKeys.PROJECT); Presentation presentation = event.getPresentation(); if(project != null && !project.isDisposed()) { FileTemplate[] allTemplates = FileTemplateManager.getInstance(project).getAllTemplates(); for (FileTemplate template : allTemplates) { if (canCreateFromTemplate(event, template)) { presentation.setEnabled(true); return; } } } presentation.setEnabled(false); }
Example #7
Source File: CreateRTAction.java From react-templates-plugin with MIT License | 6 votes |
public CreateRTAction() { super(RTBundle.message("action.gui.rt.text"), RTBundle.message("action.gui.rt.description"), RTIcons.RT); // delete obsolete template ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { public void run() { // to prevent deadlocks, this code must run while not holding the ActionManager lock FileTemplateManager manager = FileTemplateManager.getDefaultInstance(); final FileTemplate template = manager.getTemplate("RTFile3"); //noinspection HardCodedStringLiteral if (template != null && template.getExtension().equals("rt")) { manager.removeTemplate(template); } } }); }
Example #8
Source File: FileTemplateHelper.java From PackageTemplates with Apache License 2.0 | 6 votes |
private static FileTemplate getProjectTemplatePriority(String name, FileTemplateManager projectManager, FileTemplateManager defaultManager) { FileTemplate result; // Project result = getProjectTemplateOnly(name, projectManager, defaultManager); if (result != null) { return result; } // Default result = getDefaultTemplateOnly(name, projectManager, defaultManager); if (result != null) { return result; } return null; }
Example #9
Source File: WeexTemplateFactory.java From weex-language-support with MIT License | 6 votes |
public static PsiFile createFromTemplate(final PsiDirectory directory, final String name, String fileName, String templateName, @NonNls String... parameters) throws IncorrectOperationException { final FileTemplate template = FileTemplateManager.getInstance(directory.getProject()).getInternalTemplate(templateName); String text; try { text = template.getText(); } catch (Exception e) { throw new RuntimeException("Unable to load template for " + FileTemplateManager.getInstance().internalTemplateToSubject(templateName), e); } final PsiFileFactory factory = PsiFileFactory.getInstance(directory.getProject()); final PsiFile file = factory.createFileFromText(fileName, WeexFileType.INSTANCE, text); CodeStyleManager.getInstance(directory.getProject()).reformat(file); return (PsiFile) directory.add(file); }
Example #10
Source File: FileTemplatesLoader.java From consulo with Apache License 2.0 | 6 votes |
protected FileTemplatesLoader(@Nonnull FileTypeManager typeManager, @Nullable Project project) { myTypeManager = typeManager; File configDir = project == null || project.isDefault() ? new File(ContainerPathManager.get().getConfigPath(), TEMPLATES_DIR) : new File(UriUtil.trimTrailingSlashes(StorageUtil.getStoreDir(project) + "/" + TEMPLATES_DIR)); myDefaultTemplatesManager = new FTManager(FileTemplateManager.DEFAULT_TEMPLATES_CATEGORY, configDir); myInternalTemplatesManager = new FTManager(FileTemplateManager.INTERNAL_TEMPLATES_CATEGORY, new File(configDir, INTERNAL_DIR), true); myPatternsManager = new FTManager(FileTemplateManager.INCLUDES_TEMPLATES_CATEGORY, new File(configDir, INCLUDES_DIR)); myCodeTemplatesManager = new FTManager(FileTemplateManager.CODE_TEMPLATES_CATEGORY, new File(configDir, CODE_TEMPLATES_DIR)); myJ2eeTemplatesManager = new FTManager(FileTemplateManager.J2EE_TEMPLATES_CATEGORY, new File(configDir, J2EE_TEMPLATES_DIR)); myAllManagers = new FTManager[]{myDefaultTemplatesManager, myInternalTemplatesManager, myPatternsManager, myCodeTemplatesManager, myJ2eeTemplatesManager}; myDirToManagerMap.put("", myDefaultTemplatesManager); myDirToManagerMap.put(INTERNAL_DIR + "/", myInternalTemplatesManager); myDirToManagerMap.put(INCLUDES_DIR + "/", myPatternsManager); myDirToManagerMap.put(CODE_TEMPLATES_DIR + "/", myCodeTemplatesManager); myDirToManagerMap.put(J2EE_TEMPLATES_DIR + "/", myJ2eeTemplatesManager); loadDefaultTemplates(); for (FTManager manager : myAllManagers) { manager.loadCustomizedContent(); } }
Example #11
Source File: MuleMavenProjectBuilderHelper.java From mule-intellij-plugins with Apache License 2.0 | 6 votes |
private VirtualFile createLog4JTest(final Project project, final MavenId projectId, final VirtualFile appDirectory) { return new WriteCommandAction<VirtualFile>(project, "Create Log4J Test File", PsiFile.EMPTY_ARRAY) { @Override protected void run(@NotNull Result<VirtualFile> result) throws Throwable { try { VirtualFile configFile = appDirectory.findOrCreateChildData(this, "log4j2-test.xml"); final FileTemplateManager manager = FileTemplateManager.getInstance(project); final FileTemplate template = manager.getInternalTemplate(MuleFileTemplateDescriptorManager.LOG4J2_TEST); final Properties defaultProperties = manager.getDefaultProperties(); final String text = template.getText(defaultProperties); VfsUtil.saveText(configFile, text); result.setResult(configFile); } catch (IOException e) { showError(project, e); } } }.execute().getResultObject(); }
Example #12
Source File: CreateFromTemplateDialog.java From consulo with Apache License 2.0 | 5 votes |
public CreateFromTemplateDialog(@Nonnull PsiDirectory directory, @Nonnull FileTemplate template, @Nullable final AttributesDefaults attributesDefaults, @Nullable final Map<String, Object> defaultProperties) { super(directory.getProject(), true); myDirectory = directory; myProject = directory.getProject(); myTemplate = template; setTitle(IdeBundle.message("title.new.from.template", template.getName())); myDefaultProperties = defaultProperties == null ? FileTemplateManager.getInstance(myProject).getDefaultVariables() : defaultProperties; FileTemplateUtil.fillDefaultProperties(myDefaultProperties, directory); boolean mustEnterName = FileTemplateUtil.findHandler(template).isNameRequired(); if (attributesDefaults != null && attributesDefaults.isFixedName()) { myDefaultProperties.put(FileTemplate.ATTRIBUTE_NAME, attributesDefaults.getDefaultFileName()); mustEnterName = false; } String[] unsetAttributes = null; try { unsetAttributes = myTemplate.getUnsetAttributes(myDefaultProperties, myProject); } catch (ParseException e) { showErrorDialog(e); } if (unsetAttributes != null) { myAttrPanel = new CreateFromTemplatePanel(unsetAttributes, mustEnterName, attributesDefaults); myAttrComponent = myAttrPanel.getComponent(); init(); } else { myAttrPanel = null; myAttrComponent = null; } }
Example #13
Source File: FileReferenceQuickFixProvider.java From consulo with Apache License 2.0 | 5 votes |
private FileTemplate findTemplate(FileTemplateManager fileTemplateManager) { FileTemplate template = fileTemplateManager.getTemplate(myNewFileTemplateName); if (template == null) template = fileTemplateManager.findInternalTemplate(myNewFileTemplateName); if (template == null) { for (FileTemplate fileTemplate : fileTemplateManager.getAllJ2eeTemplates()) { final String fileTemplateWithExtension = fileTemplate.getName() + '.' + fileTemplate.getExtension(); if (fileTemplateWithExtension.equals(myNewFileTemplateName)) { return fileTemplate; } } } return template; }
Example #14
Source File: AsposeMavenUtil.java From Aspose.OCR-for-Java with MIT License | 5 votes |
private static void runOrApplyFileTemplate(Project project, VirtualFile file, String templateName, Properties properties) throws IOException { FileTemplateManager manager = FileTemplateManager.getInstance(); FileTemplate fileTemplate = manager.getJ2eeTemplate(templateName); Properties allProperties = manager.getDefaultProperties(project); allProperties.putAll(properties); String text = fileTemplate.getText(allProperties); Pattern pattern = Pattern.compile("\\$\\{(.*)\\}"); Matcher matcher = pattern.matcher(text); StringBuffer builder = new StringBuffer(); while (matcher.find()) { matcher.appendReplacement(builder, "\\$" + matcher.group(1).toUpperCase() + "\\$"); } matcher.appendTail(builder); text = builder.toString(); TemplateImpl template = (TemplateImpl) TemplateManager.getInstance(project).createTemplate("", "", text); for (int i = 0; i < template.getSegmentsCount(); i++) { if (i == template.getEndSegmentNumber()) continue; String name = template.getSegmentName(i); String value = "\"" + properties.getProperty(name, "") + "\""; template.addVariable(name, value, value, true); } VfsUtil.saveText(file, template.getTemplateText()); PsiFile psiFile = PsiManager.getInstance(project).findFile(file); if (psiFile != null) { new ReformatCodeProcessor(project, psiFile, null, false).run(); } }
Example #15
Source File: HaxeFileTemplateUtil.java From intellij-haxe with Apache License 2.0 | 5 votes |
public static PsiElement createClass(String className, String packageName, PsiDirectory directory, String templateName, @org.jetbrains.annotations.Nullable java.lang.ClassLoader classLoader) throws Exception { final Properties props = new Properties(FileTemplateManager.getInstance().getDefaultProperties(directory.getProject())); props.setProperty(FileTemplate.ATTRIBUTE_NAME, className); props.setProperty(FileTemplate.ATTRIBUTE_PACKAGE_NAME, packageName); final FileTemplate template = FileTemplateManager.getInstance().getInternalTemplate(templateName); return FileTemplateUtil.createFromTemplate(template, className, props, directory, classLoader); }
Example #16
Source File: FileReferenceQuickFixProvider.java From consulo with Apache License 2.0 | 5 votes |
@Override protected void openFile(@Nonnull Project project, PsiDirectory directory, PsiFile newFile, String text) { super.openFile(project, directory, newFile, text); if (!isDirectory && myNewFileTemplateName != null) { FileTemplateManager fileTemplateManager = FileTemplateManager.getInstance(project); FileTemplate template = findTemplate(fileTemplateManager); if (template != null && template.isLiveTemplateEnabled()) { CreateFromTemplateActionBase.startLiveTemplate(newFile); } } }
Example #17
Source File: MuleDomainMavenProjectBuilderHelper.java From mule-intellij-plugins with Apache License 2.0 | 5 votes |
private VirtualFile createMuleConfigFile(final Project project, final MavenId projectId, final VirtualFile appDirectory) { //final String domainConfigName = projectId.getArtifactId(); final String domainConfigName = "mule-domain-config"; //Currently Mule requires it to be mule-domain-config.xml return new WriteCommandAction<VirtualFile>(project, "Create Mule Domain Config File", PsiFile.EMPTY_ARRAY) { @Override protected void run(@NotNull Result<VirtualFile> result) throws Throwable { try { VirtualFile configFile = appDirectory.findOrCreateChildData(this, domainConfigName + ".xml"); final Properties templateProps = new Properties(); templateProps.setProperty("NAME", projectId.getArtifactId()); final FileTemplateManager manager = FileTemplateManager.getInstance(project); final FileTemplate template = manager.getInternalTemplate(MuleFileTemplateDescriptorManager.MULE_DOMAIN_CONFIGURATION_FILE); final Properties defaultProperties = manager.getDefaultProperties(); defaultProperties.putAll(templateProps); final String text = template.getText(defaultProperties); VfsUtil.saveText(configFile, text); result.setResult(configFile); } catch (IOException e) { showError(project, e); } } }.execute().getResultObject(); }
Example #18
Source File: GLSLCreateFromTemplateHandler.java From glsl4idea with GNU Lesser General Public License v3.0 | 5 votes |
/** * Return map of extensions and their preferred template. * This map is obtained from taking all internal templates and overriding them with existing custom templates. */ private static Map<String, FileTemplate> getTemplates(Project project){ final Map<String, FileTemplate> result = new HashMap<>(); FileTemplateManager manager = FileTemplateManager.getInstance(project); addTemplates(result,manager.getInternalTemplates()); addTemplates(result,manager.getAllTemplates()); return result; }
Example #19
Source File: MuleDomainMavenProjectBuilderHelper.java From mule-intellij-plugins with Apache License 2.0 | 5 votes |
private VirtualFile createMuleDeployPropertiesFile(final Project project, final MavenId projectId, final VirtualFile appDirectory) { return new WriteCommandAction<VirtualFile>(project, "Create Mule Deploy Properties File", PsiFile.EMPTY_ARRAY) { @Override protected void run(@NotNull Result<VirtualFile> result) throws Throwable { try { VirtualFile configFile = appDirectory.findOrCreateChildData(this, "mule-deploy.properties"); final Properties templateProps = new Properties(); templateProps.setProperty("NAME", projectId.getArtifactId()); final FileTemplateManager manager = FileTemplateManager.getInstance(project); final FileTemplate template = manager.getInternalTemplate(MuleFileTemplateDescriptorManager.MULE_DOMAIN_DEPLOY_PROPERTIES); final Properties defaultProperties = manager.getDefaultProperties(); defaultProperties.putAll(templateProps); final String text = template.getText(defaultProperties); VfsUtil.saveText(configFile, text); result.setResult(configFile); } catch (IOException e) { showError(project, e); } } }.execute().getResultObject(); }
Example #20
Source File: MuleDomainMavenProjectBuilderHelper.java From mule-intellij-plugins with Apache License 2.0 | 5 votes |
private VirtualFile createPomFile(final Project project, final MavenId projectId, final String muleVersion, final VirtualFile root) { return new WriteCommandAction<VirtualFile>(project, "Create Mule Domain Project", PsiFile.EMPTY_ARRAY) { @Override protected void run(@NotNull Result<VirtualFile> result) throws Throwable { try { VirtualFile pomFile = root.findOrCreateChildData(this, MavenConstants.POM_XML); final Properties templateProps = new Properties(); templateProps.setProperty("GROUP_ID", projectId.getGroupId()); templateProps.setProperty("ARTIFACT_ID", projectId.getArtifactId()); templateProps.setProperty("VERSION", projectId.getVersion()); templateProps.setProperty("MULE_VERSION", muleVersion); final FileTemplateManager manager = FileTemplateManager.getInstance(project); final FileTemplate template = manager.getInternalTemplate(MuleFileTemplateDescriptorManager.MULE_DOMAIN_MAVEN_PROJECT); final Properties defaultProperties = manager.getDefaultProperties(); defaultProperties.putAll(templateProps); final String text = template.getText(defaultProperties); VfsUtil.saveText(pomFile, text); result.setResult(pomFile); } catch (IOException e) { showError(project, e); } } }.execute().getResultObject(); }
Example #21
Source File: CreateFromTemplateActionBase.java From consulo with Apache License 2.0 | 5 votes |
@RequiredUIAccess @Override public final void actionPerformed(@Nonnull AnActionEvent e) { DataContext dataContext = e.getDataContext(); IdeView view = dataContext.getData(LangDataKeys.IDE_VIEW); if (view == null) return; PsiDirectory dir = getTargetDirectory(dataContext, view); if (dir == null) return; Project project = dir.getProject(); FileTemplate selectedTemplate = getTemplate(project, dir); if (selectedTemplate != null) { AnAction action = getReplacedAction(selectedTemplate); if (action != null) { action.actionPerformed(e); } else { FileTemplateManager.getInstance(project).addRecentName(selectedTemplate.getName()); AttributesDefaults defaults = getAttributesDefaults(dataContext); Map<String, Object> properties = defaults != null ? defaults.getDefaultProperties() : null; CreateFromTemplateDialog dialog = new CreateFromTemplateDialog(dir, selectedTemplate, defaults, properties); PsiElement createdElement = dialog.create(); if (createdElement != null) { elementCreated(dialog, createdElement); view.selectElement(createdElement); if (selectedTemplate.isLiveTemplateEnabled() && createdElement instanceof PsiFile) { Map<String, String> defaultValues = getLiveTemplateDefaults(dataContext, ((PsiFile)createdElement)); startLiveTemplate((PsiFile)createdElement, notNull(defaultValues, Collections.emptyMap())); } } } } }
Example #22
Source File: MuleMavenProjectBuilderHelper.java From mule-intellij-plugins with Apache License 2.0 | 5 votes |
private VirtualFile createMuleConfigFile(final Project project, final MavenId projectId, final VirtualFile appDirectory) { return new WriteCommandAction<VirtualFile>(project, "Create Mule Config File", PsiFile.EMPTY_ARRAY) { @Override protected void run(@NotNull Result<VirtualFile> result) throws Throwable { try { VirtualFile configFile = appDirectory.findOrCreateChildData(this, projectId.getArtifactId() + ".xml"); final Properties templateProps = new Properties(); templateProps.setProperty("NAME", projectId.getArtifactId()); final FileTemplateManager manager = FileTemplateManager.getInstance(project); final FileTemplate template = manager.getInternalTemplate(MuleFileTemplateDescriptorManager.MULE_CONFIGURATION_FILE); final Properties defaultProperties = manager.getDefaultProperties(); defaultProperties.putAll(templateProps); final String text = template.getText(defaultProperties); VfsUtil.saveText(configFile, text); result.setResult(configFile); } catch (IOException e) { showError(project, e); } } }.execute().getResultObject(); }
Example #23
Source File: MuleMavenProjectBuilderHelper.java From mule-intellij-plugins with Apache License 2.0 | 5 votes |
private VirtualFile createLog4J(final Project project, final MavenId projectId, final VirtualFile appDirectory) { return new WriteCommandAction<VirtualFile>(project, "Create Log4J File", PsiFile.EMPTY_ARRAY) { @Override protected void run(@NotNull Result<VirtualFile> result) throws Throwable { try { VirtualFile configFile = appDirectory.findOrCreateChildData(this, "log4j2.xml"); final Properties templateProps = new Properties(); templateProps.setProperty("FILE_NAME", "${sys:mule.home}${sys:file.separator}logs${sys:file.separator}" + projectId.getArtifactId().toLowerCase() + ".log"); templateProps.setProperty("FILE_PATTERN", "${sys:mule.home}${sys:file.separator}logs${sys:file.separator}" + projectId.getArtifactId().toLowerCase() + "-%i.log"); final FileTemplateManager manager = FileTemplateManager.getInstance(project); final FileTemplate template = manager.getInternalTemplate(MuleFileTemplateDescriptorManager.LOG4J2); final Properties defaultProperties = manager.getDefaultProperties(); defaultProperties.putAll(templateProps); final String text = template.getText(defaultProperties); VfsUtil.saveText(configFile, text); result.setResult(configFile); } catch (IOException e) { showError(project, e); } } }.execute().getResultObject(); }
Example #24
Source File: BitrixFramework.java From bxfs with MIT License | 5 votes |
@Override public void projectOpened() { // projectSourceRoots = ProjectRootManager.getInstance(project).getContentSourceRoots(); // for (VirtualFile resourceRoot : WebResourcesPathsConfiguration.getInstance(project).getResourceDirectories()) { // projectResourceRoots = Arrays.copyOf(projectResourceRoots, projectResourceRoots.length + 1); // projectResourceRoots[projectResourceRoots.length - 1] = resourceRoot; // } project.getMessageBus().connect(project).subscribe(ProjectTopics.PROJECT_ROOTS, this); /* Шаблоны страниц */ FileTemplateManager templateManager = FileTemplateManager.getInstance(project); for (String templateName : templates.keySet()) { if (null == templateManager.findInternalTemplate(templateName)) { Optional<String> content = getResourceFileContent( "fileTemplates/" + templates.get(templateName) + ".php.ft"); if (content.isPresent()) { FileTemplate template = templateManager.addTemplate(templateName, "php"); template.setText(content.get()); template.setReformatCode(true); } } } }
Example #25
Source File: MuleMavenProjectBuilderHelper.java From mule-intellij-plugins with Apache License 2.0 | 5 votes |
private VirtualFile createModulePomFile(final Project project, final MavenId projectId, final VirtualFile root, final MavenId parentId) { return new WriteCommandAction<VirtualFile>(project, "Create Mule Project", PsiFile.EMPTY_ARRAY) { @Override protected void run(@NotNull Result<VirtualFile> result) throws Throwable { try { VirtualFile pomFile = root.findOrCreateChildData(this, MavenConstants.POM_XML); final Properties templateProps = new Properties(); templateProps.setProperty("GROUP_ID", parentId.getGroupId()); templateProps.setProperty("ARTIFACT_ID", projectId.getArtifactId()); templateProps.setProperty("PARENT_ID", parentId.getArtifactId()); templateProps.setProperty("VERSION", parentId.getVersion()); final FileTemplateManager manager = FileTemplateManager.getInstance(project); final FileTemplate template = manager.getInternalTemplate(MuleFileTemplateDescriptorManager.MULE_MAVEN_MODULE); final Properties defaultProperties = manager.getDefaultProperties(); defaultProperties.putAll(templateProps); final String text = template.getText(defaultProperties); VfsUtil.saveText(pomFile, text); result.setResult(pomFile); } catch (IOException e) { showError(project, e); } } }.execute().getResultObject(); }
Example #26
Source File: CreateFileTemplateAction.java From PackageTemplates with Apache License 2.0 | 5 votes |
private void restoreTemplate(FileTemplate newTemplate, FileTemplateManager ftm) { // Restore Old if (backupTemplate != null) { newTemplate.setText(backupTemplate.getText()); newTemplate.setExtension(backupTemplate.getExtension()); newTemplate.setLiveTemplateEnabled(backupTemplate.isLiveTemplateEnabled()); newTemplate.setReformatCode(backupTemplate.isReformatCode()); } else { ftm.removeTemplate(newTemplate); } }
Example #27
Source File: CreateFileTemplateAction.java From PackageTemplates with Apache License 2.0 | 5 votes |
private void doRunInWrite() { String text = FileReaderUtil.readFile(fileFrom); if (text == null) { ReportHelper.setState(ExecutionState.FAILED); ReportHelper.putReport(new FailedActionReport(this, Localizer.get("error.ReadFileContent"), "FileReaderUtil.readFile return null")); return; } FileTemplateManager ftm = FileTemplateHelper.getManagerInstance(project); FileTemplate oldTemplate = ftm.getTemplate(StringTools.getNameWithoutExtension(fileFrom.getName())); if (oldTemplate != null) { ftm.removeTemplate(oldTemplate); // ftm.saveAllTemplates(); } FileTemplate[] templates = ftm.getAllTemplates(); FileTemplate template = FileTemplateUtil.createTemplate( StringTools.getNameWithoutExtension(fileFrom.getName()), StringTools.getExtensionFromName(fileFrom.getName()), text, templates ); ftm.setTemplates(FileTemplateManager.DEFAULT_TEMPLATES_CATEGORY, Arrays.asList(ArrayUtil.append(templates, template))); ReportHelper.putReport(new SuccessActionReport(this, toString())); }
Example #28
Source File: FileTemplateHelper.java From PackageTemplates with Apache License 2.0 | 5 votes |
public static ArrayList<TemplateForSearch> getTemplates(Project project, boolean addInternal, boolean addJ2EE, FileTemplateSource fileTemplateSource) { FileTemplateManager projectManager = getProjectManager(project); FileTemplateManager defaultManager = getDefaultManager(); ArrayList<FileTemplate> fileTemplates = new ArrayList<>(); switch (fileTemplateSource) { case DEFAULT_ONLY: addIfNameUnique(fileTemplates, defaultManager.getAllTemplates()); break; case PROJECT_ONLY: addIfNameUnique(fileTemplates, projectManager.getAllTemplates()); break; case PROJECT_PRIORITY: addIfNameUnique(fileTemplates, projectManager.getAllTemplates()); addIfNameUnique(fileTemplates, defaultManager.getAllTemplates()); break; case DEFAULT_PRIORITY: addIfNameUnique(fileTemplates, defaultManager.getAllTemplates()); addIfNameUnique(fileTemplates, projectManager.getAllTemplates()); break; } if (addInternal) { addIfNameUnique(fileTemplates, projectManager.getInternalTemplates()); } if (addJ2EE) { addIfNameUnique(fileTemplates, projectManager.getTemplates(FileTemplateManager.J2EE_TEMPLATES_CATEGORY)); } ArrayList<TemplateForSearch> listTemplateForSearch = new ArrayList(fileTemplates.size()); for (FileTemplate template : fileTemplates) { listTemplateForSearch.add(new TemplateForSearch(template)); } return listTemplateForSearch; }
Example #29
Source File: FileTemplateHelper.java From PackageTemplates with Apache License 2.0 | 5 votes |
private static FileTemplate getProjectTemplateOnly(String name, FileTemplateManager projectManager, FileTemplateManager defaultManager) { FileTemplate result; result = projectManager.getTemplate(name); if (result != null) { return result; } return null; }
Example #30
Source File: FileTemplateHelper.java From PackageTemplates with Apache License 2.0 | 5 votes |
private static FileTemplate getDefaultTemplateOnly(String name, FileTemplateManager projectManager, FileTemplateManager defaultManager) { FileTemplate result; result = defaultManager.getTemplate(name); if (result != null) { return result; } return null; }