Search in sources :

Example 1 with ResourceBundleAsVirtualFile

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));
            }
        });
    }
}
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)

Example 2 with ResourceBundleAsVirtualFile

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

Example 3 with ResourceBundleAsVirtualFile

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());
    }
}
Also used : FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) ResourceBundleAsVirtualFile(com.intellij.lang.properties.editor.ResourceBundleAsVirtualFile)

Example 4 with ResourceBundleAsVirtualFile

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);
}
Also used : OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) ResourceBundleAsVirtualFile(com.intellij.lang.properties.editor.ResourceBundleAsVirtualFile)

Example 5 with ResourceBundleAsVirtualFile

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();
}
Also used : ResourceBundleAsVirtualFile(com.intellij.lang.properties.editor.ResourceBundleAsVirtualFile) MultiMap(com.intellij.util.containers.MultiMap) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) TreeNode(javax.swing.tree.TreeNode) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ResourceBundle(com.intellij.lang.properties.ResourceBundle) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) MultiMap(com.intellij.util.containers.MultiMap)

Aggregations

ResourceBundleAsVirtualFile (com.intellij.lang.properties.editor.ResourceBundleAsVirtualFile)5 ResourceBundle (com.intellij.lang.properties.ResourceBundle)3 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)3 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)3 Project (com.intellij.openapi.project.Project)2 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)1 ResourceBundleManager (com.intellij.lang.properties.ResourceBundleManager)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 PsiElement (com.intellij.psi.PsiElement)1 MultiMap (com.intellij.util.containers.MultiMap)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 TreeNode (javax.swing.tree.TreeNode)1