diff --git a/platform/platform-impl/api-dump-unreviewed.txt b/platform/platform-impl/api-dump-unreviewed.txt index 5470028b6104..8eec57b2dded 100644 --- a/platform/platform-impl/api-dump-unreviewed.txt +++ b/platform/platform-impl/api-dump-unreviewed.txt @@ -4832,11 +4832,6 @@ f:com.intellij.ide.actions.QuickChangeColorSchemeAction - ():V - s:changeLafIfNecessary(com.intellij.openapi.editor.colors.EditorColorsScheme,com.intellij.openapi.editor.colors.EditorColorsScheme):V - s:changeLafIfNecessary(com.intellij.openapi.editor.colors.EditorColorsScheme,com.intellij.openapi.editor.colors.EditorColorsScheme,java.lang.Runnable):V -f:com.intellij.ide.actions.QuickChangeIdeScaleAction -- com.intellij.ide.actions.QuickSwitchSchemeAction -- sf:Companion:com.intellij.ide.actions.QuickChangeIdeScaleAction$Companion -- ():V -f:com.intellij.ide.actions.QuickChangeIdeScaleAction$Companion f:com.intellij.ide.actions.QuickChangeKeymapAction - com.intellij.ide.actions.QuickSwitchSchemeAction - ():V diff --git a/platform/platform-impl/src/com/intellij/ide/actions/QuickChangeIdeScaleAction.kt b/platform/platform-impl/src/com/intellij/ide/actions/QuickChangeIdeScaleAction.kt index 9e37d913b1b6..ada76c00e4b0 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/QuickChangeIdeScaleAction.kt +++ b/platform/platform-impl/src/com/intellij/ide/actions/QuickChangeIdeScaleAction.kt @@ -19,14 +19,15 @@ import com.intellij.openapi.ui.popup.ListPopup import com.intellij.openapi.util.Condition import com.intellij.ui.hover.HoverListener import com.intellij.ui.scale.JBUIScale -import com.intellij.util.Alarm +import com.intellij.util.concurrency.EdtScheduler +import kotlinx.coroutines.Job import java.awt.Component import javax.swing.JList import javax.swing.event.ListSelectionEvent import kotlin.math.roundToInt -class QuickChangeIdeScaleAction : QuickSwitchSchemeAction(), ActionRemoteBehaviorSpecification.Frontend { - private val switchAlarm = Alarm() +private class QuickChangeIdeScaleAction : QuickSwitchSchemeAction(), ActionRemoteBehaviorSpecification.Frontend { + private var job: Job? = null private var popupSession: PopupSession? = null override fun fillActions(project: Project?, group: DefaultActionGroup, dataContext: DataContext) { @@ -45,34 +46,32 @@ class QuickChangeIdeScaleAction : QuickSwitchSchemeAction(), ActionRemoteBehavio override fun isEnabled(): Boolean = IdeScaleTransformer.Settings.currentScaleOptions.isNotEmpty() - override fun getAidMethod(): JBPopupFactory.ActionSelectionAid { - return JBPopupFactory.ActionSelectionAid.SPEEDSEARCH - } + override fun getAidMethod(): JBPopupFactory.ActionSelectionAid = JBPopupFactory.ActionSelectionAid.SPEEDSEARCH override fun showPopup(e: AnActionEvent?, popup: ListPopup) { val initialScale = UISettingsUtils.getInstance().currentIdeScale - switchAlarm.cancelAllRequests() + cancelJob() popup.addListSelectionListener { event: ListSelectionEvent -> val item = (event.source as JList<*>).selectedValue if (item is AnActionHolder) { val anAction = item.action if (anAction is ChangeScaleAction) { - switchAlarm.cancelAllRequests() - switchAlarm.addRequest(Runnable { - applyUserScale(anAction.scale, true) + job?.cancel() + job = EdtScheduler.getInstance().schedule(SELECTION_THROTTLING_MS, Runnable { + applyUserScale(scale = anAction.scale, shouldLog = true) if (!popup.isDisposed) { popup.pack(true, true) popupSession?.updateLocation() } - }, SELECTION_THROTTLING_MS) + }) } } } popup.addListener(object : JBPopupListener { override fun onClosed(event: LightweightWindowEvent) { - switchAlarm.cancelAllRequests() + cancelJob() popupSession = null if (!event.isOk) { applyUserScale(initialScale, false) @@ -101,6 +100,13 @@ class QuickChangeIdeScaleAction : QuickSwitchSchemeAction(), ActionRemoteBehavio super.showPopup(e, popup) } + private fun cancelJob() { + job?.let { + it.cancel() + job = null + } + } + override fun preselectAction(): Condition { return Condition { a: AnAction? -> a is ChangeScaleAction && a.scale.percentValue == UISettingsUtils.getInstance().currentIdeScale.percentValue } }