Search in sources :

Example 6 with StructureViewModel

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;
}
Also used : TreeBasedStructureViewBuilder(com.intellij.ide.structureView.TreeBasedStructureViewBuilder) StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) TreeBasedStructureViewBuilder(com.intellij.ide.structureView.TreeBasedStructureViewBuilder) StructureViewModel(com.intellij.ide.structureView.StructureViewModel) StructureViewModel(com.intellij.ide.structureView.StructureViewModel) Editor(com.intellij.openapi.editor.Editor) ElixirFile(org.elixir_lang.psi.ElixirFile) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with StructureViewModel

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);
}
Also used : LanguageStructureViewBuilder(com.intellij.lang.LanguageStructureViewBuilder) TreeBasedStructureViewBuilder(com.intellij.ide.structureView.TreeBasedStructureViewBuilder) StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) NavigationItem(com.intellij.navigation.NavigationItem) TreeBasedStructureViewBuilder(com.intellij.ide.structureView.TreeBasedStructureViewBuilder) StructureViewModel(com.intellij.ide.structureView.StructureViewModel) ItemPresentation(com.intellij.navigation.ItemPresentation) PsiFile(com.intellij.psi.PsiFile)

Example 8 with StructureViewModel

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);
        }
    }
}
Also used : LanguageStructureViewBuilder(com.intellij.lang.LanguageStructureViewBuilder) StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) FileEditor(com.intellij.openapi.fileEditor.FileEditor) StructureViewModel(com.intellij.ide.structureView.StructureViewModel) StructureViewComponent(com.intellij.ide.structureView.newStructureView.StructureViewComponent) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement)

Example 9 with StructureViewModel

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));
        }
    });
}
Also used : LanguageStructureViewBuilder(com.intellij.lang.LanguageStructureViewBuilder) TreeBasedStructureViewBuilder(com.intellij.ide.structureView.TreeBasedStructureViewBuilder) StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) TreeBasedStructureViewBuilder(com.intellij.ide.structureView.TreeBasedStructureViewBuilder) StructureViewModel(com.intellij.ide.structureView.StructureViewModel) LightweightHint(com.intellij.ui.LightweightHint) PsiFile(com.intellij.psi.PsiFile) TextRange(com.intellij.openapi.util.TextRange) PsiElement(com.intellij.psi.PsiElement)

Example 10 with StructureViewModel

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);
}
Also used : Group(com.intellij.ide.util.treeView.smartTree.Group) GroupWrapper(com.intellij.ide.util.treeView.smartTree.GroupWrapper) StructureViewModel(com.intellij.ide.structureView.StructureViewModel) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement)

Aggregations

StructureViewModel (com.intellij.ide.structureView.StructureViewModel)16 StructureViewBuilder (com.intellij.ide.structureView.StructureViewBuilder)8 TreeBasedStructureViewBuilder (com.intellij.ide.structureView.TreeBasedStructureViewBuilder)7 PsiFile (com.intellij.psi.PsiFile)7 LanguageStructureViewBuilder (com.intellij.lang.LanguageStructureViewBuilder)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 XmlFile (com.intellij.psi.xml.XmlFile)4 LayoutViewElement (org.jetbrains.android.dom.layout.LayoutViewElement)3 LayoutStructureViewBuilder (org.jetbrains.android.dom.structure.layout.LayoutStructureViewBuilder)3 StructureView (com.intellij.ide.structureView.StructureView)2 TreeElement (com.intellij.ide.util.treeView.smartTree.TreeElement)2 Editor (com.intellij.openapi.editor.Editor)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 CommanderPanel (com.intellij.ide.commander.CommanderPanel)1 StructureViewTreeElement (com.intellij.ide.structureView.StructureViewTreeElement)1 StructureViewComposite (com.intellij.ide.structureView.impl.StructureViewComposite)1 StructureViewComponent (com.intellij.ide.structureView.newStructureView.StructureViewComponent)1 FileStructureDialog (com.intellij.ide.util.FileStructureDialog)1 AbstractTreeStructure (com.intellij.ide.util.treeView.AbstractTreeStructure)1