From aba4290b4b7b8dd679a4d9de81876b4d8ebe9de3 Mon Sep 17 00:00:00 2001 From: Ivan Migalev Date: Tue, 27 Aug 2024 19:14:58 +0200 Subject: [PATCH] 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 --- .../com/intellij/ide/IdeDependentAction.kt | 23 ++++++++++++---- .../intellij/ide/IdeDependentActionGroup.kt | 27 ++++++++++++------- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/IdeDependentAction.kt b/platform/platform-impl/src/com/intellij/ide/IdeDependentAction.kt index d7bee3590969..5631d189f114 100644 --- a/platform/platform-impl/src/com/intellij/ide/IdeDependentAction.kt +++ b/platform/platform-impl/src/com/intellij/ide/IdeDependentAction.kt @@ -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 diff --git a/platform/platform-impl/src/com/intellij/ide/IdeDependentActionGroup.kt b/platform/platform-impl/src/com/intellij/ide/IdeDependentActionGroup.kt index a6e4922313b8..9cbaf82f6b95 100644 --- a/platform/platform-impl/src/com/intellij/ide/IdeDependentActionGroup.kt +++ b/platform/platform-impl/src/com/intellij/ide/IdeDependentActionGroup.kt @@ -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