mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 23:39:07 +07:00
QuickChangeIdeScaleAction - get rid of alarm (we don't have coroutine scope or disposable)
GitOrigin-RevId: 48ad9b1298dda34d233e92a2e49910a7a3a5d542
This commit is contained in:
committed by
intellij-monorepo-bot
parent
5f0405cbfa
commit
ff04464943
@@ -4832,11 +4832,6 @@ f:com.intellij.ide.actions.QuickChangeColorSchemeAction
|
||||
- <init>():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
|
||||
- <init>():V
|
||||
f:com.intellij.ide.actions.QuickChangeIdeScaleAction$Companion
|
||||
f:com.intellij.ide.actions.QuickChangeKeymapAction
|
||||
- com.intellij.ide.actions.QuickSwitchSchemeAction
|
||||
- <init>():V
|
||||
|
||||
@@ -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<in AnAction?> {
|
||||
return Condition { a: AnAction? -> a is ChangeScaleAction && a.scale.percentValue == UISettingsUtils.getInstance().currentIdeScale.percentValue }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user