Created
July 30, 2023 01:49
-
-
Save igor-korotenko/a1fff0603197403450770f5e55fc0891 to your computer and use it in GitHub Desktop.
Hide Code | Split | Design panel in AS Giraffe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val actionId = "no_design" | |
var enabled = false | |
val state get() = if (enabled) "Enabled" else "Disabled" | |
val title get() = "Toggle Code | Split | Design ($state)" | |
ide.registerAction(actionId, title) { | |
enabled = !enabled | |
ide.notify(title, state) | |
ide.inspection.visitFile { _, file -> | |
if (!enabled) return@visitFile | |
file.findExistingEditor()?.component | |
?.findBorderLayoutPanel() | |
?.findSplitEditorToolbars() | |
?.runCatching { | |
if (isVisible) { | |
isVisible = false | |
ide.notify(title, "Hidden for ${file.name}") | |
} | |
} | |
} | |
} | |
ide.addShortcut(actionId, "ctrl 2") | |
fun Component.findBorderLayoutPanel(depth: Int = 10): BorderLayoutPanel? { | |
return parent as? BorderLayoutPanel ?: if (depth == 0) { | |
null | |
} else { | |
parent.findBorderLayoutPanel(depth - 1) | |
} | |
} | |
fun BorderLayoutPanel.findSplitEditorToolbars(): SplitEditorToolbar? { | |
ide.notify(title, "$componentCount") | |
for (child in components) { | |
if (child is SplitEditorToolbar) { | |
return child | |
} | |
} | |
return null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment