Search in sources :

Example 11 with StructureViewBuilder

use of com.intellij.ide.structureView.StructureViewBuilder 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 12 with StructureViewBuilder

use of com.intellij.ide.structureView.StructureViewBuilder 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 13 with StructureViewBuilder

use of com.intellij.ide.structureView.StructureViewBuilder in project intellij-community by JetBrains.

the class GotoClassAction method findMember.

@Nullable
private static Navigatable findMember(String pattern, PsiElement psiElement, VirtualFile file) {
    final PsiStructureViewFactory factory = LanguageStructureViewBuilder.INSTANCE.forLanguage(psiElement.getLanguage());
    final StructureViewBuilder builder = factory == null ? null : factory.getStructureViewBuilder(psiElement.getContainingFile());
    final FileEditor[] editors = FileEditorManager.getInstance(psiElement.getProject()).getEditors(file);
    if (builder == null || editors.length == 0) {
        return null;
    }
    final StructureView view = builder.createStructureView(editors[0], psiElement.getProject());
    try {
        final StructureViewTreeElement element = findElement(view.getTreeModel().getRoot(), psiElement, 4);
        if (element == null) {
            return null;
        }
        final MinusculeMatcher matcher = NameUtil.buildMatcher(pattern).build();
        int max = Integer.MIN_VALUE;
        Object target = null;
        for (TreeElement treeElement : element.getChildren()) {
            if (treeElement instanceof StructureViewTreeElement) {
                String presentableText = treeElement.getPresentation().getPresentableText();
                if (presentableText != null) {
                    final int degree = matcher.matchingDegree(presentableText);
                    if (degree > max) {
                        max = degree;
                        target = ((StructureViewTreeElement) treeElement).getValue();
                    }
                }
            }
        }
        return target instanceof Navigatable ? (Navigatable) target : null;
    } finally {
        Disposer.dispose(view);
    }
}
Also used : PsiStructureViewFactory(com.intellij.lang.PsiStructureViewFactory) LanguageStructureViewBuilder(com.intellij.lang.LanguageStructureViewBuilder) StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) FileEditor(com.intellij.openapi.fileEditor.FileEditor) StructureView(com.intellij.ide.structureView.StructureView) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) MinusculeMatcher(com.intellij.psi.codeStyle.MinusculeMatcher) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) Navigatable(com.intellij.pom.Navigatable) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with StructureViewBuilder

use of com.intellij.ide.structureView.StructureViewBuilder in project intellij-community by JetBrains.

the class SelectInContextImpl method doCreateEditorContext.

private static SelectInContext doCreateEditorContext(Project project, FileEditor editor, @Nullable DataContext dataContext) {
    if (project == null || editor == null) {
        return null;
    }
    VirtualFile file = FileEditorManagerEx.getInstanceEx(project).getFile(editor);
    if (file == null) {
        file = dataContext == null ? null : CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
        if (file == null) {
            return null;
        }
    }
    final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
    if (psiFile == null) {
        return null;
    }
    if (editor instanceof TextEditor) {
        return new TextEditorContext((TextEditor) editor, psiFile);
    } else {
        StructureViewBuilder builder = editor.getStructureViewBuilder();
        StructureView structureView = builder != null ? builder.createStructureView(editor, project) : null;
        Object selectorInFile = structureView != null ? structureView.getTreeModel().getCurrentEditorElement() : null;
        if (structureView != null)
            Disposer.dispose(structureView);
        return new SimpleSelectInContext(psiFile, ObjectUtils.chooseNotNull(selectorInFile, psiFile));
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) StructureView(com.intellij.ide.structureView.StructureView) PsiFile(com.intellij.psi.PsiFile)

Example 15 with StructureViewBuilder

use of com.intellij.ide.structureView.StructureViewBuilder 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)

Aggregations

StructureViewBuilder (com.intellij.ide.structureView.StructureViewBuilder)18 LanguageStructureViewBuilder (com.intellij.lang.LanguageStructureViewBuilder)11 TreeBasedStructureViewBuilder (com.intellij.ide.structureView.TreeBasedStructureViewBuilder)9 StructureViewModel (com.intellij.ide.structureView.StructureViewModel)8 PsiFile (com.intellij.psi.PsiFile)7 Nullable (org.jetbrains.annotations.Nullable)7 FileEditor (com.intellij.openapi.fileEditor.FileEditor)6 StructureView (com.intellij.ide.structureView.StructureView)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 StructureViewComposite (com.intellij.ide.structureView.impl.StructureViewComposite)4 Editor (com.intellij.openapi.editor.Editor)4 HbPsiFile (com.dmarcotte.handlebars.psi.HbPsiFile)2 TemplateLanguageStructureViewBuilder (com.intellij.ide.structureView.impl.TemplateLanguageStructureViewBuilder)2 StructureViewComponent (com.intellij.ide.structureView.newStructureView.StructureViewComponent)2 TreeElement (com.intellij.ide.util.treeView.smartTree.TreeElement)2 PsiStructureViewFactory (com.intellij.lang.PsiStructureViewFactory)2 PsiElement (com.intellij.psi.PsiElement)2 ElixirFile (org.elixir_lang.psi.ElixirFile)2 CfmlFileType (com.intellij.coldFusion.model.files.CfmlFileType)1 CfmlFileViewProvider (com.intellij.coldFusion.model.files.CfmlFileViewProvider)1