Search in sources :

Example 1 with ResourceBundle

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

the class ResourcesFavoriteNodeProvider method isInvalidElement.

@Override
public boolean isInvalidElement(final Object element) {
    if (element instanceof ResourceBundle) {
        ResourceBundle resourceBundle = (ResourceBundle) element;
        List<PropertiesFile> propertiesFiles = resourceBundle.getPropertiesFiles();
        if (propertiesFiles.size() == 1) {
            //todo result.add(new PsiFileNode(myProject, propertiesFiles.iterator().next(), this));
            return true;
        }
    }
    return false;
}
Also used : ResourceBundle(com.intellij.lang.properties.ResourceBundle) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile)

Example 2 with ResourceBundle

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

the class AddNewPropertyFileAction method update.

@Override
public void update(AnActionEvent e) {
    final Navigatable[] data = CommonDataKeys.NAVIGATABLE_ARRAY.getData(e.getDataContext());
    if (data != null && data.length == 1) {
        if (data[0] instanceof ResourceBundleNode || data[0] instanceof CustomResourceBundlePropertiesFileNode) {
            final ResourceBundle resourceBundle = (ResourceBundle) ((ProjectViewNode) data[0]).getValue();
            LOG.assertTrue(resourceBundle != null);
            if (CreateResourceBundleDialogComponent.getResourceBundlePlacementDirectory(resourceBundle) != null) {
                e.getPresentation().setEnabledAndVisible(true);
                return;
            }
        }
    }
    e.getPresentation().setEnabledAndVisible(false);
}
Also used : ResourceBundleNode(com.intellij.lang.properties.projectView.ResourceBundleNode) CustomResourceBundlePropertiesFileNode(com.intellij.lang.properties.projectView.CustomResourceBundlePropertiesFileNode) ResourceBundle(com.intellij.lang.properties.ResourceBundle) Navigatable(com.intellij.pom.Navigatable)

Example 3 with ResourceBundle

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

the class AddNewPropertyFileAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final ResourceBundle resourceBundle = getResourceBundle(e);
    new CreateResourceBundleDialogComponent.Dialog(e.getProject(), null, resourceBundle).show();
}
Also used : ResourceBundle(com.intellij.lang.properties.ResourceBundle)

Example 4 with ResourceBundle

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

the class CreateResourceBundleDialogComponent method combineToResourceBundleIfNeed.

private void combineToResourceBundleIfNeed(Collection<PsiFile> files) {
    Collection<PropertiesFile> createdFiles = ContainerUtil.map(files, (NotNullFunction<PsiFile, PropertiesFile>) dom -> {
        final PropertiesFile file = PropertiesImplUtil.getPropertiesFile(dom);
        LOG.assertTrue(file != null, dom.getName());
        return file;
    });
    ResourceBundle mainBundle = myResourceBundle;
    final Set<ResourceBundle> allBundles = new HashSet<>();
    if (mainBundle != null) {
        allBundles.add(mainBundle);
    }
    boolean needCombining = false;
    for (PropertiesFile file : createdFiles) {
        final ResourceBundle rb = file.getResourceBundle();
        if (mainBundle == null) {
            mainBundle = rb;
        } else if (!mainBundle.equals(rb)) {
            needCombining = true;
        }
        allBundles.add(rb);
    }
    if (needCombining) {
        final List<PropertiesFile> toCombine = new ArrayList<>(createdFiles);
        final String baseName = getBaseName();
        if (myResourceBundle != null) {
            toCombine.addAll(myResourceBundle.getPropertiesFiles());
        }
        ResourceBundleManager manager = ResourceBundleManager.getInstance(mainBundle.getProject());
        for (ResourceBundle bundle : allBundles) {
            manager.dissociateResourceBundle(bundle);
        }
        manager.combineToResourceBundle(toCombine, baseName);
    }
}
Also used : FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) java.util(java.util) AllIcons(com.intellij.icons.AllIcons) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) Computable(com.intellij.openapi.util.Computable) ContainerUtil(com.intellij.util.containers.ContainerUtil) ReadAction(com.intellij.openapi.application.ReadAction) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) ResourceBundle(com.intellij.lang.properties.ResourceBundle) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Messages(com.intellij.openapi.ui.Messages) Logger(com.intellij.openapi.diagnostic.Logger) ListSelectionEvent(javax.swing.event.ListSelectionEvent) InputValidatorEx(com.intellij.openapi.ui.InputValidatorEx) ValidationInfo(com.intellij.openapi.ui.ValidationInfo) JBList(com.intellij.ui.components.JBList) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) FileTemplateManager(com.intellij.ide.fileTemplates.FileTemplateManager) NotNullFunction(com.intellij.util.NotNullFunction) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) com.intellij.ui(com.intellij.ui) com.intellij.lang.properties(com.intellij.lang.properties) Nullable(org.jetbrains.annotations.Nullable) XmlPropertiesFile(com.intellij.lang.properties.xml.XmlPropertiesFile) java.awt.event(java.awt.event) FileTemplateUtil(com.intellij.ide.fileTemplates.FileTemplateUtil) PsiDirectory(com.intellij.psi.PsiDirectory) PathUtil(com.intellij.util.PathUtil) NotNull(org.jetbrains.annotations.NotNull) ListSelectionListener(javax.swing.event.ListSelectionListener) javax.swing(javax.swing) PsiFile(com.intellij.psi.PsiFile) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) XmlPropertiesFile(com.intellij.lang.properties.xml.XmlPropertiesFile) ResourceBundle(com.intellij.lang.properties.ResourceBundle)

