use of com.intellij.lang.properties.ResourceBundle 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.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;
}
use of com.intellij.lang.properties.ResourceBundle in project intellij-community by JetBrains.
the class ResourceBundleStructureViewComponent method getData.
@Override
public Object getData(final String dataId) {
if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) {
return new ResourceBundleAsVirtualFile(myResourceBundle);
} else if (PlatformDataKeys.FILE_EDITOR.is(dataId)) {
return getFileEditor();
} else if (ResourceBundle.ARRAY_DATA_KEY.is(dataId)) {
return new ResourceBundle[] { myResourceBundle };
} else if (IProperty.ARRAY_KEY.is(dataId)) {
final Collection<ResourceBundleEditorViewElement> selectedElements = ((ResourceBundleEditor) getFileEditor()).getSelectedElements();
if (selectedElements.isEmpty()) {
return null;
} else if (selectedElements.size() == 1) {
return ContainerUtil.getFirstItem(selectedElements).getProperties();
} else {
return ContainerUtil.toArray(ContainerUtil.flatten(ContainerUtil.mapNotNull(selectedElements, (NullableFunction<ResourceBundleEditorViewElement, List<IProperty>>) element -> {
final IProperty[] properties = element.getProperties();
return properties == null ? null : ContainerUtil.newArrayList(properties);
})), IProperty[]::new);
}
} else if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
final List<PsiElement> elements = new ArrayList<>();
Collections.addAll(elements, getSelectedPsiFiles());
final IProperty[] properties = (IProperty[]) getData(IProperty.ARRAY_KEY.getName());
if (properties != null) {
for (IProperty property : properties) {
final PsiElement element = property.getPsiElement();
if (element.isValid()) {
elements.add(element);
}
}
}
return elements.toArray(new PsiElement[elements.size()]);
} else if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
if (getSelectedPsiFiles().length != 0) {
return new ResourceBundleDeleteProvider();
}
final IProperty[] properties = IProperty.ARRAY_KEY.getData(this);
if (properties != null && properties.length != 0) {
return new PropertiesDeleteProvider(((ResourceBundleEditor) getFileEditor()).getPropertiesInsertDeleteManager(), properties);
}
} else if (UsageView.USAGE_TARGETS_KEY.is(dataId)) {
final PsiElement[] chosenElements = (PsiElement[]) getData(LangDataKeys.PSI_ELEMENT_ARRAY.getName());
if (chosenElements != null) {
final UsageTarget[] usageTargets = new UsageTarget[chosenElements.length];
for (int i = 0; i < chosenElements.length; i++) {
usageTargets[i] = new PsiElement2UsageTargetAdapter(chosenElements[i]);
}
return usageTargets;
}
} else if (PlatformDataKeys.COPY_PROVIDER.is(dataId)) {
return new CopyProvider() {
@Override
public void performCopy(@NotNull final DataContext dataContext) {
final PsiElement[] selectedPsiElements = (PsiElement[]) getData(LangDataKeys.PSI_ELEMENT_ARRAY.getName());
if (selectedPsiElements != null) {
final List<String> names = new ArrayList<>(selectedPsiElements.length);
for (final PsiElement element : selectedPsiElements) {
if (element instanceof PsiNamedElement) {
names.add(((PsiNamedElement) element).getName());
}
}
CopyPasteManager.getInstance().setContents(new StringSelection(StringUtil.join(names, "\n")));
}
}
@Override
public boolean isCopyEnabled(@NotNull final DataContext dataContext) {
return true;
}
@Override
public boolean isCopyVisible(@NotNull final DataContext dataContext) {
return true;
}
};
}
return super.getData(dataId);
}
use of com.intellij.lang.properties.ResourceBundle in project intellij-community by JetBrains.
the class ResourceBundleUtil method getResourceBundleFromDataContext.
/**
* Tries to derive {@link ResourceBundle resource bundle} related to the given context.
*
* @param dataContext target context
* @return {@link ResourceBundle resource bundle} related to the given context if any;
* {@code null} otherwise
*/
@Nullable
public static ResourceBundle getResourceBundleFromDataContext(@NotNull DataContext dataContext) {
PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
//rename property
if (element instanceof IProperty)
return null;
final ResourceBundle[] bundles = ResourceBundle.ARRAY_DATA_KEY.getData(dataContext);
if (bundles != null && bundles.length == 1)
return bundles[0];
VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
if (virtualFile == null) {
return null;
}
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (virtualFile instanceof ResourceBundleAsVirtualFile && project != null) {
return ((ResourceBundleAsVirtualFile) virtualFile).getResourceBundle();
}
if (project != null) {
final PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
if (psiFile instanceof PropertiesFile) {
return ((PropertiesFile) psiFile).getResourceBundle();
}
}
return null;
}
use of com.intellij.lang.properties.ResourceBundle in project intellij-community by JetBrains.
the class CustomResourceBundlePropertiesFileNode method update.
@Override
public void update(PresentationData data) {
super.update(data);
final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(getValue());
assert propertiesFile != null;
final ResourceBundle resourceBundle = propertiesFile.getResourceBundle();
data.setLocationString(PropertiesBundle.message("project.view.resource.bundle.tree.node.text", resourceBundle.getBaseName()));
}
Aggregations