Search in sources :

Example 11 with ResourceBundle

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));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) FileEditor(com.intellij.openapi.fileEditor.FileEditor) ResourceBundle(com.intellij.lang.properties.ResourceBundle)

Example 12 with ResourceBundle

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);
}
Also used : ResourceBundle(com.intellij.lang.properties.ResourceBundle)

Example 13 with ResourceBundle

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;
}
Also used : Project(com.intellij.openapi.project.Project) ResourceBundle(com.intellij.lang.properties.ResourceBundle)

Example 14 with ResourceBundle

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);
}
Also used : ResourceBundle(com.intellij.lang.properties.ResourceBundle) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with 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));
            }
        });
    }
}
Also used : Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) ResourceBundle(com.intellij.lang.properties.ResourceBundle) ResourceBundleAsVirtualFile(com.intellij.lang.properties.editor.ResourceBundleAsVirtualFile) PsiElement(com.intellij.psi.PsiElement)

Aggregations

ResourceBundle (com.intellij.lang.properties.ResourceBundle)32 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)20 Project (com.intellij.openapi.project.Project)11 NotNull (org.jetbrains.annotations.NotNull)10 PsiFile (com.intellij.psi.PsiFile)9 PsiElement (com.intellij.psi.PsiElement)7 IProperty (com.intellij.lang.properties.IProperty)6 FileEditor (com.intellij.openapi.fileEditor.FileEditor)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 ContainerUtil (com.intellij.util.containers.ContainerUtil)4 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)3 ResourceBundleAsVirtualFile (com.intellij.lang.properties.editor.ResourceBundleAsVirtualFile)3 HashSet (com.intellij.util.containers.HashSet)3 com.intellij.lang.properties (com.intellij.lang.properties)2 PropertiesImplUtil (com.intellij.lang.properties.PropertiesImplUtil)2 ResourceBundleNode (com.intellij.lang.properties.projectView.ResourceBundleNode)2 XmlPropertiesFile (com.intellij.lang.properties.xml.XmlPropertiesFile)2 GotoRelatedItem (com.intellij.navigation.GotoRelatedItem)2 Logger (com.intellij.openapi.diagnostic.Logger)2 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)2