IJPL-149459 IDEA-346408 diff: avoid re-implementing the ToggleAction icon

'isMultiChoice' flag can now be explicitly disabled.

GitOrigin-RevId: 9d9b583196cb235e3cb0be241741dc2792529e7b
This commit is contained in:
Aleksey Pivovarov
2024-05-08 14:39:21 +02:00
committed by intellij-monorepo-bot
parent 3ec904c9e1
commit 51d5167d1b
2 changed files with 13 additions and 36 deletions

View File

@@ -261,12 +261,6 @@ f:com.intellij.diff.actions.ShowStandaloneDiffAction
- sf:getEP_NAME():com.intellij.openapi.extensions.ExtensionPointName
f:com.intellij.diff.actions.ShowStandaloneDiffAction$Companion
- f:getEP_NAME():com.intellij.openapi.extensions.ExtensionPointName
f:com.intellij.diff.actions.impl.CombinedDiffToggleAction
- com.intellij.openapi.project.DumbAwareAction
- <init>():V
- actionPerformed(com.intellij.openapi.actionSystem.AnActionEvent):V
- getActionUpdateThread():com.intellij.openapi.actionSystem.ActionUpdateThread
- update(com.intellij.openapi.actionSystem.AnActionEvent):V
c:com.intellij.diff.actions.impl.DiffNavigatableArrayRule
- com.intellij.ide.impl.dataRules.GetDataRule
- <init>():V

View File

@@ -8,47 +8,30 @@ import com.intellij.diff.util.DiffUserDataKeysEx
import com.intellij.icons.AllIcons
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.ToggleAction
import com.intellij.openapi.actionSystem.impl.ActionMenu
import com.intellij.openapi.actionSystem.impl.ActionMenu.Companion.shouldConvertIconToDarkVariant
import com.intellij.openapi.project.DumbAwareAction
import com.intellij.openapi.util.IconLoader
import com.intellij.util.ui.LafIconLookup
import com.intellij.openapi.project.DumbAware
class CombinedDiffToggleAction : DumbAwareAction() {
internal class CombinedDiffToggleAction : ToggleAction(), DumbAware {
override fun update(e: AnActionEvent) {
super.update(e)
val diffModeToggle = getDiffModeToggle(e)
e.presentation.isEnabledAndVisible = diffModeToggle != null
e.presentation.putClientProperty(ActionMenu.SECONDARY_ICON, null)
e.presentation.isMultiChoice = false
diffModeToggle ?: return
if (diffModeToggle.isCombinedDiffEnabled) {
// It impossible to use ToggleAction here because it doesn't close the popup menu
// Temporary solution is to add checkmark icon on AnAction
//
var checkmark = LafIconLookup.getIcon("checkmark")
var selectedCheckmark = LafIconLookup.getSelectedIcon("checkmark")
if (shouldConvertIconToDarkVariant()) {
checkmark = IconLoader.getDarkIcon(checkmark, true)
selectedCheckmark = IconLoader.getDarkIcon(selectedCheckmark, true)
}
e.presentation.icon = checkmark
e.presentation.selectedIcon = selectedCheckmark
}
else {
e.presentation.icon = null
e.presentation.selectedIcon = null
if (CombinedDiffRegistry.showBadge()) {
e.presentation.putClientProperty(ActionMenu.SECONDARY_ICON, AllIcons.General.New_badge)
}
}
val needNewBadge = diffModeToggle != null && !diffModeToggle.isCombinedDiffEnabled && CombinedDiffRegistry.showBadge()
e.presentation.putClientProperty(ActionMenu.SECONDARY_ICON, if (needNewBadge) AllIcons.General.New_badge else null)
}
override fun actionPerformed(e: AnActionEvent) {
override fun isSelected(e: AnActionEvent): Boolean {
val diffModeToggle = getDiffModeToggle(e) ?: return false
return diffModeToggle.isCombinedDiffEnabled
}
override fun setSelected(e: AnActionEvent, state: Boolean) {
val diffModeToggle = getDiffModeToggle(e) ?: return
diffModeToggle.isCombinedDiffEnabled = !diffModeToggle.isCombinedDiffEnabled
diffModeToggle.isCombinedDiffEnabled = state
}
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT