IntelliJ Platform Plugin SDK Help

15. Structure Aware Navigation Bar

Structure aware navbar allows displaying specific file elements in the navigation bar, depending on the location of the caret in it. For example, in Java this is used to display the class and method in which the caret is currently located.

Reference: Navigation Bar

Define a SimpleStructureAwareNavbar

The simple structure aware navbar implements StructureAwareNavBarModelExtension.

// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.intellij.sdk.language; import com.intellij.icons.AllIcons; import com.intellij.ide.navigationToolbar.StructureAwareNavBarModelExtension; import com.intellij.lang.Language; import org.intellij.sdk.language.psi.SimpleFile; import org.intellij.sdk.language.psi.SimpleProperty; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.Icon; public class SimpleStructureAwareNavbar extends StructureAwareNavBarModelExtension { @NotNull @Override protected Language getLanguage() { return SimpleLanguage.INSTANCE; } @Override public @Nullable String getPresentableText(Object object) { if (object instanceof SimpleFile) { return ((SimpleFile) object).getName(); } if (object instanceof SimpleProperty) { return ((SimpleProperty) object).getName(); } return null; } @Override @Nullable public Icon getIcon(Object object) { if (object instanceof SimpleProperty) { return AllIcons.Nodes.Property; } return null; } }

Register the SimpleStructureAwareNavbar

The SimpleStructureAwareNavbar implementation is registered with the IntelliJ Platform in the plugin configuration file using the com.intellij.navbar extension point.

<extensions defaultExtensionNs="com.intellij"> <navbar implementation="org.intellij.sdk.language.SimpleStructureAwareNavbar"/> </extensions>

Run the Project

Run the project by using the Gradle runIde task.

Open the test.simple file and position the caret on any property. The navigation bar displays the name and icon of this property.

Structure Aware Navbar
Last modified: 09 June 2022