Search in sources :

Example 1 with ResourceBundleManager

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

the class CombinePropertiesFilesAction method actionPerformed.

@Override
public void actionPerformed(final AnActionEvent e) {
    final List<PropertiesFile> initialPropertiesFiles = getPropertiesFiles(e);
    final List<PropertiesFile> propertiesFiles = initialPropertiesFiles == null ? new ArrayList<>() : new ArrayList<>(initialPropertiesFiles);
    final List<ResourceBundle> resourceBundles = getResourceBundles(e);
    if (resourceBundles != null) {
        for (ResourceBundle bundle : resourceBundles) {
            propertiesFiles.addAll(bundle.getPropertiesFiles());
        }
    }
    final String newBaseName = Messages.showInputDialog(propertiesFiles.get(0).getProject(), PropertiesBundle.message("combine.properties.files.prompt.text"), PropertiesBundle.message("combine.properties.files.title"), Messages.getQuestionIcon(), PropertiesUtil.getDefaultBaseName(propertiesFiles), new MyInputValidator(propertiesFiles));
    if (newBaseName != null) {
        final Project project = propertiesFiles.get(0).getProject();
        final Set<ResourceBundle> uniqueBundlesToDissociate = new HashSet<>();
        for (PropertiesFile file : propertiesFiles) {
            final ResourceBundle resourceBundle = file.getResourceBundle();
            if (resourceBundle.getPropertiesFiles().size() != 1) {
                uniqueBundlesToDissociate.add(resourceBundle);
            }
        }
        final ResourceBundleManager resourceBundleManager = ResourceBundleManager.getInstance(project);
        for (ResourceBundle resourceBundle : uniqueBundlesToDissociate) {
            resourceBundleManager.dissociateResourceBundle(resourceBundle);
        }
        final ResourceBundle resourceBundle = resourceBundleManager.combineToResourceBundleAndGet(propertiesFiles, newBaseName);
        FileEditorManager.getInstance(project).openFile(new ResourceBundleAsVirtualFile(resourceBundle), true);
        ProjectView.getInstance(project).refresh();
    }
}
Also used : Project(com.intellij.openapi.project.Project) ResourceBundleManager(com.intellij.lang.properties.ResourceBundleManager) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) ResourceBundle(com.intellij.lang.properties.ResourceBundle) ResourceBundleAsVirtualFile(com.intellij.lang.properties.editor.ResourceBundleAsVirtualFile)

Aggregations

ResourceBundle (com.intellij.lang.properties.ResourceBundle)1 ResourceBundleManager (com.intellij.lang.properties.ResourceBundleManager)1 ResourceBundleAsVirtualFile (com.intellij.lang.properties.editor.ResourceBundleAsVirtualFile)1 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)1 Project (com.intellij.openapi.project.Project)1