Java Code Examples for com.intellij.ide.fileTemplates.FileTemplateManager#getTemplate()

The following examples show how to use com.intellij.ide.fileTemplates.FileTemplateManager#getTemplate() . 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 5 votes vote down vote up
private static FileTemplate getDefaultTemplateOnly(String name, FileTemplateManager projectManager, FileTemplateManager defaultManager) {
    FileTemplate result;

    result = defaultManager.getTemplate(name);
    if (result != null) {
        return result;
    }

    return null;
}
 
Example 2
Source File: FileTemplateHelper.java    From PackageTemplates with Apache License 2.0 5 votes vote down vote up
private static FileTemplate getProjectTemplateOnly(String name, FileTemplateManager projectManager, FileTemplateManager defaultManager) {
    FileTemplate result;

    result = projectManager.getTemplate(name);
    if (result != null) {
        return result;
    }

    return null;
}
 
Example 3
Source File: CreateFileTemplateAction.java    From PackageTemplates with Apache License 2.0 5 votes vote down vote up
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 4
Source File: FileReferenceQuickFixProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
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;
}