use of com.intellij.ide.fileTemplates.FileTemplate in project android by JetBrains.
the class CreateFileFromTemplateDialog method initKindCombo.
public void initKindCombo() {
myKindCombo.registerUpDownHint(myNameField);
myKindCombo.getComboBox().addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
if (actionEvent.getSource().equals(myKindCombo.getComboBox())) {
configureComponents(Kind.valueOfText(myKindCombo.getSelectedName()));
}
}
});
addKind(Kind.CLASS);
addKind(Kind.INTERFACE);
if (LanguageLevelProjectExtension.getInstance(myProject).getLanguageLevel().isAtLeast(LanguageLevel.JDK_1_5)) {
addKind(Kind.ENUM);
addKind(Kind.ANNOTATION);
}
final JavaCreateFromTemplateHandler handler = new JavaCreateFromTemplateHandler();
for (FileTemplate template : FileTemplateManager.getInstance(myProject).getAllTemplates()) {
if (handler.handlesTemplate(template)) {
addKind(template);
}
}
}
use of com.intellij.ide.fileTemplates.FileTemplate in project android by JetBrains.
the class AndroidResourceUtil method createFileResource.
@NotNull
public static XmlFile createFileResource(@NotNull String fileName, @NotNull PsiDirectory resSubdir, @NotNull String rootTagName, @NotNull String resourceType, boolean valuesResourceFile) throws Exception {
FileTemplateManager manager = FileTemplateManager.getInstance(resSubdir.getProject());
String templateName = getTemplateName(resourceType, valuesResourceFile, rootTagName);
FileTemplate template = manager.getJ2eeTemplate(templateName);
Properties properties = new Properties();
if (!valuesResourceFile) {
properties.setProperty(ROOT_TAG_PROPERTY, rootTagName);
}
if (ResourceType.LAYOUT.getName().equals(resourceType)) {
final Module module = ModuleUtilCore.findModuleForPsiElement(resSubdir);
final AndroidPlatform platform = module != null ? AndroidPlatform.getInstance(module) : null;
final int apiLevel = platform != null ? platform.getApiLevel() : -1;
final String value = apiLevel == -1 || apiLevel >= 8 ? "match_parent" : "fill_parent";
properties.setProperty(LAYOUT_WIDTH_PROPERTY, value);
properties.setProperty(LAYOUT_HEIGHT_PROPERTY, value);
}
PsiElement createdElement = FileTemplateUtil.createFromTemplate(template, fileName, properties, resSubdir);
assert createdElement instanceof XmlFile;
return (XmlFile) createdElement;
}
use of com.intellij.ide.fileTemplates.FileTemplate in project android by JetBrains.
the class AndroidStudioInitializer method setUpNewProjectActions.
private static void setUpNewProjectActions() {
replaceAction("NewClass", new CreateClassAction());
// Update the text for the file creation templates.
FileTemplateManager fileTemplateManager = FileTemplateManager.getDefaultInstance();
fileTemplateManager.getTemplate("Singleton").setText(fileTemplateManager.getJ2eeTemplate("Singleton").getText());
for (String templateName : new String[] { "Class", "Interface", "Enum", "AnnotationType" }) {
FileTemplate template = fileTemplateManager.getInternalTemplate(templateName);
template.setText(fileTemplateManager.getJ2eeTemplate(templateName).getText());
}
}
use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-plugins by JetBrains.
the class FlexMainStep method commit.
@Override
public void commit(final CommitType commitType) throws CommitStepException {
super.commit(commitType);
// let's replace parent component only if template contains 'Superclass' macro
final FileTemplate template;
try {
template = ClassLoaderUtil.runWithClassLoader(ActionScriptCreateClassOrInterfaceFix.class.getClassLoader(), new ThrowableComputable<FileTemplate, IOException>() {
@Override
public FileTemplate compute() throws IOException {
return FileTemplateManager.getDefaultInstance().getInternalTemplate(myModel.getTemplateName());
}
});
String[] attributes = FileTemplateUtil.calculateAttributes(template.getText(), new Properties(), true, myProject);
if (ArrayUtil.contains(ActionScriptCreateClassOrInterfaceFix.SUPERCLASS, attributes)) {
myModel.setSuperclassFqn(getSuperclassFqn());
}
} catch (IOException e) {
// ignore as the action will not succeed
} catch (ParseException e) {
// ignore as the action will not succeed
}
}
use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-plugins by JetBrains.
the class CreateStrutsXmlAction method create.
@NotNull
protected PsiElement[] create(final String newName, final PsiDirectory directory) throws Exception {
@NonNls final String fileName = getFileName(newName);
final Module module = ModuleUtilCore.findModuleForPsiElement(directory);
StrutsFileTemplateProvider templateProvider = new StrutsFileTemplateProvider(module);
final FileTemplate strutsXmlTemplate = templateProvider.determineFileTemplate(directory.getProject());
final PsiElement file = FileTemplateUtil.createFromTemplate(strutsXmlTemplate, fileName, null, directory);
return new PsiElement[] { file };
}
Aggregations