use of com.intellij.ide.structureView.StructureViewModel in project intellij-elixir by KronicDeth.
the class Factory method structureViewBuilder.
@Nullable
public static StructureViewBuilder structureViewBuilder(@NotNull final PsiFile psiFile) {
StructureViewBuilder structureViewBuilder = null;
if (psiFile instanceof ElixirFile) {
final ElixirFile elixirFile = (ElixirFile) psiFile;
structureViewBuilder = new TreeBasedStructureViewBuilder() {
@NotNull
@Override
public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
return new Model(elixirFile, editor);
}
@Override
public boolean isRootNodeShown() {
return false;
}
};
}
return structureViewBuilder;
}
use of com.intellij.ide.structureView.StructureViewModel in project intellij-community by JetBrains.
the class Bookmark method getQualifiedName.
public String getQualifiedName() {
String presentableUrl = myFile.getPresentableUrl();
if (myFile.isDirectory())
return presentableUrl;
final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(myFile);
if (psiFile == null)
return presentableUrl;
StructureViewBuilder builder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(psiFile);
if (builder instanceof TreeBasedStructureViewBuilder) {
StructureViewModel model = ((TreeBasedStructureViewBuilder) builder).createStructureViewModel(null);
Object element;
try {
element = model.getCurrentEditorElement();
} finally {
model.dispose();
}
if (element instanceof NavigationItem) {
ItemPresentation presentation = ((NavigationItem) element).getPresentation();
if (presentation != null) {
presentableUrl = ((NavigationItem) element).getName() + " " + presentation.getLocationString();
}
}
}
return IdeBundle.message("bookmark.file.X.line.Y", presentableUrl, getLine() + 1);
}
use of com.intellij.ide.structureView.StructureViewModel in project intellij-community by JetBrains.
the class JsonStructureViewTest method testSimpleStructure.
// Moved from JavaScript
public void testSimpleStructure() {
myFixture.configureByFile("structureView/" + getTestName(false) + ".json");
final StructureViewBuilder builder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(myFixture.getFile());
assertNotNull(builder);
StructureViewComponent component = null;
try {
final FileEditor editor = FileEditorManager.getInstance(getProject()).getSelectedEditor(myFixture.getFile().getVirtualFile());
component = (StructureViewComponent) builder.createStructureView(editor, myFixture.getProject());
final StructureViewModel model = component.getTreeModel();
TreeElement[] children = model.getRoot().getChildren();
assertEquals(2, children.length);
assertEquals("aaa", children[0].getPresentation().getPresentableText());
assertEquals(PlatformIcons.PROPERTY_ICON, children[0].getPresentation().getIcon(false));
assertEquals("bbb", children[1].getPresentation().getPresentableText());
assertEquals(AllIcons.Json.Property_braces, children[1].getPresentation().getIcon(false));
children = children[1].getChildren();
assertEquals(1, children.length);
assertEquals("ccc", children[0].getPresentation().getPresentableText());
assertEquals(PlatformIcons.PROPERTY_ICON, children[0].getPresentation().getIcon(false));
} finally {
if (component != null) {
Disposer.dispose(component);
}
}
}
use of com.intellij.ide.structureView.StructureViewModel in project intellij-community by JetBrains.
the class ShowContainerInfoHandler method invoke.
@Override
public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) {
PsiElement container = null;
WeakReference<LightweightHint> ref = editor.getUserData(MY_LAST_HINT_KEY);
LightweightHint hint = SoftReference.dereference(ref);
if (hint != null && hint.isVisible()) {
hint.hide();
container = hint.getUserData(CONTAINER_KEY);
if (container != null && !container.isValid()) {
container = null;
}
}
StructureViewBuilder builder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(file);
if (builder instanceof TreeBasedStructureViewBuilder) {
StructureViewModel model = ((TreeBasedStructureViewBuilder) builder).createStructureViewModel(editor);
boolean goOneLevelUp = true;
try {
if (container == null) {
goOneLevelUp = false;
Object element = model.getCurrentEditorElement();
if (element instanceof PsiElement) {
container = (PsiElement) element;
}
}
} finally {
model.dispose();
}
while (true) {
if (container == null || container instanceof PsiFile) {
return;
}
if (goOneLevelUp) {
goOneLevelUp = false;
} else {
if (!isDeclarationVisible(container, editor)) {
break;
}
}
container = container.getParent();
while (container != null && DeclarationRangeUtil.getPossibleDeclarationAtRange(container) == null) {
container = container.getParent();
if (container instanceof PsiFile)
return;
}
}
}
if (container == null) {
return;
}
final TextRange range = DeclarationRangeUtil.getPossibleDeclarationAtRange(container);
if (range == null) {
return;
}
final PsiElement _container = container;
ApplicationManager.getApplication().invokeLater(() -> {
LightweightHint hint1 = EditorFragmentComponent.showEditorFragmentHint(editor, range, true, true);
if (hint1 != null) {
hint1.putUserData(CONTAINER_KEY, _container);
editor.putUserData(MY_LAST_HINT_KEY, new WeakReference<>(hint1));
}
});
}
use of com.intellij.ide.structureView.StructureViewModel in project intellij-community by JetBrains.
the class StructureTreeBuilder method isAutoExpandNode.
@Override
protected final boolean isAutoExpandNode(NodeDescriptor nodeDescriptor) {
StructureViewModel model = myStructureModel;
if (model instanceof TreeModelWrapper) {
model = ((TreeModelWrapper) model).getModel();
}
if (model instanceof StructureViewModel.ExpandInfoProvider) {
StructureViewModel.ExpandInfoProvider provider = (StructureViewModel.ExpandInfoProvider) model;
Object element = nodeDescriptor.getElement();
if (element instanceof StructureViewComponent.StructureViewTreeElementWrapper) {
StructureViewComponent.StructureViewTreeElementWrapper wrapper = (StructureViewComponent.StructureViewTreeElementWrapper) element;
if (wrapper.getValue() instanceof StructureViewTreeElement) {
final StructureViewTreeElement value = (StructureViewTreeElement) wrapper.getValue();
if (value != null) {
return provider.isAutoExpand(value);
}
}
} else if (element instanceof GroupWrapper) {
final Group group = ((GroupWrapper) element).getValue();
for (TreeElement treeElement : group.getChildren()) {
if (treeElement instanceof StructureViewTreeElement && !provider.isAutoExpand((StructureViewTreeElement) treeElement)) {
return false;
}
}
}
}
// expand root node & its immediate children
final NodeDescriptor parent = nodeDescriptor.getParentDescriptor();
return super.isAutoExpandNode(parent == null ? nodeDescriptor : parent);
}
Aggregations