Skip to content

Instantly share code, notes, and snippets.

@dkandalov
Created December 30, 2022 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dkandalov/6a3cc9f1b6ae91e4289f01b8156a3591 to your computer and use it in GitHub Desktop.
Save dkandalov/6a3cc9f1b6ae91e4289f01b8156a3591 to your computer and use it in GitHub Desktop.
import com.intellij.application.subscribe
import com.intellij.ide.ui.LafManagerListener
import com.intellij.ui.Gray
import com.intellij.ui.JBColor
import com.intellij.util.ui.JBInsets
import javax.swing.UIManager
fun fixUI() {
// You can find more constants in:
// - https://github.com/JetBrains/intellij-community/blob/master/platform/util/ui/src/com/intellij/util/ui/JBUI.java
// - https://github.com/JetBrains/intellij-community/blob/master/platform/platform-resources/src/themes/metadata/IntelliJPlatform.themeMetadata.json
// - https://github.com/JetBrains/intellij-community/blob/master/platform/platform-resources/src/themes/metadata/JDK.themeMetadata.json
UIManager.put("RunWidget.background", Gray._55)
UIManager.put("RunWidget.runningBackground", Gray._55)
UIManager.put("ToolWindow.Header.height", 30)
UIManager.put("ToolWindow.Header.inactiveBackground", JBColor(Gray._244, Gray._55))
UIManager.put("EditorTabs.tabInsets", JBInsets.create(0, 10))
}
LafManagerListener.TOPIC.subscribe(pluginDisposable, LafManagerListener { fixUI() })
@richappow
Copy link

could you please teach me how to get the previous "Run | Debug" widget with the blue accent color?
03_window_header

@dkandalov
Copy link
Author

There is no easy answer anymore but finding JComponent and changing its background is always an option 🙈

import com.intellij.openapi.actionSystem.impl.ActionButtonWithText
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ProjectManagerListener
import com.intellij.openapi.wm.WindowManager
import com.intellij.ui.ComponentUtil
import com.intellij.ui.JBColor
import java.awt.Color
import javax.swing.JComponent

fun fixUI() {
    WindowManager.getInstance()
        .allProjectFrames.map { it.component }
        .flatMap {
            // Lookup via class name because MainToolbar is internal
            // See https://github.com/JetBrains/intellij-community/blob/b1a1086a1c762bd7c0683a87f371c9d57e34588e/platform/platform-impl/src/com/intellij/openapi/wm/impl/headertoolbar/MainToolbar.kt#L79
            val toolbarClass = this.javaClass.classLoader.loadClass("com.intellij.openapi.wm.impl.headertoolbar.MainToolbar")
            ComponentUtil.findComponentsOfType(it, toolbarClass as Class<JComponent>)
        }
        .flatMap {
            ComponentUtil.findComponentsOfType(it, ActionButtonWithText::class.java).filterNotNull()
        }
        .forEach {
            it.background = JBColor(Color(65, 104, 207), Color(65, 104, 207))
        }
}

liveplugin.registerProjectListener(pluginDisposable, object : ProjectManagerListener {
    override fun projectOpened(project: Project) = fixUI()
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment