use of com.intellij.lang.properties.editor.ResourceBundleAsVirtualFile in project intellij-community by JetBrains.
the class ResourceBundleDeleteProvider method deleteElement.
@Override
public void deleteElement(@NotNull DataContext dataContext) {
final ResourceBundle[] resourceBundles = ResourceBundle.ARRAY_DATA_KEY.getData(dataContext);
if (resourceBundles != null && resourceBundles.length != 0) {
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
LOG.assertTrue(project != null);
final PsiElement[] toDelete = Arrays.stream(resourceBundles).flatMap(rb -> rb.getPropertiesFiles().stream()).map(PropertiesFile::getContainingFile).toArray(PsiElement[]::new);
SafeDeleteHandler.invoke(project, toDelete, true, () -> {
final FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
for (ResourceBundle bundle : resourceBundles) {
fileEditorManager.closeFile(new ResourceBundleAsVirtualFile(bundle));
}
});
}
}
use of com.intellij.lang.properties.editor.ResourceBundleAsVirtualFile 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();
}
}
use of com.intellij.lang.properties.editor.ResourceBundleAsVirtualFile in project intellij-community by JetBrains.
the class ResourceBundleManager method closeResourceBundleEditors.
private static void closeResourceBundleEditors(@NotNull ResourceBundle resourceBundle) {
final FileEditorManager fileEditorManager = FileEditorManager.getInstance(resourceBundle.getProject());
fileEditorManager.closeFile(new ResourceBundleAsVirtualFile(resourceBundle));
for (final PropertiesFile propertiesFile : resourceBundle.getPropertiesFiles()) {
fileEditorManager.closeFile(propertiesFile.getVirtualFile());
}
}
use of com.intellij.lang.properties.editor.ResourceBundleAsVirtualFile in project intellij-community by JetBrains.
the class ResourceBundleNode method navigate.
@Override
public void navigate(final boolean requestFocus) {
OpenFileDescriptor descriptor = new OpenFileDescriptor(getProject(), new ResourceBundleAsVirtualFile(ObjectUtils.notNull(getValue())));
FileEditorManager.getInstance(getProject()).openTextEditor(descriptor, requestFocus);
}
use of com.intellij.lang.properties.editor.ResourceBundleAsVirtualFile 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