Search in sources :

Example 6 with TreeBasedStructureViewBuilder

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

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

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

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

TreeBasedStructureViewBuilder (com.intellij.ide.structureView.TreeBasedStructureViewBuilder)9 StructureViewBuilder (com.intellij.ide.structureView.StructureViewBuilder)8 StructureViewModel (com.intellij.ide.structureView.StructureViewModel)7 PsiFile (com.intellij.psi.PsiFile)5 LanguageStructureViewBuilder (com.intellij.lang.LanguageStructureViewBuilder)4 Editor (com.intellij.openapi.editor.Editor)4 Nullable (org.jetbrains.annotations.Nullable)3 HbPsiFile (com.dmarcotte.handlebars.psi.HbPsiFile)2 StructureView (com.intellij.ide.structureView.StructureView)2 StructureViewComposite (com.intellij.ide.structureView.impl.StructureViewComposite)2 TemplateLanguageStructureViewBuilder (com.intellij.ide.structureView.impl.TemplateLanguageStructureViewBuilder)2 FileEditor (com.intellij.openapi.fileEditor.FileEditor)2 CommanderPanel (com.intellij.ide.commander.CommanderPanel)1 FileStructureDialog (com.intellij.ide.util.FileStructureDialog)1 ItemPresentation (com.intellij.navigation.ItemPresentation)1 NavigationItem (com.intellij.navigation.NavigationItem)1 Disposable (com.intellij.openapi.Disposable)1 Document (com.intellij.openapi.editor.Document)1 EditorFactory (com.intellij.openapi.editor.EditorFactory)1 FileType (com.intellij.openapi.fileTypes.FileType)1