mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Added button to show fields in structure view (PY-3936)
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package com.jetbrains.python.structureView;
|
||||
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.ide.util.treeView.smartTree.ActionPresentation;
|
||||
import com.intellij.ide.util.treeView.smartTree.ActionPresentationData;
|
||||
import com.intellij.ide.util.treeView.smartTree.Filter;
|
||||
import com.intellij.ide.util.treeView.smartTree.TreeElement;
|
||||
import com.intellij.util.PlatformIcons;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author vlan
|
||||
*/
|
||||
public class PyFieldsFilter implements Filter {
|
||||
private static final String ID = "SHOW_FIELDS";
|
||||
|
||||
@Override
|
||||
public boolean isReverted() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible(TreeElement treeNode) {
|
||||
if (treeNode instanceof PyStructureViewElement) {
|
||||
final PyStructureViewElement sve = (PyStructureViewElement)treeNode;
|
||||
return !sve.isField();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ActionPresentation getPresentation() {
|
||||
return new ActionPresentationData(IdeBundle.message("action.structureview.show.fields"), null, PlatformIcons.FIELD_ICON);
|
||||
}
|
||||
}
|
||||
@@ -39,15 +39,17 @@ public class PyStructureViewElement implements StructureViewTreeElement {
|
||||
private Visibility myVisibility;
|
||||
private Icon myIcon;
|
||||
private boolean myInherited;
|
||||
private boolean myField;
|
||||
|
||||
public PyStructureViewElement(PyElement element, Visibility vis, boolean inherited) {
|
||||
public PyStructureViewElement(PyElement element, Visibility vis, boolean inherited, boolean field) {
|
||||
myElement = element;
|
||||
myVisibility = vis;
|
||||
myInherited = inherited;
|
||||
myField = field;
|
||||
}
|
||||
|
||||
public PyStructureViewElement(PyElement element) {
|
||||
this(element, Visibility.NORMAL, false);
|
||||
this(element, Visibility.NORMAL, false, false);
|
||||
}
|
||||
|
||||
public PyElement getValue() {
|
||||
@@ -58,6 +60,10 @@ public class PyStructureViewElement implements StructureViewTreeElement {
|
||||
return myInherited;
|
||||
}
|
||||
|
||||
public boolean isField() {
|
||||
return myField;
|
||||
}
|
||||
|
||||
public void navigate(boolean requestFocus) {
|
||||
myElement.navigate(requestFocus);
|
||||
}
|
||||
@@ -95,18 +101,22 @@ public class PyStructureViewElement implements StructureViewTreeElement {
|
||||
public StructureViewTreeElement[] getChildren() {
|
||||
final Collection<StructureViewTreeElement> children = new LinkedHashSet<StructureViewTreeElement>();
|
||||
for (PyElement e : getElementChildren(myElement)) {
|
||||
children.add(new PyStructureViewElement(e, getElementVisibility(e), false));
|
||||
children.add(new PyStructureViewElement(e, getElementVisibility(e), false, elementIsField(e)));
|
||||
}
|
||||
if (myElement instanceof PyClass) {
|
||||
for (PyClass c : ((PyClass)myElement).iterateAncestorClasses()) {
|
||||
for (PyElement e: getElementChildren(c)) {
|
||||
children.add(new PyStructureViewElement(e, getElementVisibility(e), true));
|
||||
children.add(new PyStructureViewElement(e, getElementVisibility(e), true, elementIsField(e)));
|
||||
}
|
||||
}
|
||||
}
|
||||
return children.toArray(new StructureViewTreeElement[children.size()]);
|
||||
}
|
||||
|
||||
private static boolean elementIsField(PyElement element) {
|
||||
return element instanceof PyTargetExpression && PsiTreeUtil.getParentOfType(element, PyClass.class) != null;
|
||||
}
|
||||
|
||||
private static Visibility getElementVisibility(PyElement element) {
|
||||
if (!(element instanceof PyTargetExpression) && PsiTreeUtil.getParentOfType(element, PyFunction.class) != null) {
|
||||
return Visibility.INVISIBLE;
|
||||
|
||||
@@ -40,6 +40,7 @@ public class PyStructureViewModel extends StructureViewModelBase implements Stru
|
||||
public Filter[] getFilters() {
|
||||
return new Filter[] {
|
||||
new PyInheritedMembersFilter(),
|
||||
new PyFieldsFilter(),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user