mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
scope view: sort nodes on expand/collapse for non-IDEA IDEs (IDEA-79222)
This commit is contained in:
@@ -42,7 +42,7 @@ public class ClassNode extends BasePsiNode<PsiClass> implements Comparable<Class
|
||||
public int compareTo(final ClassNode o) {
|
||||
final int comparision = ClassTreeNode.getClassPosition((PsiClass)getPsiElement()) - ClassTreeNode.getClassPosition((PsiClass)o.getPsiElement());
|
||||
if (comparision == 0) {
|
||||
return toString().compareTo(o.toString());
|
||||
return toString().compareToIgnoreCase(o.toString());
|
||||
}
|
||||
return comparision;
|
||||
}
|
||||
|
||||
@@ -79,8 +79,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.TreeExpansionEvent;
|
||||
import javax.swing.event.TreeWillExpandListener;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import javax.swing.tree.ExpandVetoException;
|
||||
import javax.swing.tree.TreePath;
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
@@ -241,9 +244,13 @@ public class ScopeTreeViewPanel extends JPanel implements Disposable {
|
||||
}
|
||||
};
|
||||
myTreeExpansionMonitor = PackageTreeExpansionMonitor.install(myTree, myProject);
|
||||
for (ScopeTreeStructureExpander expander : Extensions.getExtensions(ScopeTreeStructureExpander.EP_NAME, myProject)) {
|
||||
final ScopeTreeStructureExpander[] extensions = Extensions.getExtensions(ScopeTreeStructureExpander.EP_NAME, myProject);
|
||||
for (ScopeTreeStructureExpander expander : extensions) {
|
||||
myTree.addTreeWillExpandListener(expander);
|
||||
}
|
||||
if (extensions.length == 0) {
|
||||
myTree.addTreeWillExpandListener(new SortingExpandListener());
|
||||
}
|
||||
myTree.addKeyListener(new KeyAdapter() {
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if (KeyEvent.VK_ENTER == e.getKeyCode()) {
|
||||
@@ -947,4 +954,17 @@ public class ScopeTreeViewPanel extends JPanel implements Disposable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class SortingExpandListener implements TreeWillExpandListener {
|
||||
@Override
|
||||
public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
|
||||
final TreePath path = event.getPath();
|
||||
if (path == null) return;
|
||||
final DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent();
|
||||
TreeUtil.sort(node, getNodeComparator());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-3
@@ -16,8 +16,6 @@
|
||||
|
||||
package com.intellij.packageDependencies.ui;
|
||||
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public class DependencyNodeComparator implements Comparator<PackageDependenciesNode>{
|
||||
@@ -38,6 +36,10 @@ public class DependencyNodeComparator implements Comparator<PackageDependenciesN
|
||||
return ((Comparable)p1).compareTo(p2);
|
||||
}
|
||||
}
|
||||
return Comparing.compare(p1.toString(), p2.toString());
|
||||
final String o1 = p1.toString();
|
||||
final String o2 = p2.toString();
|
||||
if (o1 == null) return o2 == null ? 0 : -1;
|
||||
if (o2 == null) return 1;
|
||||
return o1.compareToIgnoreCase(o2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user