mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
SettingsTreeView: fix sorting after search
This commit is contained in:
+29
@@ -20,8 +20,12 @@ import com.intellij.openapi.options.ConfigurableGroup;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.options.OptionsBundle;
|
||||
import com.intellij.openapi.options.SearchableConfigurable;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
@@ -36,6 +40,7 @@ public final class MixedConfigurableGroup implements SearchableConfigurable, Con
|
||||
myConfigurables = (configurables != null)
|
||||
? configurables.toArray(new Configurable[configurables.size()])
|
||||
: new Configurable[0];
|
||||
Arrays.sort(myConfigurables, COMPARATOR);
|
||||
}
|
||||
|
||||
private MixedConfigurableGroup(String groupId, HashMap<String, ArrayList<Configurable>> configurables) {
|
||||
@@ -70,6 +75,7 @@ public final class MixedConfigurableGroup implements SearchableConfigurable, Con
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getId() {
|
||||
return "configurable.group." + myGroupId;
|
||||
@@ -146,4 +152,27 @@ public final class MixedConfigurableGroup implements SearchableConfigurable, Con
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int getGroupWeight(Configurable configurable) {
|
||||
if (configurable instanceof NodeConfigurable) {
|
||||
return ((NodeConfigurable)configurable).getGroupWeight();
|
||||
}
|
||||
if (configurable instanceof ConfigurableWrapper) {
|
||||
return ((ConfigurableWrapper)configurable).getExtensionPoint().groupWeight;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static final Comparator<Configurable> COMPARATOR = new Comparator<Configurable>() {
|
||||
@Override
|
||||
public int compare(Configurable configurable1, Configurable configurable2) {
|
||||
if (configurable1 == null || configurable2 == null) {
|
||||
return configurable2 != null ? -1 : configurable1 != null ? 1 : 0;
|
||||
}
|
||||
int weight1 = getGroupWeight(configurable1);
|
||||
int weight2 = getGroupWeight(configurable2);
|
||||
return weight1 > weight2 ? -1 : weight1 < weight2 ? 1 : StringUtil.naturalCompare(configurable1.getDisplayName(),
|
||||
configurable2.getDisplayName());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
+1
-10
@@ -1228,16 +1228,7 @@ public class OptionsEditor extends JPanel implements DataProvider, Place.Navigat
|
||||
if (searchable instanceof Configurable.Composite) {
|
||||
box.add(Box.createVerticalStrut(10));
|
||||
Configurable.Composite composite = (Configurable.Composite)searchable;
|
||||
Configurable[] configurables = composite.getConfigurables();
|
||||
if (myTreeView != null) {
|
||||
Arrays.sort(configurables, new Comparator<Configurable>() {
|
||||
@Override
|
||||
public int compare(Configurable configurable1, Configurable configurable2) {
|
||||
return myTreeView.compareConfigurables(configurable1, configurable2);
|
||||
}
|
||||
});
|
||||
}
|
||||
for (final Configurable configurable : configurables) {
|
||||
for (final Configurable configurable : composite.getConfigurables()) {
|
||||
box.add(new LinkLabel(configurable.getDisplayName(), AllIcons.Ide.Link) {
|
||||
@Override
|
||||
public void doClick() {
|
||||
|
||||
+4
-48
@@ -24,7 +24,6 @@ import com.intellij.openapi.options.ex.NodeConfigurable;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.ActionCallback;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.ui.treeStructure.CachingSimpleNode;
|
||||
import com.intellij.ui.treeStructure.SimpleNode;
|
||||
@@ -43,6 +42,8 @@ import com.intellij.util.ui.update.Update;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static com.intellij.openapi.options.ex.MixedConfigurableGroup.getGroupWeight;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.TreeExpansionEvent;
|
||||
import javax.swing.event.TreeExpansionListener;
|
||||
@@ -453,21 +454,6 @@ final class SettingsTreeView extends JComponent implements Disposable, OptionsEd
|
||||
public boolean isAlwaysLeaf() {
|
||||
return myComposite == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWeight() {
|
||||
SimpleNode parent = getParent();
|
||||
if (parent != null && myRoot == parent.getParent()) {
|
||||
if (myConfigurable instanceof NodeConfigurable) {
|
||||
return ((NodeConfigurable)myConfigurable).getGroupWeight();
|
||||
}
|
||||
if (myConfigurable instanceof ConfigurableWrapper) {
|
||||
return ((ConfigurableWrapper)myConfigurable).getExtensionPoint().groupWeight;
|
||||
}
|
||||
return 0; // sort by name
|
||||
}
|
||||
return Integer.MIN_VALUE; // do not sort
|
||||
}
|
||||
}
|
||||
|
||||
private final class MyRenderer extends GroupedElementsRenderer.Tree {
|
||||
@@ -549,7 +535,7 @@ final class SettingsTreeView extends JComponent implements Disposable, OptionsEd
|
||||
SimpleNode simpleNode = node;
|
||||
while (simpleNode != null) {
|
||||
SimpleNode parent = simpleNode.getParent();
|
||||
if (parent != null && myRoot == parent.getParent() && simpleNode.getWeight() == 0) {
|
||||
if (parent != null && myRoot == parent.getParent() && getGroupWeight(getConfigurable(simpleNode)) == 0) {
|
||||
myTextLabel.setForeground(HIDDEN_NODE);
|
||||
parent = null;
|
||||
}
|
||||
@@ -775,7 +761,7 @@ final class SettingsTreeView extends JComponent implements Disposable, OptionsEd
|
||||
boolean myWasHoldingFilter;
|
||||
|
||||
public MyBuilder(SimpleTreeStructure structure) {
|
||||
super(myTree, myFilter, structure, COMPARATOR);
|
||||
super(myTree, myFilter, structure, null);
|
||||
myTree.addTreeExpansionListener(new TreeExpansionListener() {
|
||||
public void treeExpanded(TreeExpansionEvent event) {
|
||||
invalidateExpansions();
|
||||
@@ -863,34 +849,4 @@ final class SettingsTreeView extends JComponent implements Disposable, OptionsEd
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final Comparator<NodeDescriptor> COMPARATOR = new Comparator<NodeDescriptor>() {
|
||||
@Override
|
||||
public int compare(NodeDescriptor descriptor1, NodeDescriptor descriptor2) {
|
||||
return compareNodes(extractNode(descriptor1), extractNode(descriptor2));
|
||||
}
|
||||
};
|
||||
|
||||
int compareConfigurables(Configurable configurable1, Configurable configurable2) {
|
||||
return compareNodes(myConfigurableToNodeMap.get(configurable1), myConfigurableToNodeMap.get(configurable2));
|
||||
}
|
||||
|
||||
private static int compareNodes(MyNode node1, MyNode node2) {
|
||||
if (node1 == null || node2 == null) {
|
||||
return node2 != null ? -1 : node1 != null ? 1 : 0;
|
||||
}
|
||||
int weight1 = node1.getWeight();
|
||||
int weight2 = node2.getWeight();
|
||||
|
||||
if (weight1 > weight2) {
|
||||
return -1;
|
||||
}
|
||||
if (weight1 < weight2) {
|
||||
return 1;
|
||||
}
|
||||
if (weight1 == Integer.MIN_VALUE) {
|
||||
return 0; // do not sort if undefined weight
|
||||
}
|
||||
return StringUtil.naturalCompare(node1.myDisplayName, node2.myDisplayName);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user