use of com.intellij.lang.properties.ResourceBundle in project intellij-community by JetBrains.
the class ResourceBundleRenamerFactory method isApplicable.
@Override
public boolean isApplicable(@NotNull final PsiElement element) {
if (!(element instanceof PsiFile)) {
return false;
}
final PropertiesFile file = PropertiesImplUtil.getPropertiesFile(element);
if (file == null) {
return false;
}
final ResourceBundle resourceBundle = file.getResourceBundle();
return resourceBundle.getBaseDirectory() != null && resourceBundle.getPropertiesFiles().size() != 1;
}
use of com.intellij.lang.properties.ResourceBundle in project intellij-community by JetBrains.
the class ResourceBundleNode method drop.
@Override
public void drop(TreeNode[] sourceNodes, DataContext dataContext) {
MultiMap<ResourceBundle, PropertiesFile> bundleGrouping = new MultiMap<>();
for (TreeNode sourceNode : sourceNodes) {
final PropertiesFile propertiesFile = extractPropertiesFileFromNode(sourceNode);
if (propertiesFile == null)
return;
bundleGrouping.putValue(propertiesFile.getResourceBundle(), propertiesFile);
}
final ResourceBundle resourceBundle = ObjectUtils.notNull(getValue());
bundleGrouping.remove(resourceBundle);
final ResourceBundleManager resourceBundleManager = ResourceBundleManager.getInstance(myProject);
final List<PropertiesFile> toAddInResourceBundle = new ArrayList<>();
for (Map.Entry<ResourceBundle, Collection<PropertiesFile>> entry : bundleGrouping.entrySet()) {
toAddInResourceBundle.addAll(entry.getValue());
final ResourceBundle currentBundle = entry.getKey();
final Collection<PropertiesFile> propertiesFilesToMove = entry.getValue();
if (currentBundle.getPropertiesFiles().size() - propertiesFilesToMove.size() > 0) {
final String currentBundleBaseName = currentBundle.getBaseName();
final ArrayList<PropertiesFile> files = new ArrayList<>(currentBundle.getPropertiesFiles());
files.removeAll(propertiesFilesToMove);
resourceBundleManager.dissociateResourceBundle(currentBundle);
resourceBundleManager.combineToResourceBundle(files, currentBundleBaseName);
}
}
toAddInResourceBundle.addAll(resourceBundle.getPropertiesFiles());
final String baseName = resourceBundle.getBaseName();
final FileEditorManager fileEditorManager = FileEditorManager.getInstance(getProject());
fileEditorManager.closeFile(new ResourceBundleAsVirtualFile(resourceBundle));
resourceBundleManager.dissociateResourceBundle(resourceBundle);
final ResourceBundle updatedBundle = resourceBundleManager.combineToResourceBundleAndGet(toAddInResourceBundle, baseName);
FileEditorManager.getInstance(getProject()).openFile(new ResourceBundleAsVirtualFile(updatedBundle), true);
ProjectView.getInstance(getProject()).refresh();
}
Aggregations