Search in sources :

Example 16 with StructureViewBuilder

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

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

the class HbStructureViewFactory method getStructureViewBuilder.

@Nullable
@Override
public StructureViewBuilder getStructureViewBuilder(@NotNull 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)

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