mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
resource bundle editor: delete properties on multiple selection fixed
This commit is contained in:
-2
@@ -16,9 +16,7 @@
|
||||
package com.intellij.lang.properties.editor;
|
||||
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author Dmitry Batkovich
|
||||
|
||||
@@ -60,7 +60,7 @@ class NewPropertyAction extends AnAction {
|
||||
prefix = null;
|
||||
separator = null;
|
||||
} else {
|
||||
final ResourceBundleEditorViewElement selectedElement = resourceBundleEditor.getSelectedElement();
|
||||
final ResourceBundleEditorViewElement selectedElement = resourceBundleEditor.getSelectedElementIfOnlyOne();
|
||||
if (selectedElement == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
+39
-19
@@ -57,7 +57,10 @@ import com.intellij.ui.JBColor;
|
||||
import com.intellij.ui.JBSplitter;
|
||||
import com.intellij.ui.components.JBScrollPane;
|
||||
import com.intellij.util.Alarm;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.NullableFunction;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.ContainerUtilRt;
|
||||
import com.intellij.util.containers.Stack;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
@@ -129,7 +132,7 @@ public class ResourceBundleEditor extends UserDataHolderBase implements FileEdit
|
||||
@Override
|
||||
public void valueChanged(TreeSelectionEvent e) {
|
||||
// filter out temp unselect/select events
|
||||
if (getSelectedProperty() == null) return;
|
||||
if (Comparing.equal(e.getNewLeadSelectionPath(), e.getOldLeadSelectionPath()) || getSelectedProperty() == null) return;
|
||||
if (!arePropertiesEquivalent(selectedProperty, getSelectedProperty()) ||
|
||||
!Comparing.equal(selectedPropertiesFile, getSelectedPropertiesFile())) {
|
||||
|
||||
@@ -570,13 +573,21 @@ public class ResourceBundleEditor extends UserDataHolderBase implements FileEdit
|
||||
document.replaceString(0, document.getTextLength(), text);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private DefaultMutableTreeNode getSelectedNode() {
|
||||
@NotNull
|
||||
private Collection<DefaultMutableTreeNode> getSelectedNodes() {
|
||||
if (!isValid()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
JTree tree = myStructureViewComponent.getTree();
|
||||
if (tree == null) return null;
|
||||
TreePath selected = tree.getSelectionModel().getSelectionPath();
|
||||
if (selected == null) return null;
|
||||
return (DefaultMutableTreeNode)selected.getLastPathComponent();
|
||||
if (tree == null) return Collections.emptyList();
|
||||
TreePath[] selected = tree.getSelectionModel().getSelectionPaths();
|
||||
if (selected == null || selected.length == 0) return Collections.emptyList();
|
||||
return ContainerUtil.map(selected, new Function<TreePath, DefaultMutableTreeNode>() {
|
||||
@Override
|
||||
public DefaultMutableTreeNode fun(TreePath treePath) {
|
||||
return (DefaultMutableTreeNode)treePath.getLastPathComponent();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -587,25 +598,34 @@ public class ResourceBundleEditor extends UserDataHolderBase implements FileEdit
|
||||
|
||||
@Nullable
|
||||
private IProperty getSelectedProperty() {
|
||||
final DefaultMutableTreeNode selectedNode = getSelectedNode();
|
||||
if (selectedNode == null) {
|
||||
final Collection<DefaultMutableTreeNode> selectedNode = getSelectedNodes();
|
||||
if (selectedNode.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
final ResourceBundleEditorViewElement element = getSelectedElement(selectedNode);
|
||||
final ResourceBundleEditorViewElement element = getSelectedElement(ContainerUtil.getFirstItem(selectedNode));
|
||||
return element instanceof ResourceBundlePropertyStructureViewElement ? ((ResourceBundlePropertyStructureViewElement)element).getProperty()
|
||||
: null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Collection<ResourceBundleEditorViewElement> getSelectedElements() {
|
||||
final Collection<DefaultMutableTreeNode> selectedNodes = getSelectedNodes();
|
||||
return ContainerUtil.mapNotNull(selectedNodes, new NullableFunction<DefaultMutableTreeNode, ResourceBundleEditorViewElement>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public ResourceBundleEditorViewElement fun(DefaultMutableTreeNode selectedNode) {
|
||||
Object userObject = selectedNode.getUserObject();
|
||||
if (!(userObject instanceof AbstractTreeNode)) return null;
|
||||
Object value = ((AbstractTreeNode)userObject).getValue();
|
||||
return value instanceof ResourceBundleEditorViewElement ? (ResourceBundleEditorViewElement) value : null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ResourceBundleEditorViewElement getSelectedElement() {
|
||||
final DefaultMutableTreeNode selectedNode = getSelectedNode();
|
||||
if (selectedNode == null) {
|
||||
return null;
|
||||
}
|
||||
Object userObject = selectedNode.getUserObject();
|
||||
if (!(userObject instanceof AbstractTreeNode)) return null;
|
||||
Object value = ((AbstractTreeNode)userObject).getValue();
|
||||
return value instanceof ResourceBundleEditorViewElement ? (ResourceBundleEditorViewElement) value : null;
|
||||
public ResourceBundleEditorViewElement getSelectedElementIfOnlyOne() {
|
||||
final Collection<ResourceBundleEditorViewElement> selectedElements = getSelectedElements();
|
||||
return selectedElements.size() == 1 ? ContainerUtil.getFirstItem(selectedElements) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+14
-4
@@ -25,7 +25,6 @@ import com.intellij.lang.properties.psi.Property;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.ide.CopyPasteManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiNamedElement;
|
||||
@@ -34,10 +33,13 @@ import com.intellij.refactoring.safeDelete.SafeDeleteHandler;
|
||||
import com.intellij.ui.PopupHandler;
|
||||
import com.intellij.usages.UsageTarget;
|
||||
import com.intellij.usages.UsageView;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -74,9 +76,17 @@ class ResourceBundleStructureViewComponent extends PropertiesGroupingStructureVi
|
||||
} else if (PlatformDataKeys.FILE_EDITOR.is(dataId)) {
|
||||
return getFileEditor();
|
||||
} else if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
|
||||
final ResourceBundleEditorViewElement selectedElement = ((ResourceBundleEditor)getFileEditor()).getSelectedElement();
|
||||
if (selectedElement != null) {
|
||||
return selectedElement.getPsiElements();
|
||||
final Collection<ResourceBundleEditorViewElement> selectedElements = ((ResourceBundleEditor)getFileEditor()).getSelectedElements();
|
||||
if (selectedElements.isEmpty()) {
|
||||
return null;
|
||||
} else if (selectedElements.size() == 1) {
|
||||
return ContainerUtil.getFirstItem(selectedElements).getPsiElements();
|
||||
} else {
|
||||
final List<PsiElement> psiElements = new ArrayList<PsiElement>();
|
||||
for (ResourceBundleEditorViewElement selectedElement : selectedElements) {
|
||||
Collections.addAll(psiElements, selectedElement.getPsiElements());
|
||||
}
|
||||
return psiElements.toArray(new PsiElement[psiElements.size()]);
|
||||
}
|
||||
} else if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
|
||||
final PsiElement[] psiElements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(this);
|
||||
|
||||
+1
-1
@@ -74,7 +74,7 @@ public class ResourceBundleFromEditorRenameHandler implements RenameHandler {
|
||||
public void invoke(final @NotNull Project project, Editor editor, final PsiFile file, DataContext dataContext) {
|
||||
final ResourceBundleEditor resourceBundleEditor = (ResourceBundleEditor)PlatformDataKeys.FILE_EDITOR.getData(dataContext);
|
||||
assert resourceBundleEditor != null;
|
||||
final ResourceBundleEditorViewElement selectedElement = resourceBundleEditor.getSelectedElement();
|
||||
final ResourceBundleEditorViewElement selectedElement = resourceBundleEditor.getSelectedElementIfOnlyOne();
|
||||
if (selectedElement != null) {
|
||||
CommandProcessor.getInstance().runUndoTransparentAction(new Runnable() {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user