mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-27 08:47:50 +08:00
Add article and tutorial about Navigation Bar
* add docs about navigation bar for Custom Language Support topic * add info in `topics/intro/content_updates.md` * renumber articles after the added tutorial * add `custom_language_tutorial_header` to `structure_aware_navbar.md`
This commit is contained in:
parent
5189cec79f
commit
2fe69083d1
@ -0,0 +1,44 @@
|
||||
// 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;
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// 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;
|
||||
|
||||
@ -20,7 +20,7 @@ public class SimpleStructureViewFactory implements PsiStructureViewFactory {
|
||||
@NotNull
|
||||
@Override
|
||||
public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
|
||||
return new SimpleStructureViewModel(psiFile);
|
||||
return new SimpleStructureViewModel(editor, psiFile);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// 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;
|
||||
|
||||
@ -6,15 +6,17 @@ import com.intellij.ide.structureView.StructureViewModel;
|
||||
import com.intellij.ide.structureView.StructureViewModelBase;
|
||||
import com.intellij.ide.structureView.StructureViewTreeElement;
|
||||
import com.intellij.ide.util.treeView.smartTree.Sorter;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.intellij.sdk.language.psi.SimpleProperty;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class SimpleStructureViewModel extends StructureViewModelBase implements
|
||||
StructureViewModel.ElementInfoProvider {
|
||||
|
||||
public SimpleStructureViewModel(PsiFile psiFile) {
|
||||
super(psiFile, new SimpleStructureViewElement(psiFile));
|
||||
public SimpleStructureViewModel(@Nullable Editor editor, PsiFile psiFile) {
|
||||
super(psiFile, editor, new SimpleStructureViewElement(psiFile));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@ -33,4 +35,8 @@ public class SimpleStructureViewModel extends StructureViewModelBase implements
|
||||
return element.getValue() instanceof SimpleProperty;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?> @NotNull [] getSuitableClasses() {
|
||||
return new Class[]{SimpleProperty.class};
|
||||
}
|
||||
}
|
||||
|
@ -63,6 +63,7 @@
|
||||
<gotoSymbolContributor implementation="org.intellij.sdk.language.SimpleChooseByNameContributor"/>
|
||||
<lang.psiStructureViewFactory language="Simple"
|
||||
implementationClass="org.intellij.sdk.language.SimpleStructureViewFactory"/>
|
||||
<navbar implementation="org.intellij.sdk.language.SimpleStructureAwareNavbar"/>
|
||||
<lang.formatter language="Simple" implementationClass="org.intellij.sdk.language.SimpleFormattingModelBuilder"/>
|
||||
<codeStyleSettingsProvider implementation="org.intellij.sdk.language.SimpleCodeStyleSettingsProvider"/>
|
||||
<langCodeStyleSettingsProvider implementation="org.intellij.sdk.language.SimpleLanguageCodeStyleSettingsProvider"/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user