use of com.intellij.lang.properties.ResourceBundle in project intellij-community by JetBrains.
the class ResourceBundleFromEditorRenameHandler method isAvailableOnDataContext.
@Override
public boolean isAvailableOnDataContext(DataContext dataContext) {
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (project == null) {
return false;
}
final ResourceBundle bundle = ResourceBundleUtil.getResourceBundleFromDataContext(dataContext);
if (bundle == null) {
return false;
}
final FileEditor fileEditor = PlatformDataKeys.FILE_EDITOR.getData(dataContext);
if (fileEditor == null || !(fileEditor instanceof ResourceBundleEditor)) {
return false;
}
final VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
return !(virtualFile == null || !(virtualFile instanceof ResourceBundleAsVirtualFile));
}
use of com.intellij.lang.properties.ResourceBundle in project intellij-community by JetBrains.
the class ResourceBundleFromProjectViewRenameHandler method invoke.
@Override
public void invoke(@NotNull final Project project, Editor editor, final PsiFile file, DataContext dataContext) {
final ResourceBundle resourceBundle = ResourceBundleUtil.getResourceBundleFromDataContext(dataContext);
assert resourceBundle != null;
RefactoringActionHandlerFactory.getInstance().createRenameHandler().invoke(project, new PsiElement[] { resourceBundle.getDefaultPropertiesFile().getContainingFile() }, dataContext);
}
use of com.intellij.lang.properties.ResourceBundle in project intellij-community by JetBrains.
the class ResourceBundleFromProjectViewRenameHandler method isAvailableOnDataContext.
@Override
public boolean isAvailableOnDataContext(DataContext dataContext) {
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (project == null) {
return false;
}
final ResourceBundle bundle = ResourceBundleUtil.getResourceBundleFromDataContext(dataContext);
if (bundle == null || bundle.getPropertiesFiles().size() < 2) {
return false;
}
return PlatformDataKeys.FILE_EDITOR.getData(dataContext) == null && CommonDataKeys.VIRTUAL_FILE.getData(dataContext) == null;
}
use of com.intellij.lang.properties.ResourceBundle in project intellij-community by JetBrains.
the class ResourceBundleEditorProvider method createEditor.
@Override
@NotNull
public FileEditor createEditor(@NotNull Project project, @NotNull final VirtualFile file) {
ResourceBundle resourceBundle;
if (file instanceof ResourceBundleAsVirtualFile) {
resourceBundle = ((ResourceBundleAsVirtualFile) file).getResourceBundle();
} else {
PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
if (psiFile == null) {
throw new IllegalArgumentException("psifile cannot be null");
}
resourceBundle = PropertiesImplUtil.getPropertiesFile(psiFile).getResourceBundle();
}
return new ResourceBundleEditor(resourceBundle);
}
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));
}
});
}
}
Aggregations