Example 5 with ResourceBundle

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

the class DissociateResourceBundleAction method extractResourceBundles.

@NotNull
private static Collection<ResourceBundle> extractResourceBundles(final AnActionEvent event) {
    final Set<ResourceBundle> targetResourceBundles = new HashSet<>();
    final ResourceBundle[] chosenResourceBundles = event.getData(ResourceBundle.ARRAY_DATA_KEY);
    if (chosenResourceBundles != null) {
        for (ResourceBundle resourceBundle : chosenResourceBundles) {
            if (resourceBundle.getPropertiesFiles().size() > 1) {
                targetResourceBundles.add(resourceBundle);
            }
        }
    }
    final PsiElement[] psiElements = event.getData(LangDataKeys.PSI_ELEMENT_ARRAY);
    if (psiElements != null) {
        for (PsiElement element : psiElements) {
            final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(element);
            if (propertiesFile != null) {
                final ResourceBundle bundle = propertiesFile.getResourceBundle();
                if (bundle.getPropertiesFiles().size() > 1) {
                    targetResourceBundles.add(bundle);
                }
            }
        }
    }
    return targetResourceBundles;
}
Also used : ResourceBundle(com.intellij.lang.properties.ResourceBundle) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) PsiElement(com.intellij.psi.PsiElement) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ResourceBundle (com.intellij.lang.properties.ResourceBundle)32 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)20 Project (com.intellij.openapi.project.Project)11 NotNull (org.jetbrains.annotations.NotNull)10 PsiFile (com.intellij.psi.PsiFile)9 PsiElement (com.intellij.psi.PsiElement)7 IProperty (com.intellij.lang.properties.IProperty)6 FileEditor (com.intellij.openapi.fileEditor.FileEditor)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 ContainerUtil (com.intellij.util.containers.ContainerUtil)4 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)3 ResourceBundleAsVirtualFile (com.intellij.lang.properties.editor.ResourceBundleAsVirtualFile)3 HashSet (com.intellij.util.containers.HashSet)3 com.intellij.lang.properties (com.intellij.lang.properties)2 PropertiesImplUtil (com.intellij.lang.properties.PropertiesImplUtil)2 ResourceBundleNode (com.intellij.lang.properties.projectView.ResourceBundleNode)2 XmlPropertiesFile (com.intellij.lang.properties.xml.XmlPropertiesFile)2 GotoRelatedItem (com.intellij.navigation.GotoRelatedItem)2 Logger (com.intellij.openapi.diagnostic.Logger)2 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)2