Search in sources :

Example 1 with StructureView

use of com.intellij.ide.structureView.StructureView in project idea-handlebars by dmarcotte.

the class HbStructureViewFactory method getStructureViewBuilder.

@Nullable
@Override
public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile) {
    return new TemplateLanguageStructureViewBuilder(psiFile) {

        @Override
        protected StructureViewComposite.StructureViewDescriptor createMainView(FileEditor fileEditor, PsiFile mainFile) {
            if (!psiFile.isValid())
                return null;
            final StructureViewBuilder builder = new TreeBasedStructureViewBuilder() {

                @NotNull
                @Override
                public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
                    return new HbStructureViewModel((HbPsiFile) psiFile, editor);
                }
            };
            StructureView structureView = builder.createStructureView(fileEditor, psiFile.getProject());
            return new StructureViewComposite.StructureViewDescriptor(HbLanguage.INSTANCE.getDisplayName(), structureView, HbFileType.INSTANCE.getIcon());
        }
    };
}
Also used : TreeBasedStructureViewBuilder(com.intellij.ide.structureView.TreeBasedStructureViewBuilder) TemplateLanguageStructureViewBuilder(com.intellij.ide.structureView.impl.TemplateLanguageStructureViewBuilder) StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) FileEditor(com.intellij.openapi.fileEditor.FileEditor) StructureView(com.intellij.ide.structureView.StructureView) TreeBasedStructureViewBuilder(com.intellij.ide.structureView.TreeBasedStructureViewBuilder) HbPsiFile(com.dmarcotte.handlebars.psi.HbPsiFile) PsiFile(com.intellij.psi.PsiFile) TemplateLanguageStructureViewBuilder(com.intellij.ide.structureView.impl.TemplateLanguageStructureViewBuilder) Editor(com.intellij.openapi.editor.Editor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Nullable(org.jetbrains.annotations.Nullable) StructureViewComposite(com.intellij.ide.structureView.impl.StructureViewComposite) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with StructureView

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

the class ViewStructureAction method createPopup.

@Nullable
public static FileStructurePopup createPopup(@NotNull Project project, @NotNull FileEditor fileEditor) {
    StructureViewBuilder structureViewBuilder = fileEditor.getStructureViewBuilder();
    if (structureViewBuilder == null)
        return null;
    StructureView structureView = structureViewBuilder.createStructureView(fileEditor, project);
    StructureViewModel model = structureView.getTreeModel();
    if (model instanceof PlaceHolder) {
        //noinspection unchecked
        ((PlaceHolder) model).setPlace(TreeStructureUtil.PLACE);
    }
    return createStructureViewPopup(project, fileEditor, structureView);
}
Also used : StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) StructureView(com.intellij.ide.structureView.StructureView) PlaceHolder(com.intellij.ui.PlaceHolder) StructureViewModel(com.intellij.ide.structureView.StructureViewModel) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with StructureView

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

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

use of com.intellij.ide.structureView.StructureView in project intellij-plugins by JetBrains.

the class CfmlStructureViewTest method getTopLevelItems.

private Object[] getTopLevelItems() {
    StructureView structureView = createStructureViewModel();
    final StructureViewModel structureViewModel = structureView.getTreeModel();
    AbstractTreeStructure jsTreeStructure = new SmartTreeStructure(getProject(), structureViewModel);
    Object[] items = jsTreeStructure.getChildElements(jsTreeStructure.getRootElement());
    structureViewModel.dispose();
    Disposer.dispose(structureView);
    return items;
}
Also used : StructureView(com.intellij.ide.structureView.StructureView) StructureViewModel(com.intellij.ide.structureView.StructureViewModel) SmartTreeStructure(com.intellij.ide.util.treeView.smartTree.SmartTreeStructure) AbstractTreeStructure(com.intellij.ide.util.treeView.AbstractTreeStructure)

Aggregations

StructureView (com.intellij.ide.structureView.StructureView)6 StructureViewBuilder (com.intellij.ide.structureView.StructureViewBuilder)5 Nullable (org.jetbrains.annotations.Nullable)4 FileEditor (com.intellij.openapi.fileEditor.FileEditor)3 PsiFile (com.intellij.psi.PsiFile)3 HbPsiFile (com.dmarcotte.handlebars.psi.HbPsiFile)2 StructureViewModel (com.intellij.ide.structureView.StructureViewModel)2 TreeBasedStructureViewBuilder (com.intellij.ide.structureView.TreeBasedStructureViewBuilder)2 StructureViewComposite (com.intellij.ide.structureView.impl.StructureViewComposite)2 TemplateLanguageStructureViewBuilder (com.intellij.ide.structureView.impl.TemplateLanguageStructureViewBuilder)2 Editor (com.intellij.openapi.editor.Editor)2 StructureViewTreeElement (com.intellij.ide.structureView.StructureViewTreeElement)1 AbstractTreeStructure (com.intellij.ide.util.treeView.AbstractTreeStructure)1 SmartTreeStructure (com.intellij.ide.util.treeView.smartTree.SmartTreeStructure)1 TreeElement (com.intellij.ide.util.treeView.smartTree.TreeElement)1 LanguageStructureViewBuilder (com.intellij.lang.LanguageStructureViewBuilder)1 PsiStructureViewFactory (com.intellij.lang.PsiStructureViewFactory)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 Navigatable (com.intellij.pom.Navigatable)1 MinusculeMatcher (com.intellij.psi.codeStyle.MinusculeMatcher)1