Skip to content

Instantly share code, notes, and snippets.

@igor-korotenko
Created July 30, 2023 01:49
Show Gist options
  • Save igor-korotenko/a1fff0603197403450770f5e55fc0891 to your computer and use it in GitHub Desktop.
Save igor-korotenko/a1fff0603197403450770f5e55fc0891 to your computer and use it in GitHub Desktop.
Hide Code | Split | Design panel in AS Giraffe
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