Fix RIDER-100926: IdeDependentAction/Group should update their template presentation to reflect the customized mnemonics

At least the main menu uses the template presentation to determine what action to call by a mnemonic, which leads to confusing results (see the issue description).

Unfortunately, it's not possible to work with the template presentation in the normal way in constructor, because we need action id and thus need access to the action manager, and trying to access the action manager from the action constructor leads to a circular dependency.

So, let's invent a hack that will update the template presentation on the first normal action update.

GitOrigin-RevId: 59930563efac394c3cd225aae4cd698c414fac9c
This commit is contained in:
Ivan Migalev
2024-08-27 19:46:24 +00:00
committed by intellij-monorepo-bot
parent f4a3a5bfae
commit aba4290b4b
2 changed files with 36 additions and 14 deletions
@@ -1,23 +1,36 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.ide
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.Presentation
import com.intellij.openapi.project.DumbAwareAction
import com.intellij.ui.IdeUICustomization
import java.util.concurrent.atomic.AtomicBoolean
abstract class IdeDependentAction : DumbAwareAction() {
private val id by lazy { ActionManager.getInstance().getId(this)!! }
private val templatePresentationInitialized = AtomicBoolean()
override fun update(e: AnActionEvent) {
super.update(e)
IdeUICustomization.getInstance().getActionText(id)?.let {
e.presentation.text = it
fun initializePresentation(p: Presentation) {
val customization = IdeUICustomization.getInstance()
customization.getActionText(id)?.let {
p.text = it
}
customization.getActionDescription(id)?.let {
p.description = it
}
}
IdeUICustomization.getInstance().getActionDescription(id)?.let {
e.presentation.description = it
if (!templatePresentationInitialized.getAndSet(true)) { // one-time init
initializePresentation(templatePresentation)
}
initializePresentation(e.presentation)
}
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
@@ -1,23 +1,32 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.ide
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.DefaultActionGroup
import com.intellij.openapi.actionSystem.*
import com.intellij.ui.IdeUICustomization
import java.util.concurrent.atomic.AtomicBoolean
open class IdeDependentActionGroup : DefaultActionGroup() {
private val id by lazy { ActionManager.getInstance().getId(this)!! }
private val templatePresentationInitialized = AtomicBoolean()
override fun update(e: AnActionEvent) {
super.update(e)
IdeUICustomization.getInstance().getActionText(id)?.let {
e.presentation.text = it
fun initializePresentation(p: Presentation) {
val customization = IdeUICustomization.getInstance()
customization.getActionText(id)?.let {
p.text = it
}
customization.getActionDescription(id)?.let {
p.description = it
}
}
IdeUICustomization.getInstance().getActionDescription(id)?.let {
e.presentation.description = it
if (!templatePresentationInitialized.getAndSet(true)) { // one-time init
initializePresentation(templatePresentation)
}
initializePresentation(e.presentation)
}
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT