Search in sources :

Example 1 with XmlPropertiesFile

use of com.intellij.lang.properties.xml.XmlPropertiesFile in project intellij-community by JetBrains.

the class I18nUtil method defaultSuggestPropertiesFiles.

public static List<String> defaultSuggestPropertiesFiles(Project project) {
    final List<String> paths = new ArrayList<>();
    final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    PropertiesReferenceManager.getInstance(project).processAllPropertiesFiles(new PropertiesFileProcessor() {

        @Override
        public boolean process(String baseName, PropertiesFile propertiesFile) {
            if (propertiesFile instanceof XmlPropertiesFile) {
                return true;
            }
            VirtualFile virtualFile = propertiesFile.getVirtualFile();
            if (projectFileIndex.isInContent(virtualFile)) {
                String path = FileUtil.toSystemDependentName(virtualFile.getPath());
                paths.add(path);
            }
            return true;
        }
    });
    return paths;
}
Also used : XmlPropertiesFile(com.intellij.lang.properties.xml.XmlPropertiesFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PropertiesFileProcessor(com.intellij.lang.properties.PropertiesFileProcessor) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) ArrayList(java.util.ArrayList) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) XmlPropertiesFile(com.intellij.lang.properties.xml.XmlPropertiesFile)

Example 2 with XmlPropertiesFile

use of com.intellij.lang.properties.xml.XmlPropertiesFile in project intellij-community by JetBrains.

the class CreateResourceBundleDialogComponent method createPropertiesFiles.

private List<PsiFile> createPropertiesFiles() {
    final Set<String> fileNames = getFileNamesToCreate();
    final List<PsiFile> createdFiles = WriteCommandAction.runWriteCommandAction(myProject, new Computable<List<PsiFile>>() {

        @Override
        public List<PsiFile> compute() {
            return ReadAction.compute(() -> ContainerUtil.map(fileNames, n -> {
                final boolean isXml = myResourceBundle == null ? myUseXMLBasedPropertiesCheckBox.isSelected() : myResourceBundle.getDefaultPropertiesFile() instanceof XmlPropertiesFile;
                if (isXml) {
                    FileTemplate template = FileTemplateManager.getInstance(myProject).getInternalTemplate("XML Properties File.xml");
                    LOG.assertTrue(template != null);
                    try {
                        return (PsiFile) FileTemplateUtil.createFromTemplate(template, n, null, myDirectory);
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                } else {
                    return myDirectory.createFile(n);
                }
            }));
        }
    });
    combineToResourceBundleIfNeed(createdFiles);
    return createdFiles;
}
Also used : XmlPropertiesFile(com.intellij.lang.properties.xml.XmlPropertiesFile) FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) JBList(com.intellij.ui.components.JBList) PsiFile(com.intellij.psi.PsiFile)

Aggregations

XmlPropertiesFile (com.intellij.lang.properties.xml.XmlPropertiesFile)2 FileTemplate (com.intellij.ide.fileTemplates.FileTemplate)1 PropertiesFileProcessor (com.intellij.lang.properties.PropertiesFileProcessor)1 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)1 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 JBList (com.intellij.ui.components.JBList)1 ArrayList (java.util.ArrayList)1