Added Structure View filters for Symbols, Macros and Labels.
This commit is contained in:
parent
ef900e9c19
commit
128330d2c7
@ -70,7 +70,7 @@ make it work with JUnit 5. Feel free to use the code (in package ```de.platon42.
|
||||
|
||||
### V0.4 (unreleased)
|
||||
|
||||
-
|
||||
- Enhancement: Added Structure View filters.
|
||||
|
||||
### V0.3 (28-Jul-21)
|
||||
|
||||
|
@ -57,6 +57,10 @@ runPluginVerifier {
|
||||
|
||||
patchPluginXml {
|
||||
setChangeNotes("""
|
||||
<h4>V0.4 (unreleased)</h4>
|
||||
<ul>
|
||||
<li>Enhancement: Added Structure View filters.
|
||||
</ul>
|
||||
<h4>V0.3 (28-Jul-21)</h4>
|
||||
<ul>
|
||||
<li>Enhancement: Macro contents are no longer parsed, added syntax highlighting options for macros.
|
||||
|
@ -3,24 +3,77 @@ package de.platon42.intellij.plugins.m68k.structureview
|
||||
import com.intellij.ide.structureView.StructureViewModel.ElementInfoProvider
|
||||
import com.intellij.ide.structureView.StructureViewModelBase
|
||||
import com.intellij.ide.structureView.StructureViewTreeElement
|
||||
import com.intellij.ide.util.treeView.smartTree.Sorter
|
||||
import com.intellij.ide.util.treeView.smartTree.*
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.psi.PsiFile
|
||||
import de.platon42.intellij.plugins.m68k.M68kIcons
|
||||
import de.platon42.intellij.plugins.m68k.psi.M68kGlobalLabel
|
||||
import de.platon42.intellij.plugins.m68k.psi.M68kLocalLabel
|
||||
import de.platon42.intellij.plugins.m68k.psi.M68kMacroDefinition
|
||||
import de.platon42.intellij.plugins.m68k.psi.M68kSymbolDefinition
|
||||
|
||||
class M68kStructureViewModel(psiFile: PsiFile, editor: Editor?) :
|
||||
StructureViewModelBase(psiFile, editor, M68kStructureViewElement(psiFile)), ElementInfoProvider {
|
||||
|
||||
override fun isAlwaysShowsPlus(element: StructureViewTreeElement): Boolean {
|
||||
return false
|
||||
companion object {
|
||||
val FILTERS = arrayOf(SymbolsFilter(), MacrosFilter(), GlobalLabelFilter(), LocalLabelFilter())
|
||||
|
||||
const val SYMBOLS_FILTER_ID = "SHOW_SYMBOLS"
|
||||
const val MACROS_FILTER_ID = "SHOW_MACROS"
|
||||
const val GLOBAL_LABEL_FILTER_ID = "SHOW_GLOBAL_LABELS"
|
||||
const val LOCAL_LABEL_FILTER_ID = "SHOW_LOCAL_LABELS"
|
||||
}
|
||||
|
||||
override fun isAlwaysShowsPlus(element: StructureViewTreeElement): Boolean = false
|
||||
|
||||
override fun isAlwaysLeaf(element: StructureViewTreeElement): Boolean {
|
||||
return element.value is M68kLocalLabel || element.value is M68kMacroDefinition
|
||||
return when (element.value) {
|
||||
is M68kLocalLabel, is M68kMacroDefinition, is M68kSymbolDefinition -> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
override fun getSorters(): Array<Sorter> {
|
||||
return arrayOf(Sorter.ALPHA_SORTER)
|
||||
override fun getSorters(): Array<Sorter> = arrayOf(Sorter.ALPHA_SORTER)
|
||||
|
||||
override fun getFilters(): Array<Filter> = FILTERS
|
||||
|
||||
class SymbolsFilter : Filter {
|
||||
override fun getPresentation(): ActionPresentation = ActionPresentationData("Show Symbols", null, M68kIcons.SYMBOL_DEF)
|
||||
|
||||
override fun getName(): String = SYMBOLS_FILTER_ID
|
||||
|
||||
override fun isVisible(treeNode: TreeElement?) = (treeNode as? StructureViewTreeElement)?.value !is M68kSymbolDefinition
|
||||
|
||||
override fun isReverted() = true
|
||||
}
|
||||
|
||||
class MacrosFilter : Filter {
|
||||
override fun getPresentation(): ActionPresentation = ActionPresentationData("Show Macros", null, M68kIcons.MACRO_DEF)
|
||||
|
||||
override fun getName(): String = MACROS_FILTER_ID
|
||||
|
||||
override fun isVisible(treeNode: TreeElement?) = (treeNode as? StructureViewTreeElement)?.value !is M68kMacroDefinition
|
||||
|
||||
override fun isReverted() = true
|
||||
}
|
||||
|
||||
class GlobalLabelFilter : Filter {
|
||||
override fun getPresentation(): ActionPresentation = ActionPresentationData("Show Global Labels", null, M68kIcons.GLOBAL_LABEL)
|
||||
|
||||
override fun getName(): String = GLOBAL_LABEL_FILTER_ID
|
||||
|
||||
override fun isVisible(treeNode: TreeElement?) = (treeNode as? StructureViewTreeElement)?.value !is M68kGlobalLabel
|
||||
|
||||
override fun isReverted() = true
|
||||
}
|
||||
|
||||
class LocalLabelFilter : Filter {
|
||||
override fun getPresentation(): ActionPresentation = ActionPresentationData("Show Local Labels", null, M68kIcons.LOCAL_LABEL)
|
||||
|
||||
override fun getName(): String = LOCAL_LABEL_FILTER_ID
|
||||
|
||||
override fun isVisible(treeNode: TreeElement?) = (treeNode as? StructureViewTreeElement)?.value !is M68kLocalLabel
|
||||
|
||||
override fun isReverted() = true
|
||||
}
|
||||
}
|
@ -32,6 +32,93 @@ internal class M68kStructureViewTest : AbstractM68kTest() {
|
||||
.loopw
|
||||
main
|
||||
exit
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
internal fun macros_filter_works(@MyFixture myFixture: CodeInsightTestFixture) {
|
||||
myFixture.configureByFile("basic_example.asm")
|
||||
myFixture.testStructureView {
|
||||
val tree = it.tree
|
||||
it.setActionActive(M68kStructureViewModel.MACROS_FILTER_ID, true)
|
||||
PlatformTestUtil.waitWhileBusy(tree)
|
||||
PlatformTestUtil.assertTreeEqual(
|
||||
tree, """-basic_example.asm
|
||||
PIC_WIDTH
|
||||
PIC_HEIGHT
|
||||
DEBUG_LEVEL
|
||||
entry
|
||||
-init
|
||||
.looph
|
||||
.loopw
|
||||
main
|
||||
exit
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
internal fun symbols_filter_works(@MyFixture myFixture: CodeInsightTestFixture) {
|
||||
myFixture.configureByFile("basic_example.asm")
|
||||
myFixture.testStructureView {
|
||||
val tree = it.tree
|
||||
it.setActionActive(M68kStructureViewModel.SYMBOLS_FILTER_ID, true)
|
||||
PlatformTestUtil.waitWhileBusy(tree)
|
||||
PlatformTestUtil.assertTreeEqual(
|
||||
tree, """-basic_example.asm
|
||||
BLTHOGON
|
||||
BLTHOGOFF
|
||||
entry
|
||||
-init
|
||||
.looph
|
||||
.loopw
|
||||
main
|
||||
exit
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
internal fun global_labels_filter_works(@MyFixture myFixture: CodeInsightTestFixture) {
|
||||
myFixture.configureByFile("basic_example.asm")
|
||||
myFixture.testStructureView {
|
||||
val tree = it.tree
|
||||
it.setActionActive(M68kStructureViewModel.GLOBAL_LABEL_FILTER_ID, true)
|
||||
PlatformTestUtil.waitWhileBusy(tree)
|
||||
PlatformTestUtil.assertTreeEqual(
|
||||
tree, """-basic_example.asm
|
||||
PIC_WIDTH
|
||||
PIC_HEIGHT
|
||||
DEBUG_LEVEL
|
||||
BLTHOGON
|
||||
BLTHOGOFF
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
internal fun local_labels_filter_works(@MyFixture myFixture: CodeInsightTestFixture) {
|
||||
myFixture.configureByFile("basic_example.asm")
|
||||
myFixture.testStructureView {
|
||||
val tree = it.tree
|
||||
it.setActionActive(M68kStructureViewModel.LOCAL_LABEL_FILTER_ID, true)
|
||||
PlatformTestUtil.waitWhileBusy(tree)
|
||||
PlatformTestUtil.assertTreeEqual(
|
||||
tree, """-basic_example.asm
|
||||
PIC_WIDTH
|
||||
PIC_HEIGHT
|
||||
DEBUG_LEVEL
|
||||
BLTHOGON
|
||||
BLTHOGOFF
|
||||
entry
|
||||
init
|
||||
main
|
||||
exit
|
||||
"""
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user